21 : maxRtr(maxRtr1), maxNode(maxNode1), maxLink(maxLink1),
27 routers =
new UiSetPair(maxRtr);
39 if (pthread_mutex_init(&
glock,NULL) != 0)
40 fatal(
"NetInfo::NetInfo: cannot initialize lock");
53 pthread_mutex_destroy(&
glock);
63 for (
int i = 1; i <=
getNumIf(rtr); i++) {
66 if (llnk >= links.first && llnk <= links.second)
return i;
84 rtr[r].
name = name; (*nameNodeMap)[name] = r;
88 pair<double,double> loc(UNDEF_LAT,UNDEF_LONG);
90 pair<fAdr_t,fAdr_t> range(-1,-1);
109 rtr[r].
numIf = numIf;
121 int ln =
leaves->firstOut();
122 if (ln == 0)
return 0;
126 int nodeNum = ln +
maxRtr;
127 leaf[ln].
name = name;
128 (*nameNodeMap)[name] = nodeNum;
133 pair<double,double> loc(UNDEF_LAT,UNDEF_LONG);
151 if (lnk == 0)
return 0;
155 netTopo->remove(lnk);
return 0;
163 netTopo->remove(lnk);
return 0;
207 if (!Util::skipBlank(in) || Util::verify(in,
';'))
break;
208 if (!Util::readWord(in, s)) {
209 cerr <<
"NetInfo:: read: syntax error: expected "
210 "(;) or keyword (router,leaf,link)\n";
215 cerr <<
"NetInfo::read: error when attempting "
216 " to read " << rtrNum <<
"-th router ("
222 cerr <<
"NetInfo::read: cannot add router "
223 << cRtr.
name << endl;
227 pair<double,double> loc(cRtr.
latitude/1000000.0,
234 for (
int i = 1; i <=
getNumIf(r); i++)
235 rtr[r].iface[i] = iface[i];
237 }
else if (s ==
"leaf") {
239 cerr <<
"NetInfo::read: error when attempting "
240 " to read " << leafNum <<
"-th leaf ("
246 cerr <<
"NetInfo::read: cannot add leaf "
247 << cLeaf.
name << endl;
253 pair<double,double> loc(cLeaf.
latitude/1000000.0,
257 }
else if (s ==
"link") {
259 cerr <<
"NetInfo::read: error when attempting "
260 " to read " << linkNum <<
"-th link ("
265 map<string,int>::iterator pp;
268 cerr <<
"NetInfo::read: error when attempting "
269 " to read " << linkNum <<
"-th link ("
270 << cLink.nameL <<
" invalid node name)\n";
275 cerr <<
"NetInfo::read: error when attempting "
276 " to read " << linkNum <<
"-th link ("
277 << cLink.
nameR <<
" invalid node name)\n";
282 cerr <<
"NetInfo::read: can't add link ("
283 << cLink.nameL <<
"." << cLink.numL <<
","
284 << cLink.
nameR <<
"." << cLink.
numR <<
")"
293 }
else if (s ==
"defaultLeafRates") {
295 cerr <<
"NetInfo::read: can't read default "
300 cerr <<
"NetInfo::read: unrecognized keyword (" << s
321 string name;
fAdr_t fadr; pair<double,double> loc;
322 pair<fAdr_t,fAdr_t> adrRange;
325 if (!Util::verify(in,
'(',50) ||
326 !Util::readWord(in,name) || !Util::verify(in,
',',20)) {
327 errMsg =
"could not read router name";
331 errMsg =
"could not read Forest address for router " + name;
334 if (!
readLocation(in,loc) || !Util::verify(in,
',',20)) {
335 errMsg =
"could not read location for router " + name;
338 if (!
readAdrRange(in,adrRange) || !Util::verify(in,
',',20)) {
339 errMsg =
"could not read address range for router " + name;
344 if (rv == 0)
return false;
346 while (Util::verify(in,
',',20)) {
349 if (rv == 0)
return false;
350 maxif = max(rv,maxif);
352 if (!Util::verify(in,
')',50))
return false;
355 rtr.
latitude = (int) 1000000*loc.first;
356 rtr.
longitude = (
int) 1000000*loc.second;
368 if (!Util::verify(in,
'(',50))
return false;
369 in >> loc.first;
if (in.fail())
return false;
370 if (!Util::verify(in,
',',20))
return false;
371 in >> loc.second;
if (in.fail())
return false;
372 if (!Util::verify(in,
')',20))
return false;
383 return Util::verify(in,
'(',50) &&
385 Util::verify(in,
'-',20) &&
387 Util::verify(in,
')',20);
396 int bru, brd, pru, prd;
397 if (!Util::verify(in,
'(',50))
return false;
398 in >> bru;
if (in.fail())
return false;
399 if (!Util::verify(in,
',',20))
return false;
400 in >> brd;
if (in.fail())
return false;
401 if (!Util::verify(in,
',',20))
return false;
402 in >> pru;
if (in.fail())
return false;
403 if (!Util::verify(in,
',',20))
return false;
404 in >> prd;
if (in.fail())
return false;
405 if (!Util::verify(in,
')',20))
return false;
406 rs.
set(bru,brd,pru,prd);
422 if (!Util::verify(in,
'[',50)) {
423 errMsg =
"syntax error: expected left bracket";
428 errMsg =
"could not read interface number";
433 ss <<
"interface number " << ifn <<
" exceeds allowed range";
437 if (!Util::verify(in,
',',20) ||
439 ss <<
"could not read ip address for interface " << ifn;
443 if (!Util::verify(in,
',',20)) {
444 ss <<
"syntax error in iface " << ifn <<
", expected comma";
450 ss <<
"could not read link range for iface " << ifn;
455 if (Util::verify(in,
'-',20)) {
458 ss <<
"could not read link range for iface " << ifn;
463 if (!Util::verify(in,
',',20)) {
464 ss <<
"syntax error in iface " << ifn <<
", expected comma";
469 ss <<
"could not read ip address for interface " << ifn;
473 if (!Util::verify(in,
']',20)) {
474 ss <<
"syntax error in iface " << ifn
475 <<
", expected right bracket";
479 ifaces[ifn].
ipAdr = ip;
482 ifaces[ifn].
rates = rs;
499 pair<double,double> loc;
502 if (!Util::verify(in,
'(',50) ||
503 !Util::readWord(in,name) || !Util::verify(in,
',',20)) {
504 errMsg =
"could not read leaf node name";
508 if (!Util::readWord(in,typstr) ||
509 (ntyp = Forest::getNodeType(typstr)) == Forest::UNDEF_NODE ||
510 !Util::verify(in,
',',20)) {
511 errMsg =
"could not read leaf node name";
515 errMsg =
"could not read IP address for leaf node " + name;
519 errMsg =
"could not read Forest address for leaf node " + name;
522 if (!
readLocation(in,loc) || !Util::verify(in,
')',20)) {
523 errMsg =
"could not read location for leaf node " + name;
528 leaf.
latitude = (int) 1000000*loc.first;
529 leaf.
longitude = (
int) 1000000*loc.second;
543 string nameL, nameR;
int numL, numR, length;
RateSpec rs;
546 if (!Util::verify(in,
'(',50) ||
548 errMsg =
"could not first link endpoint";
552 errMsg =
"could not read second link endpoint";
557 errMsg =
"could not read link length";
560 if (Util::verify(in,
')',20)) {
564 errMsg =
"could not read rate specification";
567 if (!Util::verify(in,
')',20)) {
568 errMsg =
"syntax error, expected right paren";
572 link.nameL = nameL; link.numL = numL;
585 if (!Util::readWord(in,name))
return false;
587 if (Util::verify(in,
'.')) {
589 if (in.fail() || num < 1)
return false;
603 cerr <<
"NetInfo::check: no routers in network, terminating\n";
645 cerr <<
"NetInfo::checkLocalLinks: "
646 "detected two links at router "
647 << rtr <<
" with same local link "
659 cerr <<
"NetInfo::checkLocalLinks: link "
661 <<
" is not in the range assigned "
662 "to any valid interface\n";
677 while (!pending.empty()) {
678 int u = pending.front(); pending.pop();
683 if (seen.find(v) != seen.end())
continue;
689 cerr <<
"NetInfo::checkBackbone: network is not connected";
703 cerr <<
"NetInfo::check: detected two nodes "
729 if (rzip != flzip || rzip != llzip) {
730 cerr <<
"netInfo::checkLeafRange: detected router " << r
731 <<
"with incompatible address and leaf address "
735 if (range.first > range.second) {
736 cerr <<
"netInfo::check: detected router " << r
737 <<
"with empty leaf address range\n";
748 if (range1.first > range2.first)
continue;
749 if (range2.first <= range1.second) {
750 cerr <<
"netInfo::checkLeafRange: detected two "
751 "routers " << r1 <<
" and " << r2
752 <<
" with overlapping address ranges\n";
770 cerr <<
"NetInfo::checkLeafNodes: detected a leaf node "
772 status =
false;
continue;
776 cerr <<
"NetInfo::checkLeafNodes: detected a leaf node "
777 <<
getNodeName(u,s)<<
" with more than one link\n";
778 status =
false;
continue;
782 cerr <<
"NetInfo::checkLeafNodes: detected a leaf node "
785 status =
false;
continue;
790 if (adr < range.first || adr > range.second) {
792 cerr <<
"NetInfo::checkLeafNodes: detected a leaf node "
794 " the leaf address range of its router\n";
795 status =
false;
continue;
814 cerr <<
"NetInfo::check: detected a link "
816 "outside the allowed range\n";
835 for (
int i = 1; i <=
getNumIf(r); i++) {
839 cerr <<
"NetInfo::checkRtrRates: interface "
840 << i <<
"at router " << r <<
" has "
841 "rates outside the allowed range\n";
848 for (
int i = 0; i <=
getNumIf(r); i++) ifrates[i].set(0);
855 ifrates[iface].
add(rs);
857 for (
int i = 0; i <=
getNumIf(r); i++) {
861 cerr <<
"NetInfo::check: links at interface "
863 <<
" exceed its capacity\n";
877 stringstream ss;
string s1;
878 if (lnk == 0) { s =
"-";
return s; }
895 if (lnk == 0) { s =
"-";
return s; }
896 stringstream ss;
string s1;
914 if (lnk == 0) { s =
"-";
return s; }
915 stringstream ss;
string s1;
957 s +=
";\n";
return s;
966 stringstream ss;
string s1;
970 ss <<
"(" << loc.first <<
"," << loc.second <<
"), ";
974 bool firstIface =
true;
975 for (
int i = 1; i <=
getNumIf(rtr); i++) {
977 if (firstIface) firstIface =
false;
979 ss <<
"\t[ " << i <<
", "
982 if (links.first == links.second) {
983 ss << links.first <<
", ";
985 ss << links.first <<
"-" << links.second <<
", ";
1000 stringstream ss;
string s1;
1002 ss << Forest::nodeType2string(
getNodeType(leaf),s1) <<
", ";
1006 ss <<
"(" << loc.first <<
"," << loc.second <<
")";