forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
CtlPktX.cpp
1 
23 #include "CtlPkt.h"
24 
25 namespace forest {
26 
29 CtlPkt::CtlPkt() { reset(); }
30 
34 CtlPkt::CtlPkt(const Packet& p) { reset(p); }
35 
42 CtlPkt::CtlPkt(uint32_t* payload1, int len) {
43  reset(payload1,len);
44 }
45 
52 CtlPkt::CtlPkt(CpType type1, CpMode mode1, uint64_t seqNum1,
53  uint32_t* payload1) {
54  reset(type1, mode1, seqNum1, payload1);
55 }
56 
57 CtlPkt::CtlPkt(CpType type1, CpMode mode1, uint64_t seqNum1) {
58  reset(type1, mode1, seqNum1);
59 }
60 
62 CtlPkt::~CtlPkt() { }
63 
70 void CtlPkt::reset(CpType type1, CpMode mode1, uint64_t seqNum1,
71  uint32_t* payload1) {
72  reset();
73  type = type1; mode = mode1; seqNum = seqNum1;
74  payload = payload1;
75 }
76 
77 void CtlPkt::reset(CpType type1, CpMode mode1, uint64_t seqNum1) {
78  reset();
79  type = type1; mode = mode1; seqNum = seqNum1;
80 }
81 
88 void CtlPkt::reset(uint32_t* payload1, int len) {
89  reset(); payload = payload1; paylen = len;
90 }
91 
96 void CtlPkt::reset(const Packet& p) {
97  reset();
98  payload = p.payload(); paylen = p.length-Forest::OVERHEAD; unpack();
99 }
100 
101 void CtlPkt::reset() {
102  // initialize all fields to undefined values
103  type = UNDEF_CPTYPE; mode = UNDEF_MODE; seqNum = 0;
104  adr1 = adr2 = adr3 = 0;
105  ip1 = 0; ip2 = 0;
106  port1 = 0; port2 = 0;
107  nonce = 0;
108  rspec1.set(-1); rspec2.set(-1);
109  coreFlag = -1;
110  iface = 0; link = 0;
111  nodeType = Forest::UNDEF_NODE;
112  comtree = 0; comtreeOwner = 0;
113  index1 = -1; index2 = -1;
114  count = -1;
115  queue = 0;
116  zipCode = 0;
117  errMsg.clear();
118  stringData.clear();
119  ivec.clear();
120  payload = 0; paylen = 0;
121 }
122 
123 #define packWord(x) {payload[pp++] = htonl(x);}
124 #define packInt32(x,y) {packWord(((x) << 16) | 4); packWord(y);}
125 #define packNonce(x,y) {packWord((x) << 16 | 8); \
126  packWord(((int) (((y)>>32)&0xffffffff))); \
127  packWord((int) ((y)&0xffffffff)); }
128 #define packRspec(x,y) {packWord(x); \
129  packWord(y.bitRateUp); packWord(y.bitRateDown); \
130  packWord(y.pktRateUp); packWord(y.pktRateDown); \
131  }
132 #define packString() { int len = min<int>(stringData.length(), 1300); \
133  packWord(STRING << 16 | len); \
134  stringData.copy((char *) &payload[pp],len); \
135  pp += (len+3)/4; }
136 
141 int CtlPkt::pack() {
142  if (payload == 0) return 0;
143 
144  int pp = 0;
145  payload[pp++] = htonl(type);
146  payload[pp++] = htonl(mode);
147  payload[pp++] = htonl((uint32_t) (seqNum >> 32));
148  payload[pp++] = htonl((uint32_t) (seqNum & 0xffffffff));
149 
150  if (mode == NEG_REPLY) {
151  int len = errMsg.length();
152  if (len > 0) {
153  len = min<int>(len,MAX_STRING);
154  payload[pp++] = htonl(ERRMSG);
155  payload[pp++] = htonl(len);
156  errMsg.copy((char*) &payload[pp], len);
157  }
158  paylen = 4*(pp + (len+3)/4);
159  return paylen;
160  }
161 
162  switch (type) {
163  case ADD_IFACE:
164  if (mode == REQUEST) {
165  if (iface == 0 || ip1 == 0 || !rspec1.isSet())
166  return 0;
167  packInt32(IFACE,iface);
168  packInt32(IP1,ip1);
169  packRspec(RSPEC1,rspec1);
170  } else {
171  if (ip1 == 0 || port1 == 0) return 0;
172  packInt32(IP1,ip1);
173  packInt32(PORT1,port1);
174  }
175  break;
176  case DROP_IFACE:
177  if (mode == REQUEST) {
178  if (iface == 0) return 0;
179  packInt32(IFACE,iface);
180  }
181  break;
182  case GET_IFACE:
183  if (mode == REQUEST) {
184  if (iface == 0) return 0;
185  packInt32(IFACE,iface);
186  } else {
187  if (iface == 0 || ip1 == 0 ||
188  !rspec1.isSet() || !rspec2.isSet())
189  return 0;
190  packInt32(IFACE,iface);
191  packInt32(IP1,ip1);
192  packInt32(PORT1,port1);
193  packRspec(RSPEC1,rspec1);
194  packRspec(RSPEC2,rspec2);
195  }
196  break;
197  case MOD_IFACE:
198  if (mode == REQUEST) {
199  if (iface == 0 || !rspec1.isSet())
200  return 0;
201  packInt32(IFACE,iface);
202  packRspec(RSPEC1,rspec1);
203  }
204  break;
205  case ADD_LINK:
206  if (mode == REQUEST) {
207  if (nodeType == 0 || iface == 0) return 0;
208  packInt32(NODE_TYPE,nodeType);
209  packInt32(IFACE,iface);
210  if (link != 0) packInt32(LINK,link);
211  if (ip1 != 0) packInt32(IP1,ip1);
212  if (port1 != 0) packInt32(PORT1,port1);
213  if (adr1 != 0) packInt32(ADR1,adr1);
214  if (nonce != 0) packNonce(NONCE,nonce);
215  } else {
216  if (link != 0) packInt32(LINK,link);
217  if (adr1 != 0) packInt32(ADR1,adr1);
218  }
219  break;
220  case DROP_LINK:
221  if (mode == REQUEST) {
222  if (link == 0 && adr1 == 0) return 0;
223  if (link != 0) packInt32(LINK,link);
224  if (adr1 != 0) packInt32(ADR1,adr1);
225  }
226  break;
227  case GET_LINK:
228  if (mode == REQUEST) {
229  if (link == 0) return 0;
230  packInt32(LINK,link);
231  } else {
232  if (link == 0 || iface == 0 || nodeType == 0 ||
233  ip1 == 0 || port1 == 0 || adr1 == 0 ||
234  !rspec1.isSet() || !rspec2.isSet())
235  return 0;
236  packInt32(LINK,link);
237  packInt32(IFACE,iface);
238  packInt32(NODE_TYPE,nodeType);
239  packInt32(IP1,ip1);
240  packInt32(PORT1,port1);
241  packInt32(ADR1,adr1);
242  packRspec(RSPEC1,rspec1);
243  packRspec(RSPEC2,rspec2);
244  packInt32(COUNT,count);
245  }
246  break;
247  case GET_LINK_SET:
248  if (mode == REQUEST) {
249  if (index1 == -1 || count == -1) return 0;
250  packInt32(INDEX1,index1);
251  packInt32(COUNT,count);
252  } else {
253  if (index1 == -1 || index2 == -1 || count == -1)
254  return 0;
255  packInt32(INDEX1,index1);
256  packInt32(INDEX2,index2);
257  packInt32(COUNT,count);
258  packString();
259  }
260  break;
261  case GET_COMTREE_SET:
262  if (mode == REQUEST) {
263  if (index1 == -1 || count == -1) return 0;
264  packInt32(INDEX1,index1);
265  packInt32(COUNT,count);
266  } else {
267  if (index1 == -1 || index2 == -1 || count == -1)
268  return 0;
269  packInt32(INDEX1,index1);
270  packInt32(INDEX2,index2);
271  packInt32(COUNT,count);
272  packString();
273  }
274  break;
275  case GET_IFACE_SET:
276  if (mode == REQUEST) {
277  if (index1 == -1 || count == -1) return 0;
278  packInt32(INDEX1,index1);
279  packInt32(COUNT,count);
280  } else {
281  if (index1 == -1 || index2 == -1 || count == -1)
282  return 0;
283  packInt32(INDEX1,index1);
284  packInt32(INDEX2,index2);
285  packInt32(COUNT,count);
286  packString();
287  }
288  break;
289  case GET_ROUTE_SET:
290  if (mode == REQUEST) {
291  if (index1 == -1 || count == -1) return 0;
292  packInt32(INDEX1,index1);
293  packInt32(COUNT,count);
294  } else {
295  if (index1 == -1 || index2 == -1 || count == -1)
296  return 0;
297  packInt32(INDEX1,index1);
298  packInt32(INDEX2,index2);
299  packInt32(COUNT,count);
300  packString();
301  }
302  break;
303  case MOD_LINK:
304  if (mode == REQUEST) {
305  if (link == 0 || !rspec1.isSet()) return 0;
306  packInt32(LINK,link);
307  packRspec(RSPEC1,rspec1);
308  }
309  break;
310  case ADD_COMTREE:
311  if (mode == REQUEST) {
312  if (comtree == 0) return 0;
313  packInt32(COMTREE,comtree);
314  }
315  break;
316  case DROP_COMTREE:
317  if (mode == REQUEST) {
318  if (comtree == 0) return 0;
319  packInt32(COMTREE,comtree);
320  }
321  break;
322  case GET_COMTREE:
323  if (mode == REQUEST) {
324  if (comtree == 0) return 0;
325  packInt32(COMTREE,comtree);
326  } else {
327  if (comtree == 0 || coreFlag == -1 ||
328  link == 0 || count == -1)
329  return 0;
330  packInt32(COMTREE,comtree);
331  packInt32(CORE_FLAG,coreFlag);
332  packInt32(LINK,link);
333  packInt32(count,count);
334  }
335  break;
336  case MOD_COMTREE:
337  if (mode == REQUEST) {
338  if (comtree == 0) return 0;
339  packInt32(COMTREE,comtree);
340  if (coreFlag != -1) packInt32(CORE_FLAG,coreFlag);
341  if (link != 0) packInt32(LINK,link);
342  }
343  break;
344  case ADD_COMTREE_LINK:
345  if (mode == REQUEST) {
346  if (comtree == 0) return 0;
347  packInt32(COMTREE,comtree);
348  if (link != 0) packInt32(LINK,link);
349  if (coreFlag != -1) packInt32(CORE_FLAG,coreFlag);
350  if (ip1 != 0) packInt32(IP1,ip1);
351  if (port1 != 0) packInt32(PORT1,port1);
352  if (adr1 != 0) packInt32(ADR1,adr1);
353  } else {
354  if (link == 0) return 0;
355  packInt32(LINK,link);
356  if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
357  }
358  break;
359  case DROP_COMTREE_LINK:
360  if (mode == REQUEST) {
361  if (comtree == 0) return 0;
362  packInt32(COMTREE,comtree);
363  if (link != 0) packInt32(LINK,link);
364  if (ip1 != 0) packInt32(IP1,ip1);
365  if (port1 != 0) packInt32(PORT1,port1);
366  if (adr1 != 0) packInt32(ADR1,adr1);
367  } else
368  if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
369  break;
370  case MOD_COMTREE_LINK:
371  if (mode == REQUEST) {
372  if (comtree == 0 || link == 0) return 0;
373  packInt32(COMTREE,comtree);
374  packInt32(LINK,link);
375  if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
376  } else
377  if (rspec1.isSet()) packRspec(RSPEC1,rspec1);
378  break;
379  case GET_COMTREE_LINK:
380  if (mode == REQUEST) {
381  if (comtree == 0 || link == 0) return 0;
382  packInt32(COMTREE,comtree);
383  packInt32(LINK,link);
384  } else {
385  if (comtree == 0 || link == 0 ||
386  !rspec1.isSet() || queue == 0 || adr1 == 0)
387  return 0;
388  packInt32(COMTREE,comtree);
389  packInt32(LINK,link);
390  packRspec(RSPEC1,rspec1);
391  packInt32(QUEUE,queue);
392  packInt32(ADR1,adr1);
393  }
394  break;
395  case ADD_ROUTE:
396  if (mode == REQUEST) {
397  if (comtree == 0 || adr1 == 0 || link == 0) return 0;
398  packInt32(COMTREE,comtree);
399  packInt32(ADR1,adr1);
400  packInt32(LINK,link);
401  if (queue != 0) packInt32(QUEUE,queue);
402  }
403  break;
404  case DROP_ROUTE:
405  if (mode == REQUEST) {
406  if (comtree == 0 || adr1 == 0) return 0;
407  packInt32(COMTREE,comtree);
408  packInt32(ADR1,adr1);
409  }
410  break;
411  case GET_ROUTE:
412  if (mode == REQUEST) {
413  if (comtree == 0 || adr1 == 0) return 0;
414  packInt32(COMTREE,comtree);
415  packInt32(ADR1,adr1);
416  } else {
417  if (comtree == 0 || adr1 == 0 || link == 0)
418  return 0;
419  packInt32(COMTREE,comtree);
420  packInt32(ADR1,adr1);
421  packInt32(LINK,link);
422  }
423  break;
424  case MOD_ROUTE:
425  if (mode == REQUEST) {
426  if (comtree == 0 || adr1 == 0) return 0;
427  packInt32(COMTREE,comtree);
428  packInt32(ADR1,adr1);
429  if (link != 0) packInt32(LINK,link);
430  if (queue != 0) packInt32(QUEUE,queue);
431  }
432  break;
433  case ADD_ROUTE_LINK:
434  if (mode == REQUEST) {
435  if (comtree == 0 || adr1 == 0 || link == 0) return 0;
436  packInt32(COMTREE,comtree);
437  packInt32(ADR1,adr1);
438  packInt32(LINK,link);
439  }
440  break;
441  case DROP_ROUTE_LINK:
442  if (mode == REQUEST) {
443  if (comtree == 0 || adr1 == 0 || link == 0) return 0;
444  packInt32(COMTREE,comtree);
445  packInt32(ADR1,adr1);
446  packInt32(LINK,link);
447  }
448  break;
449 
450  case ADD_FILTER:
451  if (mode == POS_REPLY && index1 == -1)
452  return false;
453  packInt32(INDEX1,index1);
454  break;
455  case DROP_FILTER:
456  if (mode == REQUEST && index1 == -1)
457  return false;
458  packInt32(INDEX1,index1);
459  break;
460 
461  case GET_FILTER:
462  if (mode == REQUEST) {
463  if (index1 == -1) return false;
464  packInt32(INDEX1,index1);
465  } else if (mode == POS_REPLY) {
466  if (stringData.length() == 0) return false;
467  packString();
468  }
469  break;
470  case MOD_FILTER:
471  if (mode == REQUEST) {
472  if (index1 == -1 || stringData.length() == 0)
473  return false;
474  packInt32(INDEX1,index1);
475  packString();
476  }
477  break;
478  case GET_FILTER_SET:
479  if (mode == REQUEST) {
480  if (index1 == -1 || count == -1) return false;
481  packInt32(INDEX1,index1);
482  packInt32(COUNT,count);
483  } else if (mode == POS_REPLY) {
484  if (index1 == -1 || index2 == -1 || count == -1 ||
485  (count > 0 && stringData.length() == 0))
486  return false;
487  packInt32(INDEX1,index1);
488  packInt32(INDEX2,index2);
489  packInt32(COUNT,count);
490  if (count > 0) packString();
491  }
492  break;
493  case GET_LOGGED_PACKETS:
494  if (mode == POS_REPLY) {
495  if (count == -1 ||
496  (count > 0 && stringData.length() == 0))
497  return false;
498  packInt32(COUNT,count);
499  if (count > 0) packString();
500  }
501  break;
502  case ENABLE_PACKET_LOG:
503  if (mode == REQUEST && (index1 == -1 || index2 == -1))
504  return false;
505  packInt32(INDEX1,index1);
506  packInt32(INDEX2,index2);
507  break;
508 
509  case NEW_SESSION:
510  if (mode == REQUEST) {
511  if (ip1 == 0 || !rspec1.isSet()) return 0;
512  packInt32(IP1,ip1);
513  packRspec(RSPEC1,rspec1);
514  } else {
515  if (adr1 == 0 || adr2 == 0 || adr3 == 0 ||
516  ip1 == 0 || nonce == 0)
517  return 0;
518  packInt32(ADR1,adr1);
519  packInt32(ADR2,adr2);
520  packInt32(ADR3,adr3);
521  packInt32(IP1,ip1);
522  packInt32(PORT1,port1);
523  packNonce(NONCE,nonce);
524  }
525  break;
526  case CANCEL_SESSION:
527  if (mode == REQUEST) {
528  if (adr1 == 0 || adr2 == 0) return 0;
529  packInt32(ADR1,adr1); packInt32(ADR2,adr2);
530  }
531  case CLIENT_CONNECT:
532  if (mode == REQUEST) {
533  if (adr1 == 0 || adr2 == 0) return 0;
534  packInt32(ADR1,adr1);
535  packInt32(ADR2,adr2);
536  }
537  break;
538  case CLIENT_DISCONNECT:
539  if (mode == REQUEST) {
540  if (adr1 == 0 || adr2 == 0) return 0;
541  packInt32(ADR1,adr1);
542  packInt32(ADR2,adr2);
543  }
544  break;
545  case CONFIG_LEAF:
546  if (mode == REQUEST) {
547  if (adr1 == 0 || adr2 == 0 || ip1 == 0 ||
548  port1 == 0 || nonce == 0) return 0;
549  packInt32(ADR1,adr1); packInt32(ADR2,adr2);
550  packInt32(IP1,ip1); packInt32(PORT1,port1);
551  packNonce(NONCE,nonce);
552  }
553  break;
554  case SET_LEAF_RANGE:
555  if (mode == REQUEST) {
556  if (adr1 == 0 || adr2 == 0) return 0;
557  packInt32(ADR1,adr1); packInt32(ADR2,adr2);
558  }
559  break;
560  case BOOT_ROUTER:
561  case BOOT_LEAF:
562  case BOOT_COMPLETE:
563  case BOOT_ABORT:
564  break;
565 
566  case COMTREE_PATH:
567  if (mode == REQUEST) {
568  // request contains address of client and
569  // the number of the comtree we want to join
570  if (adr1 == 0 || comtree == 0) return 0;
571  packInt32(ADR1,adr1); packInt32(COMTREE, comtree);
572  } else {
573  // reply contains a vector of local link numbers
574  // that define a path from the new leaf router
575  // to the root of the comtree
576  // it also contains two rate specs;
577  // the first is to be used for new backbone links,
578  // the second is an upper bound on the access link rate
579  if (!rspec1.isSet() || !rspec2.isSet())
580  return 0;
581  packRspec(RSPEC1,rspec1);
582  packRspec(RSPEC2,rspec2);
583  packWord(INTVEC);
584  int len = ivec.size();
585  if (len > 50) return 0;
586  packWord(len);
587  for (int i = 0; i < len; i++)
588  packWord(ivec[i]);
589  }
590  break;
591 
592  case ADD_NODE:
593  if (mode == REQUEST) {
594  // Sent by router to inform ComtCtl of new leaf.
595  // This is typically sent to the ComtCtl after the
596  // successful completion of a NEW_BRANCH operation.
597  // Contains address and link number of new leaf,
598  // ratespec for comtree on access link, comtree number
599  // and path to the comtree root used when adding
600  // the branch. This is represented by a vector of
601  // local link numbers at the new routers along the
602  // path. The vector may have zero length, but must
603  // be present. The packet also contains the address
604  // of the first router on the path that was already
605  // in the comtree when the new branch was added.
606  // Also contains a second rspec which represents
607  // the rates reserved on the path added to the comtree
608  if (adr1 == 0 || link == 0 || adr2 == 0 ||
609  comtree == 0 || !rspec1.isSet() || !rspec2.isSet())
610  return 0;
611  packInt32(COMTREE,comtree);
612  packInt32(ADR1,adr1);
613  packInt32(ADR2,adr2);
614  packInt32(LINK,link);
615  packRspec(RSPEC1,rspec1);
616  packRspec(RSPEC2,rspec2);
617  packWord(INTVEC);
618  int len = ivec.size();
619  if (len > 50) return 0;
620  packWord(len);
621  for (int i = 0; i < len; i++) packWord(ivec[i]);
622  }
623  break;
624 
625  case ADD_BRANCH:
626  if (mode == REQUEST) {
627  // Sent by router to the next one up the new branch
628  // being added. Contains an ivec containing the link
629  // numbers that define the path from the leaf
630  // router to the root, along with an index that
631  // identifies the position in the ivec of the
632  // next router in the path. Also contains an
633  // rspec to be used for the links on the path,
634  // and a second RSPEC that represents the default
635  // for new leaf nodes.
636  if (index1 == 0 || !rspec1.isSet()) return 0;
637  packWord(INTVEC);
638  int len = ivec.size();
639  if (len > 50) return 0;
640  packWord(len);
641  for (int i = 0; i < len; i++) packWord(ivec[i]);
642  packInt32(INDEX1,index1);
643  packRspec(RSPEC1,rspec1);
644  if (rspec2.isSet()) packRspec(RSPEC2,rspec2);
645  } else {
646  // Reply contains address of "branch router",
647  // that is, the first router on the branch path
648  // that was already in the comtree.
649  if (adr1 == 0) return 0;
650  packInt32(ADR1,adr1);
651  }
652  break;
653  case PRUNE:
654  if (mode == REQUEST) {
655  // Sent by router to ComtCtl to inform it when
656  // a node has left the comtree. There are two
657  // cases. When a client leaves, the access router
658  // sends a prune message containing the forest
659  // address of the leaf that is dropping out.
660  // When a router leaves the comtree, it
661  // sends a message with its own address.
662  // This can also be used by a router to inform
663  // its parent that it is leaving the comtree.
664  if (adr1 == 0 || comtree == 0) return 0;
665  packInt32(COMTREE,comtree);
666  packInt32(ADR1,adr1);
667  }
668  break;
669 
670  default: break;
671  }
672  paylen = 4*pp;
673  return paylen;
674 }
675 
676 #define unpackWord(x) { x = ntohl(payload[pp++]); }
677 #define unpackRspec(x) { int bru; unpackWord(bru); int brd; unpackWord(brd); \
678  int pru; unpackWord(pru); int prd; unpackWord(prd); \
679  (x).set(bru,brd,pru,prd); }
680 
684 bool CtlPkt::unpack() {
685  if (payload == 0) return false;
686 
687  int pp = 0;
688  uint32_t x, y;
689  unpackWord(x); type = (CpType) x;
690  unpackWord(x); mode = (CpMode) x;
691  unpackWord(x); unpackWord(y);
692  seqNum = x; seqNum <<= 32; seqNum |= y;
693 
694  if (mode == NEG_REPLY) {
695  if (paylen > 4*pp && ntohl(payload[pp]) == ERRMSG) {
696  pp++;
697  int len; unpackWord(len);
698  errMsg.assign((char*) &payload[pp], len);
699  }
700  return true;
701  }
702 
703  while (4*pp < paylen) {
704  uint32_t x; unpackWord(x);
705  uint16_t attr = (uint16_t) (x >> 16);
706  uint16_t len = (uint16_t) (x & 0xffff);
707  switch (attr) {
708  case ADR1: unpackWord(adr1); break;
709  case ADR2: unpackWord(adr2); break;
710  case ADR3: unpackWord(adr3); break;
711  case IP1: unpackWord(ip1); break;
712  case IP2: unpackWord(ip2); break;
713  case PORT1: unpackWord(port1); break;
714  case PORT2: unpackWord(port2); break;
715  case NONCE: uint32_t hi,lo; unpackWord(hi); unpackWord(lo);
716  nonce = hi; nonce <<= 32; nonce |= lo; break;
717  case RSPEC1: unpackRspec(rspec1); break;
718  case RSPEC2: unpackRspec(rspec2); break;
719  case CORE_FLAG: unpackWord(coreFlag); break;
720  case IFACE: unpackWord(iface); break;
721  case LINK: unpackWord(link); break;
722  case NODE_TYPE: nodeType =(Forest::ntyp_t) ntohl(payload[pp++]);
723  break;
724  case COMTREE: unpackWord(comtree); break;
725  case COMTREE_OWNER: unpackWord(comtreeOwner); break;
726  case INDEX1: unpackWord(index1); break;
727  case INDEX2: unpackWord(index2); break;
728  case COUNT: unpackWord(count); break;
729  case QUEUE: unpackWord(queue); break;
730  case ZIPCODE: unpackWord(zipCode); break;
731  case STRING: stringData.assign((char *) &payload[pp], len);
732  pp += (len+3)/4;
733  break;
734  case INTVEC: ivec.resize(len);
735  for (int i = 0; i < len; i++) {
736  int x; unpackWord(x); ivec[i] = x;
737  }
738  default: pp += (len+3)/4;
739  }
740  }
741 
742  switch (type) {
743  case ADD_IFACE:
744  if ((mode == REQUEST &&
745  (iface == 0 || ip1 == 0 || !rspec1.isSet())) ||
746  (mode == POS_REPLY && (ip1 == 0 || port1 == 0)))
747  return false;
748  break;
749  case DROP_IFACE:
750  if (mode == REQUEST && iface == 0)
751  return false;
752  break;
753  case GET_IFACE:
754  if ((mode == REQUEST && iface == 0) ||
755  (mode == POS_REPLY &&
756  (iface == 0 || ip1 == 0 || port1 == 0 ||
757  !rspec1.isSet() || !rspec2.isSet())))
758  return false;
759  break;
760  case MOD_IFACE:
761  if ((mode == REQUEST &&
762  (iface == 0 || !rspec1.isSet())))
763  return false;
764  break;
765  case GET_IFACE_SET:
766  if (mode == REQUEST && (index1 == -1 || count == -1))
767  return false;
768  if (mode == POS_REPLY &&
769  (index1 == -1 || index2 == -1 || count == -1))
770  return false;
771  break;
772 
773  case ADD_LINK:
774  if (mode == REQUEST && (nodeType == 0 || iface == 0))
775  return false;
776  break;
777  case DROP_LINK:
778  if (mode == REQUEST && link == 0 && adr1 == 0)
779  return false;
780  break;
781  case GET_LINK:
782  if ((mode == REQUEST && link == 0) ||
783  (mode == POS_REPLY &&
784  (link == 0 || iface == 0 || nodeType == 0 ||
785  ip1 == 0 || port1 == 0 || adr1 == 0 ||
786  !rspec1.isSet() || !rspec2.isSet())))
787  return false;
788  break;
789  case MOD_LINK:
790  if (mode == REQUEST && link == 0)
791  return false;
792  break;
793  case GET_LINK_SET:
794  if (mode == REQUEST && (index1 == -1 || count == -1))
795  return false;
796  if (mode == POS_REPLY &&
797  (index1 == -1 || index2 == -1 || count == -1))
798  return false;
799  break;
800 
801  case ADD_COMTREE:
802  if (mode == REQUEST && comtree == 0)
803  return false;
804  break;
805  case DROP_COMTREE:
806  if (mode == REQUEST && comtree == 0)
807  return false;
808  break;
809  case GET_COMTREE:
810  if ((mode == REQUEST && comtree == 0) ||
811  (mode == POS_REPLY &&
812  (comtree == 0 || coreFlag == -1 || link == 0 ||
813  count == 0)))
814  return false;
815  break;
816  case MOD_COMTREE:
817  if (mode == REQUEST && comtree == 0)
818  return false;
819  break;
820  case GET_COMTREE_SET:
821  if (mode == REQUEST && (index1 == -1 || count == -1))
822  return false;
823  if (mode == POS_REPLY &&
824  (index1 == -1 || index2 == -1 || count == -1))
825  return false;
826  break;
827 
828  case ADD_COMTREE_LINK:
829  if (mode == REQUEST && (comtree == 0 ||
830  (link == 0 && (ip1 == 0 || port1 == 0)
831  && (adr1 == 0))))
832  return false;
833  break;
834  case DROP_COMTREE_LINK:
835  if (mode == REQUEST && (comtree == 0 ||
836  (link == 0 && (ip1 == 0 || port1 == 0)
837  && (adr1 == 0))))
838  return false;
839  break;
840  case MOD_COMTREE_LINK:
841  if (mode == REQUEST && (comtree == 0 || link == 0))
842  return false;
843  break;
844  case GET_COMTREE_LINK:
845  if ((mode == REQUEST &&
846  (comtree == 0 || link == 0)) ||
847  (mode == POS_REPLY &&
848  (comtree == 0 || link == 0 || !rspec1.isSet() ||
849  queue == 0 || adr1 == 0)))
850  return false;
851  break;
852 
853  case ADD_ROUTE:
854  if (mode == REQUEST && (comtree == 0 || adr1 == 0 || link == 0))
855  return false;
856  break;
857  case DROP_ROUTE:
858  if (mode == REQUEST && (comtree == 0 || adr1 == 0))
859  return false;
860  break;
861  case GET_ROUTE:
862  if ((mode == REQUEST &&
863  (comtree == 0 || adr1 == 0)) ||
864  (mode == POS_REPLY &&
865  (comtree == 0 || adr1 == 0 || link == 0)))
866  return false;
867  break;
868  case MOD_ROUTE:
869  if (mode == REQUEST && (comtree == 0 || adr1 == 0))
870  return false;
871  break;
872  case ADD_ROUTE_LINK:
873  if (mode == REQUEST &&
874  (comtree == 0 || adr1 == 0 || link == 0))
875  return false;
876  break;
877  case DROP_ROUTE_LINK:
878  if (mode == REQUEST &&
879  (comtree == 0 || adr1 == 0 || link == 0))
880  return false;
881  break;
882  case GET_ROUTE_SET:
883  if (mode == REQUEST && (index1 == -1 || count == -1))
884  return false;
885  if (mode == POS_REPLY &&
886  (index1 == -1 || index2 == -1 || count == -1))
887  return false;
888  break;
889 
890  case ADD_FILTER:
891  if (mode == POS_REPLY && index1 == -1)
892  return false;
893  break;
894  case DROP_FILTER:
895  if (mode == REQUEST && index1 == -1)
896  return false;
897  break;
898  case GET_FILTER:
899  if ((mode == REQUEST && index1 == -1) ||
900  (mode == POS_REPLY && stringData.length() == 0))
901  return false;
902  break;
903  case MOD_FILTER:
904  if (mode == REQUEST &&
905  (index1 == -1 || stringData.length() == 0))
906  return false;
907  break;
908  case GET_FILTER_SET:
909  if (mode == REQUEST && (index1 == -1 || count == -1))
910  return false;
911  if (mode == POS_REPLY &&
912  (index1 == -1 || index2 == -1 || count == -1 ||
913  (count > 0 && stringData.length() == 0)))
914  return false;
915  break;
916  case GET_LOGGED_PACKETS:
917  if (mode == POS_REPLY && (count == -1 ||
918  (count > 0 && stringData.length() == 0)))
919  return false;
920  break;
921  case ENABLE_PACKET_LOG:
922  if (mode == REQUEST && (index1 == -1 || index2 == -1))
923  return false;
924  break;
925 
926  case NEW_SESSION:
927  if ((mode == REQUEST &&
928  (ip1 == 0 || !rspec1.isSet())) ||
929  (mode == POS_REPLY &&
930  (adr1 == 0 || adr2 == 0 || adr3 == 0 ||
931  ip1 == 0 || nonce == 0)))
932  return false;
933  break;
934  case CANCEL_SESSION:
935  if (mode == REQUEST && (adr1 == 0 || adr2 == 0))
936  return false;
937  break;
938  case CLIENT_CONNECT:
939  if (mode == REQUEST && (adr1 == 0 || adr2 == 0))
940  return false;
941  break;
942  case CLIENT_DISCONNECT:
943  if (mode == REQUEST && (adr1 == 0 || adr2 == 0))
944  return false;
945  break;
946  case CONFIG_LEAF:
947  if (mode == REQUEST &&
948  (adr1 == 0 || adr2 == 0 || ip1 == 0 || port1 == 0 ||
949  nonce == 0))
950  return false;
951  break;
952  case SET_LEAF_RANGE:
953  if (mode == REQUEST && (adr1 == 0 || adr2 == 0)) return false;
954  break;
955  case BOOT_ROUTER:
956  case BOOT_LEAF:
957  case BOOT_COMPLETE:
958  case BOOT_ABORT:
959  break;
960 
961  case COMTREE_PATH:
962  if ((mode == REQUEST && (adr1 == 0 || comtree == 0)) ||
963  (mode == POS_REPLY && (!rspec1.isSet() || !rspec2.isSet())))
964  return 0;
965  break;
966 
967  case ADD_NODE:
968  if (mode == REQUEST &&
969  (adr1 == 0 || link == 0 || adr2 == 0 || comtree == 0 ||
970  !rspec1.isSet() || !rspec2.isSet()))
971  return 0;
972  break;
973 
974  case ADD_BRANCH:
975  if ((mode == REQUEST && (index1 == 0 || !rspec1.isSet() ||
976  !rspec2.isSet())) ||
977  (mode == POS_REPLY && adr1 == 0))
978  return 0;
979  break;
980 
981  case PRUNE:
982  if (mode == REQUEST && (comtree == 0 || adr1 == 0))
983  return 0;
984  break;
985 
986  default: return false;
987  }
988  return true;
989 }
990 
995 string CtlPkt::avPair2string(CpAttr attr) {
996  stringstream ss; int len;
997  switch (attr) {
998  case ADR1:
999  if (adr1 != 0) ss << "adr1=" << Forest::fAdr2string(adr1);
1000  break;
1001  case ADR2:
1002  if (adr2 != 0) ss << "adr2=" << Forest::fAdr2string(adr2);
1003  break;
1004  case ADR3:
1005  if (adr3 != 0) ss << "adr3=" << Forest::fAdr2string(adr3);
1006  break;
1007  case IP1:
1008  if (ip1 != 0) ss << "ip1=" << Np4d::ip2string(ip1);
1009  break;
1010  case IP2:
1011  if (ip2 != 0) ss << "ip2=" << Np4d::ip2string(ip2);
1012  break;
1013  case PORT1:
1014  if (port1 != 0) ss << "port1=" << port1;
1015  break;
1016  case PORT2:
1017  if (port2 != 0) ss << "port2=" << port2;
1018  break;
1019  case RSPEC1:
1020  if (rspec1.isSet()) ss << "rspec1=" << rspec1.toString();
1021  break;
1022  case RSPEC2:
1023  if (rspec2.isSet()) ss << "rspec2=" << rspec2.toString();
1024  break;
1025  case CORE_FLAG:
1026  if (coreFlag >= 0)
1027  ss << "coreFlag=" << (coreFlag ? "true" : "false");
1028  break;
1029  case IFACE:
1030  if (iface != 0) ss << "iface=" << iface;
1031  break;
1032  case LINK:
1033  if (link != 0) ss << "link=" << link;
1034  break;
1035  case NODE_TYPE:
1036  if (nodeType != Forest::UNDEF_NODE)
1037  ss << "nodeType="
1038  << Forest::nodeType2string(nodeType);
1039  break;
1040  case COMTREE:
1041  if (comtree != 0) ss << "comtree=" << comtree;
1042  break;
1043  case COMTREE_OWNER:
1044  ss << "comtreeOwner=" << Forest::fAdr2string(comtreeOwner);
1045  break;
1046  case INDEX1:
1047  if (index1 >= 0) ss << "index1=" << index1;
1048  break;
1049  case INDEX2:
1050  if (index2 >= 0) ss << "index2=" << index2;
1051  break;
1052  case COUNT:
1053  if (count >= 0) ss << "count=" << count;
1054  break;
1055  case QUEUE:
1056  if (queue != 0) ss << "queue=" << queue;
1057  break;
1058  case NONCE:
1059  if (nonce != 0) ss << "nonce=" << nonce;
1060  break;
1061  case ZIPCODE:
1062  if (zipCode != 0) ss << "zipCode=" << zipCode;
1063  break;
1064  case ERRMSG:
1065  if (errMsg.length() != 0) ss << "errMsg=" << errMsg;
1066  break;
1067  case STRING:
1068  if (stringData.length() != 0) ss << "stringData=" << stringData;
1069  break;
1070  case INTVEC:
1071  len = ivec.size();
1072  if (len != 0) {
1073  ss << "ivec=";
1074  for (int i = 0; i < len; i++) ss << ivec[i] << " ";
1075  }
1076  break;
1077  default: break;
1078  }
1079  return ss.str();
1080 }
1081 
1082 
1083 string CtlPkt::cpType2string(CpType type) {
1084  string s;
1085  switch (type) {
1086  case ADD_IFACE: s = "add_iface"; break;
1087  case DROP_IFACE: s = "drop_iface"; break;
1088  case GET_IFACE: s = "get_iface"; break;
1089  case MOD_IFACE: s = "mod_iface"; break;
1090  case ADD_LINK: s = "add_link"; break;
1091  case DROP_LINK: s = "drop_link"; break;
1092  case GET_LINK: s = "get_link"; break;
1093  case GET_LINK_SET: s = "get_link_set"; break;
1094  case GET_COMTREE_SET: s = "get_comtree_set"; break;
1095  case GET_IFACE_SET: s = "get_iface_set"; break;
1096  case GET_ROUTE_SET: s = "get_route_set"; break;
1097  case MOD_LINK: s = "mod_link"; break;
1098  case ADD_COMTREE: s = "add_comtree"; break;
1099  case DROP_COMTREE: s = "drop_comtree"; break;
1100  case GET_COMTREE: s = "get_comtree"; break;
1101  case MOD_COMTREE: s = "mod_comtree"; break;
1102  case ADD_COMTREE_LINK: s = "add_comtree_link"; break;
1103  case DROP_COMTREE_LINK: s = "drop_comtree_link"; break;
1104  case MOD_COMTREE_LINK: s = "mod_comtree_link"; break;
1105  case GET_COMTREE_LINK: s = "get_comtree_link"; break;
1106  case ADD_ROUTE: s = "add_route"; break;
1107  case DROP_ROUTE: s = "drop_route"; break;
1108  case GET_ROUTE: s = "get_route"; break;
1109  case MOD_ROUTE: s = "mod_route"; break;
1110  case ADD_ROUTE_LINK: s = "add_route_link"; break;
1111  case DROP_ROUTE_LINK: s = "drop_route_link"; break;
1112 
1113  case ADD_FILTER: s = "add_filter"; break;
1114  case DROP_FILTER: s = "drop_filter"; break;
1115  case GET_FILTER: s = "get_filter"; break;
1116  case MOD_FILTER: s = "mod_filter"; break;
1117  case GET_FILTER_SET: s = "get_filter_set"; break;
1118  case GET_LOGGED_PACKETS: s = "get_logged_packets"; break;
1119  case ENABLE_PACKET_LOG: s = "enable_packet_log"; break;
1120 
1121  case NEW_SESSION: s = "new_session"; break;
1122  case CANCEL_SESSION: s = "cancel_session"; break;
1123  case CLIENT_CONNECT: s = "client_connect"; break;
1124  case CLIENT_DISCONNECT: s = "client_disconnect"; break;
1125  case CONFIG_LEAF: s = "config_leaf"; break;
1126  case SET_LEAF_RANGE: s = "set_leaf_range"; break;
1127  case BOOT_ROUTER: s = "boot_router"; break;
1128  case BOOT_LEAF: s = "boot_leaf"; break;
1129  case BOOT_COMPLETE: s = "boot_complete"; break;
1130  case BOOT_ABORT: s = "boot_abort"; break;
1131  case COMTREE_PATH: s = "comtree_path"; break;
1132  case ADD_NODE: s = "comtree_new_leaf"; break;
1133  case ADD_BRANCH: s = "comtree_add_branch"; break;
1134  case PRUNE: s = "comtree_prune"; break;
1135  default: s = "undefined"; break;
1136  }
1137  return s;
1138 }
1139 
1140 bool CtlPkt::string2cpType(string& s, CpType& type) {
1141  if (s == "undef") type = UNDEF_CPTYPE;
1142 
1143  else if (s == "add_iface") type = ADD_IFACE;
1144  else if (s == "drop_iface") type = DROP_IFACE;
1145  else if (s == "get_iface") type = GET_IFACE;
1146  else if (s == "mod_iface") type = MOD_IFACE;
1147 
1148  else if (s == "add_link") type = ADD_LINK;
1149  else if (s == "drop_link") type = DROP_LINK;
1150  else if (s == "get_link") type = GET_LINK;
1151  else if (s == "mod_link") type = MOD_LINK;
1152  else if (s == "get_link_set") type = GET_LINK_SET;
1153 
1154  else if (s == "add_comtree") type = ADD_COMTREE;
1155  else if (s == "drop_comtree") type = DROP_COMTREE;
1156  else if (s == "get_comtree") type = GET_COMTREE;
1157  else if (s == "mod_comtree") type = MOD_COMTREE;
1158 
1159  else if (s == "add_comtree_link") type = ADD_COMTREE_LINK;
1160  else if (s == "drop_comtree_link") type = DROP_COMTREE_LINK;
1161  else if (s == "get_comtree_link") type = GET_COMTREE_LINK;
1162  else if (s == "mod_comtree_link") type = MOD_COMTREE_LINK;
1163 
1164  else if (s == "add_route") type = ADD_ROUTE;
1165  else if (s == "drop_route") type = DROP_ROUTE;
1166  else if (s == "get_route") type = GET_ROUTE;
1167  else if (s == "mod_route") type = MOD_ROUTE;
1168  else if (s == "add_route_link") type = ADD_ROUTE;
1169  else if (s == "drop_route_link") type = DROP_ROUTE;
1170 
1171  else if (s == "add_filter") type = ADD_FILTER;
1172  else if (s == "drop_filter") type = DROP_FILTER;
1173  else if (s == "mod_filter") type = MOD_FILTER;
1174  else if (s == "get_filter") type = GET_FILTER;
1175  else if (s == "get_filter_set") type = GET_FILTER_SET;
1176  else if (s == "get_logged_packets") type = GET_LOGGED_PACKETS;
1177  else if (s == "enable_packet_log") type = ENABLE_PACKET_LOG;
1178 
1179  else if (s == "new_session") type = NEW_SESSION;
1180  else if (s == "cancel_session") type = CANCEL_SESSION;
1181  else if (s == "client_connect") type = CLIENT_CONNECT;
1182  else if (s == "client_disconnect") type = CLIENT_DISCONNECT;
1183 
1184  else if (s == "set_leaf_range") type = SET_LEAF_RANGE;
1185  else if (s == "config_leaf") type = CONFIG_LEAF;
1186 
1187  else if (s == "boot_router") type = BOOT_ROUTER;
1188  else if (s == "boot_complete") type = BOOT_COMPLETE;
1189  else if (s == "boot_abort") type = BOOT_ABORT;
1190  else if (s == "boot_leaf") type = BOOT_LEAF;
1191 
1192  else if (s == "comtree_path") type = COMTREE_PATH;
1193  else if (s == "comtree_new_leaf") type = ADD_NODE;
1194  else if (s == "comtree_add_branch") type = ADD_BRANCH;
1195  else if (s == "comtree_prune") type = PRUNE;
1196 
1197  else return false;
1198  return true;
1199 }
1200 
1201 string CtlPkt::cpMode2string(CpMode mode) {
1202  string s;
1203  switch (mode) {
1204  case REQUEST: s = "request"; break;
1205  case POS_REPLY: s = "pos reply"; break;
1206  case NEG_REPLY: s = "neg reply"; break;
1207  default: break;
1208  }
1209  return s;
1210 }
1211 
1212 bool CtlPkt::string2cpMode(string& s, CpMode& mode) {
1213  if (s == "undef") mode = UNDEF_MODE;
1214  else if (s == "request") mode = REQUEST;
1215  else if (s == "pos reply") mode = POS_REPLY;
1216  else if (s == "neg reply") mode = NEG_REPLY;
1217  else return false;
1218  return true;
1219 }
1220 
1224 string CtlPkt::toString() {
1225  stringstream ss;
1226 
1227  //if (payload != 0) unpack();
1228  ss << cpType2string(type);
1229  ss << " (" << cpMode2string(mode) << "," << seqNum << "): ";
1230  if (mode == NEG_REPLY) {
1231  ss << errMsg << endl;
1232  return ss.str();
1233  }
1234  switch (type) {
1235  case ADD_IFACE:
1236  if (mode == REQUEST) {
1237  ss << " " << avPair2string(IFACE);
1238  ss << " " << avPair2string(IP1);
1239  ss << " " << avPair2string(RSPEC1);
1240  } else {
1241  ss << " " << avPair2string(IP1);
1242  ss << " " << avPair2string(PORT1);
1243  }
1244  break;
1245  case DROP_IFACE:
1246  if (mode == REQUEST) {
1247  ss << " " << avPair2string(IFACE);
1248  }
1249  break;
1250  case GET_IFACE:
1251  if (mode == REQUEST) {
1252  ss << " " << avPair2string(IFACE);
1253  } else {
1254  ss << " " << avPair2string(IFACE);
1255  ss << " " << avPair2string(IP1);
1256  ss << " " << avPair2string(RSPEC1);
1257  ss << " " << avPair2string(RSPEC2);
1258  }
1259  break;
1260  case MOD_IFACE:
1261  if (mode == REQUEST) {
1262  ss << " " << avPair2string(IFACE);
1263  ss << " " << avPair2string(RSPEC1);
1264  }
1265  break;
1266  case ADD_LINK:
1267  if (mode == REQUEST) {
1268  ss << " " << avPair2string(IFACE);
1269  ss << " " << avPair2string(LINK);
1270  ss << " " << avPair2string(NODE_TYPE);
1271  ss << " " << avPair2string(IP1);
1272  ss << " " << avPair2string(PORT1);
1273  ss << " " << avPair2string(ADR1);
1274  ss << " " << avPair2string(NONCE);
1275  } else {
1276  ss << " " << avPair2string(LINK);
1277  ss << " " << avPair2string(ADR1);
1278  ss << " " << avPair2string(IP1);
1279  }
1280  break;
1281  case DROP_LINK:
1282  if (mode == REQUEST) {
1283  if (link != 0) ss << " " << avPair2string(LINK);
1284  if (adr1 != 0) ss << " " << avPair2string(ADR1);
1285  }
1286  break;
1287  case GET_LINK:
1288  if (mode == REQUEST) {
1289  ss << " " << avPair2string(LINK);
1290  } else {
1291  ss << " " << avPair2string(LINK);
1292  ss << " " << avPair2string(IFACE);
1293  ss << " " << avPair2string(NODE_TYPE);
1294  ss << " " << avPair2string(IP1);
1295  ss << " " << avPair2string(PORT1);
1296  ss << " " << avPair2string(ADR1);
1297  ss << " " << avPair2string(RSPEC1);
1298  ss << " " << avPair2string(RSPEC2);
1299  }
1300  break;
1301  case GET_LINK_SET:
1302  if (mode == REQUEST) {
1303  ss << " " << avPair2string(INDEX1);
1304  ss << " " << avPair2string(COUNT);
1305  } else {
1306  ss << " " << avPair2string(INDEX1);
1307  ss << " " << avPair2string(INDEX2);
1308  ss << " " << avPair2string(COUNT);
1309  ss << " " << avPair2string(STRING);
1310  }
1311  break;
1312  case GET_COMTREE_SET:
1313  if (mode == REQUEST) {
1314  ss << " " << avPair2string(INDEX1);
1315  ss << " " << avPair2string(COUNT);
1316  } else {
1317  ss << " " << avPair2string(INDEX1);
1318  ss << " " << avPair2string(INDEX2);
1319  ss << " " << avPair2string(COUNT);
1320 
1321  ss << " " << avPair2string(STRING);
1322  }
1323  break;
1324  case GET_IFACE_SET:
1325  if (mode == REQUEST) {
1326  ss << " " << avPair2string(INDEX1);
1327  ss << " " << avPair2string(COUNT);
1328  } else {
1329  ss << " " << avPair2string(INDEX1);
1330  ss << " " << avPair2string(INDEX2);
1331  ss << " " << avPair2string(COUNT);
1332 
1333  ss << " " << avPair2string(STRING);
1334  }
1335  break;
1336  case GET_ROUTE_SET:
1337  if (mode == REQUEST) {
1338  ss << " " << avPair2string(INDEX1);
1339  ss << " " << avPair2string(COUNT);
1340  } else {
1341  ss << " " << avPair2string(INDEX1);
1342  ss << " " << avPair2string(INDEX2);
1343  ss << " " << avPair2string(COUNT);
1344 
1345  ss << " " << avPair2string(STRING);
1346  }
1347  break;
1348  case MOD_LINK:
1349  if (mode == REQUEST) {
1350  ss << " " << avPair2string(LINK);
1351  ss << " " << avPair2string(RSPEC1);
1352  }
1353  break;
1354  case ADD_COMTREE:
1355  if (mode == REQUEST) {
1356  ss << " " << avPair2string(COMTREE);
1357  }
1358  break;
1359  case DROP_COMTREE:
1360  if (mode == REQUEST) {
1361  ss << " " << avPair2string(COMTREE);
1362  } else
1363  if (rspec1.isSet()) avPair2string(RSPEC1);
1364  break;
1365  case GET_COMTREE:
1366  if (mode == REQUEST) {
1367  ss << " " << avPair2string(COMTREE);
1368  } else {
1369  ss << " " << avPair2string(COMTREE);
1370  ss << " " << avPair2string(CORE_FLAG);
1371  ss << " " << avPair2string(LINK);
1372  ss << " " << avPair2string(COUNT);
1373  }
1374  break;
1375  case MOD_COMTREE:
1376  if (mode == REQUEST) {
1377  ss << " " << avPair2string(COMTREE);
1378  ss << " " << avPair2string(CORE_FLAG);
1379  ss << " " << avPair2string(LINK);
1380  }
1381  break;
1382  case ADD_COMTREE_LINK:
1383  if (mode == REQUEST) {
1384  ss << " " << avPair2string(COMTREE);
1385  ss << " " << avPair2string(LINK);
1386  ss << " " << avPair2string(CORE_FLAG);
1387  ss << " " << avPair2string(IP1);
1388  ss << " " << avPair2string(PORT1);
1389  ss << " " << avPair2string(ADR1);
1390  } else {
1391  ss << " " << avPair2string(LINK);
1392  ss << " " << avPair2string(RSPEC1);
1393  }
1394  break;
1395  case DROP_COMTREE_LINK:
1396  if (mode == REQUEST) {
1397  ss << " " << avPair2string(COMTREE);
1398  ss << " " << avPair2string(LINK);
1399  ss << " " << avPair2string(IP1);
1400  ss << " " << avPair2string(PORT1);
1401  ss << " " << avPair2string(ADR1);
1402  } else
1403  ss << " " << avPair2string(RSPEC1);
1404  break;
1405  case MOD_COMTREE_LINK:
1406  if (mode == REQUEST) {
1407  ss << " " << avPair2string(COMTREE);
1408  ss << " " << avPair2string(LINK);
1409  ss << " " << avPair2string(RSPEC1);
1410  } else
1411  ss << " " << avPair2string(RSPEC1);
1412  break;
1413  case GET_COMTREE_LINK:
1414  if (mode == REQUEST) {
1415  ss << " " << avPair2string(COMTREE);
1416  ss << " " << avPair2string(LINK);
1417  } else {
1418  ss << " " << avPair2string(COMTREE);
1419  ss << " " << avPair2string(LINK);
1420  ss << " " << avPair2string(RSPEC1);
1421  ss << " " << avPair2string(QUEUE);
1422  ss << " " << avPair2string(ADR1);
1423  }
1424  break;
1425  case ADD_ROUTE:
1426  if (mode == REQUEST) {
1427  ss << " " << avPair2string(COMTREE);
1428  ss << " " << avPair2string(ADR1);
1429  ss << " " << avPair2string(LINK);
1430  ss << " " << avPair2string(QUEUE);
1431  }
1432  break;
1433  case DROP_ROUTE:
1434  if (mode == REQUEST) {
1435  ss << " " << avPair2string(COMTREE);
1436  ss << " " << avPair2string(ADR1);
1437  }
1438  break;
1439  case GET_ROUTE:
1440  if (mode == REQUEST) {
1441  ss << " " << avPair2string(COMTREE);
1442  ss << " " << avPair2string(ADR1);
1443  } else {
1444  ss << " " << avPair2string(COMTREE);
1445  ss << " " << avPair2string(ADR1);
1446  ss << " " << avPair2string(LINK);
1447  }
1448  break;
1449  case MOD_ROUTE:
1450  if (mode == REQUEST) {
1451  ss << " " << avPair2string(COMTREE);
1452  ss << " " << avPair2string(ADR1);
1453  ss << " " << avPair2string(LINK);
1454  ss << " " << avPair2string(QUEUE);
1455  }
1456  break;
1457  case ADD_ROUTE_LINK:
1458  if (mode == REQUEST) {
1459  ss << " " << avPair2string(COMTREE);
1460  ss << " " << avPair2string(ADR1);
1461  ss << " " << avPair2string(LINK);
1462  }
1463  break;
1464  case DROP_ROUTE_LINK:
1465  if (mode == REQUEST) {
1466  ss << " " << avPair2string(COMTREE);
1467  ss << " " << avPair2string(ADR1);
1468  ss << " " << avPair2string(LINK);
1469  }
1470  break;
1471 
1472  case ADD_FILTER:
1473  if (mode == POS_REPLY) {
1474  ss << " " << avPair2string(INDEX1);
1475  ss << " " << avPair2string(STRING);
1476  }
1477  break;
1478  case DROP_FILTER:
1479  if (mode == REQUEST) {
1480  ss << " " << avPair2string(INDEX1);
1481  }
1482  break;
1483  case MOD_FILTER:
1484  if (mode == REQUEST) {
1485  ss << " " << avPair2string(INDEX1);
1486  ss << " " << avPair2string(STRING);
1487  }
1488  break;
1489  case GET_FILTER:
1490  if (mode == REQUEST) {
1491  ss << " " << avPair2string(INDEX1);
1492  } else {
1493  ss << " " << avPair2string(STRING);
1494  }
1495  break;
1496  case GET_FILTER_SET:
1497  if (mode == REQUEST) {
1498  ss << " " << avPair2string(INDEX1);
1499  ss << " " << avPair2string(COUNT);
1500  } else {
1501  ss << " " << avPair2string(INDEX1);
1502  ss << " " << avPair2string(INDEX2);
1503  ss << " " << avPair2string(COUNT);
1504  ss << " " << avPair2string(STRING);
1505  }
1506  break;
1507  case GET_LOGGED_PACKETS:
1508  if (mode == POS_REPLY) {
1509  ss << " " << avPair2string(COUNT);
1510  ss << " " << avPair2string(STRING);
1511  }
1512  break;
1513  case ENABLE_PACKET_LOG:
1514  if (mode == REQUEST)
1515  ss << " " << (index1 ? "on" : "off");
1516  ss << " " << (index2 ? "local" : "remote");
1517  break;
1518 
1519  case NEW_SESSION:
1520  if (mode == REQUEST) {
1521  ss << " " << avPair2string(IP1);
1522  ss << " " << avPair2string(RSPEC1);
1523  } else {
1524  ss << " " << avPair2string(ADR1);
1525  ss << " " << avPair2string(ADR2);
1526  ss << " " << avPair2string(ADR3);
1527  ss << " " << avPair2string(IP1);
1528  ss << " " << avPair2string(PORT1);
1529  ss << " " << avPair2string(NONCE);
1530  }
1531  break;
1532  case CANCEL_SESSION:
1533  if (mode == REQUEST) {
1534  ss << " " << avPair2string(ADR1);
1535  ss << " " << avPair2string(ADR2);
1536  }
1537  break;
1538  case CLIENT_CONNECT:
1539  if (mode == REQUEST) {
1540  ss << " " << avPair2string(ADR1);
1541  ss << " " << avPair2string(ADR2);
1542  }
1543  break;
1544  case CLIENT_DISCONNECT:
1545  if (mode == REQUEST) {
1546  ss << " " << avPair2string(ADR1);
1547  ss << " " << avPair2string(ADR2);
1548  }
1549  break;
1550  case CONFIG_LEAF:
1551  if (mode == REQUEST) {
1552  ss << " " << avPair2string(ADR1);
1553  ss << " " << avPair2string(ADR2);
1554  ss << " " << avPair2string(IP1);
1555  ss << " " << avPair2string(PORT1);
1556  ss << " " << avPair2string(NONCE);
1557  }
1558  break;
1559  case SET_LEAF_RANGE:
1560  if (mode == REQUEST) {
1561  ss << " " << avPair2string(ADR1);
1562  ss << " " << avPair2string(ADR2);
1563  }
1564  break;
1565  case BOOT_ROUTER:
1566  case BOOT_LEAF:
1567  case BOOT_COMPLETE:
1568  case BOOT_ABORT:
1569  break;
1570 
1571  case COMTREE_PATH:
1572  if (mode == REQUEST) {
1573  ss << " " << avPair2string(COMTREE);
1574  ss << " " << avPair2string(ADR1);
1575  } else {
1576  ss << " " << avPair2string(RSPEC1);
1577  ss << " " << avPair2string(RSPEC2);
1578  ss << " " << avPair2string(INTVEC);
1579  }
1580  break;
1581 
1582  case ADD_NODE:
1583  if (mode == REQUEST) {
1584  ss << " " << avPair2string(COMTREE);
1585  ss << " " << avPair2string(ADR1);
1586  ss << " " << avPair2string(LINK);
1587  ss << " " << avPair2string(ADR2);
1588  ss << " " << avPair2string(RSPEC1);
1589  ss << " " << avPair2string(RSPEC2);
1590  ss << " " << avPair2string(INTVEC);
1591  }
1592  break;
1593 
1594  case ADD_BRANCH:
1595  if (mode == REQUEST) {
1596  ss << " " << avPair2string(INTVEC);
1597  ss << " " << avPair2string(INDEX1);
1598  ss << " " << avPair2string(RSPEC1);
1599  ss << " " << avPair2string(RSPEC2);
1600  } else if (mode == POS_REPLY) {
1601  ss << " " << avPair2string(ADR1);
1602  }
1603  break;
1604 
1605  case PRUNE:
1606  if (mode == REQUEST) {
1607  ss << " " << avPair2string(COMTREE);
1608  ss << " " << avPair2string(ADR1);
1609  }
1610  break;
1611 
1612  default: break;
1613  }
1614  ss << endl;
1615  return ss.str();
1616 }
1617 
1618 } // ends namespace
1619