49 JOIN_COMTREE = 10, LEAVE_COMTREE = 11,
51 CLIENT_NET_SIG_SEP = 29,
53 ADD_IFACE = 30, DROP_IFACE = 31,
54 GET_IFACE = 32, MOD_IFACE = 33,
57 ADD_LINK = 40, DROP_LINK = 41,
58 GET_LINK = 42, MOD_LINK = 43,
61 ADD_COMTREE = 50, DROP_COMTREE = 51,
62 GET_COMTREE = 52, MOD_COMTREE = 53,
64 ADD_COMTREE_LINK = 54, DROP_COMTREE_LINK = 55,
65 MOD_COMTREE_LINK = 56, GET_COMTREE_LINK = 57,
68 ADD_ROUTE = 70, DROP_ROUTE = 71,
69 GET_ROUTE = 72, MOD_ROUTE = 73,
70 ADD_ROUTE_LINK = 74, DROP_ROUTE_LINK = 75,
73 ADD_FILTER = 80, DROP_FILTER = 81,
74 GET_FILTER = 82, MOD_FILTER = 83,
75 GET_FILTER_SET = 84, GET_LOGGED_PACKETS = 85,
76 ENABLE_PACKET_LOG = 86,
78 NEW_SESSION = 100, CANCEL_SESSION = 103,
79 CLIENT_CONNECT = 101, CLIENT_DISCONNECT = 102,
81 SET_LEAF_RANGE = 110, CONFIG_LEAF = 111,
83 BOOT_ROUTER = 120, BOOT_COMPLETE = 121, BOOT_ABORT = 122,
87 ADD_BRANCH = 131, CONFIRM = 132, ABORT = 133,
88 PRUNE = 134, ADD_NODE = 135, DROP_NODE = 136
104 UNDEF_MODE = 0, REQUEST = 1, POS_REPLY = 2, NEG_REPLY = 3
114 void reset(
const Packet&);
124 void put(
const string&);
125 void put(
const vector<int32_t>&);
138 bool get(vector<int32_t>&);
144 void fmtError(
const string&, int64_t=0);
145 bool xtrError(
string&);
147 void fmtAddIface(
int, ipa_t,
RateSpec, int64_t);
148 bool xtrAddIface(
int&, ipa_t&,
RateSpec&);
149 void fmtAddIfaceReply(ipa_t, ipp_t, int64_t=0);
150 bool xtrAddIfaceReply(ipa_t&, ipp_t&);
152 void fmtDropIface(
int, int64_t);
153 bool xtrDropIface(
int&);
154 void fmtDropIfaceReply(int64_t=0);
155 bool xtrDropIfaceReply();
157 void fmtModIface(
int,
RateSpec, int64_t);
159 void fmtModIfaceReply(int64_t=0);
160 bool xtrModIfaceReply();
162 void fmtGetIface(
int, int64_t);
163 bool xtrGetIface(
int&);
164 void fmtGetIfaceReply(
int, ipa_t, ipp_t,
RateSpec,
166 bool xtrGetIfaceReply(
int&, ipa_t&, ipp_t&,
RateSpec&,
169 void fmtGetIfaceSet(
int,
int, int64_t);
170 bool xtrGetIfaceSet(
int&,
int&);
171 void fmtGetIfaceSetReply(
int,
int,
string, int64_t=0);
172 bool xtrGetIfaceSetReply(
int&,
int&,
string&);
175 fAdr_t, uint64_t, int64_t);
178 void fmtAddLinkReply(
int,
fAdr_t, int64_t=0);
179 bool xtrAddLinkReply(
int&,
fAdr_t&);
181 void fmtDropLink(
int,
fAdr_t, int64_t);
182 bool xtrDropLink(
int&,
fAdr_t&);
183 void fmtDropLinkReply(int64_t=0);
184 bool xtrDropLinkReply();
186 void fmtModLink(
int,
RateSpec, int64_t);
188 void fmtModLinkReply(int64_t=0);
189 bool xtrModLinkReply();
191 void fmtGetLink(
int, int64_t);
192 bool xtrGetLink(
int&);
198 void fmtGetLinkSet(
int,
int, int64_t);
199 bool xtrGetLinkSet(
int&,
int&);
200 void fmtGetLinkSetReply(
int,
int,
string, int64_t=0);
201 bool xtrGetLinkSetReply(
int&,
int&,
string&);
203 void fmtAddComtree(
comt_t, int64_t);
204 bool xtrAddComtree(
comt_t&);
205 void fmtAddComtreeReply(int64_t=0);
206 bool xtrAddComtreeReply();
208 void fmtDropComtree(
comt_t, int64_t);
209 bool xtrDropComtree(
comt_t&);
210 void fmtDropComtreeReply(
RateSpec, int64_t=0);
211 bool xtrDropComtreeReply(
RateSpec&);
213 void fmtModComtree(
comt_t,
int,
int, int64_t);
214 bool xtrModComtree(
comt_t&,
int&,
int&);
215 void fmtModComtreeReply(int64_t=0);
216 bool xtrModComtreeReply();
218 void fmtGetComtree(
comt_t, int64_t);
219 bool xtrGetComtree(
comt_t&);
220 void fmtGetComtreeReply(
comt_t,
int,
int,
int, int64_t=0);
221 bool xtrGetComtreeReply(
comt_t&,
int&,
int&,
int&);
223 void fmtGetComtreeSet(
comt_t,
int, int64_t);
224 bool xtrGetComtreeSet(
comt_t&,
int&);
225 void fmtGetComtreeSetReply(
int,
comt_t,
string, int64_t=0);
226 bool xtrGetComtreeSetReply(
int&,
comt_t&,
string&);
228 void fmtAddComtreeLink(
comt_t,
int,
int, ipa_t, ipp_t,
230 bool xtrAddComtreeLink(
comt_t&,
int&,
int&, ipa_t&, ipp_t&,
232 void fmtAddComtreeLinkReply(
int,
RateSpec, int64_t=0);
233 bool xtrAddComtreeLinkReply(
int&,
RateSpec&);
235 void fmtDropComtreeLink(
comt_t,
int, ipa_t, ipp_t,
fAdr_t, int64_t);
236 bool xtrDropComtreeLink(
comt_t&,
int&, ipa_t&, ipp_t&,
fAdr_t&);
237 void fmtDropComtreeLinkReply(
RateSpec, int64_t=0);
238 bool xtrDropComtreeLinkReply(
RateSpec&);
242 void fmtModComtreeLinkReply(
RateSpec&, int64_t=0);
243 bool xtrModComtreeLinkReply(
RateSpec&);
245 void fmtGetComtreeLink(
comt_t,
int, int64_t);
246 bool xtrGetComtreeLink(
comt_t&,
int&);
254 void fmtAddRouteReply(int64_t=0);
255 bool xtrAddRouteReply();
259 void fmtDropRouteReply(int64_t=0);
260 bool xtrDropRouteReply();
264 void fmtModRouteReply(int64_t=0);
265 bool xtrModRouteReply();
272 void fmtGetRouteSet(
int,
int, int64_t);
273 bool xtrGetRouteSet(
int&,
int&);
274 void fmtGetRouteSetReply(
int,
int,
string, int64_t=0);
275 bool xtrGetRouteSetReply(
int&,
int&,
string&);
279 void fmtAddRouteLinkReply(int64_t=0);
280 bool xtrAddRouteLinkReply();
284 void fmtDropRouteLinkReply(int64_t=0);
285 bool xtrDropRouteLinkReply();
287 void fmtAddFilter(int64_t);
289 void fmtAddFilterReply(
int, int64_t=0);
290 bool xtrAddFilterReply(
int&);
292 void fmtDropFilter(
int, int64_t);
293 bool xtrDropFilter(
int&);
294 void fmtDropFilterReply(int64_t=0);
295 bool xtrDropFilterReply();
297 void fmtModFilter(
int,
string, int64_t);
298 bool xtrModFilter(
int&,
string&);
299 void fmtModFilterReply(int64_t=0);
300 bool xtrModFilterReply();
302 void fmtGetFilter(
int, int64_t);
303 bool xtrGetFilter(
int&);
304 void fmtGetFilterReply(
string, int64_t=0);
305 bool xtrGetFilterReply(
string&);
307 void fmtGetFilterSet(
int,
int, int64_t);
308 bool xtrGetFilterSet(
int&,
int&);
309 void fmtGetFilterSetReply(
int,
int,
string, int64_t=0);
310 bool xtrGetFilterSetReply(
int&,
int&,
string&);
312 void fmtGetLoggedPackets(int64_t);
313 bool xtrGetLoggedPackets();
314 void fmtGetLoggedPacketsReply(
int,
string, int64_t=0);
315 bool xtrGetLoggedPacketsReply(
int&,
string&);
317 void fmtEnablePacketLog(
int,
int, int64_t);
318 bool xtrEnablePacketLog(
int&,
int&);
319 void fmtEnablePacketLogReply(int64_t=0);
320 bool xtrEnablePacketLogReply();
322 void fmtNewSession(ipa_t,
RateSpec, int64_t);
323 bool xtrNewSession(ipa_t&,
RateSpec&);
325 uint64_t, int64_t=0);
326 bool xtrNewSessionReply(
fAdr_t&,
fAdr_t&, ipa_t&, ipp_t&,
331 void fmtCancelSessionReply(int64_t=0);
332 bool xtrCancelSessionReply();
336 void fmtClientConnectReply(int64_t=0);
337 bool xtrClientConnectReply();
341 void fmtClientDisconnectReply(int64_t=0);
342 bool xtrClientDisconnectReply();
346 bool xtrConfigLeaf(
fAdr_t&,
fAdr_t&, ipa_t&, ipp_t&, uint64_t&);
347 void fmtConfigLeafReply(int64_t=0);
348 bool xtrConfigLeafReply();
352 void fmtSetLeafRangeReply(int64_t=0);
353 bool xtrSetLeafRangeReply();
355 void fmtBootRouter(int64_t);
356 bool xtrBootRouter();
357 void fmtBootRouterReply(int64_t=0);
358 bool xtrBootRouterReply();
360 void fmtBootLeaf(int64_t);
362 void fmtBootLeafReply(int64_t=0);
363 bool xtrBootLeafReply();
365 void fmtBootComplete(int64_t);
366 bool xtrBootComplete();
367 void fmtBootCompleteReply(int64_t=0);
368 bool xtrBootCompleteReply();
370 void fmtBootAbort(int64_t);
372 void fmtBootAbortReply(int64_t=0);
373 bool xtrBootAbortReply();
375 static string cpType2string(CpType);
376 static string cpMode2string(CpMode);
377 static bool string2cpType(
string&, CpType&);
378 static bool string2cpMode(
string&, CpMode&);
380 string avPair2string(CpAttr);
397 inline void CtlPkt::fmtBase() {
399 *((int16_t*) next)=htons((int16_t) type); next+=
sizeof(int16_t);
400 *((int16_t*) next)=htons((int16_t) mode); next+=
sizeof(int16_t);
401 *((int32_t*) next)=htonl((int32_t) ((seqNum >> 32) & 0xffffffff));
402 next+=
sizeof(int32_t);
403 *((int32_t*) next)=htonl((int32_t) (seqNum & 0xffffffff));
404 next+=
sizeof(int32_t);
405 paylen = next - payload;
412 inline bool CtlPkt::xtrBase() {
414 type = (
CpType) ntohs(*((int16_t*) next)); next +=
sizeof(int16_t);
415 mode = (
CpMode) ntohs(*((int16_t*) next)); next +=
sizeof(int16_t);
416 seqNum = ntohl(*((uint32_t*) next)); next +=
sizeof(uint32_t);
418 seqNum |= ntohl(*((uint32_t*) next)); next +=
sizeof(uint32_t);
419 return (paylen >= next - payload);
424 inline void CtlPkt::updateSeqNum() {
425 char* p = payload + 2*
sizeof(int16_t);
426 *((int32_t*) p) = htonl((int32_t) ((seqNum >> 32) & 0xffffffff));
427 p +=
sizeof(int32_t);
428 *((int32_t*) ) = htonl((int32_t) (seqNum & 0xffffffff));
434 inline void CtlPkt::put(int16_t x) {
435 *((int16_t*) next)=htons(s16); next+=
sizeof(int16_t);
436 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
437 *((int16_t*) next)=htons(x); next+=
sizeof(x);
443 inline void CtlPkt::put(uint16_t x) {
444 *((int16_t*) next)=htons(u16); next+=
sizeof(int16_t);
445 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
446 *((uint16_t*) next)=htons(x); next+=
sizeof(x);
452 inline void CtlPkt::put(int32_t x) {
453 *((int16_t*) next)=htons(s32); next+=
sizeof(int16_t);
454 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
455 *((int32_t*) next)=htonl(x); next+=
sizeof(x);
461 inline void CtlPkt::put(uint32_t x) {
462 *((int16_t*) next)=htons(u32); next+=
sizeof(int16_t);
463 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
464 *((uint32_t*) next)=htonl(x); next+=
sizeof(x);
470 inline void CtlPkt::put(int64_t x) {
471 *((int16_t*) next)=htons(s64); next+=
sizeof(int16_t);
472 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
473 *((int32_t*) next)=htonl((int32_t) ((x >> 32) & 0xffffffff));
474 next+=
sizeof(int32_t);
475 *((int32_t*) next)=htonl((int32_t) (x & 0xffffffff));
476 next+=
sizeof(int32_t);
482 inline void CtlPkt::put(uint64_t x) {
483 *((int16_t*) next)=htons(u64); next+=
sizeof(int16_t);
484 *((int16_t*) next)=htons((int16_t)
sizeof(x)); next+=
sizeof(int16_t);
485 *((int32_t*) next)=htonl((uint32_t) ((x >> 32) & 0xffffffff));
486 next+=
sizeof(int32_t);
487 *((int32_t*) next)=htonl((uint32_t) (x & 0xffffffff));
488 next+=
sizeof(int32_t);
495 *((int16_t*) next)=htons(u64); next+=
sizeof(int16_t);
496 *((int16_t*) next)=htons((int16_t)
sizeof(int16_t));
497 next+=
sizeof(int16_t);
498 *((int16_t*) next)=htons((int16_t) x); next+=
sizeof(int16_t);
505 *((int16_t*) next)=htons(rateSpec); next+=
sizeof(int16_t);
506 *((int16_t*) next)=htons((int16_t)
sizeof(rs)); next+=
sizeof(int16_t);
507 *((int32_t*) next)=htonl(rs.
bitRateUp); next+=
sizeof(uint32_t);
508 *((int32_t*) next)=htonl(rs.
bitRateDown); next+=
sizeof(uint32_t);
509 *((int32_t*) next)=htonl(rs.
pktRateUp); next+=
sizeof(uint32_t);
510 *((int32_t*) next)=htonl(rs.
pktRateDown); next+=
sizeof(uint32_t);
516 inline void CtlPkt::put(
const string& s) {
517 *((int16_t*) next) = htons(attrString); next+=
sizeof(int16_t);
518 *((int16_t*) next) = htons((int16_t) s.length()); next+=
sizeof(int16_t);
519 std::copy(s.c_str(),s.c_str()+s.length(),next); next+=s.length();
525 inline void CtlPkt::put(
const vector<int32_t>& v) {
526 *((int16_t*) next) = htons(intVec); next+=
sizeof(int16_t);
527 *((int16_t*) next) = htons((int16_t) v.size()*
sizeof(int32_t));
528 next+=
sizeof(int16_t);
529 std::copy(v.begin(),v.end(),(int32_t*) next);
530 next+=v.size()*
sizeof(int32_t);
537 inline int CtlPkt::availSpace() {
538 return (payload + (Forest::MAX_PLENG-Forest::OVERHEAD))
539 - (next + 2*
sizeof(int16_t));
546 inline bool CtlPkt::get(int16_t& x) {
547 if (ntohs(*((int16_t*) next)) != s16)
return false;
548 next +=
sizeof(int16_t);
549 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
550 next +=
sizeof(int16_t);
551 x = ntohs(*((int16_t*) next));
559 inline bool CtlPkt::get(uint16_t& x) {
560 if (ntohs(*((int16_t*) next)) != u16)
return false;
561 next +=
sizeof(int16_t);
562 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
563 next +=
sizeof(int16_t);
564 x = ntohs(*((uint16_t*) next));
572 inline bool CtlPkt::get(int32_t& x) {
573 if (ntohs(*((int16_t*) next)) != s32)
return false;
574 next +=
sizeof(int16_t);
575 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
576 next +=
sizeof(int16_t);
577 x = ntohl(*((int32_t*) next));
585 inline bool CtlPkt::get(uint32_t& x) {
586 if (ntohs(*((int16_t*) next)) != u32)
return false;
587 next +=
sizeof(int16_t);
588 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
589 next +=
sizeof(int16_t);
590 x = ntohl(*((uint32_t*) next));
598 inline bool CtlPkt::get(int64_t& x) {
599 if (ntohs(*((int16_t*) next)) != s64)
return false;
600 next +=
sizeof(int16_t);
601 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
602 next +=
sizeof(int16_t);
603 x = ntohl(*((int64_t*) next));
611 inline bool CtlPkt::get(uint64_t& x) {
612 if (ntohs(*((int16_t*) next)) != u64)
return false;
613 next +=
sizeof(int16_t);
614 if (ntohs(*((int16_t*) next)) !=
sizeof(x))
return false;
615 next +=
sizeof(int16_t);
616 x = ntohl(*((uint64_t*) next));
625 if (ntohs(*((int16_t*) next)) != u32)
return false;
626 next +=
sizeof(int16_t);
627 if (ntohs(*((int16_t*) next)) !=
sizeof(int16_t))
return false;
628 next +=
sizeof(int16_t);
630 next +=
sizeof(int16_t);
638 if (ntohs(*((int16_t*) next)) != rateSpec)
return false;
639 next +=
sizeof(int16_t);
640 if (ntohs(*((int16_t*) next)) !=
sizeof(rs))
return false;
641 next +=
sizeof(int16_t);
642 rs.
bitRateUp = ntohl(*((int64_t*) next)); next +=
sizeof(uint32_t);
643 rs.
bitRateDown = ntohl(*((int64_t*) next)); next +=
sizeof(uint32_t);
644 rs.
pktRateUp = ntohl(*((int64_t*) next)); next +=
sizeof(uint32_t);
645 rs.
pktRateDown = ntohl(*((int64_t*) next)); next +=
sizeof(uint32_t);
652 inline bool CtlPkt::get(
string& s) {
653 if (ntohs(*((int16_t*) next)) != attrString)
return false;
654 next +=
sizeof(int16_t);
655 int len = ntohs(*((int16_t*) next));
656 next +=
sizeof(int16_t);
657 std::copy(next, next+len, s.begin());
665 inline bool CtlPkt::get(vector<int32_t>& v) {
666 if (ntohs(*((int16_t*) next)) != attrString)
return false;
667 next +=
sizeof(int16_t);
668 int len = ntohs(*((int16_t*) next))/
sizeof(int32_t);
669 next +=
sizeof(int16_t);
670 int32_t* vv = (int32_t*) next;
671 std::copy(vv, vv+len, v.begin());
672 next += len *
sizeof(int32_t);