OpenSDN source code
bgp/evpn/evpn_route.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include "bgp/evpn/evpn_route.h"
7 
8 #include <algorithm>
9 #include <sstream>
10 
11 #include "base/string_util.h"
12 #include "bgp/bgp_server.h"
13 #include "bgp/evpn/evpn_table.h"
14 
15 using std::copy;
16 using std::string;
17 using std::vector;
18 
20 const uint32_t EvpnPrefix::kInvalidLabel = 0x01000000;
21 const uint32_t EvpnPrefix::kNullTag = 0;
22 const uint32_t EvpnPrefix::kMaxTag = 0xFFFFFFFF;
23 const uint32_t EvpnPrefix::kMaxVni = 0x00FFFFFF;
24 const int32_t EvpnPrefix::kMaxVniSigned =
25  static_cast<uint32_t>(EvpnPrefix::kMaxVni);
26 
29 const size_t EvpnPrefix::kTagSize = 4;
30 const size_t EvpnPrefix::kIp4AddrSize = 4;
31 const size_t EvpnPrefix::kIp6AddrSize = 16;
32 const size_t EvpnPrefix::kMacSize = MacAddress::size();
34 
36  kRdSize + kEsiSize + kTagSize;
38  kRdSize + kEsiSize + kTagSize + 1 + kMacSize + 1;
40  kRdSize + kTagSize + 1;
42  kRdSize + kTagSize + 3;
44  kRdSize + kEsiSize + 1;
46  kRdSize + kEsiSize + kTagSize + 1 + 2 * kIp4AddrSize;
48  kRdSize + kEsiSize + kTagSize + 1 + 2 * kIp6AddrSize;
49 
50 //
51 // Read label from the BgpProtoPrefix.
52 // If the encapsulation is VXLAN and ethernet tag is non-zero use that as
53 // the label for backward compatibility with older JUNOS code.
54 //
55 // Note that Ethernet AD Routes per ESI always set ethernet tag to kMaxTag
56 // and their label is supposed to be set to 0 on write and ignored on read.
57 //
58 static uint32_t ReadLabel(const BgpProtoPrefix &proto_prefix,
59  const BgpAttr *attr, size_t offset, uint32_t tag = EvpnPrefix::kNullTag) {
60  if (!attr)
61  return 0;
62  const ExtCommunity *extcomm = attr->ext_community();
63  if (extcomm && extcomm->ContainsTunnelEncapVxlan()) {
64  if (tag) {
65  if (tag == EvpnPrefix::kMaxTag) {
66  return 0;
67  } else if (tag <= EvpnPrefix::kMaxVni) {
68  return tag;
69  } else {
70  return proto_prefix.ReadLabel(offset, true);
71  }
72  } else {
73  return proto_prefix.ReadLabel(offset, true);
74  }
75  } else {
76  return proto_prefix.ReadLabel(offset, false);
77  }
78 }
79 
80 //
81 // Write label to the BgpProtoPrefix.
82 //
83 static void WriteLabel(BgpProtoPrefix *proto_prefix,
84  const BgpAttr *attr, size_t offset, uint32_t label) {
85  const ExtCommunity *extcomm = attr ? attr->ext_community() : NULL;
86  if (extcomm && extcomm->ContainsTunnelEncapVxlan()) {
87  proto_prefix->WriteLabel(offset, label, true);
88  } else {
89  proto_prefix->WriteLabel(offset, label, false);
90  }
91 }
92 
93 //
94 // Read gateway address from the BgpProtoPrefix.
95 //
96 static IpAddress ReadGwAddress(const BgpProtoPrefix &proto_prefix,
97  size_t gw_offset, size_t ip_size) {
98  assert(ip_size == EvpnPrefix::kIp4AddrSize ||
99  ip_size == EvpnPrefix::kIp6AddrSize);
100  if (ip_size == EvpnPrefix::kIp4AddrSize) {
101  Ip4Address::bytes_type bytes;
102  copy(proto_prefix.prefix.begin() + gw_offset,
103  proto_prefix.prefix.begin() + gw_offset + ip_size, bytes.begin());
104  return Ip4Address(bytes);
105  } else {
106  Ip6Address::bytes_type bytes;
107  copy(proto_prefix.prefix.begin() + gw_offset,
108  proto_prefix.prefix.begin() + gw_offset + ip_size, bytes.begin());
109  return Ip6Address(bytes);
110  }
111  return IpAddress();
112 }
113 
115  : type_(Unspecified),
116  tag_(EvpnPrefix::kNullTag),
117  family_(Address::UNSPEC),
118  ip_prefixlen_(0) {
119 }
120 
122  const EthernetSegmentId &esi, uint32_t tag)
123  : type_(AutoDiscoveryRoute),
124  rd_(rd),
125  esi_(esi),
126  tag_(tag),
127  family_(Address::UNSPEC),
128  ip_prefixlen_(0) {
129 }
130 
132  const MacAddress &mac_addr, const IpAddress &ip_address)
133  : type_(MacAdvertisementRoute),
134  rd_(rd),
135  tag_(EvpnPrefix::kNullTag),
136  mac_addr_(mac_addr),
137  family_(Address::UNSPEC),
138  ip_address_(ip_address),
139  ip_prefixlen_(0) {
140  if (ip_address_.is_v4() && !ip_address_.is_unspecified()) {
142  } else if (ip_address_.is_v6() && !ip_address_.is_unspecified()) {
144  }
145 }
146 
148  const MacAddress &mac_addr, const IpAddress &ip_address)
149  : type_(MacAdvertisementRoute), rd_(rd), tag_(tag),
150  mac_addr_(mac_addr), family_(Address::UNSPEC),
151  ip_address_(ip_address), ip_prefixlen_(0) {
152  if (ip_address_.is_v4() && !ip_address_.is_unspecified()) {
154  } else if (ip_address_.is_v6() && !ip_address_.is_unspecified()) {
156  }
157 }
158 
160  const IpAddress &ip_address)
161  : type_(InclusiveMulticastRoute),
162  rd_(rd),
163  tag_(tag),
164  family_(Address::UNSPEC),
165  ip_address_(ip_address),
166  ip_prefixlen_(0) {
167  if (ip_address_.is_v4() && !ip_address_.is_unspecified()) {
169  } else if (ip_address_.is_v6() && !ip_address_.is_unspecified()) {
171  }
172 }
173 
175  const EthernetSegmentId &esi, const IpAddress &ip_address)
176  : type_(SegmentRoute),
177  rd_(rd),
178  esi_(esi),
179  tag_(EvpnPrefix::kNullTag),
180  family_(Address::UNSPEC),
181  ip_address_(ip_address),
182  ip_prefixlen_(0) {
183  if (ip_address_.is_v4() && !ip_address_.is_unspecified()) {
185  } else if (ip_address_.is_v6() && !ip_address_.is_unspecified()) {
187  }
188 }
189 
191  const IpAddress &ip_address, uint8_t ip_prefixlen)
192  : type_(IpPrefixRoute),
193  rd_(rd),
194  tag_(0),
195  family_(Address::UNSPEC),
196  ip_address_(ip_address),
197  ip_prefixlen_(ip_prefixlen) {
198  assert(ip_address_.is_v4() || ip_address_.is_v6());
199  if (ip_address_.is_v4()) {
201  } else if (ip_address_.is_v6()) {
203  }
204 }
205 
207  const IpAddress &source, const IpAddress &group,
208  const IpAddress &ip_address)
209  : type_(SelectiveMulticastRoute),
210  rd_(rd),
211  tag_(tag),
212  family_(Address::UNSPEC),
213  ip_address_(ip_address),
214  source_(source),
215  group_(group),
216  ip_prefixlen_(0), flags_(0x2) {
217  if (ip_address_.is_v4() && !ip_address_.is_unspecified()) {
219  } else if (ip_address_.is_v6() && !ip_address_.is_unspecified()) {
221  }
222  string ip = group.to_v4().to_string();
223  char *str = const_cast<char *>(ip.c_str());
224  char * mac_ip = strstr(str, ".");
225  std::ostringstream oss;
226  oss << "01:00:5e:" << strtok(mac_ip, ".");
227  oss << ":" << strtok(NULL, ".");
228  oss << ":" << strtok(NULL, "");
229  mac_addr_ = MacAddress::FromString(oss.str(), NULL);
230 }
231 
233  const BgpProtoPrefix &proto_prefix, const BgpAttr *attr,
234  const Address::Family family, EvpnPrefix *prefix, BgpAttrPtr *new_attr,
235  uint32_t *label, uint32_t *l3_label) {
236  *new_attr = attr;
237  *label = 0;
238  if (l3_label)
239  *l3_label = 0;
240  prefix->type_ = proto_prefix.type;
241  size_t nlri_size = proto_prefix.prefix.size();
242 
243  switch (prefix->type_) {
244  case AutoDiscoveryRoute: {
245  size_t expected_min_nlri_size =
246  kMinAutoDiscoveryRouteSize + (attr ? kLabelSize : 0);
247  if (nlri_size < expected_min_nlri_size)
248  return -1;
249  size_t rd_offset = 0;
250  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
251  size_t esi_offset = rd_offset + kRdSize;
252  prefix->esi_ = EthernetSegmentId(&proto_prefix.prefix[esi_offset]);
253  size_t tag_offset = esi_offset + kEsiSize;
254  prefix->tag_ = get_value(&proto_prefix.prefix[tag_offset], kTagSize);
255  size_t label_offset = tag_offset + kTagSize;
256  *label = ReadLabel(proto_prefix, attr, label_offset, prefix->tag_);
257  break;
258  }
259  case MacAdvertisementRoute: {
260  size_t expected_min_nlri_size =
262  if (nlri_size < expected_min_nlri_size)
263  return -1;
264  size_t rd_offset = 0;
265  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
266  size_t esi_offset = rd_offset + kRdSize;
267  if (attr) {
268  EthernetSegmentId esi(&proto_prefix.prefix[esi_offset]);
269  *new_attr = server->attr_db()->ReplaceEsiAndLocate(attr, esi);
270  }
271  size_t tag_offset = esi_offset + kEsiSize;
272  prefix->tag_ = get_value(&proto_prefix.prefix[tag_offset], kTagSize);
273  size_t mac_len_offset = tag_offset + kTagSize;
274  size_t mac_len = proto_prefix.prefix[mac_len_offset];
275  if (mac_len != 48)
276  return -1;
277  size_t mac_offset = mac_len_offset + 1;
278  prefix->mac_addr_ = MacAddress(&proto_prefix.prefix[mac_offset]);
279  size_t ip_len_offset = mac_offset + kMacSize;
280  size_t ip_len = proto_prefix.prefix[ip_len_offset];
281  if (ip_len != 0 && ip_len != 32 && ip_len != 128)
282  return -1;
283  size_t ip_size = ip_len / 8;
284  if (nlri_size < expected_min_nlri_size + ip_size)
285  return -1;
286  size_t ip_offset = ip_len_offset + 1;
287  prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_size);
288  size_t label_offset = ip_offset + ip_size;
289  *label = ReadLabel(proto_prefix, attr, label_offset, prefix->tag_);
290  size_t l3_label_offset = label_offset + kLabelSize;
291  if (l3_label && nlri_size >= l3_label_offset + kLabelSize) {
292  *l3_label = ReadLabel(proto_prefix, attr, l3_label_offset);
293  }
294  break;
295  }
297  if (nlri_size < kMinInclusiveMulticastRouteSize)
298  return -1;
299  size_t rd_offset = 0;
300  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
301  size_t tag_offset = rd_offset + kRdSize;
302  prefix->tag_ = get_value(&proto_prefix.prefix[tag_offset], kTagSize);
303  size_t ip_len_offset = tag_offset + kTagSize;
304  size_t ip_len = proto_prefix.prefix[ip_len_offset];
305  if (ip_len != 32 && ip_len != 128)
306  return -1;
307  size_t ip_size = ip_len / 8;
308  if (nlri_size < kMinInclusiveMulticastRouteSize + ip_size)
309  return -1;
310  size_t ip_offset = ip_len_offset + 1;
311  prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_size);
312  const PmsiTunnel *pmsi_tunnel = attr ? attr->pmsi_tunnel() : NULL;
313  if (pmsi_tunnel &&
314  (pmsi_tunnel->tunnel_type() == PmsiTunnelSpec::IngressReplication ||
315  pmsi_tunnel->tunnel_type() ==
317  const ExtCommunity *extcomm = attr ? attr->ext_community() : NULL;
318  if (extcomm && extcomm->ContainsTunnelEncapVxlan()) {
319  if (prefix->tag_ && prefix->tag_ <= kMaxVni) {
320  *label = prefix->tag_;
321  } else {
322  *label = pmsi_tunnel->GetLabel(extcomm);
323  }
324  } else {
325  *label = pmsi_tunnel->GetLabel(extcomm);
326  }
327  }
328  break;
329  }
330  case SegmentRoute: {
331  if (nlri_size < kMinSegmentRouteSize)
332  return -1;
333  size_t rd_offset = 0;
334  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
335  size_t esi_offset = rd_offset + kRdSize;
336  prefix->esi_ = EthernetSegmentId(&proto_prefix.prefix[esi_offset]);
337  size_t ip_len_offset = esi_offset + kEsiSize;
338  size_t ip_len = proto_prefix.prefix[ip_len_offset];
339  if (ip_len != 32 && ip_len != 128)
340  return -1;
341  size_t ip_size = ip_len / 8;
342  if (nlri_size < kMinSegmentRouteSize + ip_size)
343  return -1;
344  size_t ip_offset = ip_len_offset + 1;
345  prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_size);
346  break;
347  }
348  case IpPrefixRoute: {
349  size_t ip_size;
350  if (attr) {
351  if (nlri_size == kMinInet6PrefixRouteSize + kLabelSize) {
352  ip_size = kIp6AddrSize;
353  } else if (nlri_size == kMinInetPrefixRouteSize + kLabelSize) {
354  ip_size = kIp4AddrSize;
355  } else {
356  return -1;
357  }
358  } else {
359  if (nlri_size == kMinInet6PrefixRouteSize ||
360  nlri_size == kMinInet6PrefixRouteSize + kLabelSize) {
361  ip_size = kIp6AddrSize;
362  } else if (nlri_size == kMinInetPrefixRouteSize ||
363  nlri_size == kMinInetPrefixRouteSize + kLabelSize) {
364  ip_size = kIp4AddrSize;
365  } else {
366  return -1;
367  }
368  }
369 
370  size_t rd_offset = 0;
371  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
372  size_t esi_offset = rd_offset + kRdSize;
373  EthernetSegmentId esi(&proto_prefix.prefix[esi_offset]);
374  if (!esi.IsZero())
375  return -1;
376  size_t tag_offset = esi_offset + kEsiSize;
377  // Ignore tag for type5 routes.
378  prefix->tag_ = 0;
379  size_t ip_plen_offset = tag_offset + kTagSize;
380  prefix->ip_prefixlen_ = proto_prefix.prefix[ip_plen_offset];
381  if (ip_size == kIp4AddrSize && prefix->ip_prefixlen_ > 32)
382  return -1;
383  if (ip_size == kIp6AddrSize && prefix->ip_prefixlen_ > 128)
384  return -1;
385  size_t ip_offset = ip_plen_offset + 1;
386  size_t ip_psize = (prefix->ip_prefixlen_ + 7) / 8;
387  prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_psize);
388  size_t gw_offset = ip_offset + ip_size;
389  IpAddress gw_address = ReadGwAddress(proto_prefix, gw_offset, ip_size);
390  if (!gw_address.is_unspecified())
391  return -1;
392  size_t label_offset = gw_offset + ip_size;
393  *label = ReadLabel(proto_prefix, attr, label_offset);
394  break;
395  }
397  if (nlri_size < kMinSelectiveMulticastRouteSize)
398  return -1;
399  size_t rd_offset = 0;
400  prefix->rd_ = RouteDistinguisher(&proto_prefix.prefix[rd_offset]);
401  size_t tag_offset = rd_offset + kRdSize;
402  prefix->tag_ = get_value(&proto_prefix.prefix[tag_offset], kTagSize);
403  size_t src_len_offset = tag_offset + kTagSize;
404  size_t src_len = proto_prefix.prefix[src_len_offset];
405  if (src_len != 32 && src_len != 128 && src_len != 0)
406  return -1;
407  size_t src_size = src_len / 8;
408  size_t src_offset = src_len_offset + 1;
409  if (src_size > 0) {
410  if (nlri_size < src_offset + src_size)
411  return -1;
412  prefix->ReadSource(proto_prefix, src_offset, src_size);
413  }
414  size_t grp_len_offset = src_offset + src_size;
415  size_t grp_len = proto_prefix.prefix[grp_len_offset];
416  if (grp_len != 32 && grp_len != 128)
417  return -1;
418  size_t grp_size = grp_len / 8;
419  size_t grp_offset = grp_len_offset + 1;
420  if (nlri_size < grp_offset + grp_size)
421  return -1;
422  prefix->ReadGroup(proto_prefix, grp_offset, grp_size);
423  size_t ip_len_offset = grp_offset + grp_size;
424  size_t ip_len = proto_prefix.prefix[ip_len_offset];
425  if (ip_len != 32 && ip_len != 128)
426  return -1;
427  size_t ip_size = ip_len / 8;
428  size_t ip_offset = ip_len_offset + 1;
429  if (nlri_size < ip_offset + ip_size)
430  return -1;
431  prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_size);
432  size_t flag_offset = ip_offset + ip_size;
433  if (nlri_size <= flag_offset + 4)
434  prefix->flags_ = get_value(&proto_prefix.prefix[flag_offset], 4);
435  break;
436  }
437  default: {
438  return -1;
439  break;
440  }
441  }
442  return 0;
443 }
444 
445 //
446 // Build the BgpProtoPrefix for this EvpnPrefix.
447 //
448 // The ESI for MacAdvertisementRoute is not part of the key and hence
449 // must be obtained from the BgpAttr. The BgpAttr is NULL and label is
450 // 0 when withdrawing the route.
451 //
453  const BgpAttr *attr, uint32_t label, uint32_t l3_label) const {
454  proto_prefix->type = type_;
455  proto_prefix->prefix.clear();
456 
457  switch (type_) {
458  case AutoDiscoveryRoute: {
459  size_t nlri_size = kMinAutoDiscoveryRouteSize + kLabelSize;
460  proto_prefix->prefixlen = nlri_size * 8;
461  proto_prefix->prefix.resize(nlri_size, 0);
462 
463  size_t rd_offset = 0;
464  copy(rd_.GetData(), rd_.GetData() + kRdSize,
465  proto_prefix->prefix.begin() + rd_offset);
466  size_t esi_offset = rd_offset + kRdSize;
467  copy(esi_.GetData(), esi_.GetData() + kEsiSize,
468  proto_prefix->prefix.begin() + esi_offset);
469  size_t tag_offset = esi_offset + kEsiSize;
470  put_value(&proto_prefix->prefix[tag_offset], kTagSize, tag_);
471  size_t label_offset = tag_offset + kTagSize;
472  WriteLabel(proto_prefix, attr, label_offset, label);
473  break;
474  }
475  case MacAdvertisementRoute: {
476  size_t ip_size = GetIpAddressSize();
477  size_t nlri_size = kMinMacAdvertisementRouteSize + ip_size + kLabelSize;
478  if (l3_label)
479  nlri_size += kLabelSize;
480  proto_prefix->prefixlen = nlri_size * 8;
481  proto_prefix->prefix.resize(nlri_size, 0);
482 
483  size_t rd_offset = 0;
484  copy(rd_.GetData(), rd_.GetData() + kRdSize,
485  proto_prefix->prefix.begin() + rd_offset);
486  size_t esi_offset = rd_offset + kRdSize;
487  if (attr) {
488  copy(attr->esi().GetData(), attr->esi().GetData() + kEsiSize,
489  proto_prefix->prefix.begin() + esi_offset);
490  }
491  size_t tag_offset = esi_offset + kEsiSize;
492  put_value(&proto_prefix->prefix[tag_offset], kTagSize, tag_);
493  size_t mac_len_offset = tag_offset + kTagSize;
494  proto_prefix->prefix[mac_len_offset] = 48;
495  size_t mac_offset = mac_len_offset + 1;
497  proto_prefix->prefix.begin() + mac_offset);
498  size_t ip_len_offset = mac_offset + kMacSize;
499  proto_prefix->prefix[ip_len_offset] = ip_size * 8;
500  size_t ip_offset = ip_len_offset + 1;
501  WriteIpAddress(proto_prefix, ip_offset);
502  size_t label_offset = ip_offset + ip_size;
503  WriteLabel(proto_prefix, attr, label_offset, label);
504  if (l3_label) {
505  size_t l3_label_offset = label_offset + kLabelSize;
506  WriteLabel(proto_prefix, attr, l3_label_offset, l3_label);
507  }
508  break;
509  }
511  size_t ip_size = GetIpAddressSize();
512  size_t nlri_size = kMinInclusiveMulticastRouteSize + ip_size;
513  proto_prefix->prefixlen = nlri_size * 8;
514  proto_prefix->prefix.resize(nlri_size, 0);
515 
516  size_t rd_offset = 0;
517  copy(rd_.GetData(), rd_.GetData() + kRdSize,
518  proto_prefix->prefix.begin() + rd_offset);
519  size_t tag_offset = rd_offset + kRdSize;
520  put_value(&proto_prefix->prefix[tag_offset], kTagSize, tag_);
521  size_t ip_len_offset = tag_offset + kTagSize;
522  proto_prefix->prefix[ip_len_offset] = ip_size * 8;
523  size_t ip_offset = ip_len_offset + 1;
524  WriteIpAddress(proto_prefix, ip_offset);
525  break;
526  }
527  case SegmentRoute: {
528  size_t ip_size = GetIpAddressSize();
529  size_t nlri_size = kMinSegmentRouteSize + ip_size;
530  proto_prefix->prefixlen = nlri_size * 8;
531  proto_prefix->prefix.resize(nlri_size, 0);
532 
533  size_t rd_offset = 0;
534  copy(rd_.GetData(), rd_.GetData() + kRdSize,
535  proto_prefix->prefix.begin() + rd_offset);
536  size_t esi_offset = rd_offset + kRdSize;
537  copy(esi_.GetData(), esi_.GetData() + kEsiSize,
538  proto_prefix->prefix.begin() + esi_offset);
539  size_t ip_len_offset = esi_offset + kEsiSize;
540  proto_prefix->prefix[ip_len_offset] = ip_size * 8;
541  size_t ip_offset = ip_len_offset + 1;
542  WriteIpAddress(proto_prefix, ip_offset);
543  break;
544  }
545  case IpPrefixRoute: {
546  size_t ip_size, nlri_size;
547  if (family_ == Address::INET) {
548  ip_size = kIp4AddrSize;
549  nlri_size = kMinInetPrefixRouteSize + kLabelSize;
550  } else {
551  ip_size = kIp6AddrSize;
552  nlri_size = kMinInet6PrefixRouteSize + kLabelSize;
553  }
554  proto_prefix->prefixlen = nlri_size * 8;
555  proto_prefix->prefix.resize(nlri_size, 0);
556 
557  size_t rd_offset = 0;
558  copy(rd_.GetData(), rd_.GetData() + kRdSize,
559  proto_prefix->prefix.begin() + rd_offset);
560  size_t esi_offset = rd_offset + kRdSize;
561  if (attr) {
562  copy(attr->esi().GetData(), attr->esi().GetData() + kEsiSize,
563  proto_prefix->prefix.begin() + esi_offset);
564  }
565  size_t tag_offset = esi_offset + kEsiSize;
566  // Tag is not applicable for type5 routes.
567  put_value(&proto_prefix->prefix[tag_offset], kTagSize, 0);
568  size_t ip_plen_offset = tag_offset + kTagSize;
569  proto_prefix->prefix[ip_plen_offset] = ip_prefixlen_;
570  size_t ip_offset = ip_plen_offset + 1;
571  WriteIpAddress(proto_prefix, ip_offset);
572  size_t gw_offset = ip_offset + ip_size;
573  size_t label_offset = gw_offset + ip_size;
574  WriteLabel(proto_prefix, attr, label_offset, label);
575  break;
576  }
578  size_t ip_size = GetIpAddressSize();
579  size_t nlri_size = kMinSelectiveMulticastRouteSize + 2 * ip_size + 1;
580  if (!source_.is_unspecified())
581  nlri_size += ip_size;
582  proto_prefix->prefixlen = nlri_size * 8;
583  proto_prefix->prefix.resize(nlri_size, 0);
584 
585  size_t rd_offset = 0;
586  copy(rd_.GetData(), rd_.GetData() + kRdSize,
587  proto_prefix->prefix.begin() + rd_offset);
588  size_t tag_offset = rd_offset + kRdSize;
589  put_value(&proto_prefix->prefix[tag_offset], kTagSize, tag_);
590  size_t src_len_offset = tag_offset + kTagSize;
591  size_t grp_len_offset = src_len_offset + 1;
592  if (source_.is_unspecified()) {
593  proto_prefix->prefix[src_len_offset] = 0;
594  } else {
595  proto_prefix->prefix[src_len_offset] = ip_size * 8;
596  size_t src_offset = src_len_offset + 1;
597  WriteSource(proto_prefix, src_offset);
598  grp_len_offset += ip_size;
599  }
600  proto_prefix->prefix[grp_len_offset] = ip_size * 8;
601  size_t grp_offset = grp_len_offset + 1;
602  WriteGroup(proto_prefix, grp_offset);
603  size_t ip_len_offset = grp_offset + ip_size;
604  proto_prefix->prefix[ip_len_offset] = ip_size * 8;
605  size_t ip_offset = ip_len_offset + 1;
606  WriteIpAddress(proto_prefix, ip_offset);
607  size_t flag_offset = ip_offset + ip_size;
608  put_value(&proto_prefix->prefix[flag_offset], 1, flags_);
609  break;
610  }
611  default: {
612  assert(false);
613  break;
614  }
615  }
616 }
617 
618 int EvpnPrefix::CompareTo(const EvpnPrefix &rhs) const {
619  KEY_COMPARE(type_, rhs.type_);
620 
621  switch (type_) {
622  case AutoDiscoveryRoute:
623  KEY_COMPARE(rd_, rhs.rd_);
624  KEY_COMPARE(esi_, rhs.esi_);
625  KEY_COMPARE(tag_, rhs.tag_);
626  break;
628  KEY_COMPARE(rd_, rhs.rd_);
629  KEY_COMPARE(tag_, rhs.tag_);
632  break;
634  KEY_COMPARE(rd_, rhs.rd_);
635  KEY_COMPARE(tag_, rhs.tag_);
637  break;
638  case SegmentRoute:
639  KEY_COMPARE(rd_, rhs.rd_);
640  KEY_COMPARE(esi_, rhs.esi_);
642  break;
643  case IpPrefixRoute:
644  KEY_COMPARE(rd_, rhs.rd_);
645  KEY_COMPARE(tag_, rhs.tag_);
648  break;
650  KEY_COMPARE(rd_, rhs.rd_);
651  KEY_COMPARE(tag_, rhs.tag_);
653  KEY_COMPARE(group_, rhs.group_);
655  default:
656  break;
657  }
658 
659  return 0;
660 }
661 
662 // Check whether 'this' is more specific than rhs.
663 bool EvpnPrefix::IsMoreSpecific(const EvpnPrefix &rhs) const {
664  switch (type_) {
665  case IpPrefixRoute:
666  if (family_ == Address::INET) {
667  return inet_prefix().IsMoreSpecific(rhs.inet_prefix());
668  } else {
669  return inet6_prefix().IsMoreSpecific(rhs.inet6_prefix());
670  }
671  break;
672  default:
673  break;
674  }
675  return false;
676 }
677 
678 bool EvpnPrefix::GetSourceFromString(EvpnPrefix *prefix, const string &str,
679  size_t pos1, size_t *pos2, boost::system::error_code *errorp) {
680  *pos2 = str.find('-', pos1 + 1);
681  if (*pos2 == string::npos) {
682  if (errorp != NULL) {
683  *errorp = make_error_code(boost::system::errc::invalid_argument);
684  }
685  return false;
686  }
687  string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
688  boost::system::error_code source_err;
689  prefix->source_ = Ip4Address::from_string(temp_str, source_err);
690  if (source_err.failed()) {
691  if (errorp != NULL) {
692  *errorp = source_err;
693  }
694  return false;
695  }
696  return true;
697 }
698 
699 bool EvpnPrefix::GetGroupFromString(EvpnPrefix *prefix, const string &str,
700  size_t pos1, size_t *pos2, boost::system::error_code *errorp) {
701  *pos2 = str.find('-', pos1 + 1);
702  if (*pos2 == string::npos) {
703  if (errorp != NULL) {
704  *errorp = make_error_code(boost::system::errc::invalid_argument);
705  }
706  return false;
707  }
708  string temp_str = str.substr(pos1 + 1, *pos2 - pos1 - 1);
709  boost::system::error_code group_err;
710  prefix->group_ = Ip4Address::from_string(temp_str, group_err);
711  if (group_err.failed()) {
712  if (errorp != NULL) {
713  *errorp = group_err;
714  }
715  return false;
716  }
717  return true;
718 }
719 
721  boost::system::error_code *errorp) {
722  EvpnPrefix prefix;
723 
724  // Parse type.
725  size_t pos1 = str.find('-');
726  if (pos1 == string::npos) {
727  if (errorp != NULL) {
728  *errorp = make_error_code(boost::system::errc::invalid_argument);
729  }
731  }
732 
733  string type_str = str.substr(0, pos1);
734  bool ret = stringToInteger(type_str, prefix.type_);
735  if (!ret) {
736  if (errorp != NULL) {
737  *errorp = make_error_code(boost::system::errc::invalid_argument);
738  }
740  }
741 
742  if (prefix.type_ < EvpnPrefix::AutoDiscoveryRoute ||
744  if (errorp != NULL) {
745  *errorp = make_error_code(boost::system::errc::invalid_argument);
746  }
748  }
749 
750  // Parse RD.
751  size_t pos2 = str.find('-', pos1 + 1);
752  if (pos2 == string::npos) {
753  if (errorp != NULL) {
754  *errorp = make_error_code(boost::system::errc::invalid_argument);
755  }
757  }
758  string rd_str = str.substr(pos1 + 1, pos2 - pos1 - 1);
759  boost::system::error_code rd_err;
760  prefix.rd_ = RouteDistinguisher::FromString(rd_str, &rd_err);
761  if (rd_err.failed()) {
762  if (errorp != NULL) {
763  *errorp = rd_err;
764  }
766  }
767 
768  switch (prefix.type_) {
769  case AutoDiscoveryRoute: {
770  // Parse ESI.
771  size_t pos3 = str.find('-', pos2 + 1);
772  if (pos3 == string::npos) {
773  if (errorp != NULL) {
774  *errorp =
775  make_error_code(boost::system::errc::invalid_argument);
776  }
778  }
779  string esi_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
780  boost::system::error_code esi_err;
781  prefix.esi_ = EthernetSegmentId::FromString(esi_str, &esi_err);
782  if (esi_err.failed()) {
783  if (errorp != NULL) {
784  *errorp = esi_err;
785  }
787  }
788 
789  // Parse tag.
790  string tag_str = str.substr(pos3 + 1, string::npos);
791  bool ret = stringToInteger(tag_str, prefix.tag_);
792  if (!ret) {
793  if (errorp != NULL) {
794  *errorp =
795  make_error_code(boost::system::errc::invalid_argument);
796  }
798  }
799 
800  break;
801  }
802 
803  case MacAdvertisementRoute: {
804  // Parse tag.
805  size_t pos3 = str.find('-', pos2 + 1);
806  if (pos3 == string::npos) {
807  if (errorp != NULL) {
808  *errorp =
809  make_error_code(boost::system::errc::invalid_argument);
810  }
812  }
813  string tag_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
814  bool ret = stringToInteger(tag_str, prefix.tag_);
815  if (!ret) {
816  if (errorp != NULL) {
817  *errorp =
818  make_error_code(boost::system::errc::invalid_argument);
819  }
821  }
822 
823  // Parse MAC.
824  size_t pos4 = str.rfind(',');
825  string mac_str = str.substr(pos3 + 1, pos4 - pos3 -1);
826  boost::system::error_code mac_err;
827  prefix.mac_addr_ = MacAddress::FromString(mac_str, &mac_err);
828  if (mac_err.failed()) {
829  if (errorp != NULL) {
830  *errorp = mac_err;
831  }
833  }
834 
835  // Parse IP - treat all 0s as unspecified.
836  string ip_str = str.substr(pos4 + 1, string::npos);
837  boost::system::error_code ip_err;
838  prefix.ip_address_ = IpAddress::from_string(ip_str, ip_err);
839  if (ip_err.failed()) {
840  if (errorp != NULL) {
841  *errorp = ip_err;
842  }
844  }
845  if (prefix.ip_address_.is_v4() && !prefix.ip_address_.is_unspecified())
846  prefix.family_ = Address::INET;
847  if (prefix.ip_address_.is_v6() && !prefix.ip_address_.is_unspecified())
848  prefix.family_ = Address::INET6;
849 
850  break;
851  }
852 
854  // Parse tag.
855  size_t pos3 = str.find('-', pos2 + 1);
856  if (pos3 == string::npos) {
857  if (errorp != NULL) {
858  *errorp =
859  make_error_code(boost::system::errc::invalid_argument);
860  }
862  }
863  string tag_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
864  bool ret = stringToInteger(tag_str, prefix.tag_);
865  if (!ret) {
866  if (errorp != NULL) {
867  *errorp =
868  make_error_code(boost::system::errc::invalid_argument);
869  }
871  }
872 
873  // Parse IP.
874  string ip_str = str.substr(pos3 + 1, string::npos);
875  boost::system::error_code ip_err;
876  prefix.ip_address_ = IpAddress::from_string(ip_str, ip_err);
877  if (ip_err.failed()) {
878  if (errorp != NULL) {
879  *errorp = ip_err;
880  }
882  }
883  prefix.family_ =
884  prefix.ip_address_.is_v4() ? Address::INET : Address::INET6;
885 
886  break;
887  }
888 
889  case SegmentRoute: {
890  // Parse ESI.
891  size_t pos3 = str.find('-', pos2 + 1);
892  if (pos3 == string::npos) {
893  if (errorp != NULL) {
894  *errorp =
895  make_error_code(boost::system::errc::invalid_argument);
896  }
898  }
899  string esi_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
900  boost::system::error_code esi_err;
901  prefix.esi_ = EthernetSegmentId::FromString(esi_str, &esi_err);
902  if (esi_err.failed()) {
903  if (errorp != NULL) {
904  *errorp = esi_err;
905  }
907  }
908 
909  // Parse IP.
910  string ip_str = str.substr(pos3 + 1, string::npos);
911  boost::system::error_code ip_err;
912  prefix.ip_address_ = IpAddress::from_string(ip_str, ip_err);
913  if (ip_err.failed()) {
914  if (errorp != NULL) {
915  *errorp = ip_err;
916  }
918  }
919  prefix.family_ =
920  prefix.ip_address_.is_v4() ? Address::INET : Address::INET6;
921 
922  break;
923  }
924 
925  case IpPrefixRoute: {
926  // Parse tag.
927  size_t pos3 = str.find('-', pos2 + 1);
928  if (pos3 == string::npos) {
929  if (errorp != NULL) {
930  *errorp =
931  make_error_code(boost::system::errc::invalid_argument);
932  }
934  }
935  string tag_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
936  bool ret = stringToInteger(tag_str, prefix.tag_);
937  if (!ret) {
938  if (errorp != NULL) {
939  *errorp =
940  make_error_code(boost::system::errc::invalid_argument);
941  }
943  }
944 
945  // Parse IP prefix - first try v4, then v6.
946  string ip_str = str.substr(pos3 + 1, string::npos);
947  boost::system::error_code ip_err;
948 
949  Ip4Prefix inet_prefix = Ip4Prefix::FromString(ip_str, &ip_err);
950  if (!ip_err) {
951  prefix.family_ = Address::INET;
952  prefix.ip_address_ = inet_prefix.addr();
954  return prefix;
955  }
956 
958  if (!ip_err) {
959  prefix.family_ = Address::INET6;
960  prefix.ip_address_ = inet6_prefix.addr();
962  return prefix;
963  }
964 
965  if (errorp != NULL) {
966  *errorp = make_error_code(boost::system::errc::invalid_argument);
967  }
969  break;
970  }
971 
973  // Parse tag.
974  size_t pos3 = str.find('-', pos2 + 1);
975  if (pos3 == string::npos) {
976  if (errorp != NULL) {
977  *errorp =
978  make_error_code(boost::system::errc::invalid_argument);
979  }
981  }
982  string tag_str = str.substr(pos2 + 1, pos3 - pos2 - 1);
983  bool ret = stringToInteger(tag_str, prefix.tag_);
984  if (!ret) {
985  if (errorp != NULL) {
986  *errorp =
987  make_error_code(boost::system::errc::invalid_argument);
988  }
990  }
991 
992  // Look for source.
993  size_t pos4;
994  if (!GetSourceFromString(&prefix, str, pos3, &pos4, errorp))
996 
997  // Look for group.
998  size_t pos5;
999  if (!GetGroupFromString(&prefix, str, pos4, &pos5, errorp))
1000  return EvpnPrefix::kNullPrefix;
1001 
1002  // Parse IP.
1003  string ip_str = str.substr(pos5 + 1, string::npos);
1004  boost::system::error_code ip_err;
1005  prefix.ip_address_ = IpAddress::from_string(ip_str, ip_err);
1006  if (ip_err.failed()) {
1007  if (errorp != NULL) {
1008  *errorp = ip_err;
1009  }
1010  return EvpnPrefix::kNullPrefix;
1011  }
1012  prefix.family_ =
1013  prefix.ip_address_.is_v4() ? Address::INET : Address::INET6;
1014 
1015  break;
1016  }
1017 
1018  }
1019 
1020  return prefix;
1021 }
1022 
1023 string EvpnPrefix::ToString() const {
1024  string str = integerToString(type_);
1025  str += "-" + rd_.ToString();
1026  switch (type_) {
1027  case AutoDiscoveryRoute:
1028  str += "-" + esi_.ToString();
1029  str += "-" + integerToString(tag_);
1030  break;
1031  case MacAdvertisementRoute:
1032  str += "-" + integerToString(tag_);
1033  str += "-" + mac_addr_.ToString();
1034  str += "," + ip_address_.to_string();
1035  break;
1037  str += "-" + integerToString(tag_);
1038  str += "-" + ip_address_.to_string();
1039  break;
1040  case SegmentRoute:
1041  str += "-" + esi_.ToString();
1042  str += "-" + ip_address_.to_string();
1043  break;
1044  case IpPrefixRoute:
1045  str += "-" + integerToString(tag_);
1046  if (family_ == Address::INET) {
1047  str += "-" + inet_prefix().ToString();
1048  } else {
1049  str += "-" + inet6_prefix().ToString();
1050  }
1051  break;
1053  str += "-" + integerToString(tag_);
1054  if (!source_.is_unspecified())
1055  str += "-" + source_.to_string();
1056  str += "-" + group_.to_string();
1057  str += "-" + ip_address_.to_string();
1058  break;
1059  default:
1060  break;
1061  }
1062 
1063  return str;
1064 }
1065 
1067  string str;
1068  if (tag_ != 0)
1069  str += integerToString(tag_) + "-";
1070  str += mac_addr_.ToString();
1071  str += "," + ip_address_.to_string() + "/" +
1073  if (!group_.is_unspecified()) {
1074  str += "," + group_.to_string() + "," +
1075  source_.to_string();
1076  }
1077  return str;
1078 }
1079 
1081  if (type_ == IpPrefixRoute)
1082  return ip_prefixlen_;
1083  if (family_ == Address::INET)
1084  return 32;
1085  if (family_ == Address::INET6)
1086  return 128;
1087  return 32;
1088 }
1089 
1091  if (family_ == Address::INET)
1092  return kIp4AddrSize;
1093  if (family_ == Address::INET6)
1094  return kIp6AddrSize;
1095  return 0;
1096 }
1097 
1098 void EvpnPrefix::ReadSource(const BgpProtoPrefix &proto_prefix,
1099  size_t ip_offset, size_t ip_size) {
1100  if (ip_size == 0) {
1102  } else if (ip_size == kIp4AddrSize) {
1104  Ip4Address::bytes_type bytes = { { 0 } };
1105  copy(proto_prefix.prefix.begin() + ip_offset,
1106  proto_prefix.prefix.begin() + ip_offset + ip_size, bytes.begin());
1107  source_ = Ip4Address(bytes);
1108  } else if (ip_size == kIp6AddrSize) {
1110  Ip6Address::bytes_type bytes = { { 0 } };
1111  copy(proto_prefix.prefix.begin() + ip_offset,
1112  proto_prefix.prefix.begin() + ip_offset + ip_size, bytes.begin());
1113  source_ = Ip6Address(bytes);
1114  }
1115 }
1116 
1117 void EvpnPrefix::ReadGroup(const BgpProtoPrefix &proto_prefix,
1118  size_t ip_offset, size_t ip_size) {
1119  if (ip_size == 0) {
1121  } else if (ip_size == kIp4AddrSize) {
1123  Ip4Address::bytes_type bytes = { { 0 } };
1124  copy(proto_prefix.prefix.begin() + ip_offset,
1125  proto_prefix.prefix.begin() + ip_offset + ip_size, bytes.begin());
1126  group_ = Ip4Address(bytes);
1127  } else if (ip_size == kIp6AddrSize) {
1129  Ip6Address::bytes_type bytes = { { 0 } };
1130  copy(proto_prefix.prefix.begin() + ip_offset,
1131  proto_prefix.prefix.begin() + ip_offset + ip_size, bytes.begin());
1132  group_ = Ip6Address(bytes);
1133  }
1134 }
1135 
1137  size_t ip_offset, size_t ip_size, size_t ip_psize) {
1138  assert(ip_psize <= ip_size);
1139  if (ip_size == 0) {
1141  } else if (ip_size == kIp4AddrSize) {
1143  Ip4Address::bytes_type bytes = { { 0 } };
1144  copy(proto_prefix.prefix.begin() + ip_offset,
1145  proto_prefix.prefix.begin() + ip_offset + ip_psize, bytes.begin());
1146  ip_address_ = Ip4Address(bytes);
1147  } else if (ip_size == kIp6AddrSize) {
1149  Ip6Address::bytes_type bytes = { { 0 } };
1150  copy(proto_prefix.prefix.begin() + ip_offset,
1151  proto_prefix.prefix.begin() + ip_offset + ip_psize, bytes.begin());
1152  ip_address_ = Ip6Address(bytes);
1153  }
1154 }
1155 
1157  size_t ip_offset) const {
1158  if (family_ == Address::INET) {
1159  const Ip4Address::bytes_type &bytes = ip_address_.to_v4().to_bytes();
1160  copy(bytes.begin(), bytes.begin() + kIp4AddrSize,
1161  proto_prefix->prefix.begin() + ip_offset);
1162  } else if (family_ == Address::INET6) {
1163  const Ip6Address::bytes_type &bytes = ip_address_.to_v6().to_bytes();
1164  copy(bytes.begin(), bytes.begin() + kIp6AddrSize,
1165  proto_prefix->prefix.begin() + ip_offset);
1166  }
1167 }
1168 
1170  size_t ip_offset) const {
1171  if (family_ == Address::INET) {
1172  const Ip4Address::bytes_type &bytes = source_.to_v4().to_bytes();
1173  copy(bytes.begin(), bytes.begin() + kIp4AddrSize,
1174  proto_prefix->prefix.begin() + ip_offset);
1175  } else if (family_ == Address::INET6) {
1176  const Ip6Address::bytes_type &bytes = source_.to_v6().to_bytes();
1177  copy(bytes.begin(), bytes.begin() + kIp6AddrSize,
1178  proto_prefix->prefix.begin() + ip_offset);
1179  }
1180 }
1181 
1183  size_t ip_offset) const {
1184  if (family_ == Address::INET) {
1185  const Ip4Address::bytes_type &bytes = group_.to_v4().to_bytes();
1186  copy(bytes.begin(), bytes.begin() + kIp4AddrSize,
1187  proto_prefix->prefix.begin() + ip_offset);
1188  } else if (family_ == Address::INET6) {
1189  const Ip6Address::bytes_type &bytes = group_.to_v6().to_bytes();
1190  copy(bytes.begin(), bytes.begin() + kIp6AddrSize,
1191  proto_prefix->prefix.begin() + ip_offset);
1192  }
1193 }
1194 
1196  : prefix_(prefix) {
1197 }
1198 
1199 int EvpnRoute::CompareTo(const Route &rhs) const {
1200  const EvpnRoute &evpn_rhs = static_cast<const EvpnRoute &>(rhs);
1201  return prefix_.CompareTo(evpn_rhs.prefix_);
1202 }
1203 
1204 string EvpnRoute::ToString() const {
1205  return prefix_.ToString();
1206 }
1207 
1209  if (xmpp_id_str_.empty())
1211  return xmpp_id_str_;
1212 }
1213 
1214 bool EvpnRoute::IsValid() const {
1215  if (!BgpRoute::IsValid())
1216  return false;
1217 
1218  const BgpAttr *attr = BestPath()->GetAttr();
1219  switch (prefix_.type()) {
1221  if (prefix_.tag() == EvpnPrefix::kMaxTag)
1222  return true;
1223  break;
1224  }
1226  return true;
1227  }
1229  const PmsiTunnel *pmsi_tunnel = attr->pmsi_tunnel();
1230  if (!pmsi_tunnel)
1231  return false;
1232  uint8_t tunnel_type = pmsi_tunnel->tunnel_type();
1233  uint8_t tunnel_flags = pmsi_tunnel->tunnel_flags();
1234  uint8_t ar_type =
1236  if (tunnel_type == PmsiTunnelSpec::IngressReplication) {
1237  if (ar_type == PmsiTunnelSpec::RegularNVE)
1238  return true;
1239  if (ar_type == PmsiTunnelSpec::ARReplicator &&
1240  (tunnel_flags & PmsiTunnelSpec::LeafInfoRequired)) {
1241  return true;
1242  }
1243  return false;
1244  }
1245  if (tunnel_type == PmsiTunnelSpec::AssistedReplicationContrail &&
1246  ar_type == PmsiTunnelSpec::ARLeaf) {
1247  return true;
1248  }
1249  return false;
1250  }
1251  case EvpnPrefix::SegmentRoute: {
1252  return false;
1253  }
1255  return false;
1256  }
1258  return false;
1259  }
1260  default: {
1261  break;
1262  }
1263  }
1264 
1265  return false;
1266 }
1267 
1268 void EvpnRoute::SetKey(const DBRequestKey *reqkey) {
1269  const EvpnTable::RequestKey *key =
1270  static_cast<const EvpnTable::RequestKey *>(reqkey);
1271  prefix_ = key->prefix;
1272 }
1273 
1275  const BgpAttr *attr, uint32_t label, uint32_t l3_label) const {
1276  prefix_.BuildProtoPrefix(proto_prefix, attr, label, l3_label);
1277 }
1278 
1279 void EvpnRoute::BuildBgpProtoNextHop(vector<uint8_t> &nh,
1280  IpAddress nexthop) const {
1281  nh.resize(4);
1282  const Ip4Address::bytes_type &addr_bytes = nexthop.to_v4().to_bytes();
1283  copy(addr_bytes.begin(), addr_bytes.end(), nh.begin());
1284 }
1285 
1288  return KeyPtr(key);
1289 }
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
static uint32_t ReadLabel(const BgpProtoPrefix &proto_prefix, const BgpAttr *attr, size_t offset, uint32_t tag=EvpnPrefix::kNullTag)
static void WriteLabel(BgpProtoPrefix *proto_prefix, const BgpAttr *attr, size_t offset, uint32_t label)
static IpAddress ReadGwAddress(const BgpProtoPrefix &proto_prefix, size_t gw_offset, size_t ip_size)
boost::intrusive_ptr< const BgpAttr > BgpAttrPtr
Definition: bgp_attr.h:999
Family
Definition: address.h:25
@ INET
Definition: address.h:27
@ INET6
Definition: address.h:28
@ UNSPEC
Definition: address.h:26
BgpAttrPtr ReplaceEsiAndLocate(const BgpAttr *attr, const EthernetSegmentId &esi)
Definition: bgp_attr.cc:1415
const ExtCommunity * ext_community() const
Definition: bgp_attr.h:918
const EthernetSegmentId & esi() const
Definition: bgp_attr.h:900
const PmsiTunnel * pmsi_tunnel() const
Definition: bgp_attr.h:923
const BgpAttr * GetAttr() const
Definition: bgp_path.h:88
const BgpPath * BestPath() const
Definition: bgp_route.cc:48
virtual bool IsValid() const
Definition: bgp_route.cc:340
BgpAttrDB * attr_db()
Definition: bgp_server.h:188
std::unique_ptr< DBRequestKey > KeyPtr
Definition: db_entry.h:25
std::string ToString() const
Definition: esi.cc:121
static const int kSize
Definition: esi.h:16
bool IsZero() const
Definition: esi.h:44
const uint8_t * GetData() const
Definition: esi.h:61
static EthernetSegmentId FromString(const std::string &str, boost::system::error_code *errorp=NULL)
Definition: esi.cc:30
uint32_t tag() const
Ip4Prefix inet_prefix() const
uint8_t type() const
std::string ToXmppIdString() const
static const size_t kMinSelectiveMulticastRouteSize
Address::Family family_
void WriteIpAddress(BgpProtoPrefix *proto_prefix, size_t ip_offset) const
bool IsMoreSpecific(const EvpnPrefix &rhs) const
static const uint32_t kMaxVni
const EthernetSegmentId & esi() const
static int FromProtoPrefix(BgpServer *server, const BgpProtoPrefix &proto_prefix, const BgpAttr *attr, const Address::Family family, EvpnPrefix *evpn_prefix, BgpAttrPtr *new_attr, uint32_t *label, uint32_t *l3_label=NULL)
uint8_t ip_address_length() const
static const size_t kRdSize
static const size_t kMinAutoDiscoveryRouteSize
static const uint32_t kMaxTag
static const size_t kMinSegmentRouteSize
static const size_t kEsiSize
RouteDistinguisher rd_
void ReadGroup(const BgpProtoPrefix &proto_prefix, size_t ip_offset, size_t ip_size)
void BuildProtoPrefix(BgpProtoPrefix *proto_prefix, const BgpAttr *attr, uint32_t label, uint32_t l3_label=0) const
static const uint32_t kNullTag
static const EvpnPrefix kNullPrefix
size_t GetIpAddressSize() const
static const size_t kMinInclusiveMulticastRouteSize
static const size_t kMinInet6PrefixRouteSize
IpAddress ip_address_
static EvpnPrefix FromString(const std::string &str, boost::system::error_code *errorp=NULL)
static const int32_t kMaxVniSigned
static const size_t kMinMacAdvertisementRouteSize
static const size_t kIp4AddrSize
static const uint32_t kInvalidLabel
void WriteGroup(BgpProtoPrefix *proto_prefix, size_t ip_offset) const
void ReadSource(const BgpProtoPrefix &proto_prefix, size_t ip_offset, size_t ip_size)
static const size_t kTagSize
EthernetSegmentId esi_
std::string ToString() const
void ReadIpAddress(const BgpProtoPrefix &proto_prefix, size_t ip_offset, size_t ip_size, size_t ip_psize)
int CompareTo(const EvpnPrefix &rhs) const
static const size_t kMacSize
IpAddress group() const
Inet6Prefix inet6_prefix() const
void WriteSource(BgpProtoPrefix *proto_prefix, size_t ip_offset) const
static bool GetSourceFromString(EvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *errorp)
static const size_t kLabelSize
static const size_t kMinInetPrefixRouteSize
MacAddress mac_addr_
static bool GetGroupFromString(EvpnPrefix *prefix, const std::string &str, size_t pos1, size_t *pos2, boost::system::error_code *errorp)
static const size_t kIp6AddrSize
virtual std::string ToXmppIdString() const
virtual void SetKey(const DBRequestKey *reqkey)
EvpnRoute(const EvpnPrefix &prefix)
virtual int CompareTo(const Route &rhs) const
virtual void BuildProtoPrefix(BgpProtoPrefix *proto_prefix, const BgpAttr *attr=NULL, uint32_t label=0, uint32_t l3_label=0) const
virtual void BuildBgpProtoNextHop(std::vector< uint8_t > &nh, IpAddress nexthop) const
const EvpnPrefix & GetPrefix() const
virtual bool IsValid() const
EvpnPrefix prefix_
std::string xmpp_id_str_
virtual std::string ToString() const
virtual KeyPtr GetDBRequestKey() const
bool ContainsTunnelEncapVxlan() const
Definition: community.cc:725
static Inet6Prefix FromString(const std::string &str, boost::system::error_code *errorp=NULL)
Definition: inet6_route.cc:59
std::string ToString() const
Definition: inet6_route.cc:37
int prefixlen() const
Definition: inet6_route.h:34
Ip6Address addr() const
Definition: inet6_route.h:27
bool IsMoreSpecific(const Inet6Prefix &rhs) const
Definition: inet6_route.cc:70
int prefixlen() const
Definition: inet_route.h:28
bool IsMoreSpecific(const Ip4Prefix &rhs) const
Definition: inet_route.cc:97
Ip4Address addr() const
Definition: inet_route.h:25
std::string ToString() const
Definition: inet_route.cc:61
static Ip4Prefix FromString(const std::string &str, boost::system::error_code *errorp=NULL)
Definition: inet_route.cc:85
std::string ToString() const
Definition: mac_address.cc:54
const uint8_t * GetData() const
Definition: mac_address.h:144
static size_t size()
Definition: mac_address.h:58
static MacAddress FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: mac_address.cc:72
const uint8_t tunnel_flags() const
Definition: bgp_attr.h:383
uint32_t GetLabel(const ExtCommunity *ext) const
Definition: bgp_attr.cc:416
const uint8_t tunnel_type() const
Definition: bgp_attr.h:384
static RouteDistinguisher FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: rd.cc:84
static const size_t kSize
Definition: rd.h:14
const uint8_t * GetData() const
Definition: rd.h:60
std::string ToString() const
Definition: rd.cc:57
Definition: route.h:15
static void put_value(uint8_t *data, int size, uint64_t value)
Definition: parse_object.h:56
static uint64_t get_value(const uint8_t *data, int size)
Definition: parse_object.h:40
bool stringToInteger(const std::string &str, NumberType &num)
Definition: string_util.h:72
static const std::string integerToString(const NumberType &num)
Definition: string_util.h:20
void WriteLabel(size_t label_offset, uint32_t label, bool is_vni=false)
uint32_t ReadLabel(size_t label_offset, bool is_vni=false) const
static const size_t kLabelSize
std::vector< uint8_t > prefix
@ AssistedReplicationType
Definition: bgp_attr.h:318
@ IngressReplication
Definition: bgp_attr.h:335
@ AssistedReplicationContrail
Definition: bgp_attr.h:337
#define KEY_COMPARE(x, y)
Definition: util.h:71