forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
CtlPkt.cpp
Go to the documentation of this file.
1 
23 #include "CtlPkt.h"
24 
25 namespace forest {
26 
30  payload = 0; paylen = 0;
31 }
32 
36 CtlPkt::CtlPkt(const Packet& p) { reset(p); }
37 
40 
48 void CtlPkt::reset(const Packet& p) {
49  payload = (char*) p.payload();
51  xtrBase();
52 }
53 
59 void CtlPkt::fmtError(const string& msg, int64_t snum) {
60  mode = NEG_REPLY; if (snum != 0) seqNum = snum;
61  fmtBase();
62  put(msg); paylen = next - payload;
63 }
64 
70 bool CtlPkt::xtrError(string& msg) {
71  return mode == NEG_REPLY && get(msg) && paylen == (next - payload);
72 }
73 
77 void CtlPkt::fmtReply() {
78  mode = POS_REPLY; fmtBase();
79 }
80 
87 void CtlPkt::fmtAddIface(int iface, ipa_t ip, RateSpec rates, int64_t snum) {
88  type = ADD_IFACE; mode = REQUEST; seqNum = snum;
89  fmtBase();
90  put(iface); put(ip); put(rates);
91  paylen = next - payload;
92 }
93 
100 bool CtlPkt::xtrAddIface(int& iface, ipa_t& ip, RateSpec& rates) {
101  return type == ADD_IFACE && mode == REQUEST
102  && get(iface) && get(ip) && get(rates)
103  && paylen >= (next - payload);
104 }
105 
111 void CtlPkt::fmtAddIfaceReply(ipa_t ip, ipp_t port, int64_t snum) {
112  type = ADD_IFACE; mode = POS_REPLY;
113  if (snum != 0) seqNum = snum;
114  fmtBase();
115  put(ip); put(port);
116  paylen = next - payload;
117 }
118 
124 bool CtlPkt::xtrAddIfaceReply(ipa_t& ip, ipp_t& port) {
125  return type == ADD_IFACE && mode == REQUEST
126  && get(ip) && get(port)
127  && paylen >= (next - payload);
128 }
129 
134 void CtlPkt::fmtDropIface(int iface, int64_t snum) {
135  type = DROP_IFACE; mode = REQUEST; seqNum = snum;
136  fmtBase();
137  put(iface);
138  paylen = next - payload;
139 }
140 
145 bool CtlPkt::xtrDropIface(int& iface) {
146  return type == DROP_IFACE && mode == REQUEST
147  && get(iface)
148  && paylen >= (next - payload);
149 }
150 
154 void CtlPkt::fmtDropIfaceReply(int64_t snum) {
155  type = DROP_IFACE; mode = POS_REPLY;
156  if (snum != 0) seqNum = snum;
157  fmtBase();
158 }
159 
164  return type == DROP_IFACE && mode == REQUEST
165  && paylen >= (next - payload);
166 }
167 
173 void CtlPkt::fmtModIface(int iface, RateSpec rates, int64_t snum) {
174  type = MOD_IFACE; mode = REQUEST; seqNum = snum;
175  fmtBase();
176  put(iface); put(rates);
177  paylen = next - payload;
178 }
179 
185 bool CtlPkt::xtrModIface(int& iface, RateSpec& rates) {
186  return type == MOD_IFACE && mode == REQUEST
187  && get(iface) && get(rates)
188  && paylen >= (next - payload);
189 }
190 
194 void CtlPkt::fmtModIfaceReply(int64_t snum) {
195  type = MOD_IFACE; mode = POS_REPLY;
196  if (snum != 0) seqNum = snum;
197  fmtBase();
198 }
199 
204  return type == MOD_IFACE && mode == REQUEST
205  && paylen >= (next - payload);
206 }
207 
212 void CtlPkt::fmtGetIface(int iface, int64_t snum) {
213  type = GET_IFACE; mode = REQUEST; seqNum = snum;
214  fmtBase();
215  put(iface);
216  paylen = next - payload;
217 }
218 
223 bool CtlPkt::xtrGetIface(int& iface) {
224  return type == GET_IFACE && mode == REQUEST
225  && get(iface)
226  && paylen >= (next - payload);
227 }
228 
237 void CtlPkt::fmtGetIfaceReply(int iface, ipa_t ip, ipp_t port, RateSpec rates, RateSpec availRates, int64_t snum) {
238  type = GET_IFACE; mode = POS_REPLY;
239  if (snum != 0) seqNum = snum;
240  fmtBase();
241  put(iface); put(ip); put(port); put(rates); put(availRates);
242  paylen = next - payload;
243 }
244 
253 bool CtlPkt::xtrGetIfaceReply(int& iface, ipa_t& ip, ipp_t& port, RateSpec& rates, RateSpec& availRates) {
254  return type == GET_IFACE && mode == REQUEST
255  && get(iface) && get(ip) && get(port) && get(rates) && get(availRates)
256  && paylen >= (next - payload);
257 }
258 
264 void CtlPkt::fmtGetIfaceSet(int iface, int count, int64_t snum) {
265  type = GET_IFACE_SET; mode = REQUEST; seqNum = snum;
266  fmtBase();
267  put(iface); put(count);
268  paylen = next - payload;
269 }
270 
276 bool CtlPkt::xtrGetIfaceSet(int& iface, int& count) {
277  return type == GET_IFACE_SET && mode == REQUEST
278  && get(iface) && get(count)
279  && paylen >= (next - payload);
280 }
281 
288 void CtlPkt::fmtGetIfaceSetReply(int count, int nexti, string s, int64_t snum) {
289  type = GET_IFACE_SET; mode = POS_REPLY;
290  if (snum != 0) seqNum = snum;
291  fmtBase();
292  put(count); put(nexti); put(s);
293  paylen = next - payload;
294 }
295 
302 bool CtlPkt::xtrGetIfaceSetReply(int& count, int& nexti, string& s) {
303  return type == GET_IFACE_SET && mode == REQUEST
304  && get(count) && get(nexti) && get(s)
305  && paylen >= (next - payload);
306 }
307 
319 void CtlPkt::fmtAddLink(Forest::ntyp_t nodeType, int iface, int lnk, ipa_t peerIp, ipp_t peerPort, fAdr_t peerAdr, uint64_t nonce, int64_t snum) {
320  type = ADD_LINK; mode = REQUEST; seqNum = snum;
321  fmtBase();
322  put(nodeType); put(iface); put(lnk); put(peerIp); put(peerPort);
323  put(peerAdr); put(nonce);
324  paylen = next - payload;
325 }
326 
338 bool CtlPkt::xtrAddLink(Forest::ntyp_t& nodeType, int& iface, int& lnk,
339  ipa_t& peerIp, ipp_t& peerPort, fAdr_t& peerAdr, uint64_t& nonce) {
340  return type == ADD_LINK && mode == REQUEST
341  && get(nodeType) && get(iface) && get(lnk) && get(peerIp)
342  && get(peerPort) && get(peerAdr) && get(nonce)
343  && paylen >= (next - payload);
344 }
345 
352 void CtlPkt::fmtAddLinkReply(int lnk, fAdr_t peerAdr, int64_t snum) {
353  type = ADD_LINK; mode = POS_REPLY;
354  if (snum != 0) seqNum = snum;
355  fmtBase();
356  put(lnk); put(peerAdr);
357  paylen = next - payload;
358 }
359 
366 bool CtlPkt::xtrAddLinkReply(int& lnk, fAdr_t& peerAdr) {
367  return type == ADD_LINK && mode == REQUEST
368  && get(lnk) && get(peerAdr)
369  && paylen >= (next - payload);
370 }
371 
378 void CtlPkt::fmtDropLink(int lnk, fAdr_t peerAdr, int64_t snum) {
379  type = DROP_LINK; mode = REQUEST; seqNum = snum;
380  fmtBase();
381  put(lnk); put(peerAdr);
382  paylen = next - payload;
383 }
384 
391 bool CtlPkt::xtrDropLink(int& lnk, fAdr_t& peerAdr) {
392  return type == DROP_LINK && mode == REQUEST
393  && get(lnk) && get(peerAdr)
394  && paylen >= (next - payload);
395 }
396 
400 void CtlPkt::fmtDropLinkReply(int64_t snum) {
401  type = DROP_LINK; mode = POS_REPLY;
402  if (snum != 0) seqNum = snum;
403  fmtBase();
404  paylen = next - payload;
405 }
406 
411  return type == DROP_LINK && mode == REQUEST
412  && paylen >= (next - payload);
413 }
414 
420 void CtlPkt::fmtModLink(int lnk, RateSpec rates, int64_t snum) {
421  type = MOD_LINK; mode = REQUEST; seqNum = snum;
422  fmtBase();
423  put(lnk); put(rates);
424  paylen = next - payload;
425 }
426 
432 bool CtlPkt::xtrModLink(int& lnk, RateSpec& rates) {
433  return type == MOD_LINK && mode == REQUEST
434  && get(lnk) && get(rates)
435  && paylen >= (next - payload);
436 }
437 
441 void CtlPkt::fmtModLinkReply(int64_t snum) {
442  type = MOD_LINK; mode = POS_REPLY;
443  if (snum != 0) seqNum = snum;
444  fmtBase();
445 }
446 
451  return type == MOD_LINK && mode == REQUEST
452  && paylen >= (next - payload);
453 }
454 
459 void CtlPkt::fmtGetLink(int lnk, int64_t snum) {
460  type = GET_LINK; mode = REQUEST; seqNum = snum;
461  fmtBase();
462  put(lnk);
463  paylen = next - payload;
464 }
465 
470 bool CtlPkt::xtrGetLink(int& lnk) {
471  return type == GET_LINK && mode == REQUEST
472  && get(lnk)
473  && paylen >= (next - payload);
474 }
475 
480 void CtlPkt::fmtGetLinkReply(int lnk, int iface, Forest::ntyp_t ntyp,
481  ipa_t peerIp, ipp_t peerPort, fAdr_t peerAdr,
482  RateSpec& rates, RateSpec& availRates,int64_t snum) {
483  type = GET_LINK; mode = POS_REPLY;
484  if (snum != 0) seqNum = snum;
485  fmtBase();
486  put(lnk); put(iface); put(ntyp); put(peerIp); put(peerPort);
487  put(peerAdr); put(rates); put(availRates);
488  paylen = next - payload;
489 }
490 
495 bool CtlPkt::xtrGetLinkReply(int& lnk, int& iface, Forest::ntyp_t& ntyp,
496  ipa_t& peerIp, ipp_t& peerPort, fAdr_t& peerAdr,
497  RateSpec& rates, RateSpec& availRates) {
498  return type == GET_LINK && mode == REQUEST
499  && get(lnk) && get(iface) && get(ntyp) && get(peerIp)
500  && get(peerPort) && get(peerAdr)
501  && get(rates) && get(availRates)
502  && paylen >= (next - payload);
503 }
504 
510 void CtlPkt::fmtGetLinkSet(int lnk, int count, int64_t snum) {
511  type = GET_LINK_SET; mode = REQUEST; seqNum = snum;
512  fmtBase();
513  put(lnk); put(count);
514  paylen = next - payload;
515 }
516 
522 bool CtlPkt::xtrGetLinkSet(int& lnk, int& count) {
523  return type == GET_LINK_SET && mode == REQUEST
524  && get(lnk) && get(count)
525  && paylen >= (next - payload);
526 }
527 
533 void CtlPkt::fmtGetLinkSetReply(int count, int nexti, string s, int64_t snum) {
534  type = GET_LINK_SET; mode = POS_REPLY;
535  if (snum != 0) seqNum = snum;
536  fmtBase();
537  put(count); put(nexti); put(s);
538  paylen = next - payload;
539 }
540 
546 bool CtlPkt::xtrGetLinkSetReply(int& count, int& nexti, string& s) {
547  return type == GET_LINK_SET && mode == REQUEST
548  && get(count) && get(nexti) && get(s)
549  && paylen >= (next - payload);
550 }
551 
556 void CtlPkt::fmtAddComtree(comt_t comt, int64_t snum) {
557  type = ADD_COMTREE; mode = REQUEST; seqNum = snum;
558  fmtBase();
559  put(comt);
560  paylen = next - payload;
561 }
562 
568  return type == ADD_COMTREE && mode == REQUEST
569  && get(comt)
570  && paylen >= (next - payload);
571 }
572 
576 void CtlPkt::fmtAddComtreeReply(int64_t snum) {
577  type = ADD_COMTREE; mode = POS_REPLY;
578  if (snum != 0) seqNum = snum;
579  fmtBase();
580 }
581 
586  return type == ADD_COMTREE && mode == REQUEST
587  && paylen >= (next - payload);
588 }
589 
594 void CtlPkt::fmtDropComtree(comt_t comt, int64_t snum) {
595  type = DROP_COMTREE; mode = REQUEST; seqNum = snum;
596  fmtBase();
597  put(comt);
598  paylen = next - payload;
599 }
600 
606  return type == DROP_COMTREE && mode == REQUEST
607  && get(comt)
608  && paylen >= (next - payload);
609 }
610 
615 void CtlPkt::fmtDropComtreeReply(RateSpec plnkAvailRates, int64_t snum) {
616  type = DROP_COMTREE; mode = POS_REPLY;
617  if (snum != 0) seqNum = snum;
618  fmtBase();
619  put(plnkAvailRates);
620  paylen = next - payload;
621 }
622 
627 bool CtlPkt::xtrDropComtreeReply(RateSpec& plnkAvailRates) {
628  return type == DROP_COMTREE && mode == REQUEST
629  && get(plnkAvailRates)
630  && paylen >= (next - payload);
631 }
632 
639 void CtlPkt::fmtModComtree(comt_t comt, int coreFlag, int plnk, int64_t snum) {
640  type = MOD_COMTREE; mode = REQUEST; seqNum = snum;
641  fmtBase();
642  put(comt); put(coreFlag); put(plnk);
643  paylen = next - payload;
644 }
645 
653 bool CtlPkt::xtrModComtree(comt_t& comt, int& coreFlag, int& plnk) {
654  return type == MOD_COMTREE && mode == REQUEST
655  && get(comt) && get(coreFlag) && get(plnk)
656  && paylen >= (next - payload);
657 }
658 
662 void CtlPkt::fmtModComtreeReply(int64_t snum) {
663  type = MOD_COMTREE; mode = POS_REPLY;
664  if (snum != 0) seqNum = snum;
665  fmtBase();
666 }
667 
672  return type == MOD_COMTREE && mode == REQUEST
673  && paylen >= (next - payload);
674 }
675 
680 void CtlPkt::fmtGetComtree(comt_t comt, int64_t snum) {
681  type = GET_COMTREE; mode = REQUEST; seqNum = snum;
682  fmtBase();
683  put(comt);
684  paylen = next - payload;
685 }
686 
692  return type == GET_COMTREE && mode == REQUEST
693  && get(comt)
694  && paylen >= (next - payload);
695 }
696 
704 void CtlPkt::fmtGetComtreeReply(comt_t comt, int coreFlag, int plnk, int lnkCount, int64_t snum) {
705  type = GET_COMTREE; mode = POS_REPLY;
706  if (snum != 0) seqNum = snum;
707  fmtBase();
708  put(comt); put(coreFlag); put(plnk); put(lnkCount);
709  paylen = next - payload;
710 }
711 
719 bool CtlPkt::xtrGetComtreeReply(comt_t& comt, int& coreFlag, int& plnk, int& lnkCount) {
720  return type == GET_COMTREE && mode == REQUEST
721  && get(comt) && get(coreFlag) && get(plnk) && get(lnkCount)
722  && paylen >= (next - payload);
723 }
724 
730 void CtlPkt::fmtGetComtreeSet(comt_t comt, int count, int64_t snum) {
731  type = GET_COMTREE_SET; mode = REQUEST; seqNum = snum;
732  fmtBase();
733  put(comt); put(count);
734  paylen = next - payload;
735 }
736 
742 bool CtlPkt::xtrGetComtreeSet(comt_t& comt, int& count) {
743  return type == GET_COMTREE_SET && mode == REQUEST
744  && get(comt) && get(count)
745  && paylen >= (next - payload);
746 }
747 
754 void CtlPkt::fmtGetComtreeSetReply(int count, comt_t nextc, string s,
755  int64_t snum) {
756  type = GET_COMTREE_SET; mode = POS_REPLY;
757  if (snum != 0) seqNum = snum;
758  fmtBase();
759  put(count); put(nextc); put(s);
760  paylen = next - payload;
761 }
762 
769 bool CtlPkt::xtrGetComtreeSetReply(int& count, comt_t& nextc, string& s) {
770  return type == GET_COMTREE_SET && mode == REQUEST
771  && get(count) && get(nextc) && get(s)
772  && paylen >= (next - payload);
773 }
774 
785 void CtlPkt::fmtAddComtreeLink(comt_t comt, int lnk, int coreFlag,
786  ipa_t peerIp, ipp_t peerPort, fAdr_t peerAdr, int64_t snum) {
787  type = ADD_COMTREE_LINK; mode = REQUEST; seqNum = snum;
788  fmtBase();
789  put(comt); put(lnk); put(coreFlag); put(peerIp); put(peerPort);
790  put(peerAdr);
791  paylen = next - payload;
792 }
793 
804 bool CtlPkt::xtrAddComtreeLink(comt_t& comt, int& lnk, int& coreFlag,
805  ipa_t& peerIp, ipp_t& peerPort, fAdr_t& peerAdr) {
806  return type == ADD_COMTREE_LINK && mode == REQUEST
807  && get(comt) && get(lnk) && get(coreFlag)
808  && get(peerIp) && get(peerPort) && get(peerAdr)
809  && paylen >= (next - payload);
810 }
811 
818 void CtlPkt::fmtAddComtreeLinkReply(int lnk, RateSpec availRates, int64_t snum){
819  type = ADD_COMTREE_LINK; mode = POS_REPLY;
820  if (snum != 0) seqNum = snum;
821  fmtBase();
822  put(lnk); put(availRates);
823  paylen = next - payload;
824 }
825 
832 bool CtlPkt::xtrAddComtreeLinkReply(int& lnk, RateSpec& availRates) {
833  return type == ADD_COMTREE_LINK && mode == REQUEST
834  && get(lnk) && get(availRates)
835  && paylen >= (next - payload);
836 }
837 
846 void CtlPkt::fmtDropComtreeLink(comt_t comt, int lnk, ipa_t peerIp,
847  ipp_t peerPort, fAdr_t peerAdr, int64_t snum) {
848  type = DROP_COMTREE_LINK; mode = REQUEST; seqNum = snum;
849  fmtBase();
850 }
851 
860 bool CtlPkt::xtrDropComtreeLink(comt_t& comt, int& lnk, ipa_t& peerIp,
861  ipp_t& peerPort, fAdr_t& peerAdr) {
862  return type == DROP_COMTREE_LINK && mode == REQUEST
863  && get(comt) && get(lnk) && get(peerIp)
864  && get(peerPort) && get(peerAdr)
865  && paylen >= (next - payload);
866 }
867 
872 void CtlPkt::fmtDropComtreeLinkReply(RateSpec availRates, int64_t snum) {
873  type = DROP_COMTREE_LINK; mode = POS_REPLY;
874  if (snum != 0) seqNum = snum;
875  fmtBase();
876  put(availRates);
877  paylen = next - payload;
878 }
879 
885  return type == DROP_COMTREE_LINK && mode == REQUEST
886  && get(availRates)
887  && paylen >= (next - payload);
888 }
889 
896 void CtlPkt::fmtModComtreeLink(comt_t comt, int lnk, RateSpec rates,int64_t snum) {
897  type = MOD_COMTREE_LINK; mode = REQUEST; seqNum = snum;
898  fmtBase();
899  put(comt); put(lnk); put(rates);
900  paylen = next - payload;
901 }
902 
909 bool CtlPkt::xtrModComtreeLink(comt_t& comt, int& lnk, RateSpec& rates) {
910  return type == MOD_COMTREE_LINK && mode == REQUEST
911  && get(comt) && get(lnk) && get(rates)
912  && paylen >= (next - payload);
913 }
914 
919 void CtlPkt::fmtModComtreeLinkReply(RateSpec& availRates, int64_t snum) {
920  type = MOD_COMTREE_LINK; mode = POS_REPLY;
921  if (snum != 0) seqNum = snum;
922  fmtBase();
923  put(availRates);
924  paylen = next - payload;
925 }
926 
932  return type == MOD_COMTREE_LINK && mode == REQUEST
933  && get(availRates)
934  && paylen >= (next - payload);
935 }
936 
942 void CtlPkt::fmtGetComtreeLink(comt_t comt, int lnk, int64_t snum) {
943  type = GET_COMTREE_LINK; mode = REQUEST; seqNum = snum;
944  fmtBase();
945  put(comt); put(lnk);
946  paylen = next - payload;
947 }
948 
954 bool CtlPkt::xtrGetComtreeLink(comt_t& comt, int& lnk) {
955  return type == GET_COMTREE_LINK && mode == REQUEST
956  && get(comt) && get(lnk)
957  && paylen >= (next - payload);
958 }
959 
969  int qid, fAdr_t dest, int64_t snum) {
970  type = GET_COMTREE_LINK; mode = POS_REPLY;
971  if (snum != 0) seqNum = snum;
972  fmtBase();
973  put(comt); put(lnk); put(rates); put(qid); put(dest);
974  paylen = next - payload;
975 }
976 
985 bool CtlPkt::xtrGetComtreeLinkReply(comt_t& comt, int& lnk, RateSpec& rates,
986  int& qid, fAdr_t& dest) {
987  return type == GET_COMTREE_LINK && mode == REQUEST
988  && get(comt) && get(lnk) && get(rates)
989  && get(qid) && get(dest)
990  && paylen >= (next - payload);
991 }
992 
999 void CtlPkt::fmtAddRoute(comt_t comt, fAdr_t destAdr, int lnk, int64_t snum) {
1000  type = ADD_ROUTE; mode = REQUEST; seqNum = snum;
1001  fmtBase();
1002  put(comt); put(destAdr); put(lnk);
1003  paylen = next - payload;
1004 }
1005 
1012 bool CtlPkt::xtrAddRoute(comt_t& comt, fAdr_t& destAdr, int& lnk) {
1013  return type == ADD_ROUTE && mode == REQUEST
1014  && get(comt) && get(destAdr) && get(lnk)
1015  && paylen >= (next - payload);
1016 }
1017 
1021 void CtlPkt::fmtAddRouteReply(int64_t snum) {
1022  type = ADD_ROUTE; mode = POS_REPLY;
1023  if (snum != 0) seqNum = snum;
1024  fmtBase();
1025 }
1026 
1031  return type == ADD_ROUTE && mode == REQUEST
1032  && paylen >= (next - payload);
1033 }
1034 
1041 void CtlPkt::fmtDropRoute(comt_t comt, fAdr_t destAdr, int64_t snum) {
1042  type = DROP_ROUTE; mode = REQUEST; seqNum = snum;
1043  fmtBase();
1044  put(comt); put(destAdr);
1045  paylen = next - payload;
1046 }
1047 
1054 bool CtlPkt::xtrDropRoute(comt_t& comt, fAdr_t& destAdr) {
1055  return type == DROP_ROUTE && mode == REQUEST
1056  && get(comt) && get(destAdr)
1057  && paylen >= (next - payload);
1058 }
1059 
1063 void CtlPkt::fmtDropRouteReply(int64_t snum) {
1064  type = DROP_ROUTE; mode = POS_REPLY;
1065  if (snum != 0) seqNum = snum;
1066  fmtBase();
1067 }
1068 
1073  return type == DROP_ROUTE && mode == REQUEST
1074  && paylen >= (next - payload);
1075 }
1076 
1084 void CtlPkt::fmtModRoute(comt_t comt, fAdr_t destAdr, int lnk, int64_t snum) {
1085  type = MOD_ROUTE; mode = REQUEST; seqNum = snum;
1086  fmtBase();
1087  put(comt); put(destAdr); put(lnk);
1088  paylen = next - payload;
1089 }
1090 
1097 bool CtlPkt::xtrModRoute(comt_t& comt, fAdr_t& destAdr, int& lnk) {
1098  return type == MOD_ROUTE && mode == REQUEST
1099  && get(comt) && get(destAdr) && get(lnk)
1100  && paylen >= (next - payload);
1101 }
1102 
1106 void CtlPkt::fmtModRouteReply(int64_t snum) {
1107  type = MOD_ROUTE; mode = POS_REPLY;
1108  if (snum != 0) seqNum = snum;
1109  fmtBase();
1110 }
1111 
1116  return type == MOD_ROUTE && mode == REQUEST
1117  && paylen >= (next - payload);
1118 }
1119 
1126 void CtlPkt::fmtGetRoute(comt_t comt, fAdr_t destAdr, int64_t snum) {
1127  type = GET_ROUTE; mode = REQUEST; seqNum = snum;
1128  fmtBase();
1129  put(comt); put(destAdr);
1130  paylen = next - payload;
1131 }
1132 
1139 bool CtlPkt::xtrGetRoute(comt_t& comt, fAdr_t& destAdr) {
1140  return type == GET_ROUTE && mode == REQUEST
1141  && get(comt) && get(destAdr)
1142  && paylen >= (next - payload);
1143 }
1144 
1151 void CtlPkt::fmtGetRouteReply(comt_t comt, fAdr_t destAdr, int lnk, int64_t snum) {
1152  type = GET_ROUTE; mode = POS_REPLY;
1153  if (snum != 0) seqNum = snum;
1154  fmtBase();
1155  put(comt); put(destAdr); put(lnk);
1156  paylen = next - payload;
1157 }
1158 
1165 bool CtlPkt::xtrGetRouteReply(comt_t& comt, fAdr_t& destAdr, int& lnk) {
1166  return type == GET_ROUTE && mode == REQUEST
1167  && get(comt) && get(destAdr) && get(lnk)
1168  && paylen >= (next - payload);
1169 }
1170 
1177 void CtlPkt::fmtGetRouteSet(int rtx, int count, int64_t snum) {
1178  type = GET_ROUTE_SET; mode = REQUEST; seqNum = snum;
1179  fmtBase();
1180  put(rtx); put(count);
1181  paylen = next - payload;
1182 }
1183 
1190 bool CtlPkt::xtrGetRouteSet(int& rtx, int& count) {
1191  return type == GET_ROUTE_SET && mode == REQUEST
1192  && get(rtx) && get(count)
1193  && paylen >= (next - payload);
1194 }
1195 
1202 void CtlPkt::fmtGetRouteSetReply(int count, int nextRtx, string s,
1203  int64_t snum) {
1204  type = GET_ROUTE_SET; mode = POS_REPLY;
1205  if (snum != 0) seqNum = snum;
1206  fmtBase();
1207  put(count); put(nextRtx); put(s);
1208  paylen = next - payload;
1209 }
1210 
1217 bool CtlPkt::xtrGetRouteSetReply(int& count, int& nextRtx, string& s) {
1218  return type == GET_ROUTE_SET && mode == REQUEST
1219  && get(count) && get(nextRtx) && get(s)
1220  && paylen >= (next - payload);
1221 }
1222 
1229 void CtlPkt::fmtAddRouteLink(comt_t comt, fAdr_t destAdr, int lnk, int64_t snum) {
1230  type = ADD_ROUTE_LINK; mode = REQUEST; seqNum = snum;
1231  fmtBase();
1232  put(comt); put(destAdr); put(lnk);
1233  paylen = next - payload;
1234 }
1235 
1242 bool CtlPkt::xtrAddRouteLink(comt_t& comt, fAdr_t& destAdr, int& lnk) {
1243  return type == ADD_ROUTE_LINK && mode == REQUEST
1244  && get(comt) && get(destAdr) && get(lnk)
1245  && paylen >= (next - payload);
1246 }
1247 
1251 void CtlPkt::fmtAddRouteLinkReply(int64_t snum) {
1252  type = ADD_ROUTE_LINK; mode = POS_REPLY;
1253  if (snum != 0) seqNum = snum;
1254  fmtBase();
1255 }
1256 
1261  return type == ADD_ROUTE_LINK && mode == REQUEST
1262  && paylen >= (next - payload);
1263 }
1264 
1271 void CtlPkt::fmtDropRouteLink(comt_t comt, fAdr_t destAdr, int lnk, int64_t snum) {
1272  type = DROP_ROUTE_LINK; mode = REQUEST; seqNum = snum;
1273  fmtBase();
1274  put(comt); put(destAdr); put(lnk);
1275  paylen = next - payload;
1276 }
1277 
1284 bool CtlPkt::xtrDropRouteLink(comt_t& comt, fAdr_t& destAdr, int& lnk) {
1285  return type == DROP_ROUTE_LINK && mode == REQUEST
1286  && get(comt) && get(destAdr) && get(lnk)
1287  && paylen >= (next - payload);
1288 }
1289 
1293 void CtlPkt::fmtDropRouteLinkReply(int64_t snum) {
1294  type = DROP_ROUTE_LINK; mode = POS_REPLY;
1295  if (snum != 0) seqNum = snum;
1296  fmtBase();
1297 }
1298 
1303  return type == DROP_ROUTE_LINK && mode == REQUEST
1304  && paylen >= (next - payload);
1305 }
1306 
1310 void CtlPkt::fmtAddFilter(int64_t snum) {
1311  type = ADD_FILTER; mode = REQUEST; seqNum = snum;
1312  fmtBase();
1313 }
1314 
1319  return type == ADD_FILTER && mode == REQUEST
1320  && paylen >= (next - payload);
1321 }
1322 
1327 void CtlPkt::fmtAddFilterReply(int filterNum, int64_t snum) {
1328  type = ADD_FILTER; mode = POS_REPLY;
1329  if (snum != 0) seqNum = snum;
1330  fmtBase();
1331  put(filterNum);
1332  paylen = next - payload;
1333 }
1334 
1339 bool CtlPkt::xtrAddFilterReply(int& filterNum) {
1340  return type == ADD_FILTER && mode == REQUEST
1341  && get(filterNum)
1342  && paylen >= (next - payload);
1343 }
1344 
1349 void CtlPkt::fmtDropFilter(int filterNum, int64_t snum) {
1350  type = DROP_FILTER; mode = REQUEST; seqNum = snum;
1351  fmtBase();
1352  put(filterNum);
1353  paylen = next - payload;
1354 }
1355 
1360 bool CtlPkt::xtrDropFilter(int& filterNum) {
1361  return type == DROP_FILTER && mode == REQUEST
1362  && get(filterNum)
1363  && paylen >= (next - payload);
1364 }
1365 
1369 void CtlPkt::fmtDropFilterReply(int64_t snum) {
1370  type = DROP_FILTER; mode = POS_REPLY;
1371  if (snum != 0) seqNum = snum;
1372  fmtBase();
1373 }
1374 
1379  return type == DROP_FILTER && mode == REQUEST
1380  && paylen >= (next - payload);
1381 }
1382 
1388 void CtlPkt::fmtModFilter(int filterNum, string filterString, int64_t snum) {
1389  type = MOD_FILTER; mode = REQUEST; seqNum = snum;
1390  fmtBase();
1391  put(filterNum); put(filterString);
1392  paylen = next - payload;
1393 }
1394 
1400 bool CtlPkt::xtrModFilter(int& filterNum, string& filterString) {
1401  return type == MOD_FILTER && mode == REQUEST
1402  && get(filterNum) && get(filterString)
1403  && paylen >= (next - payload);
1404 }
1405 
1409 void CtlPkt::fmtModFilterReply(int64_t snum) {
1410  type = MOD_FILTER; mode = POS_REPLY;
1411  if (snum != 0) seqNum = snum;
1412  fmtBase();
1413 }
1414 
1419  return type == MOD_FILTER && mode == REQUEST
1420  && paylen >= (next - payload);
1421 }
1422 
1427 void CtlPkt::fmtGetFilter(int filterNum, int64_t snum) {
1428  type = GET_FILTER; mode = REQUEST; seqNum = snum;
1429  fmtBase();
1430  put(filterNum);
1431  paylen = next - payload;
1432 }
1433 
1438 bool CtlPkt::xtrGetFilter(int& filterNum) {
1439  return type == GET_FILTER && mode == REQUEST
1440  && get(filterNum)
1441  && paylen >= (next - payload);
1442 }
1443 
1448 void CtlPkt::fmtGetFilterReply(string filterString, int64_t snum) {
1449  type = GET_FILTER; mode = POS_REPLY;
1450  if (snum != 0) seqNum = snum;
1451  fmtBase();
1452  put(filterString);
1453  paylen = next - payload;
1454 }
1455 
1460 bool CtlPkt::xtrGetFilterReply(string& filterString) {
1461  return type == GET_FILTER && mode == REQUEST
1462  && get(filterString)
1463  && paylen >= (next - payload);
1464 }
1465 
1471 void CtlPkt::fmtGetFilterSet(int filterNum, int count, int64_t snum) {
1472  type = GET_FILTER_SET; mode = REQUEST; seqNum = snum;
1473  fmtBase();
1474  put(filterNum); put(count);
1475  paylen = next - payload;
1476 }
1477 
1483 bool CtlPkt::xtrGetFilterSet(int& filterNum, int& count) {
1484  return type == GET_FILTER_SET && mode == REQUEST
1485  && get(filterNum) && get(count)
1486  && paylen >= (next - payload);
1487 }
1488 
1495 void CtlPkt::fmtGetFilterSetReply(int count, int nexti, string s,int64_t snum) {
1496  type = GET_FILTER_SET; mode = POS_REPLY;
1497  if (snum != 0) seqNum = snum;
1498  fmtBase();
1499  put(count); put(nexti); put(s);
1500  paylen = next - payload;
1501 }
1502 
1508 bool CtlPkt::xtrGetFilterSetReply(int& count, int& nexti, string& s) {
1509  return type == GET_FILTER_SET && mode == REQUEST
1510  && get(count) && get(nexti) && get(s)
1511  && paylen >= (next - payload);
1512 }
1513 
1517 void CtlPkt::fmtGetLoggedPackets(int64_t snum) {
1518  type = GET_LOGGED_PACKETS; mode = REQUEST; seqNum = snum;
1519  fmtBase();
1520 }
1521 
1526  return type == GET_LOGGED_PACKETS && mode == REQUEST
1527  && paylen >= (next - payload);
1528 }
1529 
1535 void CtlPkt::fmtGetLoggedPacketsReply(int count, string logString,
1536  int64_t snum) {
1537  type = GET_LOGGED_PACKETS; mode = POS_REPLY;
1538  if (snum != 0) seqNum = snum;
1539  fmtBase();
1540  put(count); put(logString);
1541  paylen = next - payload;
1542 }
1543 
1549 bool CtlPkt::xtrGetLoggedPacketsReply(int& count, string& logString) {
1550  return type == GET_LOGGED_PACKETS && mode == REQUEST
1551  && get(count) && get(logString)
1552  && paylen >= (next - payload);
1553 }
1554 
1560 void CtlPkt::fmtEnablePacketLog(int enable, int local, int64_t snum) {
1561  type = ENABLE_PACKET_LOG; mode = REQUEST; seqNum = snum;
1562  fmtBase();
1563  put(enable); put(local);
1564  paylen = next - payload;
1565 }
1566 
1572 bool CtlPkt::xtrEnablePacketLog(int& enable, int& local) {
1573  return type == ENABLE_PACKET_LOG && mode == REQUEST
1574  && get(enable) && get(local)
1575  && paylen >= (next - payload);
1576 }
1577 
1582  type = ENABLE_PACKET_LOG; mode = POS_REPLY;
1583  if (snum != 0) seqNum = snum;
1584  fmtBase();
1585 }
1586 
1591  return type == ENABLE_PACKET_LOG && mode == REQUEST
1592  && paylen >= (next - payload);
1593 }
1594 
1600 void CtlPkt::fmtNewSession(ipa_t clientIp, RateSpec rates, int64_t snum) {
1601  type = NEW_SESSION; mode = REQUEST; seqNum = snum;
1602  fmtBase();
1603  put(clientIp); put(rates);
1604  paylen = next - payload;
1605 }
1606 
1612 bool CtlPkt::xtrNewSession(ipa_t& clientIp, RateSpec& rates) {
1613  return type == NEW_SESSION && mode == REQUEST
1614  && get(clientIp) && get(rates)
1615  && paylen >= (next - payload);
1616 }
1617 
1626 void CtlPkt::fmtNewSessionReply(fAdr_t clientAdr, fAdr_t rtrAdr, ipa_t rtrIp, ipp_t rtrPort, uint64_t nonce, int64_t snum) {
1627  type = NEW_SESSION; mode = POS_REPLY;
1628  if (snum != 0) seqNum = snum;
1629  fmtBase();
1630  put(clientAdr); put(rtrAdr); put(rtrIp); put(rtrPort); put(nonce);
1631  paylen = next - payload;
1632 }
1633 
1646  rtrIp, ipp_t& rtrPort, uint64_t& nonce) {
1647  return type == NEW_SESSION && mode == REQUEST
1648  && get(clientAdr) && get(rtrAdr)
1649  && get(rtrIp) && get(rtrPort) && get(nonce)
1650  && paylen >= (next - payload);
1651 }
1652 
1658 void CtlPkt::fmtCancelSession(fAdr_t clientAdr, fAdr_t rtrAdr, int64_t snum) {
1659  type = CANCEL_SESSION; mode = REQUEST; seqNum = snum;
1660  fmtBase();
1661  put(clientAdr); put(rtrAdr);
1662  paylen = next - payload;
1663 }
1664 
1671  return type == CANCEL_SESSION && mode == REQUEST
1672  && get(clientAdr) && get(rtrAdr)
1673  && paylen >= (next - payload);
1674 }
1675 
1679 void CtlPkt::fmtCancelSessionReply(int64_t snum) {
1680  type = CANCEL_SESSION; mode = POS_REPLY;
1681  if (snum != 0) seqNum = snum;
1682  fmtBase();
1683 }
1684 
1689  return type == CANCEL_SESSION && mode == REQUEST
1690  && paylen >= (next - payload);
1691 }
1692 
1698 void CtlPkt::fmtClientConnect(fAdr_t clientAdr, fAdr_t rtrAdr, int64_t snum) {
1699  type = CLIENT_CONNECT; mode = REQUEST; seqNum = snum;
1700  fmtBase();
1701  put(clientAdr); put(rtrAdr);
1702  paylen = next - payload;
1703 }
1704 
1711  return type == CLIENT_CONNECT && mode == REQUEST
1712  && get(clientAdr) && get(rtrAdr)
1713  && paylen >= (next - payload);
1714 }
1715 
1719 void CtlPkt::fmtClientConnectReply(int64_t snum) {
1720  type = CLIENT_CONNECT; mode = POS_REPLY;
1721  if (snum != 0) seqNum = snum;
1722  fmtBase();
1723 }
1724 
1729  return type == CLIENT_CONNECT && mode == REQUEST
1730  && paylen >= (next - payload);
1731 }
1732 
1738 void CtlPkt::fmtClientDisconnect(fAdr_t clientAdr, fAdr_t rtrAdr, int64_t snum) {
1739  type = CLIENT_DISCONNECT; mode = REQUEST; seqNum = snum;
1740  fmtBase();
1741  put(clientAdr); put(rtrAdr);
1742  paylen = next - payload;
1743 }
1744 
1751  return type == CLIENT_DISCONNECT && mode == REQUEST
1752  && get(clientAdr) && get(rtrAdr)
1753  && paylen >= (next - payload);
1754 }
1755 
1760  type = CLIENT_DISCONNECT; mode = POS_REPLY;
1761  if (snum != 0) seqNum = snum;
1762  fmtBase();
1763 }
1764 
1769  return type == CLIENT_DISCONNECT && mode == REQUEST
1770  && paylen >= (next - payload);
1771 }
1772 
1782  ipp_t port, uint64_t nonce, int64_t snum) {
1783  type = CONFIG_LEAF; mode = REQUEST; seqNum = snum;
1784  fmtBase();
1785  put(leafAdr); put(rtrAdr); put(rtrIp); put(port); put(nonce);
1786  paylen = next - payload;
1787 }
1788 
1798  ipp_t& port, uint64_t& nonce) {
1799  return type == CONFIG_LEAF && mode == REQUEST
1800  && get(leafAdr) && get(rtrAdr) && get(rtrIp)
1801  && get(port) && get(nonce)
1802  && paylen >= (next - payload);
1803 }
1804 
1808 void CtlPkt::fmtConfigLeafReply(int64_t snum) {
1809  type = CONFIG_LEAF; mode = POS_REPLY;
1810  if (snum != 0) seqNum = snum;
1811  fmtBase();
1812 }
1813 
1818  return type == CONFIG_LEAF && mode == REQUEST
1819  && paylen >= (next - payload);
1820 }
1821 
1822 
1828 void CtlPkt::fmtSetLeafRange(fAdr_t firstAdr, fAdr_t lastAdr, int64_t snum) {
1829  type = SET_LEAF_RANGE; mode = REQUEST; seqNum = snum;
1830  fmtBase();
1831  put(firstAdr); put(lastAdr);
1832  paylen = next - payload;
1833 }
1834 
1840 bool CtlPkt::xtrSetLeafRange(fAdr_t& firstAdr, fAdr_t& lastAdr) {
1841  return type == SET_LEAF_RANGE && mode == REQUEST
1842  && get(firstAdr) && get(lastAdr)
1843  && paylen >= (next - payload);
1844 }
1845 
1849 void CtlPkt::fmtSetLeafRangeReply(int64_t snum) {
1850  type = SET_LEAF_RANGE; mode = POS_REPLY;
1851  if (snum != 0) seqNum = snum;
1852  fmtBase();
1853 }
1854 
1859  return type == SET_LEAF_RANGE && mode == REQUEST
1860  && paylen >= (next - payload);
1861 }
1862 
1866 void CtlPkt::fmtBootRouter(int64_t snum) {
1867  type = BOOT_ROUTER; mode = REQUEST; seqNum = snum;
1868  fmtBase();
1869 }
1870 
1875  return type == BOOT_ROUTER && mode == REQUEST
1876  && paylen >= (next - payload);
1877 }
1878 
1882 void CtlPkt::fmtBootRouterReply(int64_t snum) {
1883  type = BOOT_ROUTER; mode = POS_REPLY;
1884  if (snum != 0) seqNum = snum;
1885  fmtBase();
1886 }
1887 
1892  return type == BOOT_ROUTER && mode == REQUEST
1893  && paylen >= (next - payload);
1894 }
1895 
1899 void CtlPkt::fmtBootLeaf(int64_t snum) {
1900  type = BOOT_LEAF; mode = REQUEST; seqNum = snum;
1901  fmtBase();
1902 }
1903 
1908  return type == BOOT_LEAF && mode == REQUEST
1909  && paylen >= (next - payload);
1910 }
1911 
1915 void CtlPkt::fmtBootLeafReply(int64_t snum) {
1916  type = BOOT_LEAF; mode = POS_REPLY;
1917  if (snum != 0) seqNum = snum;
1918  fmtBase();
1919 }
1920 
1925  return type == BOOT_LEAF && mode == REQUEST
1926  && paylen >= (next - payload);
1927 }
1928 
1932 void CtlPkt::fmtBootComplete(int64_t snum) {
1933  type = BOOT_COMPLETE; mode = REQUEST; seqNum = snum;
1934  fmtBase();
1935 }
1936 
1941  return type == BOOT_COMPLETE && mode == REQUEST
1942  && paylen >= (next - payload);
1943 }
1944 
1948 void CtlPkt::fmtBootCompleteReply(int64_t snum) {
1949  type = BOOT_COMPLETE; mode = POS_REPLY;
1950  if (snum != 0) seqNum = snum;
1951  fmtBase();
1952 }
1953 
1958  return type == BOOT_COMPLETE && mode == REQUEST
1959  && paylen >= (next - payload);
1960 }
1961 
1965 void CtlPkt::fmtBootAbort(int64_t snum) {
1966  type = BOOT_ABORT; mode = REQUEST; seqNum = snum;
1967  fmtBase();
1968 }
1969 
1974  return type == BOOT_ABORT && mode == REQUEST
1975  && paylen >= (next - payload);
1976 }
1977 
1981 void CtlPkt::fmtBootAbortReply(int64_t snum) {
1982  type = BOOT_ABORT; mode = POS_REPLY;
1983  if (snum != 0) seqNum = snum;
1984  fmtBase();
1985 }
1986 
1991  return type == BOOT_ABORT && mode == REQUEST
1992  && paylen >= (next - payload);
1993 }
1994 
2088  string s;
2089  switch (type) {
2090  case ADD_IFACE: s = "add_iface"; break;
2091  case DROP_IFACE: s = "drop_iface"; break;
2092  case GET_IFACE: s = "get_iface"; break;
2093  case MOD_IFACE: s = "mod_iface"; break;
2094  case ADD_LINK: s = "add_link"; break;
2095  case DROP_LINK: s = "drop_link"; break;
2096  case GET_LINK: s = "get_link"; break;
2097  case GET_LINK_SET: s = "get_link_set"; break;
2098  case GET_COMTREE_SET: s = "get_comtree_set"; break;
2099  case GET_IFACE_SET: s = "get_iface_set"; break;
2100  case GET_ROUTE_SET: s = "get_route_set"; break;
2101  case MOD_LINK: s = "mod_link"; break;
2102  case ADD_COMTREE: s = "add_comtree"; break;
2103  case DROP_COMTREE: s = "drop_comtree"; break;
2104  case GET_COMTREE: s = "get_comtree"; break;
2105  case MOD_COMTREE: s = "mod_comtree"; break;
2106  case ADD_COMTREE_LINK: s = "add_comtree_link"; break;
2107  case DROP_COMTREE_LINK: s = "drop_comtree_link"; break;
2108  case MOD_COMTREE_LINK: s = "mod_comtree_link"; break;
2109  case GET_COMTREE_LINK: s = "get_comtree_link"; break;
2110  case ADD_ROUTE: s = "add_route"; break;
2111  case DROP_ROUTE: s = "drop_route"; break;
2112  case GET_ROUTE: s = "get_route"; break;
2113  case MOD_ROUTE: s = "mod_route"; break;
2114  case ADD_ROUTE_LINK: s = "add_route_link"; break;
2115  case DROP_ROUTE_LINK: s = "drop_route_link"; break;
2116 
2117  case ADD_FILTER: s = "add_filter"; break;
2118  case DROP_FILTER: s = "drop_filter"; break;
2119  case GET_FILTER: s = "get_filter"; break;
2120  case MOD_FILTER: s = "mod_filter"; break;
2121  case GET_FILTER_SET: s = "get_filter_set"; break;
2122  case GET_LOGGED_PACKETS: s = "get_logged_packets"; break;
2123  case ENABLE_PACKET_LOG: s = "enable_packet_log"; break;
2124 
2125  case NEW_SESSION: s = "new_session"; break;
2126  case CANCEL_SESSION: s = "cancel_session"; break;
2127  case CLIENT_CONNECT: s = "client_connect"; break;
2128  case CLIENT_DISCONNECT: s = "client_disconnect"; break;
2129  case CONFIG_LEAF: s = "config_leaf"; break;
2130  case SET_LEAF_RANGE: s = "set_leaf_range"; break;
2131  case BOOT_ROUTER: s = "boot_router"; break;
2132  case BOOT_LEAF: s = "boot_leaf"; break;
2133  case BOOT_COMPLETE: s = "boot_complete"; break;
2134  case BOOT_ABORT: s = "boot_abort"; break;
2135  case COMTREE_PATH: s = "comtree_path"; break;
2136  case ADD_NODE: s = "comtree_new_leaf"; break;
2137  case ADD_BRANCH: s = "comtree_add_branch"; break;
2138  case PRUNE: s = "comtree_prune"; break;
2139  default: s = "undefined"; break;
2140  }
2141  return s;
2142 }
2143 
2144 bool CtlPkt::string2cpType(string& s, CpType& type) {
2145  if (s == "undef") type = UNDEF_CPTYPE;
2146 
2147  else if (s == "add_iface") type = ADD_IFACE;
2148  else if (s == "drop_iface") type = DROP_IFACE;
2149  else if (s == "get_iface") type = GET_IFACE;
2150  else if (s == "mod_iface") type = MOD_IFACE;
2151 
2152  else if (s == "add_link") type = ADD_LINK;
2153  else if (s == "drop_link") type = DROP_LINK;
2154  else if (s == "get_link") type = GET_LINK;
2155  else if (s == "mod_link") type = MOD_LINK;
2156  else if (s == "get_link_set") type = GET_LINK_SET;
2157 
2158  else if (s == "add_comtree") type = ADD_COMTREE;
2159  else if (s == "drop_comtree") type = DROP_COMTREE;
2160  else if (s == "get_comtree") type = GET_COMTREE;
2161  else if (s == "mod_comtree") type = MOD_COMTREE;
2162 
2163  else if (s == "add_comtree_link") type = ADD_COMTREE_LINK;
2164  else if (s == "drop_comtree_link") type = DROP_COMTREE_LINK;
2165  else if (s == "get_comtree_link") type = GET_COMTREE_LINK;
2166  else if (s == "mod_comtree_link") type = MOD_COMTREE_LINK;
2167 
2168  else if (s == "add_route") type = ADD_ROUTE;
2169  else if (s == "drop_route") type = DROP_ROUTE;
2170  else if (s == "get_route") type = GET_ROUTE;
2171  else if (s == "mod_route") type = MOD_ROUTE;
2172  else if (s == "add_route_link") type = ADD_ROUTE;
2173  else if (s == "drop_route_link") type = DROP_ROUTE;
2174 
2175  else if (s == "add_filter") type = ADD_FILTER;
2176  else if (s == "drop_filter") type = DROP_FILTER;
2177  else if (s == "mod_filter") type = MOD_FILTER;
2178  else if (s == "get_filter") type = GET_FILTER;
2179  else if (s == "get_filter_set") type = GET_FILTER_SET;
2180  else if (s == "get_logged_packets") type = GET_LOGGED_PACKETS;
2181  else if (s == "enable_packet_log") type = ENABLE_PACKET_LOG;
2182 
2183  else if (s == "new_session") type = NEW_SESSION;
2184  else if (s == "cancel_session") type = CANCEL_SESSION;
2185  else if (s == "client_connect") type = CLIENT_CONNECT;
2186  else if (s == "client_disconnect") type = CLIENT_DISCONNECT;
2187 
2188  else if (s == "set_leaf_range") type = SET_LEAF_RANGE;
2189  else if (s == "config_leaf") type = CONFIG_LEAF;
2190 
2191  else if (s == "boot_router") type = BOOT_ROUTER;
2192  else if (s == "boot_complete") type = BOOT_COMPLETE;
2193  else if (s == "boot_abort") type = BOOT_ABORT;
2194  else if (s == "boot_leaf") type = BOOT_LEAF;
2195 
2196  else if (s == "comtree_path") type = COMTREE_PATH;
2197  else if (s == "comtree_new_leaf") type = ADD_NODE;
2198  else if (s == "comtree_add_branch") type = ADD_BRANCH;
2199  else if (s == "comtree_prune") type = PRUNE;
2200 
2201  else return false;
2202  return true;
2203 }
2204 
2205 string CtlPkt::cpMode2string(CpMode mode) {
2206  string s;
2207  switch (mode) {
2208  case REQUEST: s = "request"; break;
2209  case POS_REPLY: s = "pos reply"; break;
2210  case NEG_REPLY: s = "neg reply"; break;
2211  default: break;
2212  }
2213  return s;
2214 }
2215 
2216 bool CtlPkt::string2cpMode(string& s, CpMode& mode) {
2217  if (s == "undef") mode = UNDEF_MODE;
2218  else if (s == "request") mode = REQUEST;
2219  else if (s == "pos reply") mode = POS_REPLY;
2220  else if (s == "neg reply") mode = NEG_REPLY;
2221  else return false;
2222  return true;
2223 }
2224 
2229  xtrBase();
2230  stringstream ss;
2231  ss << cpType2string(type);
2232  ss << " (" << cpMode2string(mode) << "," << seqNum << "): ";
2233  if (mode == NEG_REPLY) {
2234  string s; xtrError(s);
2235  ss << s << endl;
2236  return ss.str();
2237  }
2238 
2239  int iface, lnk, coreFlag, qid, fltr, count, enable, local;
2240  comt_t comt; RateSpec rs1, rs2;
2241  ipa_t ip1; ipp_t port1;
2242  fAdr_t adr1, adr2;
2243  uint64_t nonce;
2244  Forest::ntyp_t ntyp;
2245  string s;
2246 
2247  switch (type) {
2248  case ADD_IFACE:
2249  if (mode == REQUEST) {
2250  xtrAddIface(iface,ip1,rs1);
2251  ss << " " << iface;
2252  ss << " " << Np4d::ip2string(ip1);
2253  ss << " " << rs1.toString();
2254  } else {
2255  xtrAddIfaceReply(ip1,port1);
2256  ss << " " << Np4d::ip2string(ip1);
2257  ss << " " << port1;
2258  }
2259  break;
2260  case DROP_IFACE:
2261  if (mode == REQUEST) {
2262  xtrDropIface(iface);
2263  ss << " " << iface;
2264  }
2265  break;
2266  case GET_IFACE:
2267  if (mode == REQUEST) {
2268  xtrGetIface(iface);
2269  ss << " " << iface;
2270  } else {
2271  xtrGetIfaceReply(iface,ip1,port1,rs1,rs2);
2272  ss << " " << iface;
2273  ss << " " << Np4d::ip2string(ip1) << " " << port1;
2274  ss << " " << rs1.toString();
2275  ss << " " << rs2.toString();
2276  }
2277  break;
2278  case MOD_IFACE:
2279  if (mode == REQUEST) {
2280  xtrModIface(iface,rs1);
2281  ss << " " << iface;
2282  ss << " " << rs1.toString();
2283  }
2284  break;
2285  case ADD_LINK:
2286  if (mode == REQUEST) {
2287  xtrAddLink(ntyp,iface,lnk,ip1,port1,adr1,nonce);
2288  ss << " " << iface;
2289  ss << " " << lnk;
2290  ss << " " << Forest::nodeType2string(ntyp);
2291  ss << " " << Np4d::ip2string(ip1);
2292  ss << " " << port1;
2293  ss << " " << Forest::fAdr2string(adr1);
2294  ss << " " << nonce;
2295  } else {
2296  xtrAddLinkReply(lnk,adr1);
2297  ss << " " << lnk;
2298  ss << " " << Forest::fAdr2string(adr1);
2299  }
2300  break;
2301  case DROP_LINK:
2302  if (mode == REQUEST) {
2303  xtrDropLink(lnk,adr1);
2304  if (link != 0) ss << " " << lnk;
2305  if (adr1 != 0) ss << " " << Forest::fAdr2string(adr1);
2306  }
2307  break;
2308  case GET_LINK:
2309  if (mode == REQUEST) {
2310  xtrGetLink(lnk);
2311  ss << " " << lnk;
2312  } else {
2313  xtrGetLinkReply(lnk,iface,ntyp,ip1,port1,adr1,rs1,rs2);
2314  ss << " " << lnk;
2315  ss << " " << iface;
2316  ss << " " << Forest::nodeType2string(ntyp);
2317  ss << " " << Np4d::ip2string(ip1);
2318  ss << " " << port1;
2319  ss << " " << Forest::fAdr2string(adr1);
2320  ss << " " << rs1.toString();
2321  ss << " " << rs2.toString();
2322  }
2323  break;
2324  case GET_LINK_SET:
2325  if (mode == REQUEST) {
2326  xtrGetLinkSet(lnk,count);
2327  ss << " " << lnk << " " << count;
2328  } else {
2329  xtrGetLinkSetReply(count,lnk,s);
2330  ss << " " << count << " " << lnk << " " << s;
2331  }
2332  break;
2333  case GET_COMTREE_SET:
2334  if (mode == REQUEST) {
2335  xtrGetComtreeSet(comt,count);
2336  ss << " " << comt << " " << count;
2337  } else {
2338  xtrGetComtreeSetReply(count,comt,s);
2339  ss << " " << count << " " << comt << " " << s;
2340  }
2341  break;
2342  case GET_IFACE_SET:
2343  if (mode == REQUEST) {
2344  xtrGetIfaceSet(lnk,count);
2345  ss << " " << lnk << " " << count;
2346  } else {
2347  xtrGetIfaceSetReply(count,lnk,s);
2348  ss << " " << count << " " << lnk << " " << s;
2349  }
2350  break;
2351  case GET_ROUTE_SET:
2352  if (mode == REQUEST) {
2353  xtrGetRouteSet(lnk,count);
2354  ss << " " << lnk << " " << count;
2355  } else {
2356  xtrGetRouteSetReply(count,lnk,s);
2357  ss << " " << count << " " << lnk << " " << s;
2358  }
2359  break;
2360  case MOD_LINK:
2361  if (mode == REQUEST) {
2362  xtrModLink(lnk,rs1);
2363  ss << " " << lnk;
2364  ss << " " << rs1.toString();
2365  }
2366  break;
2367  case ADD_COMTREE:
2368  if (mode == REQUEST) {
2369  xtrAddComtree(comt);
2370  ss << " " << comt;
2371  }
2372  break;
2373  case DROP_COMTREE:
2374  if (mode == REQUEST) {
2375  xtrDropComtree(comt);
2376  ss << " " << comt;
2377  } else
2378  xtrDropComtreeReply(rs1);
2379  rs1.toString();
2380  break;
2381  case GET_COMTREE:
2382  if (mode == REQUEST) {
2383  xtrGetComtree(comt);
2384  ss << " " << comt;
2385  } else {
2386  xtrGetComtreeReply(comt,coreFlag,lnk,count);
2387  ss << " " << comt;
2388  ss << " " << (coreFlag ? "inCore" : "notInCore");
2389  ss << " " << lnk;
2390  ss << " " << count;
2391  }
2392  break;
2393  case MOD_COMTREE:
2394  if (mode == REQUEST) {
2395  xtrModComtree(comt,coreFlag,lnk);
2396  ss << " " << comt;
2397  ss << " " << (coreFlag ? "inCore" : "notInCore");
2398  ss << " " << lnk;
2399  }
2400  break;
2401  case ADD_COMTREE_LINK:
2402  if (mode == REQUEST) {
2403  xtrAddComtreeLink(comt,lnk,coreFlag,ip1,port1,adr1);
2404  ss << " " << comt;
2405  ss << " " << lnk;
2406  ss << " " << (coreFlag ? "inCore" : "notInCore");
2407  ss << " " << Np4d::ip2string(ip1);
2408  ss << " " << port1;
2409  ss << " " << Forest::fAdr2string(adr1);
2410  } else {
2411  xtrAddComtreeLinkReply(lnk,rs1);
2412  ss << " " << lnk;
2413  ss << " " << rs1.toString();
2414  }
2415  break;
2416  case DROP_COMTREE_LINK:
2417  if (mode == REQUEST) {
2418  xtrDropComtreeLink(comt,lnk,ip1,port1,adr1);
2419  ss << " " << comt;
2420  ss << " " << lnk;
2421  ss << " " << Np4d::ip2string(ip1);
2422  ss << " " << port1;
2423  ss << " " << Forest::fAdr2string(adr1);
2424  } else
2426  ss << " " << rs1.toString();
2427  break;
2428  case MOD_COMTREE_LINK:
2429  if (mode == REQUEST) {
2430  xtrModComtreeLink(comt,lnk,rs1);
2431  ss << " " << comt;
2432  ss << " " << lnk;
2433  ss << " " << rs1.toString();
2434  } else
2436  ss << " " << rs1.toString();
2437  break;
2438  case GET_COMTREE_LINK:
2439  if (mode == REQUEST) {
2440  xtrGetComtreeLink(comt,lnk);
2441  ss << " " << comt;
2442  ss << " " << lnk;
2443  } else {
2444  xtrGetComtreeLinkReply(comt,lnk,rs1,qid,adr1);
2445  ss << " " << comt;
2446  ss << " " << lnk;
2447  ss << " " << rs1.toString();
2448  ss << " " << qid;
2449  ss << " " << Forest::fAdr2string(adr1);
2450  }
2451  break;
2452  case ADD_ROUTE:
2453  if (mode == REQUEST) {
2454  xtrAddRoute(comt,adr1,lnk);
2455  ss << " " << comt;
2456  ss << " " << Forest::fAdr2string(adr1);
2457  ss << " " << lnk;
2458  }
2459  break;
2460  case DROP_ROUTE:
2461  if (mode == REQUEST) {
2462  xtrDropRoute(comt,adr1);
2463  ss << " " << comt;
2464  ss << " " << Forest::fAdr2string(adr1);
2465  }
2466  break;
2467  case GET_ROUTE:
2468  if (mode == REQUEST) {
2469  xtrGetRoute(comt,adr1);
2470  ss << " " << comt;
2471  ss << " " << Forest::fAdr2string(adr1);
2472  } else {
2473  xtrGetRouteReply(comt,adr1,lnk);
2474  ss << " " << comt;
2475  ss << " " << Forest::fAdr2string(adr1);
2476  ss << " " << lnk;
2477  }
2478  break;
2479  case MOD_ROUTE:
2480  if (mode == REQUEST) {
2481  xtrModRoute(comt,adr1,lnk);
2482  ss << " " << comt;
2483  ss << " " << Forest::fAdr2string(adr1);
2484  ss << " " << lnk;
2485  }
2486  break;
2487  case ADD_ROUTE_LINK:
2488  if (mode == REQUEST) {
2489  xtrAddRouteLink(comt,adr1,lnk);
2490  ss << " " << comt;
2491  ss << " " << Forest::fAdr2string(adr1);
2492  ss << " " << lnk;
2493  }
2494  break;
2495  case DROP_ROUTE_LINK:
2496  if (mode == REQUEST) {
2497  xtrDropRouteLink(comt,adr1,lnk);
2498  ss << " " << comt;
2499  ss << " " << Forest::fAdr2string(adr1);
2500  ss << " " << lnk;
2501  }
2502  break;
2503 
2504  case ADD_FILTER:
2505  if (mode == POS_REPLY) {
2506  xtrAddFilterReply(fltr);
2507  ss << " " << fltr;
2508  }
2509  break;
2510  case DROP_FILTER:
2511  if (mode == REQUEST) {
2512  xtrDropFilter(fltr);
2513  ss << " " << fltr;
2514  }
2515  break;
2516  case MOD_FILTER:
2517  if (mode == REQUEST) {
2518  xtrModFilter(fltr,s);
2519  ss << " " << fltr;
2520  ss << " " << s;
2521  }
2522  break;
2523  case GET_FILTER:
2524  if (mode == REQUEST) {
2525  xtrGetFilter(fltr);
2526  ss << " " << fltr;
2527  } else {
2528  xtrGetFilterReply(s);
2529  ss << " " << s;
2530  }
2531  break;
2532  case GET_FILTER_SET:
2533  if (mode == REQUEST) {
2534  xtrGetFilterSet(fltr,count);
2535  ss << " " << fltr;
2536  ss << " " << count;
2537  } else {
2538  xtrGetFilterSetReply(fltr,count,s);
2539  ss << " " << fltr;
2540  ss << " " << count;
2541  ss << " " << s;
2542  }
2543  break;
2544  case GET_LOGGED_PACKETS:
2545  if (mode == POS_REPLY) {
2546  xtrGetLoggedPacketsReply(count,s);
2547  ss << " " << count << " " << s;
2548  }
2549  break;
2550  case ENABLE_PACKET_LOG:
2551  if (mode == REQUEST) {
2552  xtrEnablePacketLog(enable,local);
2553  ss << " " << (enable ? "on" : "off");
2554  ss << " " << (local ? "local" : "remote");
2555  }
2556  break;
2557 
2558  case NEW_SESSION:
2559  if (mode == REQUEST) {
2560  xtrNewSession(ip1,rs1);
2561  ss << " " << Np4d::ip2string(ip1);
2562  ss << " " << rs1.toString();
2563  } else {
2564  xtrNewSessionReply(adr1,adr2,ip1,port1,nonce);
2565  ss << " " << Forest::fAdr2string(adr1);
2566  ss << " " << Forest::fAdr2string(adr2);
2567  ss << " " << Np4d::ip2string(ip1);
2568  ss << " " << port1;
2569  ss << " " << nonce;
2570  }
2571  break;
2572  case CANCEL_SESSION:
2573  if (mode == REQUEST) {
2574  xtrCancelSession(adr1,adr2);
2575  ss << " " << Forest::fAdr2string(adr1);
2576  ss << " " << Forest::fAdr2string(adr2);
2577  }
2578  break;
2579  case CLIENT_CONNECT:
2580  if (mode == REQUEST) {
2581  xtrClientConnect(adr1,adr2);
2582  ss << " " << Forest::fAdr2string(adr1);
2583  ss << " " << Forest::fAdr2string(adr2);
2584  }
2585  break;
2586  case CLIENT_DISCONNECT:
2587  if (mode == REQUEST) {
2588  xtrClientDisconnect(adr1,adr2);
2589  ss << " " << Forest::fAdr2string(adr1);
2590  ss << " " << Forest::fAdr2string(adr2);
2591  }
2592  break;
2593  case CONFIG_LEAF:
2594  if (mode == REQUEST) {
2595  xtrConfigLeaf(adr1,adr2,ip1,port1,nonce);
2596  ss << " " << Forest::fAdr2string(adr1);
2597  ss << " " << Forest::fAdr2string(adr2);
2598  ss << " " << Np4d::ip2string(ip1);
2599  ss << " " << port1;
2600  ss << " " << nonce;
2601  }
2602  break;
2603  case SET_LEAF_RANGE:
2604  if (mode == REQUEST) {
2605  xtrSetLeafRange(adr1,adr2);
2606  ss << " " << Forest::fAdr2string(adr1);
2607  ss << " " << Forest::fAdr2string(adr2);
2608  }
2609  break;
2610  case BOOT_ROUTER:
2611  case BOOT_LEAF:
2612  case BOOT_COMPLETE:
2613  case BOOT_ABORT:
2614  break;
2615 
2616 /*
2617  case COMTREE_PATH:
2618  if (mode == REQUEST) {
2619  ss << " " << comt;
2620  ss << " " << Forest::fAdr2string(adr1);
2621  } else {
2622  ss << " " << rs1.toString();
2623  ss << " " << rs2.toString();
2624  ss << " " << avPair2string(INTVEC);
2625  }
2626  break;
2627 
2628  case ADD_NODE:
2629  if (mode == REQUEST) {
2630  ss << " " << comt;
2631  ss << " " << Forest::fAdr2string(adr1);
2632  ss << " " << lnk;
2633  ss << " " << Forest::fAdr2string(adr2);
2634  ss << " " << rs1.toString();
2635  ss << " " << rs2.toString();
2636  ss << " " << avPair2string(INTVEC);
2637  }
2638  break;
2639 
2640  case ADD_BRANCH:
2641  if (mode == REQUEST) {
2642  ss << " " << avPair2string(INTVEC);
2643  ss << " " << avPair2string(INDEX1);
2644  ss << " " << rs1.toString();
2645  ss << " " << rs2.toString();
2646  } else if (mode == POS_REPLY) {
2647  ss << " " << Forest::fAdr2string(adr1);
2648  }
2649  break;
2650 
2651  case PRUNE:
2652  if (mode == REQUEST) {
2653  ss << " " << comt;
2654  ss << " " << Forest::fAdr2string(adr1);
2655  }
2656  break;
2657 */
2658 
2659  default: break;
2660  }
2661  ss << endl;
2662  return ss.str();
2663 }
2664 
2665 } // ends namespace
2666