OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_proto.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/bgp_proto.h"
6 
7 #include <boost/foreach.hpp>
8 
9 #include <algorithm>
10 #include <list>
11 #include <map>
12 #include <utility>
13 
14 #include "base/proto.h"
15 #include "bgp/bgp_log.h"
16 #include "bgp/bgp_peer.h"
17 #include "bgp/bgp_server.h"
18 #include "net/bgp_af.h"
19 
20 using boost::system::error_code;
21 using boost::tie;
22 using std::cout;
23 using std::endl;
24 using std::string;
25 using std::vector;
26 
27 namespace mpl = boost::mpl;
28 
30  : BgpMessage(OPEN), as_num(-1), holdtime(-1), identifier(-1) {
31 }
32 
34  STLDeleteValues(&opt_params);
35 }
36 
37 //
38 // Validate the capabilities in an incoming Open Message.
39 //
40 // Return the capability code that's missing if a problem is detected.
41 // Return 0 if capabilities in the message are OK.
42 //
43 // Note that we must not generate an error if we see a capability that we
44 // do not support.
45 //
46 // Go through all the capabilities and make sure that there's at least one
47 // MpExtension with an (afi, safi) pair that's also configured on the peer.
48 //
49 //
51  bool mp_extension_ok = false;
52 
53  // Go through each OptParam in the OpenMessage.
54  for (vector<OptParam *>::const_iterator param_it = opt_params.begin();
55  param_it != opt_params.end(); ++param_it) {
56  const OptParam *param = *param_it;
57 
58  // Go through each Capability in the OptParam.
59  for (vector<Capability *>::const_iterator cap_it =
60  param->capabilities.begin();
61  cap_it != param->capabilities.end(); ++cap_it) {
62  const Capability *cap = *cap_it;
63 
64  // See if the (afi,safi) in the MpExtension is configured on peer.
65  if (cap->code == Capability::MpExtension) {
66  const uint8_t *data = cap->capability.data();
67  uint16_t afi = get_value(data, 2);
68  uint8_t safi = get_value(data + 3, 1);
69  Address::Family family = BgpAf::AfiSafiToFamily(afi, safi);
70  if (peer->LookupFamily(family))
71  mp_extension_ok = true;
72  }
73 
74  if (cap->code == Capability::AS4Support &&
75  peer->server()->enable_4byte_as()) {
76  const uint8_t *data = cap->capability.data();
77  as_t asn = get_value(data, 4);
78  if (asn != peer->peer_as()) {
80  BGP_PEER_DIR_IN, "Bad Peer AS Number: " << asn <<
81  ", Configured peer ASN: " << peer->peer_as());
83  }
84  }
85  }
86  }
87 
88  if (!mp_extension_ok) {
90  BGP_PEER_DIR_IN, "Unsupported Capability: " <<
91  Capability::CapabilityToString(Capability::MpExtension) <<
92  " (" << Capability::MpExtension << ")");
94  }
95 
96  return 0;
97 }
98 
99 //
100 // Validate an incoming Open Message.
101 //
102 // Return one of the values from BgpProto::Notification::OpenMsgSubCode if
103 // an error is detected.
104 // Return 0 if message is OK.
105 //
107  if (identifier == 0) {
109  BGP_PEER_DIR_IN, "Bad BGP Identifier: " << 0);
111  }
112  if (identifier == peer->server()->bgp_identifier()) {
115  "Bad (Same as mine) BGP Identifier: " <<
116  Ip4Address(identifier).to_string());
118  }
119  if (as_num != AS_TRANS && as_num != peer->peer_as()) {
121  BGP_PEER_DIR_IN, "Bad Peer AS Number: " << as_num);
123  }
124 
125  return ValidateCapabilities(peer);
126 }
127 
130  uint16_t gr_time, bool restarted, bool notification,
131  const vector<uint8_t> &gr_afi_flags,
132  const vector<Address::Family> &gr_families) {
133  assert((gr_time & ~RestartTimeMask) == 0);
134  uint16_t restart_flags = restarted ? RestartedFlag : 0;
135  restart_flags |= notification ? NotificationFlag : 0;
136  const uint16_t gr_bytes = restart_flags | gr_time;
137 
138  vector<uint8_t> restart_cap;
139  restart_cap.push_back(gr_bytes >> 8);
140  restart_cap.push_back(gr_bytes & 0xFF);
141 
142  size_t i = 0;
143  BOOST_FOREACH(const Address::Family family, gr_families) {
144  uint16_t afi;
145  uint8_t safi;
146  tie(afi, safi) = BgpAf::FamilyToAfiSafi(family);
147  restart_cap.push_back(0);
148  restart_cap.push_back(afi);
149  restart_cap.push_back(safi);
150  restart_cap.push_back(gr_afi_flags[i++]);
151  }
152  return new Capability(GracefulRestart, restart_cap.data(),
153  restart_cap.size());
154 }
155 
157  vector<string> *families) {
158  families->clear();
159  BOOST_FOREACH(Capability::GR::Family gr_family, gr_params.families) {
160  Address::Family family =
161  BgpAf::AfiSafiToFamily(gr_family.afi, gr_family.safi);
162  if (family == Address::UNSPEC) {
163  families->push_back(BgpAf::ToString(gr_family.afi, gr_family.safi));
164  } else {
165  families->push_back(Address::FamilyToString(family));
166  }
167  }
168 
169  // Keep the list sorted and unique.
170  sort(families->begin(), families->end());
171  families->erase(unique(families->begin(), families->end()),
172  families->end() );
173 }
174 
176  const vector<Capability *> &capabilities) {
177  gr_params->Initialize();
178 
179  // Find and process all GR capabilities. We are expected to receive only
180  // one. Otherwise, the only the last one should be taken into effect.
181  bool found = false;
182  for (vector<Capability *>::const_iterator cap_it = capabilities.begin();
183  cap_it != capabilities.end(); ++cap_it) {
184  if ((*cap_it)->code != GracefulRestart)
185  continue;
186  found = true;
187  gr_params->Initialize();
188 
189  uint8_t *data = (*cap_it)->capability.data();
190  uint16_t bytes = get_value(data, 2);
191  gr_params->set_flags(bytes);
192  gr_params->set_time(bytes);
193 
194  size_t offset = 2;
195  while (offset < (*cap_it)->capability.size()) {
196  uint16_t afi = get_value(data + offset, 2);
197  uint8_t safi = get_value(data + offset + 2, 1);
198  uint8_t flags = get_value(data + offset + 3, 1);
199  gr_params->families.push_back(Family(afi, safi, flags));
200  offset += 4;
201  }
202  }
203  return found;
204 }
205 
208  uint8_t llgr_afi_flags, const vector<Address::Family> &llgr_families) {
209  assert((llgr_time & ~RestartTimeMask) == 0);
210  vector<uint8_t> llgr_cap;
211  BOOST_FOREACH(const Address::Family family, llgr_families) {
212  uint16_t afi;
213  uint8_t safi;
214  tie(afi, safi) = BgpAf::FamilyToAfiSafi(family);
215  llgr_cap.push_back(0);
216  llgr_cap.push_back(afi);
217  llgr_cap.push_back(safi);
218  llgr_cap.push_back(llgr_afi_flags);
219  llgr_cap.push_back((llgr_time & 0x00FF0000) >> 16);
220  llgr_cap.push_back((llgr_time & 0x0000FF00) >> 8);
221  llgr_cap.push_back((llgr_time & 0x000000FF) >> 0);
222  }
223  return new Capability(LongLivedGracefulRestart, llgr_cap.data(),
224  llgr_cap.size());
225 }
226 
228  const vector<Capability *> &capabilities) {
229  llgr_params->Initialize();
230 
231  // Find and process all LLGR capabilities. We are expected to receive only
232  // one. Otherwise, the only the last one should be taken into effect.
233  bool found = false;
234  for (vector<Capability *>::const_iterator cap_it = capabilities.begin();
235  cap_it != capabilities.end(); ++cap_it) {
236  if ((*cap_it)->code != LongLivedGracefulRestart)
237  continue;
238  found = true;
239  llgr_params->Initialize();
240 
241  uint8_t *data = (*cap_it)->capability.data();
242  size_t offset = 0;
243  uint32_t max_time = 0;
244  while (offset < (*cap_it)->capability.size()) {
245  uint16_t afi = get_value(data + offset, 2);
246  uint8_t safi = get_value(data + offset + 2, 1);
247  uint8_t flags = get_value(data + offset + 3, 1);
248  uint32_t time = get_value(data + offset + 4, 3);
249  llgr_params->families.push_back(Family(afi, safi, flags, time));
250 
251  if (time > max_time)
252  max_time = time;
253  offset += 7;
254  }
255  llgr_params->time = max_time;
256  }
257  return found;
258 }
259 
261  const LLGR &llgr_params, vector<string> *families) {
262  families->clear();
263  BOOST_FOREACH(Capability::LLGR::Family llgr_family, llgr_params.families) {
264  Address::Family family =
265  BgpAf::AfiSafiToFamily(llgr_family.afi, llgr_family.safi);
266  if (family == Address::UNSPEC) {
267  families->push_back(BgpAf::ToString(llgr_family.afi,
268  llgr_family.safi));
269  } else {
270  families->push_back(Address::FamilyToString(family));
271  }
272  }
273 
274  // Keep the list sorted and unique.
275  sort(families->begin(), families->end());
276  families->erase(unique(families->begin(), families->end()),
277  families->end() );
278 }
279 
280 const string BgpProto::OpenMessage::ToString() const {
281  std::ostringstream os;
282 
283  error_code ec;
284  os << "AS " << as_num;
285  os << ", Hold Time " << holdtime;
286  os << ", Identifier " << Ip4Address(identifier).to_string(ec);
287 
288  // Go through each OptParam in the OpenMessage.
289  for (vector<OptParam *>::const_iterator param_it = opt_params.begin();
290  param_it != opt_params.end(); ++param_it) {
291  const OptParam *param = *param_it;
292 
293  // Go through each Capability in the OptParam.
294  vector<Capability *>::const_iterator cap_it =
295  param->capabilities.begin();
296  while (cap_it != param->capabilities.end()) {
297  const Capability *cap = *cap_it;
298 
299  os << ", Code " << Capability::CapabilityToString(cap->code);
300 
301  if (cap->code == Capability::MpExtension) {
302  const uint8_t *data = cap->capability.data();
303  uint16_t afi = get_value(data, 2);
304  uint8_t safi = get_value(data + 3, 1);
305  Address::Family family = BgpAf::AfiSafiToFamily(afi, safi);
306  os << " Family " << Address::FamilyToString(family);
307  }
308 
309  if (++cap_it == param->capabilities.end())
310  break;
311  }
312 
313  Capability::GR gr_params = Capability::GR();
314  if (Capability::GR::Decode(&gr_params, param->capabilities)) {
315  os << ", GR_Flags 0x" << std::hex << int(gr_params.flags);
316  os << ", GR_Time " << gr_params.time;
317  BOOST_FOREACH(Capability::GR::Family family, gr_params.families) {
318  os << ", GR_family " <<
319  BgpAf::AfiSafiToFamily(family.afi, family.safi);
320  os << ", GR_family_flags 0x" << std::hex << int(family.flags);
321  }
322  }
323 
324  Capability::LLGR llgr_params = Capability::LLGR();
325  if (Capability::LLGR::Decode(&llgr_params, param->capabilities)) {
326  BOOST_FOREACH(Capability::LLGR::Family family,
327  llgr_params.families) {
328  os << ", LLGR_family " <<
329  BgpAf::AfiSafiToFamily(family.afi, family.safi);
330  os << ", LLGR_family_flags 0x" << std::hex << int(family.flags);
331  os << ", LLGR_Time " << family.time << " Seconds";
332  }
333  }
334  }
335 
336  return os.str();
337 }
338 
340  : BgpMessage(NOTIFICATION), error(0), subcode(0) {
341 }
342 
343 const string BgpProto::Notification::ToString() const {
344  return toString(static_cast<BgpProto::Notification::Code>(error), subcode);
345 }
346 
348  BgpProto::Notification::Code code, int sub_code) {
349  string msg("");
350  switch (code) {
351  case MsgHdrErr:
352  msg += string("Message Header Error:") +
353  MsgHdrSubcodeToString(static_cast<MsgHdrSubCode>(sub_code));
354  break;
355  case OpenMsgErr:
356  msg += string("OPEN Message Error:") +
357  OpenMsgSubcodeToString(static_cast<OpenMsgSubCode>(sub_code));
358  break;
359  case UpdateMsgErr:
360  msg += string("UPDATE Message Error:") +
361  UpdateMsgSubCodeToString(
362  static_cast<UpdateMsgSubCode>(sub_code));
363  break;
364  case HoldTimerExp:
365  msg += "Hold Timer Expired";
366  break;
367  case FSMErr:
368  msg += string("Finite State Machine Error:") +
369  FsmSubcodeToString(static_cast<FsmSubcode>(sub_code));
370  break;
371  case Cease:
372  msg += string("Cease:") +
373  CeaseSubcodeToString(static_cast<CeaseSubCode>(sub_code));
374  break;
375  default:
376  msg += "Unknown";
377  break;
378  }
379  return msg;
380 }
381 
383  : BgpMessage(KEEPALIVE) {
384 }
385 
387  : BgpMessage(UPDATE) {
388 }
389 
391  STLDeleteValues(&withdrawn_routes);
392  STLDeleteValues(&path_attributes);
393  STLDeleteValues(&nlri);
394 }
395 
398  return lhs->code < rhs->code;
399  }
400 };
401 
402 //
403 // Validate an incoming Update Message
404 // Returns 0 if message is OK
405 // Returns one of the values from enum UpdateMsgSubCode if an error is detected
406 //
407 int BgpProto::Update::Validate(const BgpPeer *peer, string *data) {
408  BgpAttrCodeCompare comp;
409  std::sort(path_attributes.begin(), path_attributes.end(), comp);
410  bool origin = false, nh = false, as_path = false, mp_reach_nlri = false,
411  local_pref = false;
412 
413  bool ibgp = (peer->PeerType() == IBGP);
414 
415  BgpAttrSpec::const_iterator it;
416  string rxed_attr("Path attributes : ");
417  for (it = path_attributes.begin(); it < path_attributes.end(); it++) {
418  if (it+1 < path_attributes.end() && (*it)->code == (*(it+1))->code) {
419  // Duplicate attributes
421  }
422 
423  rxed_attr += (*it)->ToString() + " ";
424 
425  if ((*it)->code == BgpAttribute::Origin)
426  origin = true;
427  if ((*it)->code == BgpAttribute::LocalPref) {
428  local_pref = true;
429  } else if ((*it)->code == BgpAttribute::NextHop) {
430  nh = true;
431  } else if ((*it)->code == BgpAttribute::AsPath) {
432  as_path = true;
433  if (peer && peer->IsAs4Supported()) {
434  AsPath4ByteSpec *asp = static_cast<AsPath4ByteSpec *>(*it);
435  // Check segments size for ebgp.
436  // IBGP can have empty path for routes that are originated.
437  if (!ibgp) {
438  if (!asp->path_segments.size() ||
439  !asp->path_segments[0]->path_segment.size())
441  }
442  } else {
443  AsPathSpec *asp = static_cast<AsPathSpec *>(*it);
444  // Check segments size for ebgp.
445  // IBGP can have empty path for routes that are originated.
446  if (!ibgp) {
447  if (!asp->path_segments.size() ||
448  !asp->path_segments[0]->path_segment.size())
450  }
451  }
452  } else if ((*it)->code == BgpAttribute::MPReachNlri) {
453  mp_reach_nlri = true;
454  }
455  }
456 
457  BGP_LOG_PEER(Message, const_cast<BgpPeer *>(peer),
458  SandeshLevel::SYS_DEBUG, BGP_LOG_FLAG_TRACE,
459  BGP_PEER_DIR_IN, rxed_attr);
460  if (nlri.size() > 0 && !nh) {
461  // next-hop attribute must be present if IPv4 NLRI is present
462  char attrib_type = BgpAttribute::NextHop;
463  *data = string(&attrib_type, 1);
465  }
466  if (nlri.size() > 0 || mp_reach_nlri) {
467  // origin and as_path must be present if any NLRI is present
468  if (!origin) {
469  char attrib_type = BgpAttribute::Origin;
470  *data = string(&attrib_type, 1);
472  }
473  if (!as_path) {
474  char attrib_type = BgpAttribute::AsPath;
475  *data = string(&attrib_type, 1);
477  }
478 
479  // All validations for IBGP
480  if (ibgp && !local_pref) {
481  // If IBGP, local_pref is mandatory
482  char attrib_type = BgpAttribute::LocalPref;
483  *data = string(&attrib_type, 1);
485  }
486  }
487  return 0;
488 }
489 
491  KEY_COMPARE(withdrawn_routes.size(), rhs.withdrawn_routes.size());
492  for (size_t i = 0; i < withdrawn_routes.size(); i++) {
493  KEY_COMPARE(withdrawn_routes[i]->prefixlen,
494  rhs.withdrawn_routes[i]->prefixlen);
495  KEY_COMPARE(withdrawn_routes[i]->prefix,
496  rhs.withdrawn_routes[i]->prefix);
497  }
498 
499  KEY_COMPARE(path_attributes.size(), rhs.path_attributes.size());
500  for (size_t i = 0; i < rhs.path_attributes.size(); i++) {
501  int ret = path_attributes[i]->CompareTo(*rhs.path_attributes[i]);
502  if (ret != 0) {
503  cout << "Unequal " << TYPE_NAME(*path_attributes[i]) << endl;
504  return ret;
505  }
506  }
507 
508  KEY_COMPARE(nlri.size(), rhs.nlri.size());
509  for (size_t i = 0; i < rhs.nlri.size(); i++) {
510  KEY_COMPARE(nlri[i]->prefixlen, rhs.nlri[i]->prefixlen);
511  KEY_COMPARE(nlri[i]->prefix, rhs.nlri[i]->prefix);
512  }
513  return 0;
514 }
515 
516 class BgpMarker : public ProtoElement<BgpMarker> {
517 public:
518  static const int kSize = 16;
519  static const int kErrorCode = BgpProto::Notification::MsgHdrErr;
520  static const int kErrorSubcode = BgpProto::Notification::ConnNotSync;
521  static bool Verifier(const void *obj, const uint8_t *data, size_t size,
522  ParseContext *context) {
523  for (int i = 0; i < 16; i++) {
524  if (data[i] != 0xff) return false;
525  }
526  return true;
527  }
528  static void Writer(const void *msg, uint8_t *data, size_t size) {
529  for (int i = 0; i < 16; i++) {
530  data[i] = 0xff;
531  }
532  }
533 };
534 
535 class BgpMsgLength : public ProtoElement<BgpMsgLength> {
536 public:
537  static const int kSize = 2;
538  static const int kErrorCode = BgpProto::Notification::MsgHdrErr;
539  static const int kErrorSubcode = BgpProto::Notification::BadMsgLength;
540  struct Offset {
541  string operator()() {
542  return "BgpMsgLength";
543  }
544  };
546  static bool Verifier(const void *obj, const uint8_t *data, size_t size,
547  ParseContext *context) {
548  int value = get_short(data);
549  if (value < BgpProto::kMinMessageSize ||
550  value > BgpProto::kMaxMessageSize) {
551  return false;
552  }
553  if ((size_t) value < context->offset() + size) {
554  return false;
555  }
556  return true;
557  }
558  struct SetLength {
559  static void Callback(EncodeContext *context, uint8_t *data,
560  int offset, int element_size) {
561  put_value(data, kSize, context->length());
562  }
563  };
565 };
566 
567 // BGP OPEN
568 class BgpOpenVersion : public ProtoElement<BgpOpenVersion> {
569 public:
570  static const int kSize = 1;
571  static const int kErrorCode = BgpProto::Notification::OpenMsgErr;
572  static const int kErrorSubcode = BgpProto::Notification::UnsupportedVersion;
573  static bool Verifier(const void * obj, const uint8_t *data, size_t size,
574  ParseContext *context) {
575  return data[0] == 0x4;
576  }
577  static void Writer(const void *msg, uint8_t *data, size_t size) {
578  *data = 0x4;
579  }
580 };
581 
582 class BgpOpenAsNum : public ProtoElement<BgpOpenAsNum> {
583 public:
584  static const int kSize = 2;
585  typedef Accessor<BgpProto::OpenMessage, uint32_t,
587 };
588 
589 class BgpHoldTime : public ProtoElement<BgpHoldTime> {
590 public:
591  static const int kSize = 2;
592  static const int kErrorCode = BgpProto::Notification::OpenMsgErr;
593  static const int kErrorSubcode =
595  static bool Verifier(const BgpProto::OpenMessage *obj, const uint8_t *data,
596  size_t size, ParseContext *context) {
597  uint16_t value = get_value(data, 2);
598  return (value == 0 || value >= 3);
599  }
600  typedef Accessor<BgpProto::OpenMessage, int32_t,
602 };
603 
604 class BgpIdentifier : public ProtoElement<BgpIdentifier> {
605 public:
606  static const int kSize = 4;
607  typedef Accessor<BgpProto::OpenMessage, uint32_t,
609 };
610 
611 class BgpOpenCapabilityCode : public ProtoElement<BgpOpenCapabilityCode> {
612 public:
613  static const int kSize = 1;
616 };
617 
618 class BgpOpenCapabilityLength : public ProtoElement<BgpOpenCapabilityLength> {
619 public:
620  static const int kSize = 1;
621  typedef int SequenceLength;
622 };
623 
624 class BgpOpenCapabilityValue : public ProtoElement<BgpOpenCapabilityValue> {
625 public:
626  static const int kSize = -1;
629 };
630 
631 class BgpOpenCapability : public ProtoSequence<BgpOpenCapability> {
632 public:
635 };
636 
637 class BgpOpenCapabilities : public ProtoSequence<BgpOpenCapabilities> {
638 public:
639  static const int kSize = 1;
640  static const int kMinOccurs = 0;
641  static const int kMaxOccurs = -1;
642  typedef mpl::list<BgpOpenCapability> Sequence;
643 
645  vector<BgpProto::OpenMessage::Capability *>,
647 
648  struct OptMatch {
650  return !ctx->capabilities.empty();
651  }
652  };
654 };
655 
656 class BgpOpenOptParamChoice : public ProtoChoice<BgpOpenOptParamChoice> {
657 public:
658  static const int kSize = 1;
659  static const int kErrorCode = BgpProto::Notification::OpenMsgErr;
660  static const int kErrorSubcode =
662  typedef mpl::map<
663  mpl::pair<mpl::int_<BgpProto::OpenMessage::OPEN_OPT_CAPABILITIES>,
666 };
667 
668 class BgpOpenOptParam : public ProtoSequence<BgpOpenOptParam> {
669 public:
670  static const int kSize = 1;
671  static const int kMinOccurs = 0;
672  static const int kMaxOccurs = -1;
674  vector<BgpProto::OpenMessage::OptParam *>,
676  typedef mpl::list<BgpOpenOptParamChoice> Sequence;
677 };
678 
679 class BgpOpenMessage : public ProtoSequence<BgpOpenMessage> {
680 public:
681  typedef mpl::list<BgpOpenVersion,
682  BgpOpenAsNum,
683  BgpHoldTime,
687 };
688 
689 class NotificationErrorCode : public ProtoElement<NotificationErrorCode> {
690 public:
691  static const int kSize = 1;
692  typedef Accessor<BgpProto::Notification, int,
694 };
695 
696 class NotificationErrorSubcode : public ProtoElement<NotificationErrorSubcode> {
697 public:
698  static const int kSize = 1;
699  typedef Accessor<BgpProto::Notification, int,
701 };
702 
703 class NotificationData : public ProtoElement<NotificationData> {
704 public:
705  static const int kSize = -1;
706  typedef Accessor<BgpProto::Notification, string,
708 };
709 
710 class BgpNotificationMessage : public ProtoSequence<BgpNotificationMessage> {
711 public:
712  typedef mpl::list<NotificationErrorCode,
716 };
717 
718 class BgpKeepaliveMessage : public ProtoSequence<BgpKeepaliveMessage> {
719 public:
720  typedef mpl::list<> Sequence;
722 };
723 
724 class BgpPrefixLen : public ProtoElement<BgpPrefixLen> {
725 public:
726  static const int kSize = 1;
727  struct PrefixLen {
728  int operator()(BgpProtoPrefix *obj, const uint8_t *data, size_t size) {
729  int bits = data[0];
730  return (bits + 7) / 8;
731  }
732  };
734  typedef Accessor<BgpProtoPrefix, int,
736 };
737 
738 class BgpPrefixAddress : public ProtoElement<BgpPrefixAddress> {
739 public:
740  static const int kSize = -1;
741  typedef VectorAccessor<BgpProtoPrefix, uint8_t,
743 };
744 
746  public ProtoSequence<BgpUpdateWithdrawnRoutes> {
747 public:
748  static const int kSize = 2;
749  static const int kMinOccurs = 0;
750  static const int kMaxOccurs = -1;
751  static const int kErrorCode = BgpProto::Notification::UpdateMsgErr;
752  static const int kErrorSubcode =
754 
756  vector<BgpProtoPrefix *>,
758 
759  struct OptMatch {
760  bool match(const BgpProto::Update *ctx) {
761  return !ctx->withdrawn_routes.empty();
762  }
763  };
765 
766  typedef mpl::list<BgpPrefixLen, BgpPrefixAddress> Sequence;
767 };
768 
769 class BgpPathAttrLength : public ProtoElement<BgpPathAttrLength> {
770 public:
771  static const int kSize = -1;
772  struct AttrLen {
774  const uint8_t *data, size_t &size) {
775  if (obj->flags & BgpAttribute::ExtendedLength) {
776  // Extended Length: use 2 bytes to read
777  size = 2;
778  } else {
779  size = 1;
780  }
781  return get_value(data, size);
782  }
783  };
785  struct AttrSizeSet {
786  static int get(const BgpAttribute *obj) {
787  if (obj->GetEncodeFlags() & BgpAttribute::ExtendedLength) {
788  // Extended Length: use 2 bytes to read
789  return 2;
790  } else {
791  return 1;
792  }
793  }
794  };
796 };
797 
798 template <class Derived>
800  Derived *operator()(const BgpAttribute *attr) {
801  return new Derived(*attr);
802  }
803 };
804 
805 template <class C>
807  static bool Verifier(const C *obj, const uint8_t *data, size_t size,
808  ParseContext *context) {
809  int pre = (obj->flags & BgpAttribute::ExtendedLength) ? 4 : 3;
810  if (C::kSize > 0 &&
811  static_cast<int>(context->total_size()) != C::kSize) {
812  int offset = pre + context->total_size() - context->size();
815  TYPE_NAME(C), data - offset, context->total_size() + pre);
816  return false;
817  }
818  if ((obj->flags & BgpAttribute::FLAG_MASK) != C::kFlags) {
819  int offset = pre + context->total_size() - context->size();
822  TYPE_NAME(C), data - offset, context->total_size() + pre);
823  return false;
824  }
825  return true;
826  }
827 };
828 
829 template <>
831  static bool Verifier(const BgpAttrOrigin *obj, const uint8_t *data,
832  size_t size, ParseContext *context) {
833  int pre = (obj->flags & BgpAttribute::ExtendedLength) ? 4 : 3;
834  if (context->size() != 1) {
837  "BgpAttrOrigin", data - pre, size + pre);
838  return false;
839  }
843  "BgpAttrOrigin", data - pre, size + pre);
844  return false;
845  }
846  uint8_t value = data[0];
847  if (value != BgpAttrOrigin::IGP && value != BgpAttrOrigin::EGP &&
848  value != BgpAttrOrigin::INCOMPLETE) {
851  "BgpAttrOrigin", data - pre, size + pre);
852  return false;
853  }
854  return true;
855  }
856 };
857 
858 template <>
860  static bool Verifier(const BgpAttrNextHop *obj, const uint8_t *data,
861  size_t size, ParseContext *context) {
862  int pre = (obj->flags & BgpAttribute::ExtendedLength) ? 4 : 3;
863  if (static_cast<int>(context->size()) != BgpAttrNextHop::kSize) {
866  "BgpAttrNextHop", data - pre, size + pre);
867  return false;
868  }
872  "BgpAttrNextHop", data - pre, size + pre);
873  return false;
874  }
875  uint32_t value = get_value(data, size);
876  // TODO(sbansal): More checks are needed
877  if (value == 0) {
880  "BgpAttrNextHop", data - pre, size + pre);
881  return false;
882  }
883  return true;
884  }
885 };
886 
887 template <>
888 struct BgpAttributeVerifier<AsPathSpec::PathSegment> {
889  static bool Verifier(const AsPathSpec::PathSegment *obj,
890  const uint8_t *data, size_t size,
891  ParseContext *context) {
892  return true;
893  }
894 };
895 
896 template <>
897 struct BgpAttributeVerifier<AsPath4ByteSpec::PathSegment> {
898  static bool Verifier(const AsPath4ByteSpec::PathSegment *obj,
899  const uint8_t *data, size_t size,
900  ParseContext *context) {
901  return true;
902  }
903 };
904 
905 template <>
906 struct BgpAttributeVerifier<As4PathSpec::PathSegment> {
907  static bool Verifier(const As4PathSpec::PathSegment *obj,
908  const uint8_t *data, size_t size,
909  ParseContext *context) {
910  return true;
911  }
912 };
913 
914 template <int Size, class C, typename T, T C::*Member>
916  public ProtoElement<BgpAttributeValue<Size, C, T, Member> > {
917 public:
918  static const int kSize = Size;
919  static bool Verifier(const C *obj, const uint8_t *data, size_t size,
920  ParseContext *context) {
921  return BgpAttributeVerifier<C>::Verifier(obj, data, size, context);
922  }
924 };
925 
926 template <class C, int Size, typename T, T C::*M>
928  public ProtoSequence<BgpAttrTemplate<C, Size, T, M> > {
929 public:
930  static const int kErrorCode = BgpProto::Notification::UpdateMsgErr;
931  static const int kErrorSubcode = BgpProto::Notification::AttribLengthError;
932  typedef C ContextType;
934  typedef mpl::list<BgpPathAttrLength, BgpAttributeValue<Size, C, T, M>
936 };
937 
939  public ProtoSequence<BgpPathAttributeAtomicAggregate> {
940 public:
941  static bool Verifier(const BgpAttrAtomicAggregate * obj,
942  const uint8_t *data, size_t size,
943  ParseContext *context) {
944  if (data[0] != 0) {
947  "BgpAttrAtomicAggregate", data - 2, data[0] + 3);
948  return false;
949  }
953  "BgpAttrAtomicAggregate", data - 2, 3);
954  return false;
955  }
956  return true;
957  }
960  typedef mpl::list<BgpPathAttrLength> Sequence;
961 };
962 
964  public ProtoSequence<BgpPathAttributeAggregator> {
965 public:
968  typedef mpl::list<BgpPathAttrLength,
974 };
975 
977  public ProtoSequence<BgpPathAttributeAggregator4Byte> {
978 public:
981  typedef mpl::list<BgpPathAttrLength,
987 };
988 
990  public ProtoSequence<BgpPathAttributeAs4Aggregator> {
991 public:
994  typedef mpl::list<BgpPathAttrLength,
1000 };
1001 
1003  public ProtoElement<BgpPathAttrAsPathSegmentLength> {
1004 public:
1005  static const int kSize = 1;
1008  const uint8_t *data, size_t size) {
1009  return get_value(data, 1) * 2;
1010  }
1011  };
1013  struct SetLength {
1014  static void Callback(EncodeContext *context, uint8_t *data,
1015  int offset, int element_size) {
1016  int len = get_value(data, kSize);
1017  put_value(data, kSize, len/2);
1018  }
1019  };
1021 };
1022 
1024  public ProtoElement<BgpPathAttrAsPath4ByteSegmentLength> {
1025 public:
1026  static const int kSize = 1;
1029  const uint8_t *data, size_t size) {
1030  return get_value(data, 1) * 4;
1031  }
1032  };
1034  struct SetLength {
1035  static void Callback(EncodeContext *context, uint8_t *data,
1036  int offset, int element_size) {
1037  int len = get_value(data, kSize);
1038  put_value(data, kSize, len/4);
1039  }
1040  };
1042 };
1043 
1045  public ProtoElement<BgpPathAttrAs4PathSegmentLength> {
1046 public:
1047  static const int kSize = 1;
1050  const uint8_t *data, size_t size) {
1051  return get_value(data, 1) * 4;
1052  }
1053  };
1055  struct SetLength {
1056  static void Callback(EncodeContext *context, uint8_t *data,
1057  int offset, int element_size) {
1058  int len = get_value(data, kSize);
1059  put_value(data, kSize, len/4);
1060  }
1061  };
1063 };
1064 
1065 
1067  public ProtoElement<BgpPathAttrAsPathSegmentValue> {
1068 public:
1069  static const int kSize = -1;
1072 };
1073 
1075  public ProtoElement<BgpPathAttrAsPath4ByteSegmentValue> {
1076 public:
1077  static const int kSize = -1;
1080 };
1081 
1083  public ProtoElement<BgpPathAttrAs4PathSegmentValue> {
1084 public:
1085  static const int kSize = -1;
1088 };
1089 
1091  public ProtoSequence<BgpPathAttrAsPathSegmentList> {
1092 public:
1093  static const int kMinOccurs = 0;
1094  static const int kMaxOccurs = -1;
1095 
1096  static bool Verifier(const AsPathSpec *obj, const uint8_t *data,
1097  size_t size, ParseContext *context) {
1098  return BgpAttributeVerifier<AsPathSpec>::Verifier(obj, data, size,
1099  context);
1100  }
1101 
1103  vector<AsPathSpec::PathSegment *>,
1105 
1106  typedef mpl::list<BgpAttributeValue<1, AsPathSpec::PathSegment, int,
1111 };
1112 
1114  public ProtoSequence<BgpPathAttrAsPath4ByteSegmentList> {
1115 public:
1116  static const int kMinOccurs = 0;
1117  static const int kMaxOccurs = -1;
1118 
1119  static bool Verifier(const AsPath4ByteSpec *obj, const uint8_t *data,
1120  size_t size, ParseContext *context) {
1121  return BgpAttributeVerifier<AsPath4ByteSpec>::Verifier(obj, data, size,
1122  context);
1123  }
1124 
1126  vector<AsPath4ByteSpec::PathSegment *>,
1128 
1129  typedef mpl::list<BgpAttributeValue<1, AsPath4ByteSpec::PathSegment, int,
1134 };
1135 
1137  public ProtoSequence<BgpPathAttrAs4PathSegmentList> {
1138 public:
1139  static const int kMinOccurs = 0;
1140  static const int kMaxOccurs = -1;
1141 
1142  static bool Verifier(const As4PathSpec *obj, const uint8_t *data,
1143  size_t size, ParseContext *context) {
1144  return BgpAttributeVerifier<As4PathSpec>::Verifier(obj, data, size,
1145  context);
1146  }
1147 
1149  vector<As4PathSpec::PathSegment *>,
1151 
1152  typedef mpl::list<BgpAttributeValue<1, As4PathSpec::PathSegment, int,
1157 };
1158 
1159 class BgpPathAttributeAsPath : public ProtoSequence<BgpPathAttributeAsPath> {
1160 public:
1163  typedef mpl::list<BgpPathAttrLength, BgpPathAttrAsPathSegmentList> Sequence;
1164 };
1165 
1167  public ProtoSequence<BgpPathAttributeAsPath4Byte> {
1168 public:
1171  typedef mpl::list<BgpPathAttrLength,
1173 };
1174 
1175 class BgpPathAttributeAs4Path : public ProtoSequence<BgpPathAttributeAs4Path> {
1176 public:
1179  typedef mpl::list<BgpPathAttrLength, BgpPathAttrAs4PathSegmentList> Sequence;
1180 };
1181 
1182 class BgpPathAttributeFlags : public ProtoElement<BgpPathAttributeFlags> {
1183 public:
1184  static const int kSize = 1;
1185  struct FlagsAccessor {
1186  static void set(BgpAttribute *obj, uint8_t value) {
1187  obj->flags = value;
1188  }
1189  static uint8_t get(const BgpAttribute *obj) {
1190  return obj->GetEncodeFlags();
1191  }
1192  };
1194 };
1195 
1197  public ProtoElement<BgpPathAttributeCommunityList> {
1198 public:
1199  static const int kSize = -1;
1200  static bool Verifier(const CommunitySpec *obj, const uint8_t *data,
1201  size_t size, ParseContext *context) {
1202  return BgpAttributeVerifier<CommunitySpec>::Verifier(obj, data, size,
1203  context);
1204  }
1205 
1206  typedef VectorAccessor<CommunitySpec, uint32_t,
1208 };
1209 
1211  public ProtoSequence<BgpPathAttributeCommunities> {
1212 public:
1215  typedef mpl::list<BgpPathAttrLength,
1217 };
1218 
1220  public ProtoElement<BgpPathAttributeExtendedCommunityList> {
1221 public:
1222  static const int kSize = -1;
1223  static bool Verifier(const ExtCommunitySpec *obj, const uint8_t *data,
1224  size_t size, ParseContext *context) {
1225  return BgpAttributeVerifier<ExtCommunitySpec>::Verifier(obj, data, size,
1226  context);
1227  }
1228 
1229  typedef VectorAccessor<ExtCommunitySpec, uint64_t,
1231 };
1232 
1234  public ProtoSequence<BgpPathAttributeExtendedCommunities> {
1235 public:
1238  typedef mpl::list<BgpPathAttrLength,
1240 };
1241 
1243  public ProtoElement<BgpPathAttributeClusterListData> {
1244 public:
1245  static const int kSize = -1;
1246  typedef VectorAccessor<ClusterListSpec, uint32_t,
1248 };
1249 
1251  public ProtoSequence<BgpPathAttributeClusterList> {
1252 public:
1255  typedef mpl::list<BgpPathAttrLength,
1257 };
1258 
1260  public ProtoElement<BgpPathAttributeOriginVnList> {
1261 public:
1262  static const int kSize = -1;
1263  static bool Verifier(const OriginVnPathSpec *obj, const uint8_t *data,
1264  size_t size, ParseContext *context) {
1265  return BgpAttributeVerifier<OriginVnPathSpec>::Verifier(obj, data, size,
1266  context);
1267  }
1268 
1269  typedef VectorAccessor<OriginVnPathSpec, uint64_t,
1271 };
1272 
1274  public ProtoSequence<BgpPathAttributeOriginVnPath> {
1275 public:
1278  typedef mpl::list<BgpPathAttrLength, BgpPathAttributeOriginVnList> Sequence;
1279 };
1280 
1282  public ProtoElement<BgpPathAttributePmsiTunnelIdentifier> {
1283 public:
1284  static const int kSize = -1;
1285  static bool Verifier(const PmsiTunnelSpec *obj, const uint8_t *data,
1286  size_t size, ParseContext *context) {
1288  obj, data, size, context);
1289  }
1290 
1291  typedef VectorAccessor<PmsiTunnelSpec, uint8_t,
1293 };
1294 
1296  public ProtoSequence<BgpPathAttributePmsiTunnel> {
1297 public:
1300  typedef mpl::list<BgpPathAttrLength,
1302  uint8_t, &PmsiTunnelSpec::tunnel_flags>,
1304  uint8_t, &PmsiTunnelSpec::tunnel_type>,
1306  uint32_t, &PmsiTunnelSpec::label>,
1308 };
1309 
1311  public ProtoElement<BgpPathAttributeDiscoveryEdgeAddressLen> {
1312 public:
1313  static const int kSize = 1;
1314  static bool Verifier(const void *obj, const uint8_t *data,
1315  size_t size, ParseContext *context) {
1316  uint8_t value = get_value(data, 1);
1317  return (value == 4);
1318  }
1319  typedef int SequenceLength;
1320 };
1321 
1323  public ProtoElement<BgpPathAttributeDiscoveryEdgeAddressValue> {
1324 public:
1325  static const int kSize = -1;
1326  typedef VectorAccessor<EdgeDiscoverySpec::Edge, uint8_t,
1328 };
1329 
1331  public ProtoSequence<BgpPathAttributeDiscoveryEdgeAddress> {
1332 public:
1333  typedef mpl::list<BgpPathAttributeDiscoveryEdgeAddressLen,
1335 };
1336 
1338  public ProtoElement<BgpPathAttributeDiscoveryEdgeLabelLen> {
1339 public:
1340  static const int kSize = 1;
1341  static bool Verifier(const void *obj, const uint8_t *data,
1342  size_t size, ParseContext *context) {
1343  uint8_t value = get_value(data, 1);
1344  return (value > 0 && value % 8 == 0);
1345  }
1346  typedef int SequenceLength;
1347 };
1348 
1350  public ProtoElement<BgpPathAttributeDiscoveryEdgeLabelValues> {
1351 public:
1352  static const int kSize = -1;
1353  typedef VectorAccessor<EdgeDiscoverySpec::Edge, uint32_t,
1355 };
1356 
1358  public ProtoSequence<BgpPathAttributeDiscoveryEdgeLabels> {
1359 public:
1360  typedef mpl::list<BgpPathAttributeDiscoveryEdgeLabelLen,
1362 };
1363 
1365  public ProtoSequence<BgpPathAttributeDiscoveryEdgeList> {
1366 public:
1367  static const int kMinOccurs = 1;
1368  static const int kMaxOccurs = -1;
1369 
1370  static bool Verifier(const EdgeDiscoverySpec *obj, const uint8_t *data,
1371  size_t size, ParseContext *context) {
1373  obj, data, size, context);
1374  }
1375 
1377  vector<EdgeDiscoverySpec::Edge *>,
1379 
1380  typedef mpl::list<BgpPathAttributeDiscoveryEdgeAddress,
1382 };
1383 
1385  public ProtoSequence<BgpPathAttributeEdgeDiscovery> {
1386 public:
1389  typedef mpl::list<BgpPathAttrLength,
1391 };
1392 
1394  public ProtoElement<BgpPathAttributeForwardingEdgeLen> {
1395 public:
1396  static const int kSize = 1;
1397  static bool Verifier(const void *obj, const uint8_t *data,
1398  size_t size, ParseContext *context) {
1399  uint8_t value = get_value(data, 1);
1400  return (value == 4);
1401  }
1402  struct GetLength {
1404  const uint8_t *data, size_t size) {
1405  obj->address_len = get_value(data, 1) * 2 + 8;
1406  return obj->address_len;
1407  }
1408  };
1410  struct SetLength {
1411  static void Callback(EncodeContext *context, uint8_t *data,
1412  int offset, int element_size) {
1413  int len = get_value(data, kSize);
1414  put_value(data, kSize, (len - 8) / 2);
1415  }
1416  };
1418 };
1419 
1421  public ProtoElement<BgpPathAttributeForwardingEdgeAddressLen> {
1422 public:
1423  static const int kSize = 0;
1424  struct GetLength {
1426  const uint8_t *data, size_t size) {
1427  return (obj->address_len - 8) / 2;
1428  }
1429  };
1431 };
1432 
1434  public ProtoElement<BgpPathAttributeForwardingEdgeInAddressValue> {
1435 public:
1436  static const int kSize = -1;
1437  typedef VectorAccessor<EdgeForwardingSpec::Edge, uint8_t,
1439 };
1440 
1442  public ProtoSequence<BgpPathAttributeForwardingEdgeInAddress> {
1443 public:
1444  static const int kMinOccurs = 1;
1445  static const int kMaxOccurs = 1;
1446  typedef mpl::list<BgpPathAttributeForwardingEdgeAddressLen,
1448 };
1449 
1451  public ProtoElement<BgpPathAttributeForwardingEdgeInLabel> {
1452 public:
1453  static const int kSize = 4;
1454  typedef Accessor<EdgeForwardingSpec::Edge, uint32_t,
1456 };
1457 
1459  public ProtoElement<BgpPathAttributeForwardingEdgeOutAddressValue> {
1460 public:
1461  static const int kSize = -1;
1462  typedef VectorAccessor<EdgeForwardingSpec::Edge, uint8_t,
1464 };
1465 
1467  public ProtoSequence<BgpPathAttributeForwardingEdgeOutAddress> {
1468 public:
1469  static const int kMinOccurs = 1;
1470  static const int kMaxOccurs = 1;
1471  typedef mpl::list<BgpPathAttributeForwardingEdgeAddressLen,
1473 };
1474 
1476  public ProtoElement<BgpPathAttributeForwardingEdgeOutLabel> {
1477 public:
1478  static const int kSize = 4;
1479  typedef Accessor<EdgeForwardingSpec::Edge, uint32_t,
1481 };
1482 
1484  public ProtoSequence<BgpPathAttributeForwardingEdgeList> {
1485 public:
1486  static const int kMinOccurs = 1;
1487  static const int kMaxOccurs = -1;
1488 
1489  static bool Verifier(const EdgeForwardingSpec *obj, const uint8_t *data,
1490  size_t size, ParseContext *context) {
1492  obj, data, size, context);
1493  }
1494 
1496  vector<EdgeForwardingSpec::Edge *>,
1498 
1499  typedef mpl::list<BgpPathAttributeForwardingEdgeLen,
1504 };
1505 
1507  public ProtoSequence<BgpPathAttributeEdgeForwarding> {
1508 public:
1511  typedef mpl::list<BgpPathAttrLength,
1513 };
1514 
1515 class BgpPathAttributeReserved : public ProtoElement<BgpPathAttributeReserved> {
1516 public:
1517  static const int kSize = 1;
1518  static void Writer(const void *msg, uint8_t *data, size_t size) {
1519  *data = 0;
1520  }
1521 };
1522 
1524  public ProtoElement<BgpPathAttributeMpNlriNextHopLength> {
1525 public:
1526  static const int kSize = 1;
1527  static const int kErrorCode = BgpProto::Notification::UpdateMsgErr;
1528  static const int kErrorSubcode =
1530  typedef int SequenceLength;
1531  static bool Verifier(const BgpMpNlri *obj, const uint8_t *data, size_t size,
1532  ParseContext *context) {
1533  uint8_t len = get_value(data, kSize);
1534  uint16_t afi = obj->afi;
1535  uint8_t safi = obj->safi;
1536  if (afi == BgpAf::IPv4 && safi == BgpAf::Unicast) {
1537  return (len == Address::kMaxV4Bytes);
1538  } else if (afi == BgpAf::IPv4 && safi == BgpAf::Mpls) {
1539  return (len == Address::kMaxV4Bytes);
1540  } else if (afi == BgpAf::IPv4 && safi == BgpAf::Vpn) {
1542  } else if (afi == BgpAf::IPv6 && safi == BgpAf::Unicast) {
1543  return (len == Address::kMaxV6Bytes ||
1544  len == 2 * Address::kMaxV6Bytes);
1545  } else if (afi == BgpAf::IPv6 && safi == BgpAf::Vpn) {
1547  } else if (afi == BgpAf::L2Vpn && safi == BgpAf::EVpn) {
1548  return (len == Address::kMaxV4Bytes);
1549  } else if (afi == BgpAf::IPv4 && safi == BgpAf::RTarget) {
1550  return (len == Address::kMaxV4Bytes);
1551  } else if (afi == BgpAf::IPv4 && safi == BgpAf::ErmVpn) {
1552  return (len == Address::kMaxV4Bytes);
1553  } else if (afi == BgpAf::IPv4 && safi == BgpAf::MVpn) {
1554  return (len == Address::kMaxV4Bytes);
1555  }
1556  return false;
1557  }
1558 };
1559 
1560 
1562  public ProtoElement<BgpPathAttributeMpNlriNexthopAddr> {
1563 public:
1564  static const int kSize = -1;
1566 };
1567 
1569  public ProtoSequence<BgpPathAttributeMpNlriNextHop> {
1570 public:
1571  typedef mpl::list<BgpPathAttributeMpNlriNextHopLength,
1573 };
1574 
1575 class BgpPathAttributeMpNlri : public ProtoSequence<BgpPathAttributeMpNlri> {
1576 public:
1577  static const int kMinOccurs = 0;
1578  static const int kMaxOccurs = -1;
1579 
1580  struct OptMatch {
1581  bool match(const BgpMpNlri *obj) {
1582  return ((obj->afi == BgpAf::IPv4 && obj->safi == BgpAf::Unicast) ||
1583  (obj->afi == BgpAf::IPv4 && obj->safi == BgpAf::Mpls) ||
1584  (obj->afi == BgpAf::IPv4 && obj->safi == BgpAf::Vpn) ||
1585  (obj->afi == BgpAf::IPv6 && obj->safi == BgpAf::Unicast) ||
1586  (obj->afi == BgpAf::IPv6 && obj->safi == BgpAf::Vpn) ||
1587  (obj->afi == BgpAf::IPv4 && obj->safi == BgpAf::RTarget));
1588  }
1589  };
1590 
1594  typedef mpl::list<BgpPrefixLen, BgpPrefixAddress> Sequence;
1595 };
1596 
1597 class BgpMvpnNlriType : public ProtoElement<BgpMvpnNlriType> {
1598 public:
1599  static const int kSize = 1;
1600  typedef Accessor<BgpProtoPrefix, uint8_t,
1602 };
1603 
1604 class BgpMvpnNlriLen : public ProtoElement<BgpMvpnNlriLen> {
1605 public:
1606  static const int kSize = 1;
1607 
1608  struct MvpnPrefixLen {
1609  static void set(BgpProtoPrefix *obj, int value) {
1610  obj->prefixlen = value * 8;
1611  }
1612 
1613  static int get(const BgpProtoPrefix *obj) {
1614  return obj->prefixlen / 8;
1615  }
1616  };
1617 
1618 
1619  typedef int SequenceLength;
1620 
1622 };
1623 
1625  : public ProtoSequence<BgpPathAttributeMpMvpnNlri> {
1626 public:
1627  static const int kMinOccurs = 0;
1628  static const int kMaxOccurs = -1;
1629 
1630  struct OptMatch {
1631  bool match(const BgpMpNlri *obj) {
1632  return ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::MVpn));
1633  }
1634  };
1635 
1637 
1640 
1641  typedef mpl::list<BgpMvpnNlriType, BgpMvpnNlriLen,
1643 };
1644 
1645 class BgpErmVpnNlriType : public ProtoElement<BgpErmVpnNlriType> {
1646 public:
1647  static const int kSize = 1;
1648  typedef Accessor<BgpProtoPrefix, uint8_t,
1650 };
1651 
1652 class BgpErmVpnNlriLen : public ProtoElement<BgpErmVpnNlriLen> {
1653 public:
1654  static const int kSize = 1;
1655 
1657  static void set(BgpProtoPrefix *obj, int value) {
1658  obj->prefixlen = value * 8;
1659  }
1660 
1661  static int get(const BgpProtoPrefix *obj) {
1662  return obj->prefixlen / 8;
1663  }
1664  };
1665 
1666 
1667  typedef int SequenceLength;
1668 
1670 };
1671 
1673  : public ProtoSequence<BgpPathAttributeMpErmVpnNlri> {
1674 public:
1675  static const int kMinOccurs = 0;
1676  static const int kMaxOccurs = -1;
1677 
1678  struct OptMatch {
1679  bool match(const BgpMpNlri *obj) {
1680  return ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::ErmVpn));
1681  }
1682  };
1683 
1685 
1688 
1689  typedef mpl::list<BgpErmVpnNlriType, BgpErmVpnNlriLen,
1691 };
1692 
1693 class BgpEvpnNlriType : public ProtoElement<BgpEvpnNlriType> {
1694 public:
1695  static const int kSize = 1;
1696  typedef Accessor<BgpProtoPrefix, uint8_t,
1698 };
1699 
1700 class BgpEvpnNlriLen : public ProtoElement<BgpEvpnNlriLen> {
1701 public:
1702  static const int kSize = 1;
1703 
1704  struct EvpnPrefixLen {
1705  static void set(BgpProtoPrefix *obj, int value) {
1706  obj->prefixlen = value * 8;
1707  }
1708 
1709  static int get(const BgpProtoPrefix *obj) {
1710  return obj->prefixlen / 8;
1711  }
1712  };
1713 
1714 
1715  typedef int SequenceLength;
1716 
1718 };
1719 
1721  public ProtoSequence<BgpPathAttributeMpEvpnNlri> {
1722 public:
1723  static const int kMinOccurs = 0;
1724  static const int kMaxOccurs = -1;
1725 
1726  struct OptMatch {
1727  bool match(const BgpMpNlri *obj) {
1728  return ((obj->afi == BgpAf::L2Vpn) && (obj->safi == BgpAf::EVpn));
1729  }
1730  };
1731 
1735  typedef mpl::list<BgpEvpnNlriType, BgpEvpnNlriLen,
1737 };
1738 
1740  public ProtoChoice<BgpPathAttributeMpNlriChoice> {
1741 public:
1742  static const int kSize = 0;
1743  struct MpChoice {
1744  static void set(BgpMpNlri *obj, int &value) {
1745  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Unicast)) {
1746  value = 0;
1747  }
1748  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Mpls)) {
1749  value = 0;
1750  }
1751  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Vpn)) {
1752  value = 0;
1753  }
1754  if ((obj->afi == BgpAf::IPv6) && (obj->safi == BgpAf::Unicast)) {
1755  value = 0;
1756  }
1757  if ((obj->afi == BgpAf::IPv6) && (obj->safi == BgpAf::Vpn)) {
1758  value = 0;
1759  }
1760  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::RTarget)) {
1761  value = 0;
1762  }
1763  if ((obj->afi == BgpAf::L2Vpn) && (obj->safi == BgpAf::EVpn)) {
1764  value = 1;
1765  }
1766  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::ErmVpn)) {
1767  value = 2;
1768  }
1769  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::MVpn)) {
1770  value = 3;
1771  }
1772  }
1773 
1774  static int get(BgpMpNlri *obj) {
1775  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Unicast)) {
1776  return 0;
1777  }
1778  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Mpls)) {
1779  return 0;
1780  }
1781  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::Vpn)) {
1782  return 0;
1783  }
1784  if ((obj->afi == BgpAf::IPv6) && (obj->safi == BgpAf::Unicast)) {
1785  return 0;
1786  }
1787  if ((obj->afi == BgpAf::IPv6) && (obj->safi == BgpAf::Vpn)) {
1788  return 0;
1789  }
1790  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::RTarget)) {
1791  return 0;
1792  }
1793  if ((obj->afi == BgpAf::L2Vpn) && (obj->safi == BgpAf::EVpn)) {
1794  return 1;
1795  }
1796  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::ErmVpn)) {
1797  return 2;
1798  }
1799  if ((obj->afi == BgpAf::IPv4) && (obj->safi == BgpAf::MVpn)) {
1800  return 3;
1801  }
1802  return -1;
1803  }
1804  };
1805 
1806  typedef MpChoice Setter;
1807  typedef mpl::map<
1808  mpl::pair<mpl::int_<0>, BgpPathAttributeMpNlri>,
1809  mpl::pair<mpl::int_<1>, BgpPathAttributeMpEvpnNlri>,
1810  mpl::pair<mpl::int_<2>, BgpPathAttributeMpErmVpnNlri>,
1811  mpl::pair<mpl::int_<3>, BgpPathAttributeMpMvpnNlri>
1813 };
1814 
1816 public ProtoSequence<BgpPathAttributeMpReachNlriSequence> {
1817 public:
1818  struct Offset {
1819  string operator()() {
1820  return "MpReachUnreachNlri";
1821  }
1822  };
1826  typedef mpl::list<BgpPathAttrLength,
1832 };
1833 
1835 public ProtoSequence<BgpPathAttributeMpUnreachNlriSequence> {
1836 public:
1837  struct Offset {
1838  string operator()() {
1839  return "MpReachUnreachNlri";
1840  }
1841  };
1845  typedef mpl::list<BgpPathAttrLength,
1849 };
1850 
1851 class BgpPathAttrUnknownValue : public ProtoElement<BgpPathAttrUnknownValue> {
1852 public:
1853  static const int kSize = -1;
1854  static bool Verifier(BgpAttrUnknown *obj, const uint8_t *data, size_t size,
1855  ParseContext *context) {
1856  int pre = (obj->flags & BgpAttribute::ExtendedLength) ? 4 : 3;
1857  if (!(obj->flags & BgpAttribute::Optional)) {
1860  "BgpAttrUnknown", data - pre, context->size() + pre);
1861  return false;
1862  }
1863  return true;
1864  }
1865  typedef VectorAccessor<BgpAttrUnknown, uint8_t,
1867 };
1868 
1869 class BgpPathAttributeUnknown : public ProtoSequence<BgpPathAttributeUnknown> {
1870 public:
1873  typedef mpl::list<BgpPathAttrLength, BgpPathAttrUnknownValue> Sequence;
1874 };
1875 
1876 class BgpPathAttribute : public ProtoChoice<BgpPathAttribute> {
1877 public:
1878  static const int kSize = 1;
1879 
1881  typedef mpl::map<
1882  mpl::pair<mpl::int_<BgpAttribute::Origin>,
1885  mpl::pair<mpl::int_<BgpAttribute::AsPath>, BgpPathAttributeAsPath>,
1886  mpl::pair<mpl::int_<BgpAttribute::As4Path>, BgpPathAttributeAs4Path>,
1887  mpl::pair<mpl::int_<BgpAttribute::NextHop>,
1888  BgpAttrTemplate<BgpAttrNextHop, 4, uint32_t,
1890  mpl::pair<mpl::int_<BgpAttribute::MultiExitDisc>,
1893  mpl::pair<mpl::int_<BgpAttribute::LocalPref>,
1894  BgpAttrTemplate<BgpAttrLocalPref, 4, uint32_t,
1896  mpl::pair<mpl::int_<BgpAttribute::AtomicAggregate>,
1898  mpl::pair<mpl::int_<BgpAttribute::Aggregator>,
1900  mpl::pair<mpl::int_<BgpAttribute::As4Aggregator>,
1902  mpl::pair<mpl::int_<BgpAttribute::Communities>,
1904  mpl::pair<mpl::int_<BgpAttribute::OriginatorId>,
1905  BgpAttrTemplate<BgpAttrOriginatorId, 4, uint32_t,
1907  mpl::pair<mpl::int_<BgpAttribute::ClusterList>,
1909  mpl::pair<mpl::int_<BgpAttribute::MPReachNlri>,
1911  mpl::pair<mpl::int_<BgpAttribute::MPUnreachNlri>,
1913  mpl::pair<mpl::int_<BgpAttribute::ExtendedCommunities>,
1915  mpl::pair<mpl::int_<BgpAttribute::PmsiTunnel>,
1917  mpl::pair<mpl::int_<BgpAttribute::McastEdgeDiscovery>,
1919  mpl::pair<mpl::int_<BgpAttribute::McastEdgeForwarding>,
1921  mpl::pair<mpl::int_<BgpAttribute::OriginVnPath>,
1923  mpl::pair<mpl::int_<-1>, BgpPathAttributeUnknown>
1925 };
1926 
1927 class BgpPathAttributeAs4 : public ProtoChoice<BgpPathAttributeAs4> {
1928 public:
1929  static const int kSize = 1;
1930 
1932  typedef mpl::map<
1933  mpl::pair<mpl::int_<BgpAttribute::Origin>,
1936  mpl::pair<mpl::int_<BgpAttribute::AsPath>,
1938  mpl::pair<mpl::int_<BgpAttribute::As4Path>, BgpPathAttributeAs4Path>,
1939  mpl::pair<mpl::int_<BgpAttribute::NextHop>,
1940  BgpAttrTemplate<BgpAttrNextHop, 4, uint32_t,
1942  mpl::pair<mpl::int_<BgpAttribute::MultiExitDisc>,
1945  mpl::pair<mpl::int_<BgpAttribute::LocalPref>,
1946  BgpAttrTemplate<BgpAttrLocalPref, 4, uint32_t,
1948  mpl::pair<mpl::int_<BgpAttribute::AtomicAggregate>,
1950  mpl::pair<mpl::int_<BgpAttribute::Aggregator>,
1952  mpl::pair<mpl::int_<BgpAttribute::As4Aggregator>,
1954  mpl::pair<mpl::int_<BgpAttribute::Communities>,
1956  mpl::pair<mpl::int_<BgpAttribute::OriginatorId>,
1957  BgpAttrTemplate<BgpAttrOriginatorId, 4, uint32_t,
1959  mpl::pair<mpl::int_<BgpAttribute::ClusterList>,
1961  mpl::pair<mpl::int_<BgpAttribute::MPReachNlri>,
1963  mpl::pair<mpl::int_<BgpAttribute::MPUnreachNlri>,
1965  mpl::pair<mpl::int_<BgpAttribute::ExtendedCommunities>,
1967  mpl::pair<mpl::int_<BgpAttribute::PmsiTunnel>,
1969  mpl::pair<mpl::int_<BgpAttribute::McastEdgeDiscovery>,
1971  mpl::pair<mpl::int_<BgpAttribute::McastEdgeForwarding>,
1973  mpl::pair<mpl::int_<BgpAttribute::OriginVnPath>,
1975  mpl::pair<mpl::int_<-1>, BgpPathAttributeUnknown>
1977 };
1978 
1979 class BgpPathAttributeList : public ProtoSequence<BgpPathAttributeList> {
1980 public:
1981  static const int kSize = 2;
1982  static const int kMinOccurs = 0;
1983  static const int kMaxOccurs = -1;
1984  static const int kErrorCode = BgpProto::Notification::UpdateMsgErr;
1985  static const int kErrorSubcode =
1987  struct Offset {
1988  string operator()() {
1989  return "BgpPathAttribute";
1990  }
1991  };
1994  vector<BgpAttribute *>,
1996  typedef mpl::list<BgpPathAttributeFlags, BgpPathAttribute> Sequence;
1997 };
1998 
1999 class BgpPathAttributeAs4List : public ProtoSequence<BgpPathAttributeAs4List> {
2000 public:
2001  static const int kSize = 2;
2002  static const int kMinOccurs = 0;
2003  static const int kMaxOccurs = -1;
2004  static const int kErrorCode = BgpProto::Notification::UpdateMsgErr;
2005  static const int kErrorSubcode =
2007  struct Offset {
2008  string operator()() {
2009  return "BgpPathAttribute";
2010  }
2011  };
2014  vector<BgpAttribute *>,
2016  typedef mpl::list<BgpPathAttributeFlags, BgpPathAttributeAs4> Sequence;
2017 };
2018 
2019 class BgpUpdateNlri : public ProtoSequence<BgpUpdateNlri> {
2020 public:
2021  static const int kMinOccurs = 0;
2022  static const int kMaxOccurs = -1;
2023 
2025  vector<BgpProtoPrefix *>,
2027 
2028  struct OptMatch {
2029  bool match(const BgpProto::Update *ctx) {
2030  return !ctx->nlri.empty();
2031  }
2032  };
2034  typedef mpl::list<BgpPrefixLen, BgpPrefixAddress> Sequence;
2035 };
2036 
2037 class BgpUpdateMessageAs4 : public ProtoSequence<BgpUpdateMessageAs4> {
2038 public:
2042 };
2043 
2044 class BgpUpdateMessage : public ProtoSequence<BgpUpdateMessage> {
2045 public:
2049 };
2050 
2051 class BgpMsgType : public ProtoChoice<BgpMsgType> {
2052 public:
2053  static const int kSize = 1;
2054  static const int kErrorCode = BgpProto::Notification::MsgHdrErr;
2055  static const int kErrorSubcode = BgpProto::Notification::BadMsgType;
2056  typedef mpl::map<
2057  mpl::pair<mpl::int_<BgpProto::OPEN>, BgpOpenMessage>,
2058  mpl::pair<mpl::int_<BgpProto::NOTIFICATION>, BgpNotificationMessage>,
2059  mpl::pair<mpl::int_<BgpProto::KEEPALIVE>, BgpKeepaliveMessage>,
2060  mpl::pair<mpl::int_<BgpProto::UPDATE>, BgpUpdateMessage>
2062 };
2063 
2064 class BgpMsgTypeAs4 : public ProtoChoice<BgpMsgTypeAs4> {
2065 public:
2066  static const int kSize = 1;
2067  static const int kErrorCode = BgpProto::Notification::MsgHdrErr;
2068  static const int kErrorSubcode = BgpProto::Notification::BadMsgType;
2069  typedef mpl::map<
2070  mpl::pair<mpl::int_<BgpProto::OPEN>, BgpOpenMessage>,
2071  mpl::pair<mpl::int_<BgpProto::NOTIFICATION>, BgpNotificationMessage>,
2072  mpl::pair<mpl::int_<BgpProto::KEEPALIVE>, BgpKeepaliveMessage>,
2073  mpl::pair<mpl::int_<BgpProto::UPDATE>, BgpUpdateMessageAs4>
2075 };
2076 
2077 class BgpProtocol : public ProtoSequence<BgpProtocol> {
2078 public:
2079  typedef mpl::list<BgpMarker, BgpMsgLength, BgpMsgType> Sequence;
2080 };
2081 
2082 class BgpProtocolAs4 : public ProtoSequence<BgpProtocolAs4> {
2083 public:
2084  typedef mpl::list<BgpMarker, BgpMsgLength, BgpMsgTypeAs4> Sequence;
2085 };
2086 
2087 BgpProto::BgpMessage *BgpProto::Decode(const uint8_t *data, size_t size,
2088  ParseErrorContext *ec, bool as4) {
2089  ParseContext context;
2090  int result;
2091  if (as4) {
2092  result = BgpProtocolAs4::Parse(data, size, &context,
2093  reinterpret_cast<void *>(NULL));
2094  } else {
2095  result = BgpProtocol::Parse(data, size, &context,
2096  reinterpret_cast<void *>(NULL));
2097  }
2098  if (result < 0) {
2099  if (ec) {
2100  *ec = context.error_context();
2101  }
2102  return NULL;
2103  }
2104  return static_cast<BgpMessage *>(context.release());
2105 }
2106 
2107 int BgpProto::Encode(const BgpMessage *msg, uint8_t *data, size_t size,
2108  EncodeOffsets *offsets, bool as4) {
2109  EncodeContext ctx;
2110  int result;
2111  if (as4) {
2112  result = BgpProtocolAs4::Encode(&ctx, msg, data, size);
2113  } else {
2114  result = BgpProtocol::Encode(&ctx, msg, data, size);
2115  }
2116  if (offsets) {
2117  *offsets = ctx.encode_offsets();
2118  }
2119  return result;
2120 }
2121 
2122 int BgpProto::Encode(const BgpMpNlri *msg, uint8_t *data, size_t size,
2123  EncodeOffsets *offsets) {
2124  EncodeContext ctx;
2125  int result = 0;
2126  if ((msg->afi == BgpAf::L2Vpn) && (msg->safi == BgpAf::EVpn)) {
2127  result = BgpPathAttributeMpEvpnNlri::Encode(&ctx, msg, data, size);
2128  } else if ((msg->afi == BgpAf::IPv4) && (msg->safi == BgpAf::ErmVpn)) {
2129  result = BgpPathAttributeMpErmVpnNlri::Encode(&ctx, msg, data, size);
2130  } else if ((msg->afi == BgpAf::IPv4) && (msg->safi == BgpAf::MVpn)) {
2131  result = BgpPathAttributeMpMvpnNlri::Encode(&ctx, msg, data, size);
2132  } else {
2133  result = BgpPathAttributeMpNlri::Encode(&ctx, msg, data, size);
2134  }
2135  if (offsets) {
2136  *offsets = ctx.encode_offsets();
2137  }
2138  return result;
2139 }
mpl::map< mpl::pair< mpl::int_< BgpAttribute::Origin >, BgpAttrTemplate< BgpAttrOrigin, 1, int,&BgpAttrOrigin::origin > >, mpl::pair< mpl::int_< BgpAttribute::AsPath >, BgpPathAttributeAsPath >, mpl::pair< mpl::int_< BgpAttribute::As4Path >, BgpPathAttributeAs4Path >, mpl::pair< mpl::int_< BgpAttribute::NextHop >, BgpAttrTemplate< BgpAttrNextHop, 4, uint32_t,&BgpAttrNextHop::nexthop > >, mpl::pair< mpl::int_< BgpAttribute::MultiExitDisc >, BgpAttrTemplate< BgpAttrMultiExitDisc, 4, uint32_t,&BgpAttrMultiExitDisc::med > >, mpl::pair< mpl::int_< BgpAttribute::LocalPref >, BgpAttrTemplate< BgpAttrLocalPref, 4, uint32_t,&BgpAttrLocalPref::local_pref > >, mpl::pair< mpl::int_< BgpAttribute::AtomicAggregate >, BgpPathAttributeAtomicAggregate >, mpl::pair< mpl::int_< BgpAttribute::Aggregator >, BgpPathAttributeAggregator >, mpl::pair< mpl::int_< BgpAttribute::As4Aggregator >, BgpPathAttributeAs4Aggregator >, mpl::pair< mpl::int_< BgpAttribute::Communities >, BgpPathAttributeCommunities >, mpl::pair< mpl::int_< BgpAttribute::OriginatorId >, BgpAttrTemplate< BgpAttrOriginatorId, 4, uint32_t,&BgpAttrOriginatorId::originator_id > >, mpl::pair< mpl::int_< BgpAttribute::ClusterList >, BgpPathAttributeClusterList >, mpl::pair< mpl::int_< BgpAttribute::MPReachNlri >, BgpPathAttributeMpReachNlriSequence >, mpl::pair< mpl::int_< BgpAttribute::MPUnreachNlri >, BgpPathAttributeMpUnreachNlriSequence >, mpl::pair< mpl::int_< BgpAttribute::ExtendedCommunities >, BgpPathAttributeExtendedCommunities >, mpl::pair< mpl::int_< BgpAttribute::PmsiTunnel >, BgpPathAttributePmsiTunnel >, mpl::pair< mpl::int_< BgpAttribute::McastEdgeDiscovery >, BgpPathAttributeEdgeDiscovery >, mpl::pair< mpl::int_< BgpAttribute::McastEdgeForwarding >, BgpPathAttributeEdgeForwarding >, mpl::pair< mpl::int_< BgpAttribute::OriginVnPath >, BgpPathAttributeOriginVnPath >, mpl::pair< mpl::int_<-1 >, BgpPathAttributeUnknown > > Choice
Definition: bgp_proto.cc:1924
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:546
Accessor< C, T, Member > Setter
Definition: bgp_proto.cc:923
virtual const std::string ToString() const
Definition: bgp_proto.cc:280
mpl::list< BgpPathAttrLength, BgpPathAttributeClusterListData > Sequence
Definition: bgp_proto.cc:1256
static bool Verifier(const C *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:807
bool match(const BgpProto::Update *ctx)
Definition: bgp_proto.cc:2029
BgpContextSwap< ExtCommunitySpec > ContextSwap
Definition: bgp_proto.cc:1237
static void Writer(const void *msg, uint8_t *data, size_t size)
Definition: bgp_proto.cc:1518
std::vector< uint8_t > value
Definition: bgp_attr.h:766
uint16_t afi
Definition: bgp_attr.h:307
int Validate(BgpPeer *peer) const
Definition: bgp_proto.cc:106
CollectionAccessor< AsPath4ByteSpec, vector< AsPath4ByteSpec::PathSegment * >,&AsPath4ByteSpec::path_segments > ContextStorer
Definition: bgp_proto.cc:1127
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_attr.h:311
uint32_t originator_id
Definition: bgp_attr.h:197
int operator()(AsPathSpec::PathSegment *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:1007
BgpContextSwap< BgpMpNlri > ContextSwap
Definition: bgp_proto.cc:1844
Accessor< EdgeForwardingSpec::Edge, uint32_t,&EdgeForwardingSpec::Edge::outbound_label > Setter
Definition: bgp_proto.cc:1480
void STLDeleteValues(Container *container)
Definition: util.h:101
BgpProto::Keepalive ContextType
Definition: bgp_proto.cc:721
static Capability * Encode(uint16_t gr_time, bool restarted, bool notification, const std::vector< uint8_t > &gr_afi_flags, const std::vector< Address::Family > &gr_families)
Definition: bgp_proto.cc:129
static bool Verifier(const AsPathSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1096
mpl::map< mpl::pair< mpl::int_< BgpProto::OpenMessage::OPEN_OPT_CAPABILITIES >, BgpOpenCapabilities > > Choice
Definition: bgp_proto.cc:665
mpl::map< mpl::pair< mpl::int_< BgpAttribute::Origin >, BgpAttrTemplate< BgpAttrOrigin, 1, int,&BgpAttrOrigin::origin > >, mpl::pair< mpl::int_< BgpAttribute::AsPath >, BgpPathAttributeAsPath4Byte >, mpl::pair< mpl::int_< BgpAttribute::As4Path >, BgpPathAttributeAs4Path >, mpl::pair< mpl::int_< BgpAttribute::NextHop >, BgpAttrTemplate< BgpAttrNextHop, 4, uint32_t,&BgpAttrNextHop::nexthop > >, mpl::pair< mpl::int_< BgpAttribute::MultiExitDisc >, BgpAttrTemplate< BgpAttrMultiExitDisc, 4, uint32_t,&BgpAttrMultiExitDisc::med > >, mpl::pair< mpl::int_< BgpAttribute::LocalPref >, BgpAttrTemplate< BgpAttrLocalPref, 4, uint32_t,&BgpAttrLocalPref::local_pref > >, mpl::pair< mpl::int_< BgpAttribute::AtomicAggregate >, BgpPathAttributeAtomicAggregate >, mpl::pair< mpl::int_< BgpAttribute::Aggregator >, BgpPathAttributeAggregator4Byte >, mpl::pair< mpl::int_< BgpAttribute::As4Aggregator >, BgpPathAttributeAs4Aggregator >, mpl::pair< mpl::int_< BgpAttribute::Communities >, BgpPathAttributeCommunities >, mpl::pair< mpl::int_< BgpAttribute::OriginatorId >, BgpAttrTemplate< BgpAttrOriginatorId, 4, uint32_t,&BgpAttrOriginatorId::originator_id > >, mpl::pair< mpl::int_< BgpAttribute::ClusterList >, BgpPathAttributeClusterList >, mpl::pair< mpl::int_< BgpAttribute::MPReachNlri >, BgpPathAttributeMpReachNlriSequence >, mpl::pair< mpl::int_< BgpAttribute::MPUnreachNlri >, BgpPathAttributeMpUnreachNlriSequence >, mpl::pair< mpl::int_< BgpAttribute::ExtendedCommunities >, BgpPathAttributeExtendedCommunities >, mpl::pair< mpl::int_< BgpAttribute::PmsiTunnel >, BgpPathAttributePmsiTunnel >, mpl::pair< mpl::int_< BgpAttribute::McastEdgeDiscovery >, BgpPathAttributeEdgeDiscovery >, mpl::pair< mpl::int_< BgpAttribute::McastEdgeForwarding >, BgpPathAttributeEdgeForwarding >, mpl::pair< mpl::int_< BgpAttribute::OriginVnPath >, BgpPathAttributeOriginVnPath >, mpl::pair< mpl::int_<-1 >, BgpPathAttributeUnknown > > Choice
Definition: bgp_proto.cc:1976
VectorAccessor< PmsiTunnelSpec, uint8_t,&PmsiTunnelSpec::identifier > Setter
Definition: bgp_proto.cc:1292
BgpContextSwap< BgpAttrAtomicAggregate > ContextSwap
Definition: bgp_proto.cc:959
std::vector< uint8_t > outbound_address
Definition: bgp_attr.h:561
static void set(BgpProtoPrefix *obj, int value)
Definition: bgp_proto.cc:1705
mpl::list< BgpPathAttributeDiscoveryEdgeLabelLen, BgpPathAttributeDiscoveryEdgeLabelValues > Sequence
Definition: bgp_proto.cc:1361
static void GetFamilies(const LLGR &llgr_params, std::vector< std::string > *families)
Definition: bgp_proto.cc:260
mpl::list< BgpPrefixLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:1594
static void Writer(const void *msg, uint8_t *data, size_t size)
Definition: bgp_proto.cc:577
mpl::list< BgpPathAttrLength, BgpPathAttrAsPath4ByteSegmentList > Sequence
Definition: bgp_proto.cc:1172
mpl::list< BgpPathAttrLength, BgpPathAttributeOriginVnList > Sequence
Definition: bgp_proto.cc:1278
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:573
mpl::list< BgpPathAttrLength, BgpAttributeValue< 2, BgpAttrAggregator, as2_t,&BgpAttrAggregator::as_num >, BgpAttributeValue< 4, BgpAttrAggregator, uint32_t,&BgpAttrAggregator::address > > Sequence
Definition: bgp_proto.cc:973
static bool Verifier(const AsPath4ByteSpec::PathSegment *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:898
static bool Verifier(const ExtCommunitySpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1223
static const uint8_t kFlags
Definition: bgp_attr.h:123
std::vector< BgpProtoPrefix * > nlri
Definition: bgp_proto.h:436
static const map< MatchProtocol::MatchProtocolType, string > toString
std::vector< PathSegment * > path_segments
Definition: bgp_aspath.h:235
AsPath4ByteSpec ContextType
Definition: bgp_proto.cc:1169
mpl::list< BgpMarker, BgpMsgLength, BgpMsgType > Sequence
Definition: bgp_proto.cc:2079
Family
Definition: address.h:24
#define KEY_COMPARE(x, y)
Definition: util.h:70
mpl::list< BgpOpenOptParamChoice > Sequence
Definition: bgp_proto.cc:676
static Address::Family AfiSafiToFamily(uint16_t afi, uint8_t safi)
Definition: bgp_af.cc:71
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1314
bool LookupFamily(Address::Family family)
Definition: bgp_peer.h:197
static const uint8_t kFlags
Definition: bgp_attr.h:42
mpl::map< mpl::pair< mpl::int_< 0 >, BgpPathAttributeMpNlri >, mpl::pair< mpl::int_< 1 >, BgpPathAttributeMpEvpnNlri >, mpl::pair< mpl::int_< 2 >, BgpPathAttributeMpErmVpnNlri >, mpl::pair< mpl::int_< 3 >, BgpPathAttributeMpMvpnNlri > > Choice
Definition: bgp_proto.cc:1812
int operator()(BgpProtoPrefix *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:728
std::vector< uint8_t > address
Definition: bgp_attr.h:455
EdgeList edge_list
Definition: bgp_attr.h:459
uint8_t flags
Definition: bgp_attr_base.h:70
CollectionAccessor< BgpMpNlri, vector< BgpProtoPrefix * >,&BgpMpNlri::nlri > ContextStorer
Definition: bgp_proto.cc:1593
#define BGP_LOG_PEER_WARNING(type, peer, flags, dir, arg)
Definition: bgp_log.h:182
mpl::list< BgpPathAttrLength, BgpPathAttrAsPathSegmentList > Sequence
Definition: bgp_proto.cc:1163
bool match(const BgpMpNlri *obj)
Definition: bgp_proto.cc:1679
void set_time(uint16_t gr_cap_bytes)
Definition: bgp_proto.h:165
AttrLen SequenceLength
Definition: bgp_proto.cc:784
VectorAccessor< BgpProto::OpenMessage::Capability, uint8_t,&BgpProto::OpenMessage::Capability::capability > Setter
Definition: bgp_proto.cc:628
mpl::list< BgpPathAttributeDiscoveryEdgeAddress, BgpPathAttributeDiscoveryEdgeLabels > Sequence
Definition: bgp_proto.cc:1381
uint8_t tunnel_type
Definition: bgp_attr.h:359
mpl::list< BgpPathAttrLength, BgpPathAttributeCommunityList > Sequence
Definition: bgp_proto.cc:1216
std::vector< as_t > path_segment
Definition: bgp_aspath.h:214
Accessor< EdgeForwardingSpec::Edge, uint32_t,&EdgeForwardingSpec::Edge::inbound_label > Setter
Definition: bgp_proto.cc:1455
Accessor< BgpProto::OpenMessage, int32_t,&BgpProto::OpenMessage::holdtime > Setter
Definition: bgp_proto.cc:601
VectorAccessor< AsPath4ByteSpec::PathSegment, as_t,&AsPath4ByteSpec::PathSegment::path_segment > Setter
Definition: bgp_proto.cc:1079
virtual BgpProto::BgpPeerType PeerType() const
Definition: bgp_peer.h:208
VectorAccessor< EdgeForwardingSpec::Edge, uint8_t,&EdgeForwardingSpec::Edge::inbound_address > Setter
Definition: bgp_proto.cc:1438
mpl::list< BgpOpenVersion, BgpOpenAsNum, BgpHoldTime, BgpIdentifier, BgpOpenOptParam > Sequence
Definition: bgp_proto.cc:685
static bool Verifier(const CommunitySpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1200
bool match(const BgpMpNlri *obj)
Definition: bgp_proto.cc:1727
static uint16_t get_short(const void *ptr)
void SetError(int error, int subcode, std::string type, const uint8_t *data, int data_size)
BgpContextSwap< BgpAttr4ByteAggregator > ContextSwap
Definition: bgp_proto.cc:980
mpl::list< BgpAttributeValue< 1, AsPathSpec::PathSegment, int,&AsPathSpec::PathSegment::path_segment_type >, BgpPathAttrAsPathSegmentLength, BgpPathAttrAsPathSegmentValue > Sequence
Definition: bgp_proto.cc:1110
mpl::list< BgpMarker, BgpMsgLength, BgpMsgTypeAs4 > Sequence
Definition: bgp_proto.cc:2084
static bool Decode(GR *gr_params, const std::vector< Capability * > &capabilities)
Definition: bgp_proto.cc:175
VectorAccessor< BgpMpNlri, uint8_t,&BgpMpNlri::nexthop > Setter
Definition: bgp_proto.cc:1565
uint32_t as_t
Definition: bgp_common.h:21
Accessor< BgpProto::Notification, int,&BgpProto::Notification::error > Setter
Definition: bgp_proto.cc:693
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:39
VectorAccessor< CommunitySpec, uint32_t,&CommunitySpec::communities > Setter
Definition: bgp_proto.cc:1207
int operator()(BgpAttribute *obj, const uint8_t *data, size_t &size)
Definition: bgp_proto.cc:773
Accessor< BgpProtoPrefix, int,&BgpProtoPrefix::prefixlen > Setter
Definition: bgp_proto.cc:735
std::vector< uint32_t > cluster_list
Definition: bgp_attr.h:217
VectorAccessor< ExtCommunitySpec, uint64_t,&ExtCommunitySpec::communities > Setter
Definition: bgp_proto.cc:1230
Accessor< BgpProto::Notification, string,&BgpProto::Notification::data > Setter
Definition: bgp_proto.cc:707
static const int kMinMessageSize
Definition: bgp_proto.h:440
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1341
mpl::list< BgpPrefixLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:2034
mpl::list< BgpPathAttrLength, BgpAttributeValue< 1, PmsiTunnelSpec, uint8_t,&PmsiTunnelSpec::tunnel_flags >, BgpAttributeValue< 1, PmsiTunnelSpec, uint8_t,&PmsiTunnelSpec::tunnel_type >, BgpAttributeValue< 3, PmsiTunnelSpec, uint32_t,&PmsiTunnelSpec::label >, BgpPathAttributePmsiTunnelIdentifier > Sequence
Definition: bgp_proto.cc:1307
mpl::list< BgpPathAttrLength, BgpAttributeValue< 4, BgpAttr4ByteAggregator, as_t,&BgpAttr4ByteAggregator::as_num >, BgpAttributeValue< 4, BgpAttr4ByteAggregator, uint32_t,&BgpAttr4ByteAggregator::address > > Sequence
Definition: bgp_proto.cc:986
static bool Verifier(const OriginVnPathSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1263
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1397
Accessor< BgpProto::OpenMessage, uint32_t,&BgpProto::OpenMessage::identifier > Setter
Definition: bgp_proto.cc:608
CollectionAccessor< BgpProto::Update, vector< BgpProtoPrefix * >,&BgpProto::Update::nlri > ContextStorer
Definition: bgp_proto.cc:2026
PathSegmentLength SequenceLength
Definition: bgp_proto.cc:1012
std::vector< OptParam * > opt_params
Definition: bgp_proto.h:219
CollectionAccessor< BgpMpNlri, vector< BgpProtoPrefix * >,&BgpMpNlri::nlri > ContextStorer
Definition: bgp_proto.cc:1734
BgpAttrAtomicAggregate ContextType
Definition: bgp_proto.cc:958
std::vector< PathSegment * > path_segments
Definition: bgp_aspath.h:79
Derived * operator()(const BgpAttribute *attr)
Definition: bgp_proto.cc:800
static const size_t kSize
Definition: rd.h:13
virtual BgpServer * server()
Definition: bgp_peer.h:157
PmsiTunnelSpec ContextType
Definition: bgp_proto.cc:1298
CollectionAccessor< BgpProto::Update, vector< BgpAttribute * >,&BgpProto::Update::path_attributes > ContextStorer
Definition: bgp_proto.cc:1995
VectorAccessor< ClusterListSpec, uint32_t,&ClusterListSpec::cluster_list > Setter
Definition: bgp_proto.cc:1247
mpl::list< BgpPathAttrLength, BgpAttributeValue< Size, C, T, M > > Sequence
Definition: bgp_proto.cc:935
int CompareTo(const Update &rhs) const
Definition: bgp_proto.cc:490
bool operator()(BgpAttribute *lhs, BgpAttribute *rhs)
Definition: bgp_proto.cc:397
mpl::list< BgpEvpnNlriType, BgpEvpnNlriLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:1736
mpl::list< BgpOpenCapabilityCode, BgpOpenCapabilityLength, BgpOpenCapabilityValue > Sequence
Definition: bgp_proto.cc:634
BgpContextSwap< C > ContextSwap
Definition: bgp_proto.cc:933
static bool Verifier(const AsPathSpec::PathSegment *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:889
VectorAccessor< AsPathSpec::PathSegment, as2_t,&AsPathSpec::PathSegment::path_segment > Setter
Definition: bgp_proto.cc:1071
static BgpMessage * Decode(const uint8_t *data, size_t size, ParseErrorContext *ec=NULL, bool as4=false)
Definition: bgp_proto.cc:2087
Offset SaveOffset
Definition: bgp_proto.cc:545
VectorAccessor< OriginVnPathSpec, uint64_t,&OriginVnPathSpec::origin_vns > Setter
Definition: bgp_proto.cc:1270
CollectionAccessor< BgpProto::OpenMessage, vector< BgpProto::OpenMessage::OptParam * >,&BgpProto::OpenMessage::opt_params > ContextStorer
Definition: bgp_proto.cc:675
mpl::list< BgpErmVpnNlriType, BgpErmVpnNlriLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:1690
mpl::list< BgpPathAttrLength, BgpAttributeValue< 2, BgpMpNlri, uint16_t,&BgpMpNlri::afi >, BgpAttributeValue< 1, BgpMpNlri, uint8_t,&BgpMpNlri::safi >, BgpPathAttributeMpNlriChoice > Sequence
Definition: bgp_proto.cc:1848
mpl::list< BgpPathAttrLength > Sequence
Definition: bgp_proto.cc:960
int operator()(EdgeForwardingSpec::Edge *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:1403
std::vector< BgpProtoPrefix * > withdrawn_routes
Definition: bgp_proto.h:434
ErmVpnPrefixLen Setter
Definition: bgp_proto.cc:1669
static int Encode(const BgpMessage *msg, uint8_t *data, size_t size, EncodeOffsets *offsets=NULL, bool as4=false)
Definition: bgp_proto.cc:2107
static bool Verifier(const EdgeDiscoverySpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1370
static bool Verifier(const C *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:919
static void set(BgpProtoPrefix *obj, int value)
Definition: bgp_proto.cc:1657
CollectionAccessor< AsPathSpec, vector< AsPathSpec::PathSegment * >,&AsPathSpec::path_segments > ContextStorer
Definition: bgp_proto.cc:1104
std::vector< Family > families
Definition: bgp_proto.h:170
static const uint8_t kMaxV4Bytes
Definition: address.h:19
uint16_t as2_t
Definition: bgp_common.h:22
std::vector< uint8_t > prefix
static void GetFamilies(const GR &gr_params, std::vector< std::string > *families)
Definition: bgp_proto.cc:156
uint32_t label
Definition: bgp_attr.h:360
virtual bool IsAs4Supported() const
Definition: bgp_peer.h:314
BgpContextSwap< BgpMpNlri > ContextSwap
Definition: bgp_proto.cc:1825
OptMatch ContextMatch
Definition: bgp_proto.cc:653
EncodeOffsets & encode_offsets()
PrefixLen SequenceLength
Definition: bgp_proto.cc:733
mpl::list< BgpPathAttrLength, BgpPathAttributeForwardingEdgeList > Sequence
Definition: bgp_proto.cc:1512
bool match(const BgpMpNlri *obj)
Definition: bgp_proto.cc:1631
Accessor< BgpAttribute, uint8_t,&BgpAttribute::code > Setter
Definition: bgp_proto.cc:1931
static bool Verifier(const void *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:521
BgpAttrAs4Aggregator ContextType
Definition: bgp_proto.cc:992
VectorAccessor< EdgeDiscoverySpec::Edge, uint8_t,&EdgeDiscoverySpec::Edge::address > Setter
Definition: bgp_proto.cc:1327
mpl::list< BgpPathAttributeForwardingEdgeAddressLen, BgpPathAttributeForwardingEdgeInAddressValue > Sequence
Definition: bgp_proto.cc:1447
const ParseErrorContext & error_context()
mpl::list Sequence
Definition: bgp_proto.cc:720
static bool Verifier(const EdgeForwardingSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1489
std::vector< uint8_t > capability
Definition: bgp_proto.h:210
FlagsAccessor Setter
Definition: bgp_proto.cc:1193
mpl::list< BgpPathAttributeFlags, BgpPathAttribute > Sequence
Definition: bgp_proto.cc:1996
static Capability * Encode(uint32_t llgr_time, uint8_t llgr_afi_flags, const std::vector< Address::Family > &llgr_families)
Definition: bgp_proto.cc:207
static void Callback(EncodeContext *context, uint8_t *data, int offset, int element_size)
Definition: bgp_proto.cc:559
CollectionAccessor< EdgeDiscoverySpec, vector< EdgeDiscoverySpec::Edge * >,&EdgeDiscoverySpec::edge_list > ContextStorer
Definition: bgp_proto.cc:1378
EdgeDiscoverySpec ContextType
Definition: bgp_proto.cc:1387
BgpContextSwap< BgpAttrAs4Aggregator > ContextSwap
Definition: bgp_proto.cc:993
static std::string ToString(uint16_t afi, uint8_t safi)
Definition: bgp_af.cc:14
static bool Verifier(BgpAttrUnknown *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1854
BgpContextSwap< EdgeForwardingSpec > ContextSwap
Definition: bgp_proto.cc:1510
BgpAttr4ByteAggregator ContextType
Definition: bgp_proto.cc:979
BgpContextSwap< As4PathSpec > ContextSwap
Definition: bgp_proto.cc:1178
std::vector< uint64_t > origin_vns
static const uint8_t kMaxV6Bytes
Definition: address.h:21
uint32_t nexthop
Definition: bgp_attr.h:82
OriginVnPathSpec ContextType
Definition: bgp_proto.cc:1276
static bool Verifier(const As4PathSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1142
mpl::list< BgpPathAttrLength, BgpPathAttrAs4PathSegmentList > Sequence
Definition: bgp_proto.cc:1179
mpl::list< BgpUpdateWithdrawnRoutes, BgpPathAttributeList, BgpUpdateNlri > Sequence
Definition: bgp_proto.cc:2047
CollectionAccessor< As4PathSpec, vector< As4PathSpec::PathSegment * >,&As4PathSpec::path_segments > ContextStorer
Definition: bgp_proto.cc:1150
static int Encode(EncodeContext *context, const T *msg, uint8_t *data, size_t size)
mpl::list< BgpOpenCapability > Sequence
Definition: bgp_proto.cc:642
CollectionAccessor< BgpProto::Update, vector< BgpAttribute * >,&BgpProto::Update::path_attributes > ContextStorer
Definition: bgp_proto.cc:2015
mpl::list< BgpAttributeValue< 1, AsPath4ByteSpec::PathSegment, int,&AsPath4ByteSpec::PathSegment::path_segment_type >, BgpPathAttrAsPath4ByteSegmentLength, BgpPathAttrAsPath4ByteSegmentValue > Sequence
Definition: bgp_proto.cc:1133
std::vector< as_t > path_segment
Definition: bgp_aspath.h:374
BgpContextSwap< ClusterListSpec > ContextSwap
Definition: bgp_proto.cc:1254
int operator()(As4PathSpec::PathSegment *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:1049
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
static std::pair< uint16_t, uint8_t > FamilyToAfiSafi(Address::Family family)
Definition: bgp_af.cc:130
VectorAccessor< As4PathSpec::PathSegment, as_t,&As4PathSpec::PathSegment::path_segment > Setter
Definition: bgp_proto.cc:1087
static void Writer(const void *msg, uint8_t *data, size_t size)
Definition: bgp_proto.cc:528
Accessor< BgpProtoPrefix, uint8_t,&BgpProtoPrefix::type > Setter
Definition: bgp_proto.cc:1697
static void Callback(EncodeContext *context, uint8_t *data, int offset, int element_size)
Definition: bgp_proto.cc:1056
ClusterListSpec ContextType
Definition: bgp_proto.cc:1253
std::vector< uint8_t > identifier
Definition: bgp_attr.h:361
mpl::list< NotificationErrorCode, NotificationErrorSubcode, NotificationData > Sequence
Definition: bgp_proto.cc:714
virtual const std::string ToString() const
Definition: bgp_proto.cc:343
Accessor< BgpProtoPrefix, uint8_t,&BgpProtoPrefix::type > Setter
Definition: bgp_proto.cc:1649
static const int kMaxMessageSize
Definition: bgp_proto.h:441
static const uint8_t FLAG_MASK
Definition: bgp_attr_base.h:67
static std::string FamilyToString(Family fmly)
Definition: address.cc:63
BgpContextSwap< OriginVnPathSpec > ContextSwap
Definition: bgp_proto.cc:1277
#define TYPE_NAME(_type)
Definition: logging.h:31
uint32_t bgp_identifier() const
Definition: bgp_server.h:208
static void set(BgpAttribute *obj, uint8_t value)
Definition: bgp_proto.cc:1186
bool match(const BgpProto::Update *ctx)
Definition: bgp_proto.cc:760
static bool Verifier(const BgpAttrNextHop *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:860
bool match(const BgpProto::OpenMessage::OptParam *ctx)
Definition: bgp_proto.cc:649
uint8_t tunnel_flags
Definition: bgp_attr.h:358
Accessor< BgpProto::OpenMessage::Capability, int,&BgpProto::OpenMessage::Capability::code > Setter
Definition: bgp_proto.cc:615
uint8_t safi
Definition: bgp_attr.h:308
EdgeForwardingSpec ContextType
Definition: bgp_proto.cc:1509
#define BGP_LOG_FLAG_TRACE
Definition: bgp_log.h:43
CollectionAccessor< BgpMpNlri, vector< BgpProtoPrefix * >,&BgpMpNlri::nlri > ContextStorer
Definition: bgp_proto.cc:1639
int Validate(const BgpPeer *, std::string *data)
Definition: bgp_proto.cc:407
BgpProto::Update ContextType
Definition: bgp_proto.cc:2041
static bool Decode(LLGR *llgr_params, const std::vector< Capability * > &capabilities)
Definition: bgp_proto.cc:227
mpl::list< BgpPrefixLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:766
BgpContextSwap< PmsiTunnelSpec > ContextSwap
Definition: bgp_proto.cc:1299
static int Parse(const uint8_t *data, size_t size, ParseContext *context, T *obj)
mpl::list< BgpPathAttrLength, BgpPathAttributeExtendedCommunityList > Sequence
Definition: bgp_proto.cc:1239
Accessor< BgpProtoPrefix, uint8_t,&BgpProtoPrefix::type > Setter
Definition: bgp_proto.cc:1601
BgpContextSwap< AsPath4ByteSpec > ContextSwap
Definition: bgp_proto.cc:1170
AttrSizeSet SizeSetter
Definition: bgp_proto.cc:795
BgpContextSwap< BgpAttrAggregator > ContextSwap
Definition: bgp_proto.cc:967
CollectionAccessor< BgpProto::OpenMessage::OptParam, vector< BgpProto::OpenMessage::Capability * >,&BgpProto::OpenMessage::OptParam::capabilities > ContextStorer
Definition: bgp_proto.cc:646
BgpContextSwap< AsPathSpec > ContextSwap
Definition: bgp_proto.cc:1162
BgpProto::Update ContextType
Definition: bgp_proto.cc:2048
mpl::list< BgpPathAttrLength, BgpAttributeValue< 4, BgpAttrAs4Aggregator, as_t,&BgpAttrAs4Aggregator::as_num >, BgpAttributeValue< 4, BgpAttrAs4Aggregator, uint32_t,&BgpAttrAs4Aggregator::address > > Sequence
Definition: bgp_proto.cc:999
std::vector< Capability * > capabilities
Definition: bgp_proto.h:217
int operator()(AsPath4ByteSpec::PathSegment *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:1028
mpl::list< BgpPathAttributeFlags, BgpPathAttributeAs4 > Sequence
Definition: bgp_proto.cc:2016
CollectionAccessor< BgpMpNlri, vector< BgpProtoPrefix * >,&BgpMpNlri::nlri > ContextStorer
Definition: bgp_proto.cc:1687
Accessor< BgpAttribute, uint8_t,&BgpAttribute::code > Setter
Definition: bgp_proto.cc:1880
BgpContextSwap< CommunitySpec > ContextSwap
Definition: bgp_proto.cc:1214
uint32_t address
Definition: bgp_attr.h:162
SetLength EncodingCallback
Definition: bgp_proto.cc:564
mpl::list< BgpAttributeValue< 1, As4PathSpec::PathSegment, int,&As4PathSpec::PathSegment::path_segment_type >, BgpPathAttrAs4PathSegmentLength, BgpPathAttrAs4PathSegmentValue > Sequence
Definition: bgp_proto.cc:1156
static bool Verifier(const BgpProto::OpenMessage *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:595
int ValidateCapabilities(BgpPeer *peer) const
Definition: bgp_proto.cc:50
bool match(const BgpMpNlri *obj)
Definition: bgp_proto.cc:1581
int operator()(EdgeForwardingSpec::Edge *obj, const uint8_t *data, size_t size)
Definition: bgp_proto.cc:1425
bool enable_4byte_as() const
Definition: bgp_server.cc:726
OptMatch ContextMatch
Definition: bgp_proto.cc:2033
mpl::list< BgpMvpnNlriType, BgpMvpnNlriLen, BgpPrefixAddress > Sequence
Definition: bgp_proto.cc:1642
static void set(BgpProtoPrefix *obj, int value)
Definition: bgp_proto.cc:1609
static bool Verifier(const As4PathSpec::PathSegment *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:907
as_t peer_as() const
Definition: bgp_peer.h:184
static bool Verifier(const AsPath4ByteSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1119
EdgeList edge_list
Definition: bgp_attr.h:566
Accessor< BgpProto::OpenMessage, uint32_t,&BgpProto::OpenMessage::as_num > Setter
Definition: bgp_proto.cc:586
static void Callback(EncodeContext *context, uint8_t *data, int offset, int element_size)
Definition: bgp_proto.cc:1411
mpl::list< BgpUpdateWithdrawnRoutes, BgpPathAttributeAs4List, BgpUpdateNlri > Sequence
Definition: bgp_proto.cc:2040
BgpAttrUnknown ContextType
Definition: bgp_proto.cc:1871
mpl::map< mpl::pair< mpl::int_< BgpProto::OPEN >, BgpOpenMessage >, mpl::pair< mpl::int_< BgpProto::NOTIFICATION >, BgpNotificationMessage >, mpl::pair< mpl::int_< BgpProto::KEEPALIVE >, BgpKeepaliveMessage >, mpl::pair< mpl::int_< BgpProto::UPDATE >, BgpUpdateMessageAs4 > > Choice
Definition: bgp_proto.cc:2074
VectorAccessor< BgpProtoPrefix, uint8_t,&BgpProtoPrefix::prefix > Setter
Definition: bgp_proto.cc:742
VectorAccessor< EdgeForwardingSpec::Edge, uint8_t,&EdgeForwardingSpec::Edge::outbound_address > Setter
Definition: bgp_proto.cc:1463
std::vector< uint32_t > communities
Definition: community.h:33
static bool Verifier(const BgpAttrOrigin *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:831
static void Callback(EncodeContext *context, uint8_t *data, int offset, int element_size)
Definition: bgp_proto.cc:1014
static bool Verifier(const BgpMpNlri *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1531
std::vector< uint64_t > communities
Definition: community.h:143
mpl::list< BgpPathAttributeMpNlriNextHopLength, BgpPathAttributeMpNlriNexthopAddr > Sequence
Definition: bgp_proto.cc:1572
BgpContextSwap< EdgeDiscoverySpec > ContextSwap
Definition: bgp_proto.cc:1388
BgpAttrAggregator ContextType
Definition: bgp_proto.cc:966
std::vector< as2_t > path_segment
Definition: bgp_aspath.h:58
std::vector< PathSegment * > path_segments
Definition: bgp_aspath.h:395
Accessor< BgpProto::Notification, int,&BgpProto::Notification::subcode > Setter
Definition: bgp_proto.cc:700
mpl::list< BgpPathAttrLength, BgpAttributeValue< 2, BgpMpNlri, uint16_t,&BgpMpNlri::afi >, BgpAttributeValue< 1, BgpMpNlri, uint8_t,&BgpMpNlri::safi >, BgpPathAttributeMpNlriNextHop, BgpPathAttributeReserved, BgpPathAttributeMpNlriChoice > Sequence
Definition: bgp_proto.cc:1831
BgpContextSwap< BgpAttrUnknown > ContextSwap
Definition: bgp_proto.cc:1872
mpl::list< BgpPathAttributeForwardingEdgeAddressLen, BgpPathAttributeForwardingEdgeOutAddressValue > Sequence
Definition: bgp_proto.cc:1472
mpl::list< BgpPathAttrLength, BgpPathAttrUnknownValue > Sequence
Definition: bgp_proto.cc:1873
uint32_t local_pref
Definition: bgp_attr.h:115
std::vector< uint8_t > inbound_address
Definition: bgp_attr.h:561
static const uint8_t kFlags
Definition: bgp_attr.h:63
static void Callback(EncodeContext *context, uint8_t *data, int offset, int element_size)
Definition: bgp_proto.cc:1035
mpl::list< BgpPathAttributeForwardingEdgeLen, BgpPathAttributeForwardingEdgeInAddress, BgpPathAttributeForwardingEdgeInLabel, BgpPathAttributeForwardingEdgeOutAddress, BgpPathAttributeForwardingEdgeOutLabel > Sequence
Definition: bgp_proto.cc:1503
mpl::map< mpl::pair< mpl::int_< BgpProto::OPEN >, BgpOpenMessage >, mpl::pair< mpl::int_< BgpProto::NOTIFICATION >, BgpNotificationMessage >, mpl::pair< mpl::int_< BgpProto::KEEPALIVE >, BgpKeepaliveMessage >, mpl::pair< mpl::int_< BgpProto::UPDATE >, BgpUpdateMessage > > Choice
Definition: bgp_proto.cc:2061
PathSegmentLength SequenceLength
Definition: bgp_proto.cc:1054
VectorAccessor< EdgeDiscoverySpec::Edge, uint32_t,&EdgeDiscoverySpec::Edge::labels > Setter
Definition: bgp_proto.cc:1354
MvpnPrefixLen Setter
Definition: bgp_proto.cc:1621
static bool Verifier(const PmsiTunnelSpec *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:1285
uint8_t code
Definition: bgp_attr_base.h:68
#define AS_TRANS
Definition: bgp_common.h:23
void set_flags(uint16_t gr_cap_bytes)
Definition: bgp_proto.h:162
static const int kSize
Definition: bgp_attr.h:62
BgpProto::OpenMessage ContextType
Definition: bgp_proto.cc:686
CollectionAccessor< EdgeForwardingSpec, vector< EdgeForwardingSpec::Edge * >,&EdgeForwardingSpec::edge_list > ContextStorer
Definition: bgp_proto.cc:1497
std::vector< BgpAttribute * > path_attributes
Definition: bgp_proto.h:435
EvpnPrefixLen Setter
Definition: bgp_proto.cc:1717
#define BGP_PEER_DIR_IN
Definition: bgp_log.h:139
CollectionAccessor< BgpProto::Update, vector< BgpProtoPrefix * >,&BgpProto::Update::withdrawn_routes > ContextStorer
Definition: bgp_proto.cc:757
BgpProto::Notification ContextType
Definition: bgp_proto.cc:715
#define BGP_LOG_FLAG_ALL
Definition: bgp_log.h:44
std::vector< uint32_t > labels
Definition: bgp_attr.h:456
static const std::string toString(Code code, int subcode)
Definition: bgp_proto.cc:347
#define BGP_LOG_PEER(type, peer, level, flags, dir, arg)
Definition: bgp_log.h:159
static bool Verifier(const BgpAttrAtomicAggregate *obj, const uint8_t *data, size_t size, ParseContext *context)
Definition: bgp_proto.cc:941
static void set(BgpMpNlri *obj, int &value)
Definition: bgp_proto.cc:1744
VectorAccessor< BgpAttrUnknown, uint8_t,&BgpAttrUnknown::value > Setter
Definition: bgp_proto.cc:1866
mpl::list< BgpPathAttrLength, BgpPathAttributeDiscoveryEdgeList > Sequence
Definition: bgp_proto.cc:1390
mpl::list< BgpPathAttributeDiscoveryEdgeAddressLen, BgpPathAttributeDiscoveryEdgeAddressValue > Sequence
Definition: bgp_proto.cc:1334
static void put_value(uint8_t *data, int size, uint64_t value)
Definition: parse_object.h:55