OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
community.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include "bgp/community.h"
6 
7 #include <boost/foreach.hpp>
8 
9 #include <algorithm>
10 #include <string>
11 
12 #include "base/string_util.h"
13 #include "bgp/bgp_proto.h"
33 #include "net/community_type.h"
34 
35 using std::sort;
36 using std::string;
37 using std::unique;
38 using std::vector;
39 
41  attr->set_community(this);
42 }
43 
44 string CommunitySpec::ToString() const {
45  string repr;
46  char start[32];
47  snprintf(start, sizeof(start), "Communities: %zu [", communities.size());
48  repr += start;
49 
50  for (size_t i = 0; i < communities.size(); ++i) {
51  char community[12];
52  snprintf(community, sizeof(community), " %X", communities[i]);
53  repr += community;
54  }
55  repr += " ]";
56 
57  return repr;
58 }
59 
61  : comm_db_(comm_db), communities_(spec.communities) {
62  refcount_ = 0;
63  sort(communities_.begin(), communities_.end());
64  vector<uint32_t>::iterator it =
65  unique(communities_.begin(), communities_.end());
66  communities_.erase(it, communities_.end());
67 }
68 
69 int Community::CompareTo(const Community &rhs) const {
71  return 0;
72 }
73 
75  return communities.size() * sizeof(uint32_t);
76 }
77 
78 void Community::Append(uint32_t value) {
79  if (ContainsValue(value))
80  return;
81  communities_.push_back(value);
82  sort(communities_.begin(), communities_.end());
83 }
84 
85 void Community::Append(const std::vector<uint32_t> &communities) {
86  for (auto community : communities) {
87  communities_.push_back(community);
88  }
89  sort(communities_.begin(), communities_.end());
90  vector<uint32_t>::iterator it =
91  unique(communities_.begin(), communities_.end());
92  communities_.erase(it, communities_.end());
93 }
94 
95 void Community::Set(const std::vector<uint32_t> &communities) {
96  communities_.clear();
97  for (auto community : communities) {
98  communities_.push_back(community);
99  }
100 }
101 
102 void Community::Remove(const std::vector<uint32_t> &communities) {
103  for (auto community : communities) {
104  communities_.erase(
105  std::remove(communities_.begin(), communities_.end(), community),
106  communities_.end());
107  }
108 }
110  comm_db_->Delete(this);
111 }
112 
113 bool Community::ContainsValue(uint32_t value) const {
114  for (auto community : communities_) {
115  if (community == value)
116  return true;
117  }
118  return false;
119 }
120 
121 void Community::BuildStringList(vector<string> *list) const {
122  for (auto community : communities_) {
123  string name = CommunityType::CommunityToString(community);
124  list->push_back(name);
125  }
126 }
127 
129 }
130 
132  uint32_t value) {
133  Community *clone;
134  if (src) {
135  clone = new Community(*src);
136  } else {
137  clone = new Community(this);
138  }
139 
140  clone->Append(value);
141  return Locate(clone);
142 }
143 
145  const std::vector<uint32_t> &value) {
146  Community *clone;
147  if (src) {
148  clone = new Community(*src);
149  } else {
150  clone = new Community(this);
151  }
152 
153  clone->Append(value);
154  return Locate(clone);
155 }
156 
158  const std::vector<uint32_t> &value) {
159  Community *clone;
160  if (src) {
161  clone = new Community(*src);
162  } else {
163  clone = new Community(this);
164  }
165 
166  clone->Set(value);
167  return Locate(clone);
168 }
169 
171  const std::vector<uint32_t> &value) {
172  Community *clone;
173  if (src) {
174  clone = new Community(*src);
175  } else {
176  clone = new Community(this);
177  }
178 
179  clone->Remove(value);
180  return Locate(clone);
181 }
182 
184  uint32_t value) {
185  Community::CommunityList communities;
186  communities.push_back(value);
187  return RemoveAndLocate(src, communities);
188 }
189 
191  char repr[80];
192  snprintf(repr, sizeof(repr), "ExtCommunity <code: %d, flags: %02x>:%d",
193  code, flags, (uint32_t)communities.size());
194  return string(repr);
195 }
196 
198  return communities.size() * sizeof(uint64_t);
199 }
200 
201 int ExtCommunitySpec::CompareTo(const BgpAttribute &rhs_attr) const {
202  int ret = BgpAttribute::CompareTo(rhs_attr);
203  if (ret != 0) return ret;
205  static_cast<const ExtCommunitySpec &>(rhs_attr).communities);
206  return 0;
207 }
208 
210  attr->set_ext_community(this);
211 }
212 
213 void ExtCommunitySpec::AddTunnelEncaps(vector<string> encaps) {
214  for (vector<string>::size_type i = 0; i < encaps.size(); i++) {
215  string encap_str = encaps[i];
216  TunnelEncap tun_encap(encap_str);
217  communities.push_back(tun_encap.GetExtCommunityValue());
218  }
219 }
220 
221 int ExtCommunity::CompareTo(const ExtCommunity &rhs) const {
222  KEY_COMPARE(communities_.size(), rhs.communities_.size());
223 
224  ExtCommunityList::const_iterator i, j;
225  for (i = communities_.begin(), j = rhs.communities_.begin();
226  i < communities_.end(); ++i, ++j) {
227  if (*i < *j) {
228  return -1;
229  }
230  if (*i > *j) {
231  return 1;
232  }
233  }
234  return 0;
235 }
236 
238  for (ExtCommunityList::const_iterator it = list.begin();
239  it != list.end(); ++it) {
240  communities_.erase(std::remove(communities_.begin(),
241  communities_.end(), *it), communities_.end());
242  }
243 }
245  extcomm_db_->Delete(this);
246 }
247 
249  communities_.clear();
250  for (ExtCommunityList::const_iterator it = list.begin();
251  it != list.end(); ++it) {
252  communities_.push_back(*it);
253  }
254 }
255 
257  communities_.insert(communities_.end(), list.begin(), list.end());
258  sort(communities_.begin(), communities_.end());
259  ExtCommunityList::iterator it =
260  unique(communities_.begin(), communities_.end());
261  communities_.erase(it, communities_.end());
262 }
263 
265  communities_.push_back(value);
266  sort(communities_.begin(), communities_.end());
267  ExtCommunityList::iterator it =
268  unique(communities_.begin(), communities_.end());
269  communities_.erase(it, communities_.end());
270 }
271 
273  const string &comm, boost::system::error_code *errorp) {
274  ExtCommunityValue data;
275  put_value(&data[0], 8, 0);
276  char *end;
277  uint64_t value = strtoull(comm.c_str(), &end, 16);
278  if (value == 0 || *end) {
279  // e.g. 0 or 12x34ff (invalid hex)
280  if (errorp != NULL) {
281  *errorp = make_error_code(
282  boost::system::errc::invalid_argument);
283  return data;
284  }
285  }
286  if (comm[0] == '0' && (comm[1] == 'x' || comm[1] == 'X')) {
287  if (comm.length() > 18 && errorp != NULL) {
288  // e.g. 0xabcdef0123456789f is an invalid 8byte hex value
289  *errorp = make_error_code(
290  boost::system::errc::invalid_argument);
291  return data;
292  }
293  } else {
294  if (comm.length() > 16 && errorp != NULL) {
295  // e.g. abcdef0123456789f is an invalid 8byte hex value
296  *errorp = make_error_code(
297  boost::system::errc::invalid_argument);
298  return data;
299  }
300  }
301  put_value(&data[0], 8, value);
302  return data;
303 }
304 
306  const string &comm) {
307  ExtCommunityList commList;
308  ExtCommunityValue value;
309  size_t pos = comm.find(':');
310  string first(comm.substr(0, pos));
311  boost::system::error_code error;
312  if (first == "soo") {
313  SiteOfOrigin soo = SiteOfOrigin::FromString(comm, &error);
314  if (error) {
315  return commList;
316  }
317  commList.push_back(soo.GetExtCommunity());
318  } else if (first == "target") {
319  RouteTarget rt = RouteTarget::FromString(comm, &error);
320  if (error) {
321  return commList;
322  }
323  commList.push_back(rt.GetExtCommunity());
324  } else if (first == "source-as") {
325  SourceAs sas = SourceAs::FromString(comm, &error);
326  if (error) {
327  return commList;
328  }
329  commList.push_back(sas.GetExtCommunity());
330  } else if (first == "rt-import") {
331  VrfRouteImport vit = VrfRouteImport::FromString(comm, &error);
332  if (error) {
333  return commList;
334  }
335  commList.push_back(vit.GetExtCommunity());
336  } else if (first == "subcluster") {
337  SubCluster sc = SubCluster::FromString(comm, &error);
338  if (error) {
339  return commList;
340  }
341  commList.push_back(sc.GetExtCommunity());
342  } else {
343  value = FromHexString(comm, &error);
344  if (error) {
345  return commList;
346  }
347  commList.push_back(value);
348  }
349  return commList;
350 }
351 
353  char temp[50];
354  int len = 0;
355  for (size_t i = 0; i < comm.size(); i++) {
356  len += snprintf(temp+len, sizeof(temp) - len, "%02x", (comm)[i]);
357  }
358  return(string(temp));
359 }
360 
362  if (is_route_target(comm)) {
363  RouteTarget rt(comm);
364  return(rt.ToString());
365  } else if (is_default_gateway(comm)) {
366  DefaultGateway dgw(comm);
367  return(dgw.ToString());
368  } else if (is_es_import(comm)) {
369  EsImport es_import(comm);
370  return(es_import.ToString());
371  } else if (is_esi_label(comm)) {
372  EsiLabel esi_label(comm);
373  return(esi_label.ToString());
374  } else if (is_mac_mobility(comm)) {
375  MacMobility mm(comm);
376  return(mm.ToString());
377  } else if (is_local_sequence_number(comm)) {
378  LocalSequenceNumber lsn(comm);
379  return lsn.ToString();
380  } else if (is_etree(comm)) {
381  ETree etree(comm);
382  return(etree.ToString());
383  } else if (is_router_mac(comm)) {
384  RouterMac router_mac(comm);
385  return(router_mac.ToString());
386  } else if (is_origin_vn(comm)) {
387  OriginVn origin_vn(comm);
388  return(origin_vn.ToString());
389  } else if (is_security_group(comm)) {
390  SecurityGroup sg(comm);
391  return(sg.ToString());
392  } else if (is_site_of_origin(comm)) {
393  SiteOfOrigin soo(comm);
394  return(soo.ToString());
395  } else if (is_tunnel_encap(comm)) {
396  TunnelEncap encap(comm);
397  return(encap.ToString());
398  } else if (is_load_balance(comm)) {
399  LoadBalance load_balance(comm);
400  return(load_balance.ToString());
401  } else if (is_tag(comm)) {
402  Tag tag(comm);
403  return(tag.ToString());
404  } else if (is_source_as(comm)) {
405  SourceAs sas(comm);
406  return(sas.ToString());
407  } else if (is_vrf_route_import(comm)) {
408  VrfRouteImport rt_import(comm);
409  return(rt_import.ToString());
410  } else if (is_sub_cluster(comm)) {
411  SubCluster sc(comm);
412  return(sc.ToString());
413  }
414  return ToHexString(comm);
415 }
416 
418  for (ExtCommunityList::const_iterator it = communities_.begin();
419  it != communities_.end(); ++it) {
420  if (ExtCommunity::is_route_target(*it) && *it == val)
421  return true;
422  }
423  return false;
424 }
425 
427  for (ExtCommunityList::const_iterator it = communities_.begin();
428  it != communities_.end(); ++it) {
429  if (ExtCommunity::is_origin_vn(*it) && *it == val)
430  return true;
431  }
432  return false;
433 }
434 
435 bool ExtCommunity::ContainsOriginVn(as_t asn, uint32_t vn_index) const {
436  if (asn <= 0xffffffff) {
437  OriginVn origin_vn(asn, vn_index);
438  return ContainsOriginVn(origin_vn.GetExtCommunity());
439  }
440  OriginVn origin_vn4(asn, AS_TRANS);
441  OriginVn origin_vn(AS_TRANS, vn_index);
442  return (ContainsOriginVn(origin_vn.GetExtCommunity()) &&
443  ContainsOriginVn(origin_vn4.GetExtCommunity()));
444 }
445 
447  for (ExtCommunityList::const_iterator it = communities_.begin();
448  it != communities_.end(); ++it) {
449  if (ExtCommunity::is_source_as(*it) && *it == val)
450  return true;
451  }
452  return false;
453 }
454 
456  for (ExtCommunityList::const_iterator it = communities_.begin();
457  it != communities_.end(); ++it) {
458  if (ExtCommunity::is_sub_cluster(*it)) {
459  SubCluster sc(*it);
460  return sc.GetId();
461  }
462  }
463  return 0;
464 }
465 
467  for (ExtCommunityList::const_iterator it = communities_.begin();
468  it != communities_.end(); ++it) {
469  if (ExtCommunity::is_vrf_route_import(*it) && *it == val)
470  return true;
471  }
472  return false;
473 }
474 
476  for (ExtCommunityList::iterator it = communities_.begin();
477  it != communities_.end(); ) {
479  it = communities_.erase(it);
480  } else {
481  ++it;
482  }
483  }
484 }
485 
487  for (ExtCommunityList::iterator it = communities_.begin();
488  it != communities_.end(); ) {
490  it = communities_.erase(it);
491  } else {
492  ++it;
493  }
494  }
495 }
496 
498  for (ExtCommunityList::iterator it = communities_.begin();
499  it != communities_.end(); ) {
502  it = communities_.erase(it);
503  } else {
504  ++it;
505  }
506  }
507 }
508 
510  for (ExtCommunityList::iterator it = communities_.begin();
511  it != communities_.end(); ) {
512  if (ExtCommunity::is_tag(*it) || ExtCommunity::is_tag4(*it)) {
513  it = communities_.erase(it);
514  } else {
515  ++it;
516  }
517  }
518 }
519 
521  for (ExtCommunityList::iterator it = communities_.begin();
522  it != communities_.end(); ) {
524  it = communities_.erase(it);
525  } else {
526  ++it;
527  }
528  }
529 }
530 
532  for (ExtCommunityList::iterator it = communities_.begin();
533  it != communities_.end(); ) {
534  if (ExtCommunity::is_source_as(*it)) {
535  it = communities_.erase(it);
536  } else {
537  ++it;
538  }
539  }
540 }
542  for (ExtCommunityList::iterator it = communities_.begin();
543  it != communities_.end(); ) {
545  it = communities_.erase(it);
546  } else {
547  ++it;
548  }
549  }
550 }
551 
553  for (ExtCommunityList::iterator it = communities_.begin();
554  it != communities_.end(); ) {
556  it = communities_.erase(it);
557  else
558  ++it;
559  }
560 }
561 
563  for (ExtCommunityList::iterator it = communities_.begin();
564  it != communities_.end(); ) {
566  it = communities_.erase(it);
567  } else {
568  ++it;
569  }
570  }
571 }
572 
574  for (ExtCommunityList::iterator it = communities_.begin();
575  it != communities_.end(); ) {
577  it = communities_.erase(it);
578  } else {
579  ++it;
580  }
581  }
582 }
583 
585  for (ExtCommunityList::iterator it = communities_.begin();
586  it != communities_.end(); ) {
587  if (ExtCommunity::is_sub_cluster(*it)) {
588  it = communities_.erase(it);
589  } else {
590  ++it;
591  }
592  }
593 }
594 
595 vector<string> ExtCommunity::GetTunnelEncap() const {
596  vector<string> encap_list;
597  for (ExtCommunityList::const_iterator iter = communities_.begin();
598  iter != communities_.end(); ++iter) {
599  if (!ExtCommunity::is_tunnel_encap(*iter))
600  continue;
601  TunnelEncap encap(*iter);
602  if (encap.tunnel_encap() == TunnelEncapType::UNSPEC)
603  continue;
604  encap_list.push_back(encap.ToXmppString());
605  }
606 
607  sort(encap_list.begin(), encap_list.end());
608  vector<string>::iterator encap_iter =
609  unique(encap_list.begin(), encap_list.end());
610  encap_list.erase(encap_iter, encap_list.end());
611  return encap_list;
612 }
613 
614 vector<int> ExtCommunity::GetTagList(as2_t asn) const {
615  vector<int> tag_list;
616  for (ExtCommunityList::const_iterator iter = communities_.begin();
617  iter != communities_.end(); ++iter) {
618  if (!ExtCommunity::is_tag(*iter))
619  continue;
620  Tag tag_comm(*iter);
621  if (asn && tag_comm.as_number() != asn && !tag_comm.IsGlobal())
622  continue;
623  tag_list.push_back(tag_comm.tag());
624  }
625 
626  sort(tag_list.begin(), tag_list.end());
627  vector<int>::iterator tag_iter = unique(tag_list.begin(), tag_list.end());
628  tag_list.erase(tag_iter, tag_list.end());
629  return tag_list;
630 }
631 
632 vector<int> ExtCommunity::GetTag4List(as_t asn) const {
633  vector<int> tag_list;
634  for (ExtCommunityList::const_iterator iter = communities_.begin();
635  iter != communities_.end(); ++iter) {
636  if (!ExtCommunity::is_tag4(*iter))
637  continue;
638  Tag4ByteAs tag_comm(*iter);
639  if (asn && tag_comm.as_number() != asn && !tag_comm.IsGlobal())
640  continue;
641  vector<int> matching_tag_list = GetTagList(tag_comm.tag());
642  tag_list.insert(tag_list.end(), matching_tag_list.begin(),
643  matching_tag_list.end());
644  tag_list.push_back(tag_comm.tag());
645  }
646  if ((asn <= 0xffff) && tag_list.size() == 0)
647  tag_list = GetTagList(asn);
648 
649  sort(tag_list.begin(), tag_list.end());
650  vector<int>::iterator tag_iter = unique(tag_list.begin(), tag_list.end());
651  tag_list.erase(tag_iter, tag_list.end());
652  return tag_list;
653 }
654 
656  for (ExtCommunityList::const_iterator iter = communities_.begin();
657  iter != communities_.end(); ++iter) {
658  if (!ExtCommunity::is_tunnel_encap(*iter))
659  continue;
660  TunnelEncap encap(*iter);
661  if (encap.tunnel_encap() == TunnelEncapType::VXLAN)
662  return true;
663  }
664  return false;
665 }
666 
668  for (ExtCommunityList::const_iterator iter = communities_.begin();
669  iter != communities_.end(); ++iter) {
670  if (ExtCommunity::is_origin_vn(*iter)) {
671  OriginVn origin_vn(*iter);
672  return origin_vn.vn_index();
673  }
674  }
675  return -1;
676 }
677 
679  const ExtCommunitySpec spec) : extcomm_db_(extcomm_db) {
680  refcount_ = 0;
681  for (vector<uint64_t>::const_iterator it = spec.communities.begin();
682  it < spec.communities.end(); ++it) {
683  ExtCommunityValue comm;
684  put_value(comm.data(), comm.size(), *it);
685  communities_.push_back(comm);
686  }
687  sort(communities_.begin(), communities_.end());
688  ExtCommunityList::iterator it =
689  unique(communities_.begin(), communities_.end());
690  communities_.erase(it, communities_.end());
691 }
692 
694 }
695 
697  const ExtCommunity::ExtCommunityList &list) {
698  ExtCommunity *clone;
699  if (src) {
700  clone = new ExtCommunity(*src);
701  } else {
702  clone = new ExtCommunity(this);
703  }
704 
705  clone->Append(list);
706  return Locate(clone);
707 }
708 
710  const ExtCommunity::ExtCommunityValue &value) {
712  list.push_back(value);
713  return AppendAndLocate(src, list);
714 }
715 
717  const ExtCommunity::ExtCommunityList &list) {
718  ExtCommunity *clone;
719  if (src) {
720  clone = new ExtCommunity(*src);
721  } else {
722  clone = new ExtCommunity(this);
723  }
724 
725  clone->Remove(list);
726  return Locate(clone);
727 }
728 
730  const ExtCommunity::ExtCommunityList &export_list) {
731  ExtCommunity *clone;
732  if (src) {
733  clone = new ExtCommunity(*src);
734  } else {
735  clone = new ExtCommunity(this);
736  }
737 
738  clone->RemoveMFlags();
739  clone->Append(export_list);
740  return Locate(clone);
741 }
742 
744  const ExtCommunity::ExtCommunityList &export_list) {
745  ExtCommunity *clone;
746  if (src) {
747  clone = new ExtCommunity(*src);
748  } else {
749  clone = new ExtCommunity(this);
750  }
751 
752  clone->RemoveRTarget();
753  clone->Append(export_list);
754  return Locate(clone);
755 }
756 
758  const ExtCommunity *src,
759  const ExtCommunity::ExtCommunityList &sgid_list) {
760  ExtCommunity *clone;
761  if (src) {
762  clone = new ExtCommunity(*src);
763  } else {
764  clone = new ExtCommunity(this);
765  }
766 
767  clone->RemoveSGID();
768  clone->Append(sgid_list);
769  return Locate(clone);
770 }
771 
773  const ExtCommunity *src,
774  const ExtCommunity::ExtCommunityList &tag_list) {
775  ExtCommunity *clone;
776  if (src) {
777  clone = new ExtCommunity(*src);
778  } else {
779  clone = new ExtCommunity(this);
780  }
781 
782  clone->RemoveTag();
783  clone->Append(tag_list);
784  return Locate(clone);
785 }
786 
788  const ExtCommunity *src) {
789  ExtCommunity *clone;
790  if (src) {
791  clone = new ExtCommunity(*src);
792  } else {
793  clone = new ExtCommunity(this);
794  }
795 
796  clone->RemoveSiteOfOrigin();
797  return Locate(clone);
798 }
799 
801  const ExtCommunity *src,
802  const ExtCommunity::ExtCommunityValue &soo) {
803  ExtCommunity *clone;
804  if (src) {
805  clone = new ExtCommunity(*src);
806  } else {
807  clone = new ExtCommunity(this);
808  }
809 
810  clone->RemoveSiteOfOrigin();
811  clone->Append(soo);
812  return Locate(clone);
813 }
814 
816  const ExtCommunity *src) {
817  ExtCommunity *clone;
818  if (src) {
819  clone = new ExtCommunity(*src);
820  } else {
821  clone = new ExtCommunity(this);
822  }
823 
824  clone->RemoveSourceAS();
825  return Locate(clone);
826 }
827 
829  const ExtCommunity *src,
830  const ExtCommunity::ExtCommunityValue &sas) {
831  ExtCommunity *clone;
832  if (src) {
833  clone = new ExtCommunity(*src);
834  } else {
835  clone = new ExtCommunity(this);
836  }
837 
838  clone->RemoveSourceAS();
839  clone->Append(sas);
840  return Locate(clone);
841 }
842 
844  const ExtCommunity *src) {
845  ExtCommunity *clone;
846  if (src) {
847  clone = new ExtCommunity(*src);
848  } else {
849  clone = new ExtCommunity(this);
850  }
851 
852  clone->RemoveVrfRouteImport();
853  return Locate(clone);
854 }
855 
857  const ExtCommunity *src,
858  const ExtCommunity::ExtCommunityValue &vit) {
859  ExtCommunity *clone;
860  if (src) {
861  clone = new ExtCommunity(*src);
862  } else {
863  clone = new ExtCommunity(this);
864  }
865 
866  clone->RemoveVrfRouteImport();
867  clone->Append(vit);
868  return Locate(clone);
869 }
870 
872  const ExtCommunity *src) {
873  ExtCommunity *clone;
874  if (src) {
875  clone = new ExtCommunity(*src);
876  } else {
877  clone = new ExtCommunity(this);
878  }
879 
880  clone->RemoveOriginVn();
881  return Locate(clone);
882 }
883 
885  const ExtCommunity *src,
886  const ExtCommunity::ExtCommunityValue &origin_vn) {
887  ExtCommunity *clone;
888  if (src) {
889  clone = new ExtCommunity(*src);
890  } else {
891  clone = new ExtCommunity(this);
892  }
893 
894  clone->RemoveOriginVn();
895  clone->Append(origin_vn);
896  return Locate(clone);
897 }
898 
900  const ExtCommunity *src,
901  const ExtCommunity::ExtCommunityList &tunnel_encaps) {
902  ExtCommunity *clone;
903  if (src) {
904  clone = new ExtCommunity(*src);
905  } else {
906  clone = new ExtCommunity(this);
907  }
908 
909  clone->RemoveTunnelEncapsulation();
910  clone->Append(tunnel_encaps);
911  return Locate(clone);
912 }
913 
915  const ExtCommunity *src,
917  ExtCommunity *clone;
918  if (src) {
919  clone = new ExtCommunity(*src);
920  } else {
921  clone = new ExtCommunity(this);
922  }
923 
924  clone->RemoveLoadBalance();
925  clone->Append(lb);
926  return Locate(clone);
927 }
928 
930  const ExtCommunity *src,
932  ExtCommunity *clone;
933  if (src) {
934  clone = new ExtCommunity(*src);
935  } else {
936  clone = new ExtCommunity(this);
937  }
938 
939  clone->RemoveSubCluster();
940  clone->Append(sc);
941  return Locate(clone);
942 }
943 
945  const ExtCommunity::ExtCommunityList &value) {
946  ExtCommunity *clone;
947  if (src) {
948  clone = new ExtCommunity(*src);
949  } else {
950  clone = new ExtCommunity(this);
951  }
952 
953  clone->Set(value);
954  return Locate(clone);
955 }
956 
CommunityDB(BgpServer *server)
Definition: community.cc:128
int GetOriginVnIndex() const
Definition: community.cc:667
ExtCommunityPtr RemoveSiteOfOriginAndLocate(const ExtCommunity *src)
Definition: community.cc:787
ExtCommunityPtr ReplaceSGIDListAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &sgid_list)
Definition: community.cc:757
ExtCommunityDB * extcomm_db_
Definition: community.h:426
ExtCommunityPtr AppendAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &list)
Definition: community.cc:696
ExtCommunityPtr ReplaceOriginVnAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &origin_vn)
Definition: community.cc:884
ExtCommunityPtr ReplaceMFlagsAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &export_list)
Definition: community.cc:729
const uint64_t GetExtCommunityValue() const
Definition: tunnel_encap.h:32
boost::array< uint8_t, 8 > ExtCommunityValue
Definition: community.h:152
bool ContainsOriginVn(as_t asn, uint32_t vn_index) const
Definition: community.cc:435
Definition: etree.h:16
ExtCommunity(ExtCommunityDB *extcomm_db)
Definition: community.h:155
void RemoveSubCluster()
Definition: community.cc:584
uint32_t GetSubClusterId() const
Definition: community.cc:455
std::string ToString()
Definition: tunnel_encap.cc:51
std::vector< int > GetTagList(as2_t asn=0) const
Definition: community.cc:614
static bool is_security_group(const ExtCommunityValue &val)
Definition: community.h:304
std::string ToString() const
virtual int CompareTo(const BgpAttribute &rhs_attr) const
Definition: community.cc:201
virtual size_t EncodeLength() const
Definition: community.cc:197
void Set(const std::vector< uint32_t > &communities)
Definition: community.cc:95
virtual void Remove()
Definition: community.cc:109
#define KEY_COMPARE(x, y)
Definition: util.h:70
tbb::atomic< int > refcount_
Definition: community.h:425
static std::string ToHexString(const ExtCommunityValue &val)
Definition: community.cc:352
const bytes_type & GetExtCommunity() const
Definition: source_as.h:44
static const std::string CommunityToString(uint32_t comm)
ExtCommunityPtr RemoveOriginVnAndLocate(const ExtCommunity *src)
Definition: community.cc:871
void Append(const ExtCommunityValue &value)
Definition: community.cc:264
uint8_t flags
Definition: bgp_attr_base.h:70
static SiteOfOrigin FromString(const std::string &str, boost::system::error_code *error=NULL)
std::vector< int > GetTag4List(as_t asn=0) const
Definition: community.cc:632
CommunityPtr RemoveAndLocate(const Community *src, const std::vector< uint32_t > &value)
Definition: community.cc:170
static bool is_source_as(const ExtCommunityValue &val)
Definition: community.h:335
void set_community(CommunityPtr comm)
Definition: bgp_attr.cc:999
std::string ToString() const
static bool is_site_of_origin(const ExtCommunityValue &val)
Definition: community.h:322
ExtCommunityPtr RemoveAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &list)
Definition: community.cc:716
ExtCommunityPtr RemoveVrfRouteImportAndLocate(const ExtCommunity *src)
Definition: community.cc:843
std::string ToString() const
uint32_t as_t
Definition: bgp_common.h:21
uint32_t GetId() const
Definition: sub_cluster.cc:37
std::string ToString()
bool ContainsRTarget(const ExtCommunityValue &val) const
Definition: community.cc:417
static bool is_esi_label(const ExtCommunityValue &val)
Definition: community.h:219
std::string ToString() const
Definition: source_as.cc:50
const bytes_type & GetExtCommunity() const
static bool is_security_group4(const ExtCommunityValue &val)
Definition: community.h:313
std::string ToXmppString()
Definition: tunnel_encap.cc:57
void RemoveRTarget()
Definition: community.cc:486
static SourceAs FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: source_as.cc:68
void RemoveSourceAS()
Definition: community.cc:531
virtual size_t EncodeLength() const
Definition: community.cc:74
std::string ToString()
Definition: mac_mobility.cc:43
virtual void ToCanonical(BgpAttr *attr)
Definition: community.cc:40
bool ContainsSourceAs(const ExtCommunityValue &val) const
Definition: community.cc:446
int tag() const
virtual int CompareTo(const BgpAttribute &rhs) const
uint16_t as2_t
Definition: bgp_common.h:22
static SubCluster FromString(const std::string &str, boost::system::error_code *error=NULL)
Definition: sub_cluster.cc:80
std::string ToString() const
CommunityPtr AppendAndLocate(const Community *src, uint32_t value)
Definition: community.cc:131
static bool is_router_mac(const ExtCommunityValue &val)
Definition: community.h:257
ExtCommunityList communities_
Definition: community.h:427
boost::intrusive_ptr< const ExtCommunity > ExtCommunityPtr
Definition: community.h:448
CommunityPtr SetAndLocate(const Community *src, const std::vector< uint32_t > &value)
Definition: community.cc:157
void Delete(Type *attr)
static bool is_multicast_flags(const ExtCommunityValue &val)
Definition: community.h:248
bool ContainsValue(uint32_t value) const
Definition: community.cc:113
static ExtCommunityList ExtCommunityFromString(const std::string &comm)
Definition: community.cc:305
TunnelEncapType::Encap tunnel_encap() const
Definition: tunnel_encap.cc:40
void RemoveSiteOfOrigin()
Definition: community.cc:520
Community(CommunityDB *comm_db)
Definition: community.h:49
std::string ToString() const
Definition: es_import.cc:28
static bool is_tag4(const ExtCommunityValue &val)
Definition: community.h:384
static ExtCommunityValue FromHexString(const std::string &comm, boost::system::error_code *errorp)
Definition: community.cc:272
virtual void Remove()
Definition: community.cc:244
int CompareTo(const Community &rhs) const
Definition: community.cc:69
static std::string ToString(const ExtCommunityValue &val)
Definition: community.cc:361
static RouteTarget FromString(const std::string &str, boost::system::error_code *error=NULL)
int CompareTo(const ExtCommunity &rhs) const
Definition: community.cc:221
bool IsGlobal() const
boost::intrusive_ptr< const Community > CommunityPtr
Definition: community.h:109
ExtCommunityPtr ReplaceSourceASAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &sas)
Definition: community.cc:828
static bool is_es_import(const ExtCommunityValue &val)
Definition: community.h:211
void AddTunnelEncaps(std::vector< std::string > encaps)
Definition: community.cc:213
bool ContainsVrfRouteImport(const ExtCommunityValue &val) const
Definition: community.cc:466
void Set(const ExtCommunityList &list)
Definition: community.cc:248
static bool is_local_sequence_number(const ExtCommunityValue &val)
Definition: community.h:235
void RemoveOriginVn()
Definition: community.cc:552
virtual std::string ToString() const
Definition: community.cc:190
void RemoveSGID()
Definition: community.cc:497
ExtCommunityPtr RemoveSourceASAndLocate(const ExtCommunity *src)
Definition: community.cc:815
void RemoveTunnelEncapsulation()
Definition: community.cc:562
static bool is_sub_cluster(const ExtCommunityValue &val)
Definition: community.h:346
ExtCommunityPtr ReplaceSiteOfOriginAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &soo)
Definition: community.cc:800
static VrfRouteImport FromString(const std::string &str, boost::system::error_code *error=NULL)
ExtCommunityPtr ReplaceTagListAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &tag_list)
Definition: community.cc:772
static bool is_default_gateway(const ExtCommunityValue &val)
Definition: community.h:203
void RemoveLoadBalance()
Definition: community.cc:573
const bytes_type & GetExtCommunity() const
Definition: sub_cluster.h:44
int vn_index() const
Definition: origin_vn.cc:122
void RemoveVrfRouteImport()
Definition: community.cc:541
std::vector< ExtCommunityValue > ExtCommunityList
Definition: community.h:153
std::string ToString()
Definition: router_mac.cc:33
static bool is_tag(const ExtCommunityValue &val)
Definition: community.h:378
ExtCommunityPtr ReplaceTunnelEncapsulationAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &tunnel_encaps)
Definition: community.cc:899
bool ContainsTunnelEncapVxlan() const
Definition: community.cc:655
static bool is_route_target(const ExtCommunityValue &val)
Definition: community.h:265
static bool is_tunnel_encap(const ExtCommunityValue &val)
Definition: community.h:366
std::string ToString() const
Definition: sub_cluster.cc:59
std::vector< std::string > GetTunnelEncap() const
Definition: community.cc:595
std::vector< uint32_t > communities_
Definition: community.h:88
std::string ToString() const
ExtCommunityPtr ReplaceSubClusterAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &sc)
Definition: community.cc:929
const bytes_type & GetExtCommunity() const
Definition: origin_vn.h:33
ExtCommunityPtr ReplaceLoadBalanceAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &lb)
Definition: community.cc:914
void RemoveTag()
Definition: community.cc:509
virtual std::string ToString() const
Definition: community.cc:44
static bool is_etree(const ExtCommunityValue &val)
Definition: community.h:240
const bytes_type & GetExtCommunity() const
void set_ext_community(ExtCommunityPtr extcomm)
Definition: bgp_attr.cc:1011
std::string ToString() const
Definition: esi_label.cc:44
as2_t as_number() const
std::vector< uint32_t > communities
Definition: community.h:33
std::vector< uint64_t > communities
Definition: community.h:143
void Append(uint32_t value)
Definition: community.cc:78
std::string ToString()
Definition: origin_vn.cc:138
std::string ToString() const
ExtCommunityPtr ReplaceVrfRouteImportAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityValue &vit)
Definition: community.cc:856
static bool is_vrf_route_import(const ExtCommunityValue &val)
Definition: community.h:357
virtual void ToCanonical(BgpAttr *attr)
Definition: community.cc:209
ExtCommunityDB(BgpServer *server)
Definition: community.cc:693
void BuildStringList(std::vector< std::string > *list) const
Definition: community.cc:121
const bytes_type & GetExtCommunity() const
std::string ToString()
Definition: etree.cc:44
uint8_t code
Definition: bgp_attr_base.h:68
#define AS_TRANS
Definition: bgp_common.h:23
std::vector< uint32_t > CommunityList
Definition: community.h:48
ExtCommunityPtr SetAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &list)
Definition: community.cc:944
ExtCommunityPtr ReplaceRTargetAndLocate(const ExtCommunity *src, const ExtCommunity::ExtCommunityList &export_list)
Definition: community.cc:743
static bool is_mac_mobility(const ExtCommunityValue &val)
Definition: community.h:227
tbb::atomic< int > refcount_
Definition: community.h:86
void RemoveMFlags()
Definition: community.cc:475
static bool is_load_balance(const ExtCommunityValue &val)
Definition: community.h:372
CommunityDB * comm_db_
Definition: community.h:87
static bool is_origin_vn(const ExtCommunityValue &val)
Definition: community.h:193
static void put_value(uint8_t *data, int size, uint64_t value)
Definition: parse_object.h:55