LCOV - code coverage report
Current view: top level - bgp - bgp_attr.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 224 992 22.6 %
Date: 2026-11-16 02:06:09 Functions: 39 182 21.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include "bgp/bgp_attr.h"
       7             : 
       8             : #include <algorithm>
       9             : #include <string>
      10             : 
      11             : #include "bgp/bgp_server.h"
      12             : #include "bgp/extended-community/esi_label.h"
      13             : #include "bgp/extended-community/etree.h"
      14             : #include "bgp/extended-community/mac_mobility.h"
      15             : #include "bgp/extended-community/router_mac.h"
      16             : #include "net/bgp_af.h"
      17             : 
      18             : using std::sort;
      19             : using std::vector;
      20             : using std::string;
      21             : 
      22           0 : int BgpAttrOrigin::CompareTo(const BgpAttribute &rhs_attr) const {
      23           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
      24           0 :     if (ret != 0) return ret;
      25           0 :     KEY_COMPARE(origin, static_cast<const BgpAttrOrigin &>(rhs_attr).origin);
      26           0 :     return 0;
      27             : }
      28             : 
      29        8858 : void BgpAttrOrigin::ToCanonical(BgpAttr *attr) {
      30        8858 :     attr->set_origin(static_cast<BgpAttrOrigin::OriginType>(origin));
      31        8858 : }
      32             : 
      33        6838 : string BgpAttrOrigin::ToString() const {
      34             :     char repr[80];
      35        6838 :     snprintf(repr, sizeof(repr), "ORIGIN <code: %d, flags: %02x> : %02x",
      36        6838 :              code, flags, origin);
      37        6838 :     return string(repr);
      38             : }
      39             : 
      40           0 : int BgpAttrNextHop::CompareTo(const BgpAttribute &rhs_attr) const {
      41           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
      42           0 :     if (ret != 0) return ret;
      43           0 :     KEY_COMPARE(nexthop,
      44             :             static_cast<const BgpAttrNextHop &>(rhs_attr).nexthop);
      45           0 :     return 0;
      46             : }
      47             : 
      48        4452 : void BgpAttrNextHop::ToCanonical(BgpAttr *attr) {
      49        4452 :     if (v6_nexthop.is_unspecified()) {
      50        4452 :         attr->set_nexthop(Ip4Address(nexthop));
      51             :     } else {
      52           0 :         attr->set_nexthop(v6_nexthop);
      53             :     }
      54        4452 : }
      55             : 
      56           0 : string BgpAttrNextHop::ToString() const {
      57             :     char repr[80];
      58           0 :     snprintf(repr, sizeof(repr), "NEXTHOP <code: %d, flags: %02x> : %04x",
      59           0 :              code, flags, nexthop);
      60           0 :     return string(repr);
      61             : }
      62             : 
      63           0 : int BgpAttrMultiExitDisc::CompareTo(const BgpAttribute &rhs_attr) const {
      64           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
      65           0 :     if (ret != 0) return ret;
      66           0 :     KEY_COMPARE(med, static_cast<const BgpAttrMultiExitDisc &>(rhs_attr).med);
      67           0 :     return 0;
      68             : }
      69        4500 : void BgpAttrMultiExitDisc::ToCanonical(BgpAttr *attr) {
      70        4500 :     attr->set_med(med);
      71        4500 : }
      72             : 
      73        3604 : string BgpAttrMultiExitDisc::ToString() const {
      74             :     char repr[80];
      75        3604 :     snprintf(repr, sizeof(repr), "MED <code: %d, flags: %02x> : %d",
      76        3604 :              code, flags, med);
      77        3604 :     return string(repr);
      78             : }
      79             : 
      80           0 : int BgpAttrLocalPref::CompareTo(const BgpAttribute &rhs_attr) const {
      81           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
      82           0 :     if (ret != 0) return ret;
      83           0 :     KEY_COMPARE(local_pref,
      84             :             static_cast<const BgpAttrLocalPref &>(rhs_attr).local_pref);
      85           0 :     return 0;
      86             : }
      87        2432 : void BgpAttrLocalPref::ToCanonical(BgpAttr *attr) {
      88        2432 :     attr->set_local_pref(local_pref);
      89        2432 : }
      90             : 
      91           0 : string BgpAttrLocalPref::ToString() const {
      92             :     char repr[80];
      93           0 :     snprintf(repr, sizeof(repr), "LOCAL_PREF <code: %d, flags: %02x> : %d",
      94           0 :              code, flags, local_pref);
      95           0 :     return string(repr);
      96             : }
      97             : 
      98           0 : void BgpAttrAtomicAggregate::ToCanonical(BgpAttr *attr) {
      99           0 :     attr->set_atomic_aggregate(true);
     100           0 : }
     101             : 
     102           0 : string BgpAttrAtomicAggregate::ToString() const {
     103             :     char repr[80];
     104           0 :     snprintf(repr, sizeof(repr), "ATOMIC_AGGR <code: %d, flags: %02x>",
     105           0 :              code, flags);
     106           0 :     return string(repr);
     107             : }
     108             : 
     109           0 : int BgpAttr4ByteAggregator::CompareTo(const BgpAttribute &rhs_attr) const {
     110           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     111           0 :     if (ret != 0) return ret;
     112           0 :     KEY_COMPARE(as_num,
     113             :             static_cast<const BgpAttr4ByteAggregator &>(rhs_attr).as_num);
     114           0 :     KEY_COMPARE(address,
     115             :             static_cast<const BgpAttr4ByteAggregator &>(rhs_attr).address);
     116           0 :     return 0;
     117             : }
     118           0 : void BgpAttr4ByteAggregator::ToCanonical(BgpAttr *attr) {
     119           0 :     attr->set_aggregator(as_num, Ip4Address(address));
     120           0 : }
     121             : 
     122           0 : string BgpAttr4ByteAggregator::ToString() const {
     123             :     char repr[80];
     124           0 :     snprintf(repr, sizeof(repr),
     125             :              "Aggregator <code: %d, flags: %02x> : %d:%08x",
     126           0 :              code, flags, as_num, address);
     127           0 :     return string(repr);
     128             : }
     129             : 
     130           0 : int BgpAttrAggregator::CompareTo(const BgpAttribute &rhs_attr) const {
     131           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     132           0 :     if (ret != 0) return ret;
     133           0 :     KEY_COMPARE(as_num,
     134             :             static_cast<const BgpAttrAggregator &>(rhs_attr).as_num);
     135           0 :     KEY_COMPARE(address,
     136             :             static_cast<const BgpAttrAggregator &>(rhs_attr).address);
     137           0 :     return 0;
     138             : }
     139           0 : void BgpAttrAggregator::ToCanonical(BgpAttr *attr) {
     140           0 :     attr->set_aggregator(as_num, Ip4Address(address));
     141           0 : }
     142             : 
     143           0 : string BgpAttrAggregator::ToString() const {
     144             :     char repr[80];
     145           0 :     snprintf(repr, sizeof(repr),
     146             :              "Aggregator <code: %d, flags: %02x> : %d:%08x",
     147           0 :              code, flags, as_num, address);
     148           0 :     return string(repr);
     149             : }
     150             : 
     151           0 : int BgpAttrAs4Aggregator::CompareTo(const BgpAttribute &rhs_attr) const {
     152           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     153           0 :     if (ret != 0) return ret;
     154           0 :     KEY_COMPARE(as_num,
     155             :             static_cast<const BgpAttrAs4Aggregator &>(rhs_attr).as_num);
     156           0 :     KEY_COMPARE(address,
     157             :             static_cast<const BgpAttrAs4Aggregator &>(rhs_attr).address);
     158           0 :     return 0;
     159             : }
     160           0 : void BgpAttrAs4Aggregator::ToCanonical(BgpAttr *attr) {
     161           0 :     attr->set_as4_aggregator(as_num, Ip4Address(address));
     162           0 : }
     163             : 
     164           0 : string BgpAttrAs4Aggregator::ToString() const {
     165             :     char repr[80];
     166           0 :     snprintf(repr, sizeof(repr),
     167             :              "Aggregator <code: %d, flags: %02x> : %d:%08x",
     168           0 :              code, flags, as_num, address);
     169           0 :     return string(repr);
     170             : }
     171             : 
     172           0 : int BgpAttrOriginatorId::CompareTo(const BgpAttribute &rhs_attr) const {
     173           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     174           0 :     if (ret != 0) return ret;
     175           0 :     KEY_COMPARE(originator_id,
     176             :         static_cast<const BgpAttrOriginatorId &>(rhs_attr).originator_id);
     177           0 :     return 0;
     178             : }
     179             : 
     180           0 : void BgpAttrOriginatorId::ToCanonical(BgpAttr *attr) {
     181           0 :     attr->set_originator_id(Ip4Address(originator_id));
     182           0 : }
     183             : 
     184           0 : string BgpAttrOriginatorId::ToString() const {
     185             :     char repr[80];
     186           0 :     snprintf(repr, sizeof(repr), "OriginatorId <code: %d, flags: 0x%02x> : %s",
     187           0 :              code, flags, Ip4Address(originator_id).to_string().c_str());
     188           0 :     return string(repr);
     189             : }
     190             : 
     191           0 : ClusterListSpec::ClusterListSpec(uint32_t cluster_id,
     192           0 :     const ClusterListSpec *rhs)
     193           0 :     : BgpAttribute(BgpAttribute::ClusterList, kFlags) {
     194           0 :     cluster_list.push_back(cluster_id);
     195           0 :     if (rhs) {
     196           0 :         cluster_list.insert(cluster_list.end(), rhs->cluster_list.begin(),
     197             :             rhs->cluster_list.end());
     198             :     }
     199           0 : }
     200             : 
     201           0 : int ClusterListSpec::CompareTo(const BgpAttribute &rhs_attr) const {
     202           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     203           0 :     if (ret != 0) return ret;
     204           0 :     KEY_COMPARE(cluster_list,
     205             :         static_cast<const ClusterListSpec &>(rhs_attr).cluster_list);
     206           0 :     return 0;
     207             : }
     208             : 
     209           0 : void ClusterListSpec::ToCanonical(BgpAttr *attr) {
     210           0 :     attr->set_cluster_list(this);
     211           0 : }
     212             : 
     213           0 : string ClusterListSpec::ToString() const {
     214           0 :     std::stringstream repr;
     215           0 :     repr << "CLUSTER_LIST <code: " << int(code);
     216           0 :     repr << ", flags: 0x" << std::hex << int(flags) << "> :";
     217           0 :     for (vector<uint32_t>::const_iterator iter = cluster_list.begin();
     218           0 :          iter != cluster_list.end(); ++iter) {
     219           0 :         repr << " " << Ip4Address(*iter).to_string();
     220             :     }
     221           0 :     return repr.str();
     222           0 : }
     223             : 
     224           0 : bool ClusterListSpec::ClusterListLoop(uint32_t cluster_id) const {
     225           0 :     for (vector<uint32_t>::const_iterator iter = cluster_list.begin();
     226           0 :          iter != cluster_list.end(); ++iter) {
     227           0 :         if (*iter == cluster_id)
     228           0 :             return true;
     229             :     }
     230           0 :     return false;
     231             : }
     232             : 
     233           0 : ClusterList::ClusterList(ClusterListDB *cluster_list_db,
     234           0 :     const ClusterListSpec &spec)
     235           0 :     : cluster_list_db_(cluster_list_db),
     236           0 :       spec_(spec) {
     237           0 :     refcount_ = 0;
     238           0 : }
     239             : 
     240           0 : void ClusterList::Remove() {
     241           0 :     cluster_list_db_->Delete(this);
     242           0 : }
     243             : 
     244          20 : ClusterListDB::ClusterListDB(BgpServer *server) {
     245          20 : }
     246             : 
     247           0 : int BgpMpNlri::CompareTo(const BgpAttribute &rhs_attr) const {
     248           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     249           0 :     if (ret != 0) return ret;
     250           0 :     const BgpMpNlri &rhs = static_cast<const BgpMpNlri &>(rhs_attr);
     251           0 :     KEY_COMPARE(afi, rhs.afi);
     252           0 :     KEY_COMPARE(safi, rhs.safi);
     253           0 :     KEY_COMPARE(nexthop, rhs.nexthop);
     254           0 :     KEY_COMPARE(nlri.size(), rhs.nlri.size());
     255             : 
     256           0 :     for (size_t i = 0; i < nlri.size(); i++) {
     257           0 :         KEY_COMPARE(nlri[i]->type, rhs.nlri[i]->type);
     258           0 :         KEY_COMPARE(nlri[i]->prefixlen, rhs.nlri[i]->prefixlen);
     259           0 :         KEY_COMPARE(nlri[i]->prefix, rhs.nlri[i]->prefix);
     260             :     }
     261           0 :     return 0;
     262             : }
     263             : 
     264        9530 : void BgpMpNlri::ToCanonical(BgpAttr *attr) {
     265        9530 : }
     266             : 
     267       31012 : size_t BgpMpNlri::EncodeLength() const {
     268       31012 :     size_t sz = 2 /* safi */ + 1 /* afi */ +
     269             :                 1 /* NlriNextHopLength */ +
     270             :                 1 /* Reserved */;
     271       31012 :     sz += nexthop.size();
     272       31011 :     for (vector<BgpProtoPrefix*>::const_iterator iter = nlri.begin();
     273       51773 :          iter != nlri.end(); ++iter) {
     274       20762 :         size_t bytes = 0;
     275       20762 :         if (afi == BgpAf::L2Vpn &&
     276        3040 :             (safi == BgpAf::EVpn || safi == BgpAf::ErmVpn)) {
     277        3040 :             bytes = (*iter)->prefixlen;
     278             :         } else {
     279       17722 :             bytes = ((*iter)->prefixlen + 7) / 8;
     280             :         }
     281       20762 :         sz += 1 + bytes;
     282             :     }
     283       31006 :     return sz;
     284             : }
     285             : 
     286         256 : PmsiTunnelSpec::PmsiTunnelSpec()
     287             :     : BgpAttribute(PmsiTunnel, kFlags),
     288         256 :       tunnel_flags(0), tunnel_type(0), label(0) {
     289         256 : }
     290             : 
     291           0 : PmsiTunnelSpec::PmsiTunnelSpec(const BgpAttribute &rhs)
     292           0 :     : BgpAttribute(rhs), tunnel_flags(0), tunnel_type(0), label(0) {
     293           0 : }
     294             : 
     295           0 : int PmsiTunnelSpec::CompareTo(const BgpAttribute &rhs_attr) const {
     296           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     297           0 :     if (ret != 0) return ret;
     298           0 :     const PmsiTunnelSpec &rhs = static_cast<const PmsiTunnelSpec &>(rhs_attr);
     299           0 :     KEY_COMPARE(tunnel_flags, rhs.tunnel_flags);
     300           0 :     KEY_COMPARE(tunnel_type, rhs.tunnel_type);
     301           0 :     KEY_COMPARE(label, rhs.label);
     302           0 :     KEY_COMPARE(identifier, rhs.identifier);
     303           0 :     return 0;
     304             : }
     305             : 
     306           0 : void PmsiTunnelSpec::ToCanonical(BgpAttr *attr) {
     307           0 :     attr->set_pmsi_tunnel(this);
     308           0 : }
     309             : 
     310           0 : string PmsiTunnelSpec::ToString() const {
     311           0 :     std::ostringstream oss;
     312           0 :     oss << "PmsiTunnel <code: " << int(code);
     313           0 :     oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
     314           0 :     oss << " Tunnel Flags: 0x" << std::hex << int(tunnel_flags) << std::dec;
     315           0 :     oss << " Tunnel Type: " << int(tunnel_type);
     316           0 :     oss << " Label: 0x" << std::hex << int(label) << std::dec;
     317           0 :     oss << " (" << int(label) << ")";
     318           0 :     oss << " Identifier: " << GetIdentifier().to_string();
     319             : 
     320           0 :     return oss.str();
     321           0 : }
     322             : 
     323           0 : uint32_t PmsiTunnelSpec::GetLabel(const ExtCommunity *ext) const {
     324           0 :     assert(ext);
     325           0 :     bool is_vni = ext->ContainsTunnelEncapVxlan();
     326           0 :     return (is_vni ? label : (label >> 4));
     327             : }
     328             : 
     329           0 : void PmsiTunnelSpec::SetLabel(uint32_t in_label, const ExtCommunity *ext) {
     330           0 :     assert(ext);
     331           0 :     bool is_vni = ext->ContainsTunnelEncapVxlan();
     332           0 :     label = (is_vni ? in_label : (in_label << 4 | 0x01));
     333           0 : }
     334             : 
     335           0 : Ip4Address PmsiTunnelSpec::GetIdentifier() const {
     336           0 :     if (identifier.size() < 4)
     337           0 :         return Ip4Address();
     338           0 :     return Ip4Address(get_value(&identifier[0], 4));
     339             : }
     340             : 
     341           0 : void PmsiTunnelSpec::SetIdentifier(Ip4Address in_identifier) {
     342           0 :     identifier.resize(4, 0);
     343           0 :     const Ip4Address::bytes_type &bytes = in_identifier.to_bytes();
     344           0 :     std::copy(bytes.begin(), bytes.begin() + 4, identifier.begin());
     345           0 : }
     346             : 
     347           0 : string PmsiTunnelSpec::GetTunnelTypeString() const {
     348           0 :     switch (tunnel_type) {
     349           0 :     case RsvpP2mpLsp:
     350           0 :         return "RsvpP2mpLsp";
     351           0 :     case LdpP2mpLsp:
     352           0 :         return "LdpP2mpLsp";
     353           0 :     case PimSsmTree:
     354           0 :         return "PimSsmTree";
     355           0 :     case PimSmTree:
     356           0 :         return "PimSmTree";
     357           0 :     case BidirPimTree:
     358           0 :         return "BidirPimTree";
     359           0 :     case IngressReplication:
     360           0 :         return "IngressReplication";
     361           0 :     case MldpMp2mpLsp:
     362           0 :         return "MldpMp2mpLsp";
     363           0 :     case AssistedReplicationContrail:
     364           0 :         return "AssistedReplication";
     365           0 :     default:
     366           0 :         break;
     367             :     }
     368           0 :     std::ostringstream oss;
     369           0 :     oss << "Unknown(" << int(tunnel_type) << ")";
     370           0 :     return oss.str();
     371             : }
     372             : 
     373           0 : string PmsiTunnelSpec::GetTunnelArTypeString() const {
     374           0 :     switch (tunnel_flags & AssistedReplicationType) {
     375           0 :     case RegularNVE:
     376           0 :         return "RegularNVE";
     377           0 :     case ARReplicator:
     378           0 :         return "ARReplicator";
     379           0 :     case ARLeaf:
     380           0 :         return "ARLeaf";
     381           0 :     default:
     382           0 :         break;
     383             :     }
     384           0 :     return "Unknown";
     385             : }
     386             : 
     387           0 : vector<string> PmsiTunnelSpec::GetTunnelFlagsStrings() const {
     388           0 :     vector<string> flags;
     389           0 :     if (tunnel_flags & LeafInfoRequired) {
     390           0 :         flags.push_back("LeafInfoRequired");
     391             :     }
     392           0 :     if (tunnel_flags & EdgeReplicationSupported) {
     393           0 :         flags.push_back("EdgeReplicationSupported");
     394             :     }
     395           0 :     if (flags.empty()) {
     396           0 :         flags.push_back("None");
     397             :     }
     398           0 :     return flags;
     399           0 : }
     400             : 
     401           0 : PmsiTunnel::PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db,
     402           0 :     const PmsiTunnelSpec &pmsi_spec)
     403           0 :     : pmsi_tunnel_db_(pmsi_tunnel_db),
     404           0 :       pmsi_spec_(pmsi_spec) {
     405           0 :     refcount_ = 0;
     406           0 :     tunnel_flags_ = pmsi_spec_.tunnel_flags;
     407           0 :     tunnel_type_ = pmsi_spec_.tunnel_type;
     408           0 :     label_ = pmsi_spec_.label;
     409           0 :     identifier_ = pmsi_spec_.GetIdentifier();
     410           0 : }
     411             : 
     412           0 : void PmsiTunnel::Remove() {
     413           0 :     pmsi_tunnel_db_->Delete(this);
     414           0 : }
     415             : 
     416           0 : uint32_t PmsiTunnel::GetLabel(const ExtCommunity *ext) const {
     417           0 :     bool is_vni = false;
     418           0 :     if (ext)
     419           0 :         is_vni = ext->ContainsTunnelEncapVxlan();
     420           0 :     return (is_vni ? label_ : label_ >> 4);
     421             : }
     422             : 
     423          20 : PmsiTunnelDB::PmsiTunnelDB(BgpServer *server) {
     424          20 : }
     425             : 
     426           0 : EdgeDiscoverySpec::EdgeDiscoverySpec()
     427           0 :     : BgpAttribute(McastEdgeDiscovery, kFlags) {
     428           0 : }
     429             : 
     430           0 : EdgeDiscoverySpec::EdgeDiscoverySpec(const BgpAttribute &rhs)
     431           0 :     : BgpAttribute(rhs) {
     432           0 : }
     433             : 
     434           0 : EdgeDiscoverySpec::EdgeDiscoverySpec(const EdgeDiscoverySpec &rhs)
     435           0 :     : BgpAttribute(BgpAttribute::McastEdgeDiscovery, kFlags) {
     436           0 :     for (size_t i = 0; i < rhs.edge_list.size(); i++) {
     437           0 :         Edge *edge = new Edge;
     438           0 :         *edge = *rhs.edge_list[i];
     439           0 :         edge_list.push_back(edge);
     440             :     }
     441           0 : }
     442             : 
     443           0 : EdgeDiscoverySpec::~EdgeDiscoverySpec() {
     444           0 :     STLDeleteValues(&edge_list);
     445           0 : }
     446             : 
     447           0 : Ip4Address EdgeDiscoverySpec::Edge::GetIp4Address() const {
     448           0 :     return Ip4Address(get_value(&address[0], 4));
     449             : }
     450             : 
     451           0 : void EdgeDiscoverySpec::Edge::SetIp4Address(Ip4Address addr) {
     452           0 :     address.resize(4, 0);
     453           0 :     const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
     454           0 :     std::copy(addr_bytes.begin(), addr_bytes.begin() + 4, address.begin());
     455           0 : }
     456             : 
     457           0 : void EdgeDiscoverySpec::Edge::GetLabels(
     458             :     uint32_t *first_label, uint32_t *last_label) const {
     459           0 :     *first_label = labels[0];
     460           0 :     *last_label = labels[1];
     461           0 : }
     462             : 
     463           0 : void EdgeDiscoverySpec::Edge::SetLabels(
     464             :     uint32_t first_label, uint32_t last_label) {
     465           0 :     labels.push_back(first_label);
     466           0 :     labels.push_back(last_label);
     467           0 : }
     468             : 
     469             : struct EdgeDiscoverySpecEdgeCompare {
     470           0 :     int operator()(const EdgeDiscoverySpec::Edge *lhs,
     471             :                    const EdgeDiscoverySpec::Edge *rhs) const {
     472           0 :         KEY_COMPARE(lhs->address, rhs->address);
     473           0 :         KEY_COMPARE(lhs->labels, rhs->labels);
     474           0 :         return 0;
     475             :     }
     476             : };
     477             : 
     478           0 : int EdgeDiscoverySpec::CompareTo(const BgpAttribute &rhs_attr) const {
     479           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     480           0 :     if (ret != 0) return ret;
     481           0 :     const EdgeDiscoverySpec &rhs =
     482             :             static_cast<const EdgeDiscoverySpec &>(rhs_attr);
     483           0 :     ret = STLSortedCompare(edge_list.begin(), edge_list.end(),
     484             :                            rhs.edge_list.begin(), rhs.edge_list.end(),
     485             :                            EdgeDiscoverySpecEdgeCompare());
     486           0 :     return ret;
     487             : }
     488             : 
     489           0 : void EdgeDiscoverySpec::ToCanonical(BgpAttr *attr) {
     490           0 :     attr->set_edge_discovery(this);
     491           0 : }
     492             : 
     493           0 : string EdgeDiscoverySpec::ToString() const {
     494           0 :     std::ostringstream oss;
     495           0 :     oss << "EdgeDiscovery <code: " << int(code);
     496           0 :     oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
     497           0 :     int idx = 0;
     498           0 :     for (EdgeList::const_iterator it = edge_list.begin();
     499           0 :          it != edge_list.end(); ++it, ++idx) {
     500           0 :         const Edge *edge = *it;
     501             :         uint32_t first_label, last_label;
     502           0 :         edge->GetLabels(&first_label, &last_label);
     503           0 :         oss << " Edge[" << idx << "] = (" << edge->GetIp4Address() << ", ";
     504           0 :         oss << first_label << "-" << last_label << ")";
     505             :     }
     506             : 
     507           0 :     return oss.str();
     508           0 : }
     509             : 
     510           0 : size_t EdgeDiscoverySpec::EncodeLength() const {
     511           0 :     size_t sz = 0;
     512           0 :     for (EdgeList::const_iterator iter = edge_list.begin();
     513           0 :          iter != edge_list.end(); ++iter) {
     514           0 :         sz += 2; /* AddressLen + LabelLen */
     515           0 :         sz += (*iter)->address.size();
     516           0 :         sz += (*iter)->labels.size() * sizeof(uint32_t);
     517             :     }
     518           0 :     return sz;
     519             : }
     520             : 
     521           0 : EdgeDiscovery::Edge::Edge(const EdgeDiscoverySpec::Edge *spec_edge) {
     522           0 :     address = spec_edge->GetIp4Address();
     523             :     uint32_t first_label, last_label;
     524           0 :     spec_edge->GetLabels(&first_label, &last_label);
     525           0 :     label_block = new LabelBlock(first_label, last_label);
     526           0 : }
     527             : 
     528           0 : bool EdgeDiscovery::Edge::operator<(const Edge &rhs) const {
     529           0 :     BOOL_KEY_COMPARE(address, rhs.address);
     530           0 :     BOOL_KEY_COMPARE(label_block->first(), rhs.label_block->first());
     531           0 :     BOOL_KEY_COMPARE(label_block->last(), rhs.label_block->last());
     532           0 :     return false;
     533             : }
     534             : 
     535           0 : EdgeDiscovery::EdgeDiscovery(EdgeDiscoveryDB *edge_discovery_db,
     536           0 :     const EdgeDiscoverySpec &edspec)
     537           0 :     : edge_discovery_db_(edge_discovery_db),
     538           0 :       edspec_(edspec) {
     539           0 :     refcount_ = 0;
     540           0 :     for (EdgeDiscoverySpec::EdgeList::const_iterator it =
     541           0 :          edspec_.edge_list.begin(); it != edspec_.edge_list.end(); ++it) {
     542           0 :         Edge *edge = new Edge(*it);
     543           0 :         edge_list.push_back(edge);
     544             :     }
     545           0 :     sort(edge_list.begin(), edge_list.end(), EdgeDiscovery::EdgeCompare());
     546           0 : }
     547             : 
     548           0 : EdgeDiscovery::~EdgeDiscovery() {
     549           0 :     STLDeleteValues(&edge_list);
     550           0 : }
     551             : 
     552             : struct EdgeDiscoveryEdgeCompare {
     553           0 :     int operator()(const EdgeDiscovery::Edge *lhs,
     554             :                    const EdgeDiscovery::Edge *rhs) const {
     555           0 :         KEY_COMPARE(*lhs, *rhs);
     556           0 :         return 0;
     557             :     }
     558             : };
     559             : 
     560           0 : int EdgeDiscovery::CompareTo(const EdgeDiscovery &rhs) const {
     561           0 :     int result = STLSortedCompare(edge_list.begin(), edge_list.end(),
     562             :                                   rhs.edge_list.begin(), rhs.edge_list.end(),
     563             :                                   EdgeDiscoveryEdgeCompare());
     564           0 :     return result;
     565             : }
     566             : 
     567           0 : void EdgeDiscovery::Remove() {
     568           0 :     edge_discovery_db_->Delete(this);
     569           0 : }
     570             : 
     571          20 : EdgeDiscoveryDB::EdgeDiscoveryDB(BgpServer *server) {
     572          20 : }
     573             : 
     574           0 : EdgeForwardingSpec::EdgeForwardingSpec()
     575           0 :     : BgpAttribute(McastEdgeForwarding, kFlags) {
     576           0 : }
     577             : 
     578           0 : EdgeForwardingSpec::EdgeForwardingSpec(const BgpAttribute &rhs)
     579           0 :     : BgpAttribute(rhs) {
     580           0 : }
     581             : 
     582           0 : EdgeForwardingSpec::EdgeForwardingSpec(const EdgeForwardingSpec &rhs)
     583           0 :     : BgpAttribute(BgpAttribute::McastEdgeForwarding, kFlags) {
     584           0 :     for (size_t i = 0; i < rhs.edge_list.size(); i++) {
     585           0 :         Edge *edge = new Edge;
     586           0 :         *edge = *rhs.edge_list[i];
     587           0 :         edge_list.push_back(edge);
     588             :     }
     589           0 : }
     590             : 
     591           0 : EdgeForwardingSpec:: ~EdgeForwardingSpec() {
     592           0 :     STLDeleteValues(&edge_list);
     593           0 : }
     594             : 
     595           0 : Ip4Address EdgeForwardingSpec::Edge::GetInboundIp4Address() const {
     596           0 :     return Ip4Address(get_value(&inbound_address[0], 4));
     597             : }
     598             : 
     599           0 : Ip4Address EdgeForwardingSpec::Edge::GetOutboundIp4Address() const {
     600           0 :     return Ip4Address(get_value(&outbound_address[0], 4));
     601             : }
     602             : 
     603           0 : void EdgeForwardingSpec::Edge::SetInboundIp4Address(Ip4Address addr) {
     604           0 :     inbound_address.resize(4, 0);
     605           0 :     const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
     606           0 :     std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
     607             :         inbound_address.begin());
     608           0 : }
     609             : 
     610           0 : void EdgeForwardingSpec::Edge::SetOutboundIp4Address(Ip4Address addr) {
     611           0 :     outbound_address.resize(4, 0);
     612           0 :     const Ip4Address::bytes_type &addr_bytes = addr.to_bytes();
     613           0 :     std::copy(addr_bytes.begin(), addr_bytes.begin() + 4,
     614             :         outbound_address.begin());
     615           0 : }
     616             : 
     617             : struct EdgeForwardingSpecEdgeCompare {
     618           0 :     int operator()(const EdgeForwardingSpec::Edge *lhs,
     619             :                    const EdgeForwardingSpec::Edge *rhs) const {
     620           0 :         KEY_COMPARE(lhs->inbound_address, rhs->inbound_address);
     621           0 :         KEY_COMPARE(lhs->outbound_address, rhs->outbound_address);
     622           0 :         KEY_COMPARE(lhs->inbound_label, rhs->inbound_label);
     623           0 :         KEY_COMPARE(lhs->outbound_label, rhs->outbound_label);
     624           0 :         return 0;
     625             :     }
     626             : };
     627             : 
     628           0 : int EdgeForwardingSpec::CompareTo(const BgpAttribute &rhs_attr) const {
     629           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     630           0 :     if (ret != 0) return ret;
     631           0 :     const EdgeForwardingSpec &rhs =
     632             :             static_cast<const EdgeForwardingSpec &>(rhs_attr);
     633           0 :     ret = STLSortedCompare(edge_list.begin(), edge_list.end(),
     634             :                            rhs.edge_list.begin(), rhs.edge_list.end(),
     635             :                            EdgeForwardingSpecEdgeCompare());
     636           0 :     return ret;
     637             : }
     638             : 
     639           0 : void EdgeForwardingSpec::ToCanonical(BgpAttr *attr) {
     640           0 :     attr->set_edge_forwarding(this);
     641           0 : }
     642             : 
     643           0 : string EdgeForwardingSpec::ToString() const {
     644           0 :     std::ostringstream oss;
     645           0 :     oss << "EdgeForwarding <code: " << int(code);
     646           0 :     oss << ", flags: 0x" << std::hex << int(flags) << std::dec << ">";
     647           0 :     int idx = 0;
     648           0 :     for (EdgeList::const_iterator it = edge_list.begin();
     649           0 :          it != edge_list.end(); ++it, ++idx) {
     650           0 :         const Edge *edge = *it;
     651           0 :         oss << " Edge[" << idx << "] = (";
     652           0 :         oss << "InAddress=" << edge->GetInboundIp4Address() << ", ";
     653           0 :         oss << "InLabel=" << edge->inbound_label << ", ";
     654           0 :         oss << "OutAddress=" << edge->GetOutboundIp4Address() << ", ";
     655           0 :         oss << "OutLabel=" << edge->outbound_label << ")";
     656             :     }
     657             : 
     658           0 :     return oss.str();
     659           0 : }
     660             : 
     661           0 : size_t EdgeForwardingSpec::EncodeLength() const {
     662           0 :     size_t sz = 0;
     663           0 :     for (EdgeList::const_iterator iter = edge_list.begin();
     664           0 :          iter != edge_list.end(); ++iter) {
     665           0 :         sz += 1 /* address len */ + 8 /* 2 labels */;
     666           0 :         sz += (*iter)->inbound_address.size();
     667           0 :         sz += (*iter)->outbound_address.size();
     668             :     }
     669             : 
     670           0 :     return sz;
     671             : }
     672             : 
     673           0 : EdgeForwarding::Edge::Edge(const EdgeForwardingSpec::Edge *spec_edge) {
     674           0 :     inbound_address = spec_edge->GetInboundIp4Address();
     675           0 :     outbound_address = spec_edge->GetOutboundIp4Address();
     676           0 :     inbound_label = spec_edge->inbound_label;
     677           0 :     outbound_label = spec_edge->outbound_label;
     678           0 : }
     679             : 
     680           0 : bool EdgeForwarding::Edge::operator<(const Edge &rhs) const {
     681           0 :     BOOL_KEY_COMPARE(inbound_address, rhs.inbound_address);
     682           0 :     BOOL_KEY_COMPARE(outbound_address, rhs.outbound_address);
     683           0 :     BOOL_KEY_COMPARE(inbound_label, rhs.inbound_label);
     684           0 :     BOOL_KEY_COMPARE(outbound_label, rhs.outbound_label);
     685           0 :     return false;
     686             : }
     687             : 
     688           0 : EdgeForwarding::EdgeForwarding(EdgeForwardingDB *edge_forwarding_db,
     689           0 :     const EdgeForwardingSpec &efspec)
     690           0 :     : edge_forwarding_db_(edge_forwarding_db),
     691           0 :       efspec_(efspec) {
     692           0 :     refcount_ = 0;
     693           0 :     for (EdgeForwardingSpec::EdgeList::const_iterator it =
     694           0 :          efspec_.edge_list.begin(); it != efspec_.edge_list.end(); ++it) {
     695           0 :         Edge *edge = new Edge(*it);
     696           0 :         edge_list.push_back(edge);
     697             :     }
     698           0 :     sort(edge_list.begin(), edge_list.end(), EdgeForwarding::EdgeCompare());
     699           0 : }
     700             : 
     701           0 : EdgeForwarding::~EdgeForwarding() {
     702           0 :     STLDeleteValues(&edge_list);
     703           0 : }
     704             : 
     705             : struct EdgeForwardingEdgeCompare {
     706           0 :     int operator()(const EdgeForwarding::Edge *lhs,
     707             :                    const EdgeForwarding::Edge *rhs) const {
     708           0 :         KEY_COMPARE(*lhs, *rhs);
     709           0 :         return 0;
     710             :     }
     711             : };
     712             : 
     713           0 : int EdgeForwarding::CompareTo(const EdgeForwarding &rhs) const {
     714           0 :     int result = STLSortedCompare(edge_list.begin(), edge_list.end(),
     715             :                                   rhs.edge_list.begin(), rhs.edge_list.end(),
     716             :                                   EdgeForwardingEdgeCompare());
     717           0 :     return result;
     718             : }
     719             : 
     720           0 : void EdgeForwarding::Remove() {
     721           0 :     edge_forwarding_db_->Delete(this);
     722           0 : }
     723             : 
     724          20 : EdgeForwardingDB::EdgeForwardingDB(BgpServer *server) {
     725          20 : }
     726             : 
     727           0 : bool BgpOListElem::operator<(const BgpOListElem &rhs) const {
     728           0 :     BOOL_KEY_COMPARE(address, rhs.address);
     729           0 :     BOOL_KEY_COMPARE(label, rhs.label);
     730           0 :     BOOL_KEY_COMPARE(encap, rhs.encap);
     731           0 :     return false;
     732             : }
     733             : 
     734           0 : int BgpOListSpec::CompareTo(const BgpAttribute &rhs_attr) const {
     735           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     736           0 :     if (ret != 0) return ret;
     737           0 :     return 0;
     738             : }
     739             : 
     740           0 : void BgpOListSpec::ToCanonical(BgpAttr *attr) {
     741           0 :     if (subcode == BgpAttribute::OList) {
     742           0 :         attr->set_olist(this);
     743           0 :     } else if (subcode == BgpAttribute::LeafOList) {
     744           0 :         attr->set_leaf_olist(this);
     745             :     } else {
     746           0 :         assert(false);
     747             :     }
     748           0 : }
     749             : 
     750           0 : string BgpOListSpec::ToString() const {
     751           0 :     std::ostringstream oss;
     752           0 :     oss << "OList <subcode: " << int(subcode) << ">";
     753           0 :     int idx = 0;
     754           0 :     for (Elements::const_iterator it = elements.begin();
     755           0 :          it != elements.end(); ++it, ++idx) {
     756           0 :         BgpOListElem elem(*it);
     757           0 :         oss << "OList[" << idx << "] = (";
     758           0 :         oss << "address: " << elem.address << ", ";
     759           0 :         oss << "label: " << elem.label << ", ";
     760           0 :         oss << "encap-list:";
     761           0 :         int eid = 0;
     762           0 :         for (vector<string>::const_iterator e_it = elem.encap.begin();
     763           0 :              e_it != elem.encap.end(); ++e_it, ++eid) {
     764           0 :              oss << " " << *e_it;
     765             :         }
     766           0 :         oss << ")";
     767           0 :     }
     768           0 :     return (oss.str());
     769           0 : }
     770             : 
     771           0 : BgpOList::BgpOList(BgpOListDB *olist_db, const BgpOListSpec &olist_spec)
     772           0 :     : olist_db_(olist_db),
     773           0 :       olist_spec_(olist_spec) {
     774           0 :     refcount_ = 0;
     775           0 :     for (BgpOListSpec::Elements::const_iterator it =
     776           0 :          olist_spec_.elements.begin(); it != olist_spec_.elements.end(); ++it) {
     777           0 :         BgpOListElem *elem = new BgpOListElem(*it);
     778           0 :         sort(elem->encap.begin(), elem->encap.end());
     779           0 :         elements_.push_back(elem);
     780             :     }
     781           0 :     sort(elements_.begin(), elements_.end(), BgpOListElemCompare());
     782           0 : }
     783             : 
     784           0 : BgpOList::~BgpOList() {
     785           0 :     STLDeleteValues(&elements_);
     786           0 : }
     787             : 
     788             : struct BgpOListElementCompare {
     789           0 :     int operator()(const BgpOListElem *lhs, const BgpOListElem *rhs) const {
     790           0 :         KEY_COMPARE(*lhs, *rhs);
     791           0 :         return 0;
     792             :     }
     793             : };
     794             : 
     795           0 : int BgpOList::CompareTo(const BgpOList &rhs) const {
     796           0 :     KEY_COMPARE(olist().subcode, rhs.olist().subcode);
     797           0 :     int result = STLSortedCompare(elements().begin(), elements().end(),
     798           0 :                                   rhs.elements().begin(), rhs.elements().end(),
     799             :                                   BgpOListElementCompare());
     800           0 :     return result;
     801             : }
     802             : 
     803           0 : void BgpOList::Remove() {
     804           0 :     olist_db_->Delete(this);
     805           0 : }
     806             : 
     807          20 : BgpOListDB::BgpOListDB(BgpServer *server) {
     808          20 : }
     809             : 
     810           0 : int BgpAttrLabelBlock::CompareTo(const BgpAttribute &rhs_attr) const {
     811           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     812           0 :     if (ret != 0) return ret;
     813           0 :     KEY_COMPARE(label_block.get(),
     814             :             static_cast<const BgpAttrLabelBlock &>(rhs_attr).label_block.get());
     815           0 :     return 0;
     816             : }
     817             : 
     818           0 : void BgpAttrLabelBlock::ToCanonical(BgpAttr *attr) {
     819           0 :     attr->set_label_block(label_block);
     820           0 : }
     821             : 
     822           0 : string BgpAttrLabelBlock::ToString() const {
     823             :     char repr[80];
     824           0 :     snprintf(repr, sizeof(repr), "LabelBlock <subcode: %d> : %d-%d",
     825           0 :              subcode, label_block->first(), label_block->last());
     826           0 :     return string(repr);
     827             : }
     828             : 
     829           0 : int BgpAttrSourceRd::CompareTo(const BgpAttribute &rhs_attr) const {
     830           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     831           0 :     if (ret != 0) return ret;
     832           0 :     KEY_COMPARE(source_rd,
     833             :             static_cast<const BgpAttrSourceRd &>(rhs_attr).source_rd);
     834           0 :     return 0;
     835             : }
     836             : 
     837         768 : void BgpAttrSourceRd::ToCanonical(BgpAttr *attr) {
     838         768 :     attr->set_source_rd(source_rd);
     839         768 : }
     840             : 
     841           0 : string BgpAttrSourceRd::ToString() const {
     842             :     char repr[80];
     843           0 :     snprintf(repr, sizeof(repr), "SourceRd <subcode: %d> : %s",
     844           0 :              subcode, source_rd.ToString().c_str());
     845           0 :     return string(repr);
     846             : }
     847             : 
     848           0 : int BgpAttrEsi::CompareTo(const BgpAttribute &rhs_attr) const {
     849           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     850           0 :     if (ret != 0) return ret;
     851           0 :     KEY_COMPARE(esi, static_cast<const BgpAttrEsi &>(rhs_attr).esi);
     852           0 :     return 0;
     853             : }
     854             : 
     855           0 : void BgpAttrEsi::ToCanonical(BgpAttr *attr) {
     856           0 :     attr->set_esi(esi);
     857           0 : }
     858             : 
     859           0 : string BgpAttrEsi::ToString() const {
     860             :     char repr[80];
     861           0 :     snprintf(repr, sizeof(repr), "Esi <subcode: %d> : %s",
     862           0 :              subcode, esi.ToString().c_str());
     863           0 :     return string(repr);
     864             : }
     865             : 
     866           0 : int BgpAttrParams::CompareTo(const BgpAttribute &rhs_attr) const {
     867           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     868           0 :     if (ret != 0) return ret;
     869           0 :     KEY_COMPARE(params, static_cast<const BgpAttrParams &>(rhs_attr).params);
     870           0 :     return 0;
     871             : }
     872             : 
     873           0 : void BgpAttrParams::ToCanonical(BgpAttr *attr) {
     874           0 :     attr->set_params(params);
     875           0 : }
     876             : 
     877           0 : string BgpAttrParams::ToString() const {
     878             :     char repr[80];
     879           0 :     snprintf(repr, sizeof(repr), "Params <subcode: %d> : 0x%016jx",
     880           0 :              subcode, params);
     881           0 :     return string(repr);
     882             : }
     883             : 
     884           0 : int BgpAttrSubProtocol::CompareTo(const BgpAttribute &rhs_attr) const {
     885           0 :     int ret = BgpAttribute::CompareTo(rhs_attr);
     886           0 :     if (ret != 0) return ret;
     887           0 :     KEY_COMPARE(sbp, static_cast<const BgpAttrSubProtocol &>(rhs_attr).sbp);
     888           0 :     return 0;
     889             : }
     890             : 
     891         640 : void BgpAttrSubProtocol::ToCanonical(BgpAttr *attr) {
     892         640 :     attr->set_sub_protocol(sbp);
     893         640 : }
     894             : 
     895           0 : string BgpAttrSubProtocol::ToString() const {
     896             :     char repr[80];
     897           0 :     snprintf(repr, sizeof(repr), "SubProtocol <subcode: %d> : %s",
     898           0 :              subcode, sbp.c_str());
     899           0 :     return string(repr);
     900             : }
     901             : 
     902           0 : BgpAttr::BgpAttr()
     903           0 :     : attr_db_(NULL), origin_(BgpAttrOrigin::INCOMPLETE), nexthop_(),
     904           0 :       med_(0), local_pref_(0), atomic_aggregate_(false),
     905           0 :       aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
     906           0 :     refcount_ = 0;
     907           0 : }
     908             : 
     909           0 : BgpAttr::BgpAttr(BgpAttrDB *attr_db)
     910           0 :     : attr_db_(attr_db), origin_(BgpAttrOrigin::INCOMPLETE),
     911           0 :       nexthop_(), med_(0), local_pref_(0), atomic_aggregate_(false),
     912           0 :       aggregator_as_num_(0), aggregator_as4_num_(0), params_(0) {
     913           0 :     refcount_ = 0;
     914           0 : }
     915             : 
     916       13981 : BgpAttr::BgpAttr(BgpAttrDB *attr_db, const BgpAttrSpec &spec)
     917       13981 :     : attr_db_(attr_db), origin_(BgpAttrOrigin::INCOMPLETE),
     918       27962 :       nexthop_(), med_(0),
     919       13981 :       local_pref_(BgpAttrLocalPref::kDefault),
     920       13981 :       atomic_aggregate_(false),
     921       13981 :       aggregator_as_num_(0), aggregator_as4_num_(0), 
     922       13981 :       aggregator_address_(), params_(0) {
     923       13981 :     refcount_ = 0;
     924       13982 :     for (vector<BgpAttribute *>::const_iterator it = spec.begin();
     925       60336 :          it < spec.end(); it++) {
     926       46352 :         (*it)->ToCanonical(this);
     927             :     }
     928       13982 : }
     929             : 
     930      141301 : BgpAttr::BgpAttr(const BgpAttr &rhs)
     931      141301 :     : attr_db_(rhs.attr_db_), origin_(rhs.origin_), nexthop_(rhs.nexthop_),
     932      141201 :       med_(rhs.med_), local_pref_(rhs.local_pref_),
     933      141201 :       atomic_aggregate_(rhs.atomic_aggregate_),
     934      141201 :       aggregator_as_num_(rhs.aggregator_as_num_),
     935      141201 :       aggregator_as4_num_(rhs.aggregator_as4_num_),
     936      141201 :       aggregator_address_(rhs.aggregator_address_),
     937      141166 :       originator_id_(rhs.originator_id_),
     938      141157 :       source_rd_(rhs.source_rd_), esi_(rhs.esi_), params_(rhs.params_),
     939      141136 :       as_path_(rhs.as_path_),
     940      141250 :       aspath_4byte_(rhs.aspath_4byte_),
     941      141236 :       as4_path_(rhs.as4_path_),
     942      141201 :       cluster_list_(rhs.cluster_list_),
     943      141177 :       community_(rhs.community_),
     944      141163 :       ext_community_(rhs.ext_community_),
     945      141387 :       large_community_(rhs.large_community_),
     946      141293 :       deferred_large_spec_(nullptr),
     947      141176 :       origin_vn_path_(rhs.origin_vn_path_),
     948      141148 :       pmsi_tunnel_(rhs.pmsi_tunnel_),
     949      141127 :       edge_discovery_(rhs.edge_discovery_),
     950      141100 :       edge_forwarding_(rhs.edge_forwarding_),
     951      141084 :       label_block_(rhs.label_block_),
     952      141072 :       olist_(rhs.olist_),
     953      141058 :       leaf_olist_(rhs.leaf_olist_),
     954      282338 :       sub_protocol_(rhs.sub_protocol_) {
     955      140965 :     refcount_ = 0;
     956      141397 : }
     957             : 
     958           0 : void BgpAttr::set_as_path(AsPathPtr aspath) {
     959           0 :     as_path_ = aspath;
     960           0 : }
     961             : 
     962       19250 : void BgpAttr::set_as_path(const AsPathSpec *spec) {
     963       19250 :     if (spec) {
     964       19250 :         as_path_ = attr_db_->server()->aspath_db()->Locate(*spec);
     965             :     } else {
     966           0 :         as_path_ = NULL;
     967             :     }
     968       19262 : }
     969             : 
     970           0 : void BgpAttr::set_as4_path(As4PathPtr aspath) {
     971           0 :     as4_path_ = aspath;
     972           0 : }
     973             : 
     974           0 : void BgpAttr::set_as4_path(const As4PathSpec *spec) {
     975           0 :     if (spec) {
     976           0 :         as4_path_ = attr_db_->server()->as4path_db()->Locate(*spec);
     977             :     } else {
     978           0 :         as4_path_ = NULL;
     979             :     }
     980           0 : }
     981             : 
     982           0 : void BgpAttr::set_aspath_4byte(AsPath4BytePtr aspath) {
     983           0 :     aspath_4byte_ = aspath;
     984           0 : }
     985             : 
     986           0 : void BgpAttr::set_aspath_4byte(const AsPath4ByteSpec *spec) {
     987           0 :     if (spec) {
     988           0 :         aspath_4byte_ = attr_db_->server()->aspath_4byte_db()->Locate(*spec);
     989             :     } else {
     990           0 :         aspath_4byte_ = NULL;
     991             :     }
     992           0 : }
     993             : 
     994       12428 : void BgpAttr::set_cluster_list(const ClusterListSpec *spec) {
     995       12428 :     if (spec) {
     996           0 :         cluster_list_ = attr_db_->server()->cluster_list_db()->Locate(*spec);
     997             :     } else {
     998       12428 :         cluster_list_ = NULL;
     999             :     }
    1000       12428 : }
    1001             : 
    1002           0 : void BgpAttr::set_community(CommunityPtr comm) {
    1003           0 :     community_ = comm;
    1004           0 : }
    1005             : 
    1006           0 : void BgpAttr::set_community(const CommunitySpec *comm) {
    1007           0 :     if (comm) {
    1008           0 :         community_ = attr_db_->server()->comm_db()->Locate(*comm);
    1009             :     } else {
    1010           0 :         community_ = NULL;
    1011             :     }
    1012           0 : }
    1013             : 
    1014       42123 : void BgpAttr::set_ext_community(ExtCommunityPtr extcomm) {
    1015       42123 :     ext_community_ = extcomm;
    1016       42121 : }
    1017             : 
    1018        8340 : void BgpAttr::set_ext_community(const ExtCommunitySpec *extcomm) {
    1019        8340 :     if (extcomm) {
    1020        8340 :         LargeCommunitySpec large_spec = LargeCommunitySpec::FromTag(*extcomm);
    1021        8340 :         set_large_community(&large_spec);
    1022             :         
    1023        8339 :         if (large_spec.communities.size()) {
    1024             :             ExtCommunitySpec new_comms =
    1025           0 :                 LargeCommunitySpec::RemoveTags(*extcomm);
    1026             :             ext_community_ =
    1027           0 :                 attr_db_->server()->extcomm_db()->Locate(new_comms);
    1028           0 :             return;
    1029           0 :         }
    1030        8339 :         ext_community_ = attr_db_->server()->extcomm_db()->Locate(*extcomm);
    1031        8340 :     } else {
    1032           0 :         ext_community_ = NULL;
    1033             :     }
    1034             : }
    1035             : 
    1036           0 : void BgpAttr::set_large_community(LargeCommunityPtr largecomm) {
    1037           0 :     large_community_ = largecomm;
    1038           0 : }
    1039             : 
    1040        8340 : void BgpAttr::set_large_community(const LargeCommunitySpec *largecomm) {
    1041        8340 :     if (largecomm) {
    1042        8340 :         if (!bool(deferred_large_spec_)) {
    1043        8340 :             deferred_large_spec_.reset(new LargeCommunitySpec);
    1044        8340 :             deferred_large_spec_->communities = largecomm->communities;
    1045             :         } else {
    1046           0 :             deferred_large_spec_->communities.insert(
    1047           0 :                 deferred_large_spec_->communities.end(),
    1048             :                 largecomm->communities.begin(),
    1049             :                 largecomm->communities.end());
    1050             :         }
    1051             :         large_community_ =
    1052        8340 :             attr_db_->server()->largecomm_db()->Locate(*deferred_large_spec_);
    1053             :     } else {
    1054           0 :         large_community_ = NULL;
    1055             :     }
    1056        8339 : }
    1057             : 
    1058           0 : void BgpAttr::set_origin_vn_path(OriginVnPathPtr ovnpath) {
    1059           0 :     origin_vn_path_ = ovnpath;
    1060           0 : }
    1061             : 
    1062           0 : void BgpAttr::set_origin_vn_path(const OriginVnPathSpec *spec) {
    1063           0 :     if (spec) {
    1064           0 :         origin_vn_path_ = attr_db_->server()->ovnpath_db()->Locate(*spec);
    1065             :     } else {
    1066           0 :         origin_vn_path_ = NULL;
    1067             :     }
    1068           0 : }
    1069             : 
    1070           0 : void BgpAttr::set_pmsi_tunnel(const PmsiTunnelSpec *pmsi_spec) {
    1071           0 :     if (pmsi_spec) {
    1072           0 :         pmsi_tunnel_ = attr_db_->server()->pmsi_tunnel_db()->Locate(*pmsi_spec);
    1073             :     } else {
    1074           0 :         pmsi_tunnel_ = NULL;
    1075             :     }
    1076           0 : }
    1077             : 
    1078           0 : void BgpAttr::set_edge_discovery(const EdgeDiscoverySpec *edspec) {
    1079           0 :     if (edspec) {
    1080             :         edge_discovery_ =
    1081           0 :             attr_db_->server()->edge_discovery_db()->Locate(*edspec);
    1082             :     } else {
    1083           0 :         edge_discovery_ = NULL;
    1084             :     }
    1085           0 : }
    1086             : 
    1087           0 : void BgpAttr::set_edge_forwarding(const EdgeForwardingSpec *efspec) {
    1088           0 :     if (efspec) {
    1089             :         edge_forwarding_ =
    1090           0 :             attr_db_->server()->edge_forwarding_db()->Locate(*efspec);
    1091             :     } else {
    1092           0 :         edge_forwarding_ = NULL;
    1093             :     }
    1094           0 : }
    1095             : 
    1096           0 : void BgpAttr::set_label_block(LabelBlockPtr label_block) {
    1097           0 :     label_block_ = label_block;
    1098           0 : }
    1099             : 
    1100           0 : void BgpAttr::set_olist(const BgpOListSpec *olist_spec) {
    1101           0 :     if (olist_spec) {
    1102           0 :         olist_ = attr_db_->server()->olist_db()->Locate(*olist_spec);
    1103             :     } else {
    1104           0 :         olist_ = NULL;
    1105             :     }
    1106           0 : }
    1107             : 
    1108           0 : void BgpAttr::set_leaf_olist(const BgpOListSpec *leaf_olist_spec) {
    1109           0 :     if (leaf_olist_spec) {
    1110           0 :         leaf_olist_ = attr_db_->server()->olist_db()->Locate(*leaf_olist_spec);
    1111             :     } else {
    1112           0 :         leaf_olist_ = NULL;
    1113             :     }
    1114           0 : }
    1115             : 
    1116       59364 : int BgpAttr::max_as_path_count() const {
    1117       59364 :     int as_count = as_path_count();
    1118       59361 :     int as4_count = aspath_4byte_count();
    1119       59361 :     return as_count > as4_count ? as_count : as4_count;
    1120             : }
    1121             : 
    1122        5431 : bool BgpAttr::IsAsPathEmpty() const {
    1123        5431 :     if (as_path_ && !as_path_->empty())
    1124           0 :         return false;
    1125        5431 :     if (aspath_4byte_ && !aspath_4byte_->empty())
    1126           0 :         return false;
    1127        5431 :     return true;
    1128             : }
    1129             : 
    1130           0 : string BgpAttr::OriginToString(BgpAttrOrigin::OriginType origin) {
    1131           0 :     switch (origin) {
    1132           0 :     case BgpAttrOrigin::IGP:
    1133           0 :         return "igp";
    1134             :         break;
    1135           0 :     case BgpAttrOrigin::EGP:
    1136           0 :         return "egp";
    1137             :         break;
    1138           0 :     case BgpAttrOrigin::INCOMPLETE:
    1139           0 :         return "incomplete";
    1140             :         break;
    1141             :     }
    1142           0 :     return "unknown";
    1143             : }
    1144             : 
    1145          64 : BgpAttrOrigin::OriginType BgpAttr::OriginFromString(
    1146             :         const string &bgp_origin_type) {
    1147          64 :     if(bgp_origin_type ==  "IGP"){
    1148          64 :         return BgpAttrOrigin::IGP;
    1149           0 :     } else if( bgp_origin_type ==  "EGP") {
    1150           0 :         return BgpAttrOrigin::EGP;
    1151             :     }
    1152           0 :     return BgpAttrOrigin::INCOMPLETE;
    1153             : }
    1154             : 
    1155           0 : string BgpAttr::origin_string() const {
    1156           0 :     return OriginToString(origin());
    1157             : }
    1158             : 
    1159           0 : Address::Family BgpAttr::nexthop_family() const {
    1160           0 :     if (nexthop_.is_v6()) {
    1161           0 :         return Address::INET6;
    1162             :     } else {
    1163           0 :         return Address::INET;
    1164             :     }
    1165             : }
    1166             : 
    1167       33554 : as_t BgpAttr::neighbor_as() const {
    1168       33554 :     if (as_path_.get())
    1169       28064 :         return as_path_->neighbor_as();
    1170        5489 :     if (aspath_4byte_.get())
    1171           0 :         return aspath_4byte_->neighbor_as();
    1172        5489 :     return 0;
    1173             : }
    1174             : 
    1175       59343 : uint32_t BgpAttr::sequence_number() const {
    1176       59343 :     if (!ext_community_)
    1177        8640 :         return 0;
    1178       50714 :     for (ExtCommunity::ExtCommunityList::const_iterator it =
    1179       50708 :          ext_community_->communities().begin();
    1180      331779 :          it != ext_community_->communities().end(); ++it) {
    1181      281066 :         if (ExtCommunity::is_mac_mobility(*it)) {
    1182           0 :             MacMobility mm(*it);
    1183           0 :             return mm.sequence_number();
    1184             :         }
    1185             :     }
    1186       50687 :     return 0;
    1187             : }
    1188             : 
    1189       29687 : bool BgpAttr::evpn_sticky_mac() const {
    1190       29687 :     if (!ext_community_)
    1191        4320 :         return 0;
    1192       25362 :     for (ExtCommunity::ExtCommunityList::const_iterator it =
    1193       25369 :          ext_community_->communities().begin();
    1194      166147 :          it != ext_community_->communities().end(); ++it) {
    1195      140785 :         if (ExtCommunity::is_mac_mobility(*it)) {
    1196           0 :             MacMobility mm(*it);
    1197           0 :             return mm.sticky();
    1198             :         }
    1199             :     }
    1200       25362 :     return 0;
    1201             : }
    1202             : 
    1203       29691 : bool BgpAttr::etree_leaf() const {
    1204       29691 :     if (!ext_community_)
    1205        4320 :         return 0;
    1206       25371 :     for (ExtCommunity::ExtCommunityList::const_iterator it =
    1207       25371 :          ext_community_->communities().begin();
    1208      157124 :          it != ext_community_->communities().end(); ++it) {
    1209      136298 :         if (ExtCommunity::is_etree(*it)) {
    1210        4544 :             ETree etree(*it);
    1211        4544 :             return etree.leaf();
    1212             :         }
    1213             :     }
    1214       20819 :     return 0;
    1215             : }
    1216             : 
    1217           0 : bool BgpAttr::evpn_single_active() const {
    1218           0 :     if (!ext_community_)
    1219           0 :         return false;
    1220           0 :     for (ExtCommunity::ExtCommunityList::const_iterator it =
    1221           0 :          ext_community_->communities().begin();
    1222           0 :          it != ext_community_->communities().end(); ++it) {
    1223           0 :         if (ExtCommunity::is_esi_label(*it)) {
    1224           0 :             EsiLabel esi_label(*it);
    1225           0 :             return esi_label.single_active();
    1226             :         }
    1227             :     }
    1228           0 :     return true;
    1229             : }
    1230             : 
    1231       28662 : MacAddress BgpAttr::mac_address() const {
    1232       28662 :     if (!ext_community_)
    1233         192 :         return MacAddress::kZeroMac;
    1234       28451 :     for (ExtCommunity::ExtCommunityList::const_iterator it =
    1235       28466 :          ext_community_->communities().begin();
    1236      181255 :          it != ext_community_->communities().end(); ++it) {
    1237      152807 :         if (ExtCommunity::is_router_mac(*it)) {
    1238           0 :             RouterMac router_mac(*it);
    1239           0 :             return router_mac.mac_address();
    1240             :         }
    1241             :     }
    1242       28441 :     return MacAddress::kZeroMac;
    1243             : }
    1244             : 
    1245       11799 : void BgpAttr::Remove() {
    1246       11799 :     attr_db_->Delete(this);
    1247       11799 : }
    1248             : 
    1249       28911 : int BgpAttr::IsAsPathLoop(as_t asn, uint8_t max_loop_count) const {
    1250       28911 :     if (as_path() && as_path()->path().AsPathLoop(asn, max_loop_count)) {
    1251        9648 :         return true;
    1252             :     }
    1253       19266 :     if (aspath_4byte() &&
    1254           0 :            aspath_4byte()->path().AsPathLoop(asn, max_loop_count)) {
    1255           0 :         return true;
    1256             :     }
    1257       19266 :     if (asn > AS2_MAX && as4_path() &&
    1258           0 :            as4_path()->path().AsPathLoop(asn, max_loop_count)) {
    1259           0 :         return true;
    1260             :     }
    1261       19266 :     return false;
    1262             : }
    1263             : 
    1264     1165931 : int BgpAttr::CompareTo(const BgpAttr &rhs) const {
    1265     1165931 :     KEY_COMPARE(origin_, rhs.origin_);
    1266     1056514 :     KEY_COMPARE(nexthop_, rhs.nexthop_);
    1267      608877 :     KEY_COMPARE(med_, rhs.med_);
    1268      608877 :     KEY_COMPARE(local_pref_, rhs.local_pref_);
    1269      587140 :     KEY_COMPARE(atomic_aggregate_, rhs.atomic_aggregate_);
    1270      587140 :     KEY_COMPARE(aggregator_as_num_, rhs.aggregator_as_num_);
    1271      587140 :     KEY_COMPARE(aggregator_as4_num_, rhs.aggregator_as4_num_);
    1272      587140 :     KEY_COMPARE(aggregator_address_, rhs.aggregator_address_);
    1273      587547 :     KEY_COMPARE(originator_id_, rhs.originator_id_);
    1274      587401 :     KEY_COMPARE(pmsi_tunnel_.get(), rhs.pmsi_tunnel_.get());
    1275      587285 :     KEY_COMPARE(edge_discovery_.get(), rhs.edge_discovery_.get());
    1276      587224 :     KEY_COMPARE(edge_forwarding_.get(), rhs.edge_forwarding_.get());
    1277      587227 :     KEY_COMPARE(esi_, rhs.esi_);
    1278      587299 :     KEY_COMPARE(params_, rhs.params_);
    1279      587299 :     KEY_COMPARE(source_rd_, rhs.source_rd_);
    1280      339297 :     KEY_COMPARE(label_block_.get(), rhs.label_block_.get());
    1281      339712 :     KEY_COMPARE(olist_.get(), rhs.olist_.get());
    1282      339665 :     KEY_COMPARE(leaf_olist_.get(), rhs.leaf_olist_.get());
    1283      339650 :     KEY_COMPARE(as_path_.get(), rhs.as_path_.get());
    1284      339644 :     KEY_COMPARE(aspath_4byte_.get(), rhs.aspath_4byte_.get());
    1285      339658 :     KEY_COMPARE(as4_path_.get(), rhs.as4_path_.get());
    1286      339645 :     KEY_COMPARE(cluster_list_.get(), rhs.cluster_list_.get());
    1287      339653 :     KEY_COMPARE(community_.get(), rhs.community_.get());
    1288      339632 :     KEY_COMPARE(ext_community_.get(), rhs.ext_community_.get());
    1289      310262 :     KEY_COMPARE(large_community_.get(), rhs.large_community_.get());
    1290      310250 :     KEY_COMPARE(origin_vn_path_.get(), rhs.origin_vn_path_.get());
    1291      310243 :     KEY_COMPARE(sub_protocol_, rhs.sub_protocol_);
    1292      310245 :     return 0;
    1293             : }
    1294             : 
    1295           0 : std::size_t hash_value(BgpAttr const &attr) {
    1296           0 :     size_t hash = 0;
    1297             : 
    1298           0 :     boost::hash_combine(hash, attr.origin_);
    1299           0 :     boost::hash_combine(hash, attr.nexthop_.to_string());
    1300           0 :     boost::hash_combine(hash, attr.med_);
    1301           0 :     boost::hash_combine(hash, attr.local_pref_);
    1302           0 :     boost::hash_combine(hash, attr.atomic_aggregate_);
    1303           0 :     boost::hash_combine(hash, attr.aggregator_as_num_);
    1304           0 :     boost::hash_combine(hash, attr.aggregator_as4_num_);
    1305           0 :     boost::hash_combine(hash, attr.aggregator_address_.to_string());
    1306           0 :     boost::hash_combine(hash, attr.originator_id_.to_string());
    1307           0 :     boost::hash_combine(hash, attr.params_);
    1308           0 :     boost::hash_combine(hash, attr.source_rd_.ToString());
    1309           0 :     boost::hash_combine(hash, attr.esi_.ToString());
    1310             : 
    1311           0 :     if (attr.label_block_) {
    1312           0 :         boost::hash_combine(hash, attr.label_block_->first());
    1313           0 :         boost::hash_combine(hash, attr.label_block_->last());
    1314             :     }
    1315             : 
    1316           0 :     if (attr.olist_) {
    1317           0 :         boost::hash_range(hash, attr.olist_->elements().begin(),
    1318           0 :                           attr.olist_->elements().end());
    1319             :     }
    1320           0 :     if (attr.leaf_olist_) {
    1321           0 :         boost::hash_range(hash, attr.leaf_olist_->elements().begin(),
    1322           0 :                           attr.leaf_olist_->elements().end());
    1323             :     }
    1324             : 
    1325           0 :     if (attr.as_path_) boost::hash_combine(hash, *attr.as_path_);
    1326           0 :     if (attr.aspath_4byte_) boost::hash_combine(hash, *attr.aspath_4byte_);
    1327           0 :     if (attr.as4_path_) boost::hash_combine(hash, *attr.as4_path_);
    1328           0 :     if (attr.community_) boost::hash_combine(hash, *attr.community_);
    1329           0 :     if (attr.ext_community_) boost::hash_combine(hash, *attr.ext_community_);
    1330           0 :     if (attr.large_community_) boost::hash_combine(hash, *attr.large_community_);
    1331           0 :     if (attr.origin_vn_path_) boost::hash_combine(hash, *attr.origin_vn_path_);
    1332           0 :     if (!attr.sub_protocol_.empty()) {
    1333           0 :         boost::hash_combine(hash, attr.sub_protocol_);
    1334             :     }
    1335             : 
    1336           0 :     return hash;
    1337             : }
    1338             : 
    1339          20 : BgpAttrDB::BgpAttrDB(BgpServer *server) : server_(server) {
    1340          20 : }
    1341             : 
    1342             : // Return a clone of attribute with updated aspath.
    1343           0 : BgpAttrPtr BgpAttrDB::ReplaceAsPathAndLocate(const BgpAttr *attr,
    1344             :                                              AsPathPtr aspath) {
    1345           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1346           0 :     clone->set_as_path(aspath);
    1347           0 :     return Locate(clone);
    1348             : }
    1349             : 
    1350             : // Return a clone of attribute with updated community.
    1351           0 : BgpAttrPtr BgpAttrDB::ReplaceCommunityAndLocate(const BgpAttr *attr,
    1352             :                                                 CommunityPtr community) {
    1353           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1354           0 :     clone->set_community(community);
    1355           0 :     return Locate(clone);
    1356             : }
    1357             : 
    1358             : //Return a clone of attribute with updated origin
    1359           0 : BgpAttrPtr BgpAttrDB::ReplaceOriginAndLocate(const BgpAttr *attr,
    1360             :                                              BgpAttrOrigin::OriginType origin) {
    1361           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1362           0 :     clone->set_origin(origin);
    1363           0 :     return Locate(clone);
    1364             : }
    1365             : 
    1366             : // Return a clone of attribute with updated extended community.
    1367       42125 : BgpAttrPtr BgpAttrDB::ReplaceExtCommunityAndLocate(const BgpAttr *attr,
    1368             :                                                    ExtCommunityPtr extcomm) {
    1369       42125 :     BgpAttr *clone = new BgpAttr(*attr);
    1370       42137 :     clone->set_ext_community(extcomm);
    1371       42126 :     return Locate(clone);
    1372             : }
    1373             : 
    1374             : // Return a clone of attribute with updated large community.
    1375           0 : BgpAttrPtr BgpAttrDB::ReplaceLargeCommunityAndLocate(
    1376             :     const BgpAttr *attr, LargeCommunityPtr largecomm) {
    1377           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1378           0 :     clone->set_large_community(largecomm);
    1379           0 :     return Locate(clone);
    1380             : }
    1381             : 
    1382             : // Return a clone of attribute with updated origin vn path.
    1383           0 : BgpAttrPtr BgpAttrDB::ReplaceOriginVnPathAndLocate(const BgpAttr *attr,
    1384             :                                                    OriginVnPathPtr ovnpath) {
    1385           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1386           0 :     clone->set_origin_vn_path(ovnpath);
    1387           0 :     return Locate(clone);
    1388             : }
    1389             : 
    1390             : // Return a clone of attribute with updated local preference.
    1391           0 : BgpAttrPtr BgpAttrDB::ReplaceLocalPreferenceAndLocate(const BgpAttr *attr,
    1392             :                                                       uint32_t local_pref) {
    1393           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1394           0 :     clone->set_local_pref(local_pref);
    1395           0 :     return Locate(clone);
    1396             : }
    1397             : 
    1398             : // Return a clone of attribute with updated originator id.
    1399           0 : BgpAttrPtr BgpAttrDB::ReplaceOriginatorIdAndLocate(const BgpAttr *attr,
    1400             :                                                    Ip4Address originator_id) {
    1401           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1402           0 :     clone->set_originator_id(originator_id);
    1403           0 :     return Locate(clone);
    1404             : }
    1405             : 
    1406             : // Return a clone of attribute with updated source rd.
    1407       39446 : BgpAttrPtr BgpAttrDB::ReplaceSourceRdAndLocate(const BgpAttr *attr,
    1408             :     const RouteDistinguisher &source_rd) {
    1409       39446 :     BgpAttr *clone = new BgpAttr(*attr);
    1410       39452 :     clone->set_source_rd(source_rd);
    1411       39444 :     return Locate(clone);
    1412             : }
    1413             : 
    1414             : // Return a clone of attribute with updated esi.
    1415        1408 : BgpAttrPtr BgpAttrDB::ReplaceEsiAndLocate(const BgpAttr *attr,
    1416             :                                           const EthernetSegmentId &esi) {
    1417        1408 :     BgpAttr *clone = new BgpAttr(*attr);
    1418        1408 :     clone->set_esi(esi);
    1419        1408 :     return Locate(clone);
    1420             : }
    1421             : 
    1422             : // Return a clone of attribute with updated olist.
    1423           0 : BgpAttrPtr BgpAttrDB::ReplaceOListAndLocate(const BgpAttr *attr,
    1424             :     const BgpOListSpec *olist_spec) {
    1425           0 :     assert(olist_spec->subcode == BgpAttribute::OList);
    1426           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1427           0 :     clone->set_olist(olist_spec);
    1428           0 :     return Locate(clone);
    1429             : }
    1430             : 
    1431             : // Return a clone of attribute with updated leaf olist.
    1432           0 : BgpAttrPtr BgpAttrDB::ReplaceLeafOListAndLocate(const BgpAttr *attr,
    1433             :     const BgpOListSpec *leaf_olist_spec) {
    1434           0 :     assert(leaf_olist_spec->subcode == BgpAttribute::LeafOList);
    1435           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1436           0 :     clone->set_leaf_olist(leaf_olist_spec);
    1437           0 :     return Locate(clone);
    1438             : }
    1439             : 
    1440             : // Return a clone of attribute with updated sub-protocol.
    1441           0 : BgpAttrPtr BgpAttrDB::ReplaceSubProtocolAndLocate(const BgpAttr *attr,
    1442             :     const string &sbp) {
    1443           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1444           0 :     clone->set_sub_protocol(sbp);
    1445           0 :     return Locate(clone);
    1446             : }
    1447             : 
    1448             : 
    1449             : // Return a clone of attribute with updated pmsi tunnel.
    1450           0 : BgpAttrPtr BgpAttrDB::ReplacePmsiTunnelAndLocate(const BgpAttr *attr,
    1451             :     const PmsiTunnelSpec *pmsi_spec) {
    1452           0 :     BgpAttr *clone = new BgpAttr(*attr);
    1453           0 :     clone->set_pmsi_tunnel(pmsi_spec);
    1454           0 :     return Locate(clone);
    1455             : }
    1456             : 
    1457             : // Return a clone of attribute with updated nexthop.
    1458        6838 : BgpAttrPtr BgpAttrDB::ReplaceNexthopAndLocate(const BgpAttr *attr,
    1459             :     const IpAddress &addr) {
    1460        6838 :     BgpAttr *clone = new BgpAttr(*attr);
    1461        6838 :     clone->set_nexthop(addr);
    1462        6838 :     return Locate(clone);
    1463             : }

Generated by: LCOV version 1.14