From 023055266428e2fbe833b1a8b96585e64493f55a Mon Sep 17 00:00:00 2001 From: Mike Hibler Date: Mon, 15 May 2006 17:01:36 +0000 Subject: [PATCH] Add 'eplabconfig' (Emulatated PlanetLab Config) command --- tmcd/tmcd.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tmcd/tmcd.c b/tmcd/tmcd.c index 8229e0069..c57415f7a 100644 --- a/tmcd/tmcd.c +++ b/tmcd/tmcd.c @@ -232,6 +232,7 @@ COMMAND_PROTOTYPE(dotmcctest); COMMAND_PROTOTYPE(dofwinfo); COMMAND_PROTOTYPE(dohostinfo); COMMAND_PROTOTYPE(doemulabconfig); +COMMAND_PROTOTYPE(doeplabconfig); COMMAND_PROTOTYPE(dolocalize); COMMAND_PROTOTYPE(dobooterrno); COMMAND_PROTOTYPE(dobootlog); @@ -323,6 +324,7 @@ struct command { { "firewallinfo", FULLCONFIG_ALL, 0, dofwinfo}, { "hostinfo", FULLCONFIG_NONE, 0, dohostinfo}, { "emulabconfig", FULLCONFIG_NONE, F_ALLOCATED, doemulabconfig}, + { "eplabconfig", FULLCONFIG_NONE, F_ALLOCATED, doeplabconfig}, { "localization", FULLCONFIG_PHYS, 0, dolocalize}, { "booterrno", FULLCONFIG_NONE, 0, dobooterrno}, { "bootlog", FULLCONFIG_NONE, 0, dobootlog}, @@ -5752,6 +5754,94 @@ COMMAND_PROTOTYPE(doemulabconfig) return 0; } +/* + * Return the config for an emulated ("inner") planetlab + */ +COMMAND_PROTOTYPE(doeplabconfig) +{ + MYSQL_RES *res; + MYSQL_ROW row; + char buf[MYBUFSIZE]; + char *bufp = buf, *ebufp = &buf[sizeof(buf)]; + int nrows; + + /* + * We only respond if we are a PLC node + */ + res = mydb_query("select node_id from reserved " + "where pid='%s' and eid='%s' and plab_role='plc'", + 1, reqp->pid, reqp->eid); + if (!res) { + error("EPLABCONFIG: %s: DB Error getting plab_role\n", + reqp->nodeid); + return 1; + } + if (!mysql_num_rows(res)) { + mysql_free_result(res); + return 0; + } + row = mysql_fetch_row(res); + if (!row[0] || strcmp(row[0], reqp->nodeid) != 0) { + mysql_free_result(res); + return 0; + } + mysql_free_result(res); + + /* + * NAME= ROLE= IP= MAC= + */ + res = mydb_query("select r.vname,r.plab_role,i.IP,i.mac " + " from reserved as r join interfaces as i " + " where r.node_id=i.node_id and " + " i.role='ctrl' and r.pid='%s' and r.eid='%s'", + 4, reqp->pid, reqp->eid); + + if (!res || mysql_num_rows(res) == 0) { + error("EMULABCONFIG: %s: DB Error getting plab_in_elab info\n", + reqp->nodeid); + if (res) + mysql_free_result(res); + return 1; + } + nrows = (int)mysql_num_rows(res); + + /* + * Spit out the PLC node first just cuz + */ + bzero(buf, sizeof(buf)); + while (nrows--) { + row = mysql_fetch_row(res); + + if (!strcmp(row[1], "plc")) { + bufp += OUTPUT(bufp, ebufp - bufp, + "NAME=%s ROLE=%s IP=%s MAC=%s\n", + row[0], row[1], row[2], row[3]); + break; + } + } + + /* + * Then all the nodes + */ + mysql_data_seek(res, 0); + nrows = (int)mysql_num_rows(res); + + while (nrows--) { + row = mysql_fetch_row(res); + + if (!strcmp(row[1], "plc")) + continue; + + bufp += OUTPUT(bufp, ebufp - bufp, + "NAME=%s ROLE=%s IP=%s MAC=%s\n", + row[0], row[1], row[2], row[3]); + } + mysql_free_result(res); + + client_writeback(sock, buf, strlen(buf), tcp); + return 0; +} + /* * Hack to test timeouts and other anomolous situations for tmcc */ -- GitLab