12 using namespace forest;
23 int main(
int argc,
char *argv[]) {
26 if (argc != 4 || sscanf(argv[3],
"%d", &finTime) != 1)
27 fatal(
"usage: NetMgr topoFile prefixFile finTime");
29 fatal(
"NetMgr: initialization failure");
32 fatal(
"can't read prefix address info");
42 bool init(
const char *topoFile) {
50 int maxNode = 100000;
int maxLink = 10000;
51 int maxRtr = 5000;
int maxCtl = 200;
53 net =
new NetInfo(maxNode, maxLink, maxRtr, maxCtl);
55 ifstream fs; fs.open(topoFile);
57 cerr <<
"NetMgr::init: could not read topology file, or error "
85 cerr <<
"NetMgr:init: can't find ip address "
86 <<
"of access router\n";
103 logger->
log(
"init: can't initialize substrate",2);
106 sub->setRtrReady(
false);
109 cerr <<
"could not find netMgr or cliMgr in topology file\n";
140 bool success =
false;
144 std::cout <<
"[DEBUG] -- px < 0 " << px << std::endl;
147 std::cout <<
"[DEBUG] -- outside of handleConsole " << success << std::endl;
154 case CtlPkt::CLIENT_CONNECT:
155 case CtlPkt::CLIENT_DISCONNECT:
158 case CtlPkt::NEW_SESSION:
161 case CtlPkt::CANCEL_SESSION:
164 case CtlPkt::BOOT_LEAF:
172 case CtlPkt::BOOT_ROUTER:
181 cph.errReply(px,cp,
"invalid control packet "
188 cerr <<
"handler: operation failed\n"
203 std::cout <<
"[DEBUG] -- inside of handleConsole" << std::endl;
208 string cmd, reply =
"";
209 while (buf.readAlphas(cmd)) {
210 std::cout <<
"[DEBUG] -- CMD: " << cmd << std::endl;
212 if (cmd ==
"getNet") {
214 }
else if (cmd ==
"getLinkTable") {
215 getLinkSet(buf,reply,cph);
217 }
else if (cmd ==
"over" && buf.nextLine()) {
219 }
else if (cmd ==
"overAndOut" && buf.nextLine()) {
222 reply =
"unrecognized input";
225 if (sock == -1)
break;
228 cout <<
"TOTAL\n" << reply << endl;
234 void getNet(
NetBuffer& buf,
string& reply) {
237 std::cout <<
"[DEBUG] -- " << __FUNCTION__ <<
"() \n" << reply << std::endl;
248 if (buf.
verify(
':') && buf.
readName(router) && !router.empty() && router.size() >= 2){
249 std::cout <<
"[DEBUG] -- " << __FUNCTION__ <<
"() \n" << router << std::endl;
251 std::cout <<
"[DEBUG] -- " << __FUNCTION__ <<
"() \n" <<
net->
getNodeAdr(rNum) << std::endl;
252 int firstLinkNum = 1;
254 while (firstLinkNum != 0){
256 cout << __FILE__ <<
" " << __FUNCTION__ <<
" first link num " << firstLinkNum <<
" numOfLinks " << numOfLinks << endl;
257 firstLinkNum = repCp.nextLinkNum;
258 cout << __FILE__ <<
" " << __FUNCTION__ <<
" Next link num " << repCp.nextLinkNum << endl;
259 if (repCp.
lt == NULL) {
260 reply =
"No information for " + router +
"\n";
264 string ip, fAdr, peerType;
265 cout << __FUNCTION__ <<
" " << repCp.
lt << endl;
266 cout << __FUNCTION__ <<
" first " << repCp.
lt->
firstLink() << endl;
270 Forest::nodeType2string(repCp.
lt->getPeerType(i), peerType);
271 ss << i <<
" " << repCp.
lt->getIface(i) <<
" " << ip <<
" " << repCp.
lt->getPeerPort(i);
272 ss <<
" " << peerType <<
" " << fAdr <<
" ";
273 ss <<
"(" << repCp.
lt->getRates(i).bitRateUp <<
"," << repCp.
lt->getRates(i).bitRateDown\
274 <<
"," << repCp.
lt->getRates(i).pktRateUp <<
"," << repCp.
lt->getRates(i).pktRateDown <<
")"<<
"\r\n";
276 cout << __FILE__ <<
" " << ss.str();
281 reply =
"Unrecognized input - for example r1";
307 if (cp.
type == CtlPkt::CLIENT_CONNECT)
311 if (reply == 0)
return false;
333 cph.
errReply(px,cp,
"No router assigned to client's IP");
341 while (iface < net->getNumIf(rtr) && !
net->
validIf(rtr,iface)) iface++;
347 if (clientAdr == 0)
return false;
350 CtlPkt repCp(CtlPkt::NEW_SESSION,CtlPkt::POS_REPLY,cp.
seqNum);
377 uint64_t nonce,
CpHandler& cph,
bool useTunnel) {
387 leafAdr = 0; rates = cp.rspec1;
388 reply = cph.
addLink(dest,leafType,iface,nonce,repCp);
390 "could not add link to leaf"))
392 leafLink = repCp.
link; leafAdr = repCp.adr1;
400 reply = cph.
addLink(dest,leafType,iface,leafLink,
401 leafIp,0,leafAdr,nonce,repCp);
403 "could not add link to leaf"))
408 reply = cph.
modLink(dest,leafLink,rates,repCp);
409 if (!
processReply(px,cp,reply,repCp,cph,
"could not set link rates"))
415 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to "
416 "connection comtree"))
425 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on "
426 "connection comtree"))
432 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to client "
433 "signalling comtree"))
442 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on client "
443 "signaling comtree"))
451 if (!
processReply(px,cp,reply,repCp,cph,
"could not add leaf to network "
452 "signalling comtree"))
461 if (!
processReply(px,cp,reply,repCp,cph,
"could not set rate on network "
462 "signaling comtree"))
475 fAdr_t clientAdr = cp.adr1;
481 cph.
errReply(px,cp,
"no router with specified address");
484 pair<fAdr_t,fAdr_t> range;
486 if (clientAdr < range.first || clientAdr > range.second) {
487 cph.
errReply(px,cp,
"client address not in router's range");
492 reply = cph.
dropLink(rtrAdr,0,clientAdr,repCp);
493 if (!
processReply(px,cp,reply,repCp,cph,
"could not drop link "
498 repCp.
reset(CtlPkt::CANCEL_SESSION,CtlPkt::POS_REPLY,cp.
seqNum);
523 cph.
errReply(px,cp,
"unknown leaf address");
529 CtlPkt repCp(CtlPkt::BOOT_LEAF,CtlPkt::POS_REPLY,cp.
seqNum);
541 cph.
errReply(px,cp,
"access router is not yet up");
548 while (iface < net->getNumIf(rtr) && !
net->
validIf(rtr,iface)) iface++;
553 if (
setupLeaf(leaf,px,cp,rtr,iface,nonce,cph) == 0) {
564 if (!
processReply(px,cp,reply,repCp,cph,
"could not configure "
571 repCp.
reset(CtlPkt::BOOT_LEAF,CtlPkt::POS_REPLY,cp.
seqNum);
575 logger->
log(
"completed leaf boot request",0,p);
585 }
while (nonce == 0);
611 cph.
errReply(px,cp,msg +
" (no response from target)");
615 if (repCp.
mode != CtlPkt::POS_REPLY) {
654 cph.
errReply(px,cp,
"boot request from unknown router "
656 logger->
log(
"handleBootRequest: received boot request from "
657 "unknown router\n",2,p);
664 CtlPkt repCp(CtlPkt::BOOT_ROUTER,CtlPkt::POS_REPLY,cp.
seqNum);
675 int reply = cph.
setLeafRange(0,leafRange.first,leafRange.second,repCp);
677 "could not configure leaf range")) {
692 "could not add interface at router")) {
699 if (rtr ==
nmRtr && i == nmIface) {
700 sub->setRtrPort(repCp.port1);
730 sub->setNonce(nonce);
732 fatal(
"cannot configure NetMgr's access link");
737 repCp.
reset(CtlPkt::BOOT_ROUTER,CtlPkt::POS_REPLY,cp.
seqNum);
741 if (rtr ==
nmRtr)
sub->setRtrReady(
true);
743 logger->
log(
"completed boot request",0,p);
784 peerPort,peerAdr,nonce,repCp);
785 if (!
processReply(px,cp,reply,repCp,cph,
"could not add link at router"))
791 reply = cph.
modLink(dest,llnk,rs,repCp);
793 "could not set link rates at router"))
817 "could not add comtree at router"))
838 "could not add comtree link at router"))
843 if (peer == parent) {
851 "could not set comtree link rates at router"))
858 "could not set comtree parameters"))
871 for (
unsigned int i = 0; i < (
unsigned int) numPrefixes; ++i) {
872 string ip = prefixes[i].prefix;
874 while (j < ip.size() && j < cip.size()) {
875 if (ip[j] !=
'*' && cip[j] != ip[j])
break;
877 (j+1 == ip.size() && j+1 == cip.size())) {
878 rtrAdr = prefixes[i].rtrAdr;
899 ifstream ifs; ifs.open(filename);
900 if(ifs.fail())
return false;
908 prefixes[i].prefix = pfix;
909 prefixes[i].rtrAdr =
rtrAdr;
914 cout <<
"read address info for " << numPrefixes <<
" prefixes" << endl;