54 reset(type1, mode1, seqNum1, payload1);
58 reset(type1, mode1, seqNum1);
77 void CtlPkt::reset(CpType type1, CpMode mode1, uint64_t seqNum1) {
104 adr1 = adr2 =
adr3 = 0;
106 port1 = 0;
port2 = 0;
118 firstLinkNum = 0; numOfLinks = 0; nextLinkNum = 0;
121 #define packPair(x,y) ((payload[pp++] = htonl(x)), (payload[pp++] = htonl(y)))
122 #define packNonce(x,y) ((payload[pp++] = htonl(x)), \
123 (payload[pp++] = htonl((int) (((y)>>32)&0xffffffff))), \
124 (payload[pp++] = htonl((int) ((y)&0xffffffff))))
125 #define packRspec(x,y) ((payload[pp++] = htonl(x)), \
126 (payload[pp++] = htonl(y.bitRateUp)), \
127 (payload[pp++] = htonl(y.bitRateDown)), \
128 (payload[pp++] = htonl(y.pktRateUp)), \
129 (payload[pp++] = htonl(y.pktRateDown)) \
145 if (
mode == NEG_REPLY) {
146 int len =
errMsg.length();
148 len = min(len,MAX_STRING);
153 paylen = 4*(pp + (len+3)/4);
158 case CLIENT_ADD_COMTREE:
159 if (
mode == REQUEST) {
166 case CLIENT_DROP_COMTREE:
167 if (
mode == REQUEST) {
172 case CLIENT_GET_COMTREE:
173 if (
mode == REQUEST) {
177 !rspec1.isSet() || !
rspec2.isSet())
181 packRspec(RSPEC1,rspec1);
185 case CLIENT_MOD_COMTREE:
186 if (
mode == REQUEST) {
189 if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
196 case CLIENT_JOIN_COMTREE:
197 if (
mode == REQUEST) {
198 if (
comtree == 0 || ip1 == 0 || port1 == 0)
201 packPair(IP1,ip1); packPair(PORT1,port1);
204 case CLIENT_LEAVE_COMTREE:
205 if (
mode == REQUEST) {
208 packPair(IP1,ip1); packPair(PORT1,port1);
211 case CLIENT_RESIZE_COMTREE:
212 if (
mode == REQUEST) {
217 case CLIENT_GET_LEAF_RATE:
218 if (
mode == REQUEST) {
224 if (!rspec1.isSet())
return 0;
225 packRspec(RSPEC1,rspec1);
228 case CLIENT_MOD_LEAF_RATE:
229 if (
mode == REQUEST) {
230 if (
comtree == 0 || adr1 == 0 ||
235 packRspec(RSPEC1,rspec1);
239 if (
mode == REQUEST) {
240 if (
iface == 0 || ip1 == 0 || !rspec1.isSet())
242 packPair(IFACE,
iface);
244 packRspec(RSPEC1,rspec1);
246 if (ip1 == 0 || port1 == 0)
return 0;
248 packPair(PORT1,port1);
252 if (
mode == REQUEST) {
253 if (
iface == 0)
return 0;
254 packPair(IFACE,
iface);
258 if (
mode == REQUEST) {
259 if (
iface == 0)
return 0;
260 packPair(IFACE,
iface);
262 if (
iface == 0 || ip1 == 0 ||
263 !rspec1.isSet() || !
rspec2.isSet())
265 packPair(IFACE,
iface);
267 packPair(PORT1,port1);
268 packRspec(RSPEC1,rspec1);
273 if (
mode == REQUEST) {
274 if (
iface == 0 || !rspec1.isSet())
276 packPair(IFACE,
iface);
277 packRspec(RSPEC1,rspec1);
281 if (
mode == REQUEST) {
284 packPair(IFACE,
iface);
286 if (ip1 != 0) packPair(IP1,ip1);
287 if (port1 != 0) packPair(PORT1,port1);
288 if (adr1 != 0) packPair(ADR1,adr1);
292 if (adr1 != 0) packPair(ADR1,adr1);
296 if (
mode == REQUEST) {
297 if (
link == 0 && adr1 == 0)
return 0;
299 if (adr1 != 0) packPair(ADR1,adr1);
303 if (
mode == REQUEST) {
304 if (
link == 0)
return 0;
308 ip1 == 0 || port1 == 0 || adr1 == 0 ||
309 !rspec1.isSet() || !
rspec2.isSet())
312 packPair(IFACE,
iface);
315 packPair(PORT1,port1);
317 packRspec(RSPEC1,rspec1);
322 if (
mode == REQUEST) {
323 if (
link == 0 || !rspec1.isSet())
return 0;
325 packRspec(RSPEC1,rspec1);
329 if (
mode == REQUEST) {
335 if (
mode == REQUEST) {
341 if (
mode == REQUEST) {
355 if (
mode == REQUEST) {
362 case ADD_COMTREE_LINK:
363 if (
mode == REQUEST) {
368 if (ip1 != 0) packPair(IP1,ip1);
369 if (port1 != 0) packPair(PORT1,port1);
370 if (adr1 != 0) packPair(ADR1,adr1);
372 if (
link == 0)
return 0;
376 case DROP_COMTREE_LINK:
377 if (
mode == REQUEST) {
381 if (ip1 != 0) packPair(IP1,ip1);
382 if (port1 != 0) packPair(PORT1,port1);
383 if (adr1 != 0) packPair(ADR1,adr1);
386 case MOD_COMTREE_LINK:
387 if (
mode == REQUEST) {
391 if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
394 case GET_COMTREE_LINK:
395 if (
mode == REQUEST) {
401 !rspec1.isSet() ||
queue == 0 || adr1 == 0)
405 packRspec(RSPEC1,rspec1);
406 packPair(QUEUE,
queue);
411 if (
mode == REQUEST) {
412 if (
comtree == 0 || adr1 == 0 ||
link == 0)
return 0;
420 if (
mode == REQUEST) {
421 if (
comtree == 0 || adr1 == 0)
return 0;
427 if (
mode == REQUEST) {
428 if (
comtree == 0 || adr1 == 0)
return 0;
440 if (
mode == REQUEST) {
441 if (
comtree == 0 || adr1 == 0)
return 0;
449 if (
mode == REQUEST) {
450 if (
comtree == 0 || adr1 == 0 ||
link == 0)
return 0;
456 case DROP_ROUTE_LINK:
457 if (
mode == REQUEST) {
458 if (
comtree == 0 || adr1 == 0 ||
link == 0)
return 0;
465 if (
mode == REQUEST) {
466 if (ip1 == 0 || !rspec1.isSet())
return 0;
468 packRspec(RSPEC1,rspec1);
470 if (adr1 == 0 || adr2 == 0 ||
adr3 == 0 ||
471 ip1 == 0 ||
nonce == 0)
477 packPair(PORT1,port1);
478 packNonce(NONCE,
nonce);
482 if (
mode == REQUEST) {
483 if (adr1 == 0 || adr2 == 0)
return 0;
484 packPair(ADR1,adr1); packPair(ADR2,adr2);
487 if (
mode == REQUEST) {
488 if (adr1 == 0 || adr2 == 0)
return 0;
493 case CLIENT_DISCONNECT:
494 if (
mode == REQUEST) {
495 if (adr1 == 0 || adr2 == 0)
return 0;
501 if (
mode == REQUEST) {
502 if (adr1 == 0 || adr2 == 0 || ip1 == 0 ||
503 port1 == 0 ||
nonce == 0)
return 0;
504 packPair(ADR1,adr1); packPair(ADR2,adr2);
505 packPair(IP1,ip1); packPair(PORT1,port1);
506 packNonce(NONCE,
nonce);
510 if (
mode == REQUEST) {
511 if (adr1 == 0 || adr2 == 0)
return 0;
512 packPair(ADR1,adr1); packPair(ADR2,adr2);
516 if (
mode == POS_REPLY) {
518 payload[pp++] = htonl(CtlPkt::LINKTABLE);
520 (firstLinkNum == 1) ? i =
lt->
firstLink() : i = firstLinkNum;
521 cout << __FILE__ <<
" " << __FUNCTION__ <<
" REPLY - first link num " << firstLinkNum <<
" numOfLinks " << numOfLinks << endl;
525 packPair(IFACE,
lt->getIface(i));
526 packPair(IP1,
lt->getPeerIpAdr(i));
527 packPair(PORT1,
lt->getPeerPort(i));
528 packPair(NODE_TYPE,
lt->getPeerType(i));
529 packPair(ADR1,
lt->getPeerAdr(i));
530 packRspec(RSPEC1,
lt->getRates(i));
531 packNonce(NONCE,
nonce);
532 payload[pp++] = htonl(CtlPkt::LINKSET);
534 Forest::nodeType2string(
lt->getPeerType(i), peerType);
535 cout << __FUNCTION__ <<
" GET_LINK_SET " << peerType << endl;
537 cout << __FUNCTION__ <<
" GET_LINK_SET " << i <<
" Num " << num <<
" numOfLinks " << numOfLinks << endl;
538 if ((++num >= numOfLinks) || i == 0){
539 packPair(NEXT_LINK_NUM, i);
540 cout << __FUNCTION__ <<
" next link num " << i << endl;
545 }
else if (
mode == REQUEST){
546 packPair(FIRST_LINK_NUM, firstLinkNum);
547 packPair(NUM_OF_LINK, numOfLinks);
548 cout <<
"REQUEST -" <<
" first link num " << firstLinkNum <<
" numOfLinks " << numOfLinks << endl;
562 #define unpackWord(x) (x = ntohl(payload[pp++]))
563 #define unpackRspec(x) ((x).set(ntohl(payload[pp++]), \
564 ntohl(payload[pp++]), \
565 ntohl(payload[pp++]), \
566 ntohl(payload[pp++]) ))
572 if (
payload == 0)
return false;
578 unpackWord(x); unpackWord(y);
581 if (
mode == NEG_REPLY) {
584 int len = ntohl(
payload[pp++]);
590 uint32_t attr = 0, numLinks = 0;
595 case ADR1: unpackWord(adr1);
break;
596 case ADR2: unpackWord(adr2);
break;
597 case ADR3: unpackWord(
adr3);
break;
598 case IP1: unpackWord(ip1);
break;
599 case IP2: unpackWord(
ip2);
break;
600 case PORT1: unpackWord(port1);
break;
601 case PORT2: unpackWord(
port2);
break;
602 case NONCE: uint32_t hi,lo; unpackWord(hi); unpackWord(lo);
604 case RSPEC1: unpackRspec(rspec1);
break;
605 case RSPEC2: unpackRspec(
rspec2);
break;
606 case CORE_FLAG: unpackWord(
coreFlag);
break;
607 case IFACE: unpackWord(
iface);
break;
608 case LINK: unpackWord(
link);
break;
611 case COMTREE: unpackWord(
comtree);
break;
613 case COUNT: unpackWord(
count);
break;
614 case QUEUE: unpackWord(
queue);
break;
615 case ZIPCODE: unpackWord(
zipCode);
break;
617 unpackWord(numLinks);
621 case FIRST_LINK_NUM: unpackWord(firstLinkNum);
break;
622 case NUM_OF_LINK: unpackWord(numOfLinks);
break;
623 case NEXT_LINK_NUM: unpackWord(nextLinkNum);
break;
625 cout << __FUNCTION__ <<
" " <<
link <<
" " << ip1 <<
" " << port1 << endl;
631 cout << __FUNCTION__ <<
" " <<
lt << endl;
633 default:
return false;
638 case CLIENT_ADD_COMTREE:
643 case CLIENT_DROP_COMTREE:
647 case CLIENT_GET_COMTREE:
649 (
mode == POS_REPLY &&
651 !rspec1.isSet() || !
rspec2.isSet())))
654 case CLIENT_MOD_COMTREE:
655 if ((
mode == REQUEST &&
656 (!rspec1.isSet() || !
rspec2.isSet())) ||
660 case CLIENT_JOIN_COMTREE:
661 if (
mode == REQUEST && (comtree == 0 || ip1 == 0 || port1 == 0))
664 case CLIENT_LEAVE_COMTREE:
665 if (
mode == REQUEST && (comtree == 0 || ip1 == 0 || port1 == 0))
668 case CLIENT_RESIZE_COMTREE:
669 if (
mode == REQUEST && comtree == 0)
672 case CLIENT_GET_LEAF_RATE:
673 if ((
mode == REQUEST &&
674 (comtree == 0 || adr1 == 0)) ||
675 (
mode == POS_REPLY &&
676 (comtree == 0 || adr1 == 0 || !rspec1.isSet())))
679 case CLIENT_MOD_LEAF_RATE:
680 if ((
mode == REQUEST &&
681 (comtree == 0 || adr1 == 0 || !rspec1.isSet())))
685 if ((
mode == REQUEST &&
686 (
iface == 0 || ip1 == 0 || !rspec1.isSet())) ||
687 (
mode == POS_REPLY && (ip1 == 0 || port1 == 0)))
696 (
mode == POS_REPLY &&
697 (
iface == 0 || ip1 == 0 || port1 == 0 ||
698 !rspec1.isSet() || !
rspec2.isSet())))
702 if ((
mode == REQUEST &&
703 (iface == 0 || !rspec1.isSet())))
711 if (
mode == REQUEST &&
link == 0 && adr1 == 0)
715 if ((
mode == REQUEST &&
link == 0) ||
716 (
mode == POS_REPLY &&
718 ip1 == 0 || port1 == 0 || adr1 == 0 ||
719 !rspec1.isSet() || !
rspec2.isSet())))
723 if (
mode == REQUEST && link == 0)
727 if (
mode == REQUEST && comtree == 0)
731 if (
mode == REQUEST && comtree == 0)
735 if ((
mode == REQUEST && comtree == 0) ||
736 (
mode == POS_REPLY &&
737 (comtree == 0 ||
coreFlag == -1 || link == 0 ||
742 if (
mode == REQUEST && comtree == 0)
745 case ADD_COMTREE_LINK:
746 if (
mode == REQUEST && (comtree == 0 ||
747 (link == 0 && (ip1 == 0 || port1 == 0)
751 case DROP_COMTREE_LINK:
752 if (
mode == REQUEST && (comtree == 0 ||
753 (link == 0 && (ip1 == 0 || port1 == 0)
757 case MOD_COMTREE_LINK:
758 if (
mode == REQUEST && (comtree == 0 || link == 0))
761 case GET_COMTREE_LINK:
762 if ((
mode == REQUEST &&
763 (comtree == 0 || link == 0)) ||
764 (
mode == POS_REPLY &&
765 (comtree == 0 || link == 0 || !rspec1.isSet() ||
766 queue == 0 || adr1 == 0)))
770 if (
mode == REQUEST && (comtree == 0 || adr1 == 0 || link == 0))
774 if (
mode == REQUEST && (comtree == 0 || adr1 == 0))
778 if ((
mode == REQUEST &&
779 (comtree == 0 || adr1 == 0)) ||
780 (
mode == POS_REPLY &&
781 (comtree == 0 || adr1 == 0 || link == 0)))
785 if (
mode == REQUEST && (comtree == 0 || adr1 == 0))
789 if (
mode == REQUEST &&
790 (comtree == 0 || adr1 == 0 || link == 0))
793 case DROP_ROUTE_LINK:
794 if (
mode == REQUEST &&
795 (comtree == 0 || adr1 == 0 || link == 0))
799 if ((
mode == REQUEST &&
800 (ip1 == 0 || !rspec1.isSet())) ||
801 (
mode == POS_REPLY &&
802 (adr1 == 0 || adr2 == 0 ||
adr3 == 0 ||
803 ip1 == 0 ||
nonce == 0)))
807 if (
mode == REQUEST && (adr1 == 0 || adr2 == 0))
811 if (
mode == REQUEST && (adr1 == 0 || adr2 == 0))
814 case CLIENT_DISCONNECT:
815 if (
mode == REQUEST && (adr1 == 0 || adr2 == 0))
819 if (
mode == REQUEST &&
820 (adr1 == 0 || adr2 == 0 || ip1 == 0 || port1 == 0 ||
825 if (
mode == REQUEST && (adr1 == 0 || adr2 == 0))
return false;
834 default:
return false;
863 if (port1 != 0) ss <<
"port1=" << port1;
869 if (rspec1.isSet()) ss <<
"rspec1=" << rspec1.
toString(s);
876 ss <<
"coreFlag=" << (
coreFlag ?
"true" :
"false");
882 if (
link != 0) ss <<
"link=" <<
link;
887 << Forest::nodeType2string(
nodeType,s);
916 string& CtlPkt::typeName(
string& s) {
918 case CLIENT_ADD_COMTREE: s =
"client add comtree";
break;
919 case CLIENT_DROP_COMTREE: s =
"client drop comtree";
break;
920 case CLIENT_GET_COMTREE: s =
"client get comtree";
break;
921 case CLIENT_MOD_COMTREE: s =
"client mod comtree";
break;
922 case CLIENT_JOIN_COMTREE: s =
"client join comtree";
break;
923 case CLIENT_LEAVE_COMTREE: s =
"client leave comtree";
break;
924 case CLIENT_RESIZE_COMTREE: s =
"client resize comtree";
break;
925 case CLIENT_GET_LEAF_RATE: s =
"client get leaf rate";
break;
926 case CLIENT_MOD_LEAF_RATE: s =
"client mod leaf rate";
break;
927 case ADD_IFACE: s =
"add iface";
break;
928 case DROP_IFACE: s =
"drop iface";
break;
929 case GET_IFACE: s =
"get iface";
break;
930 case MOD_IFACE: s =
"mod iface";
break;
931 case ADD_LINK: s =
"add link";
break;
932 case DROP_LINK: s =
"drop link";
break;
933 case GET_LINK: s =
"get link";
break;
934 case MOD_LINK: s =
"mod link";
break;
935 case ADD_COMTREE: s =
"add comtree";
break;
936 case DROP_COMTREE: s =
"drop comtree";
break;
937 case GET_COMTREE: s =
"get comtree";
break;
938 case MOD_COMTREE: s =
"mod comtree";
break;
939 case ADD_COMTREE_LINK: s =
"add comtree link";
break;
940 case DROP_COMTREE_LINK: s =
"drop comtree link";
break;
941 case MOD_COMTREE_LINK: s =
"mod comtree link";
break;
942 case GET_COMTREE_LINK: s =
"get comtree link";
break;
943 case ADD_ROUTE: s =
"add route";
break;
944 case DROP_ROUTE: s =
"drop route";
break;
945 case GET_ROUTE: s =
"get route";
break;
946 case MOD_ROUTE: s =
"mod route";
break;
947 case ADD_ROUTE_LINK: s =
"add route link";
break;
948 case DROP_ROUTE_LINK: s =
"drop route link";
break;
949 case NEW_SESSION: s =
"new session";
break;
950 case CANCEL_SESSION: s =
"cancel session";
break;
951 case CLIENT_CONNECT: s =
"client connect";
break;
952 case CLIENT_DISCONNECT: s =
"client disconnect";
break;
953 case CONFIG_LEAF: s =
"config leaf";
break;
954 case SET_LEAF_RANGE: s =
"set leaf range";
break;
955 case BOOT_ROUTER: s =
"boot router";
break;
956 case BOOT_LEAF: s =
"boot leaf";
break;
957 case BOOT_COMPLETE: s =
"boot complete";
break;
958 case BOOT_ABORT: s =
"boot abort";
break;
964 string& CtlPkt::modeName(
string& s) {
966 case REQUEST: s =
"request";
break;
967 case POS_REPLY: s =
"pos reply";
break;
968 case NEG_REPLY: s =
"neg reply";
break;
979 ss <<
" (" << modeName(s) <<
"," <<
seqNum <<
"): ";
980 if (
mode == NEG_REPLY) {
986 case CLIENT_ADD_COMTREE:
987 if (
mode == REQUEST) {
993 case CLIENT_DROP_COMTREE:
994 if (
mode == REQUEST) {
998 case CLIENT_GET_COMTREE:
999 if (
mode == REQUEST) {
1008 case CLIENT_MOD_COMTREE:
1009 if (
mode == REQUEST) {
1017 case CLIENT_JOIN_COMTREE:
1018 if (
mode == REQUEST) {
1024 case CLIENT_LEAVE_COMTREE:
1025 if (
mode == REQUEST) {
1029 case CLIENT_RESIZE_COMTREE:
1030 if (
mode == REQUEST) {
1034 case CLIENT_GET_LEAF_RATE:
1035 if (
mode == REQUEST) {
1042 case CLIENT_MOD_LEAF_RATE:
1043 if (
mode == REQUEST) {
1050 if (
mode == REQUEST) {
1060 if (
mode == REQUEST) {
1065 if (
mode == REQUEST) {
1075 if (
mode == REQUEST) {
1081 if (
mode == REQUEST) {
1096 if (
mode == REQUEST) {
1102 if (
mode == REQUEST) {
1116 if (
mode == REQUEST) {
1122 if (
mode == REQUEST) {
1127 if (
mode == REQUEST) {
1132 if (
mode == REQUEST) {
1142 if (
mode == REQUEST) {
1148 case ADD_COMTREE_LINK:
1149 if (
mode == REQUEST) {
1160 case DROP_COMTREE_LINK:
1161 if (
mode == REQUEST) {
1169 case MOD_COMTREE_LINK:
1170 if (
mode == REQUEST) {
1176 case GET_COMTREE_LINK:
1177 if (
mode == REQUEST) {
1189 if (
mode == REQUEST) {
1197 if (
mode == REQUEST) {
1203 if (
mode == REQUEST) {
1213 if (
mode == REQUEST) {
1220 case ADD_ROUTE_LINK:
1221 if (
mode == REQUEST) {
1227 case DROP_ROUTE_LINK:
1228 if (
mode == REQUEST) {
1235 if (
mode == REQUEST) {
1247 case CANCEL_SESSION:
1248 if (
mode == REQUEST) {
1253 case CLIENT_CONNECT:
1254 if (
mode == REQUEST) {
1259 case CLIENT_DISCONNECT:
1260 if (
mode == REQUEST) {
1266 if (
mode == REQUEST) {
1274 case SET_LEAF_RANGE:
1275 if (
mode == REQUEST) {