12 using namespace forest;
23 int main(
int argc,
char *argv[]) {
27 sscanf(argv[3],
"%d", &finTime) != 1)
28 fatal(
"usage: NetMgr topoFile prefixFile finTime");
30 fatal(
"NetMgr: initialization failure");
33 fatal(
"can't read prefix address info");
43 bool init(
const char *topoFile) {
51 int maxNode = 100000;
int maxLink = 10000;
52 int maxRtr = 5000;
int maxCtl = 200;
54 net =
new NetInfo(maxNode, maxLink, maxRtr, maxCtl);
62 ifstream fs; fs.open(topoFile);
64 cerr <<
"NetMgr::init: could not read topology file, or error "
92 cerr <<
"NetMgr:init: can't find ip address "
93 <<
"of access router\n";
110 logger->
log(
"init: can't initialize substrate",2);
113 sub->setRtrReady(
false);
116 cerr <<
"could not find netMgr or cliMgr in topology file\n";
124 logger->
log(
"NetMgr::init: could not read adminData "
133 int n =
admTbl->getMaxAdx();
136 if (len != (n+1)*RECORD_SIZE) {
140 logger->
log(
"NetMgr::init: could not initialize lock "
141 "on client data file",2);
173 bool success =
false;
184 case CtlPkt::CLIENT_CONNECT:
185 case CtlPkt::CLIENT_DISCONNECT:
188 case CtlPkt::NEW_SESSION:
191 case CtlPkt::CANCEL_SESSION:
194 case CtlPkt::BOOT_LEAF:
202 case CtlPkt::BOOT_ROUTER:
211 cph.errReply(px,cp,
"invalid control packet "
218 cerr <<
"handler: operation failed\n"
236 string cmd, reply, adminName;
240 if (!buf.
readLine(cmd) || cmd !=
"Forest-Console-v1") {
248 cerr <<
"cmd=" << cmd << endl;
249 reply.assign(
"success\n");
253 }
else if (cmd ==
"overAndOut") {
255 }
else if (cmd ==
"login") {
256 loggedIn =
login(buf,adminName,reply);
257 }
else if (!loggedIn) {
259 }
else if (cmd ==
"newAccount") {
261 }
else if (cmd ==
"getProfile") {
263 }
else if (cmd ==
"updateProfile") {
265 }
else if (cmd ==
"changePassword") {
267 }
else if (cmd ==
"getNet") {
270 }
else if (cmd ==
"getLinkTable") {
272 }
else if (cmd ==
"getComtreeTable") {
274 }
else if (cmd ==
"getIfaceTable") {
276 }
else if (cmd ==
"getRouteTable") {
278 }
else if (cmd ==
"addFilter") {
280 }
else if (cmd ==
"modFilter") {
282 }
else if (cmd ==
"dropFilter") {
284 }
else if (cmd ==
"getFilter") {
286 }
else if (cmd ==
"getFilterSet") {
288 }
else if (cmd ==
"getLoggedPackets") {
290 }
else if (cmd ==
"enableLocalLog") {
293 reply =
"unrecognized input\n";
295 cerr <<
"sending reply: " << reply;
296 reply.append(
"over\n");
300 cerr <<
"terminating" << endl;
324 reply =
"login failed: try again\n";
331 reply =
"login failed: try again\n";
335 reply =
"misformatted login request\n";
350 string newName, pwd, s1, s2;
359 reply =
"name not available, select another\n";
368 reply =
"unable to add admin\n";
372 reply =
"misformatted new admin request\n";
385 string s, targetName;
388 reply =
"misformatted get profile request";
return;
406 string s, targetName;
409 reply =
"misformatted updateProfile request\n";
return;
413 string realName, email;
415 if (item ==
"realName" && buf.
verify(
':') &&
418 }
else if (item ==
"email" && buf.
verify(
':') &&
421 }
else if (item ==
"over" && buf.
nextLine()) {
424 reply =
"misformatted update profile request (" +
447 string targetName, pwd;
450 reply =
"misformatted change password request\n";
return;
466 string rtrName;
int rtr;
469 reply.assign(
"invalid request\n");
return;
475 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
476 reply.assign(
"could not add log filter\n");
return;
478 stringstream ss; ss << repCp.index1;
479 reply.append(ss.str());
492 string rtrName;
int rtr, fx = -1;
496 !buf.
readInt(fx) || (fx < 0) ||
498 reply.assign(
"invalid request\n");
return;
503 repx = cph.
modFilter(radr, fx, filterString, repCp);
504 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
505 reply.assign(
"could not modify log filter\n");
return;
516 string rtrName;
int rtr, fx = -1;
520 reply.assign(
"invalid request\n");
return;
526 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
527 reply.assign(
"could not drop log filter\n");
return;
539 string rtrName;
int rtr, fx = -1;
543 reply.assign(
"invalid request\n");
return;
549 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
550 reply.assign(
"could not get log filter\n");
return;
565 string rtrName;
int rtr;
568 reply.assign(
"invalid request\n");
return;
576 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
577 reply.assign(
"could not get filter set \n");
return;
580 if(repCp.
index2 == 0)
return;
594 string rtrName;
int rtr;
597 reply.assign(
"invalid request\n");
return;
603 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
604 reply.assign(
"could not get logged packets \n");
return;
617 string rtrName;
int rtr;
bool on;
621 reply.assign(
"invalid request\n");
return;
626 repx = cph.enableLocalLog(radr, on, repCp);
627 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
628 reply.assign(
"could not get logged packets \n");
return;
639 string rtrName;
int rtr;
642 reply.assign(
"invalid request\n");
return;
650 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
651 reply.assign(
"could not read link table\n");
return;
654 if (repCp.
index2 == 0)
return;
666 string rtrName;
int rtr;
669 reply.assign(
"invalid request\n");
return;
677 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
678 reply.assign(
"could not read comtree table\n");
return;
681 if (repCp.
index2 == 0)
return;
693 string rtrName;
int rtr;
696 reply.assign(
"invalid request\n");
return;
704 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
705 reply.assign(
"could not read iface table\n");
return;
708 if (repCp.
index2 == 0)
return;
720 string rtrName;
int rtr;
723 reply.assign(
"invalid request\n");
return;
731 if (repx == 0 || repCp.
mode != CtlPkt::POS_REPLY) {
732 reply.assign(
"could not read route table\n");
return;
735 if (repCp.
index2 == 0)
return;
761 if (cp.
type == CtlPkt::CLIENT_CONNECT)
765 if (reply == 0)
return false;
787 cph.
errReply(px,cp,
"No router assigned to client's IP");
795 while (iface < net->getNumIf(rtr) && !
net->
validIf(rtr,iface)) iface++;
801 if (clientAdr == 0)
return false;
804 CtlPkt repCp(CtlPkt::NEW_SESSION,CtlPkt::POS_REPLY,cp.
seqNum);
831 uint64_t nonce,
CpHandler& cph,
bool useTunnel) {
841 leafAdr = 0; rates = cp.rspec1;
842 reply = cph.
addLink(dest,leafType,iface,nonce,repCp);
844 "could not add link to leaf"))
846 leafLink = repCp.
link; leafAdr = repCp.adr1;
854 reply = cph.
addLink(dest,leafType,iface,leafLink,
855 leafIp,0,leafAdr,nonce,repCp);
857 "could not add link to leaf"))
862 reply = cph.
modLink(dest,leafLink,rates,repCp);
863 if (!
processReply(px,cp,reply,repCp,cph,
"could not set link rates"))
869 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to "
870 "connection comtree"))
879 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on "
880 "connection comtree"))
886 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to client "
887 "signalling comtree"))
896 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on client "
897 "signaling comtree"))
905 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to network "
906 "signalling comtree"))
915 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on network "
916 "signaling comtree"))
929 fAdr_t clientAdr = cp.adr1;
935 cph.
errReply(px,cp,
"no router with specified address");
938 pair<fAdr_t,fAdr_t> range;
940 if (clientAdr < range.first || clientAdr > range.second) {
941 cph.
errReply(px,cp,
"client address not in router's range");
946 reply = cph.
dropLink(rtrAdr,0,clientAdr,repCp);
947 if (!
processReply(px,cp,reply,repCp,cph,
"could not drop link "
952 repCp.
reset(CtlPkt::CANCEL_SESSION,CtlPkt::POS_REPLY,cp.
seqNum);
977 cph.
errReply(px,cp,
"unknown leaf address");
983 CtlPkt repCp(CtlPkt::BOOT_LEAF,CtlPkt::POS_REPLY,cp.
seqNum);
995 cph.
errReply(px,cp,
"access router is not yet up");
1002 while (iface < net->getNumIf(rtr) && !
net->
validIf(rtr,iface)) iface++;
1007 if (
setupLeaf(leaf,px,cp,rtr,iface,nonce,cph) == 0) {
1018 if (!
processReply(px,cp,reply,repCp,cph,
"could not configure "
1025 repCp.
reset(CtlPkt::BOOT_LEAF,CtlPkt::POS_REPLY,cp.
seqNum);
1029 logger->
log(
"completed leaf boot request",0,p);
1039 }
while (nonce == 0);
1065 cph.
errReply(px,cp,msg +
" (no response from target)");
1069 if (repCp.
mode != CtlPkt::POS_REPLY) {
1108 cph.
errReply(px,cp,
"boot request from unknown router "
1110 logger->
log(
"handleBootRequest: received boot request from "
1111 "unknown router\n",2,p);
1117 CtlPkt repCp(CtlPkt::BOOT_ROUTER,CtlPkt::POS_REPLY,cp.
seqNum);
1127 int reply = cph.
setLeafRange(0,leafRange.first,leafRange.second,repCp);
1129 "could not configure leaf range")) {
1143 "could not add interface at router")) {
1150 if (rtr ==
nmRtr && i == nmIface) {
1151 sub->setRtrPort(repCp.port1);
1166 Add code
for special
case of neighbor comtree.
1168 Drop comtree 1 from topoFiles
1185 sub->setNonce(nonce);
1187 fatal(
"cannot configure NetMgr's access link");
1194 repCp.
reset(CtlPkt::BOOT_ROUTER,CtlPkt::POS_REPLY,cp.
seqNum);
1198 if (rtr ==
nmRtr)
sub->setRtrReady(
true);
1200 logger->
log(
"completed boot request",0,p);
1241 peerPort,peerAdr,nonce,repCp);
1242 if (!
processReply(px,cp,reply,repCp,cph,
"could not add link at router"))
1248 reply = cph.
modLink(dest,llnk,rs,repCp);
1250 "could not set link rates at router"))
1274 "could not add comtree at router"))
1293 peerCoreFlag,repCp);
1295 "could not add comtree link at router"))
1300 if (peer == parent) {
1308 "could not set comtree link rates at router"))
1315 "could not set comtree parameters"))
1328 for (
unsigned int i = 0; i < (
unsigned int) numPrefixes; ++i) {
1329 string ip = prefixes[i].prefix;
1331 while (j < ip.size() && j < cip.size()) {
1332 if (ip[j] !=
'*' && cip[j] != ip[j])
break;
1334 (j+1 == ip.size() && j+1 == cip.size())) {
1335 rtrAdr = prefixes[i].rtrAdr;
1356 ifstream ifs; ifs.open(filename);
1357 if(ifs.fail())
return false;
1365 prefixes[i].prefix = pfix;
1366 prefixes[i].rtrAdr =
rtrAdr;
1371 cout <<
"read address info for " << numPrefixes <<
" prefixes" << endl;
1380 if (adx < 0 || adx >=
admTbl->getMaxAdmins())
return;
1398 if (
admTbl->validAdmin(adx)) {
1403 s.erase(RECORD_SIZE-1); s +=
"\n";
1405 s.erase(s.length()-1);
1406 int len = RECORD_SIZE - s.length();