Skip to content

Commit

Permalink
Use 24-bit label when encoding/decoding VNI in PmsiTunnel
Browse files Browse the repository at this point in the history
Change-Id: I3f2abe0922ea69742a325765a5df95899149798f
Closes-Bug: 1464781
  • Loading branch information
Nischal Sheth committed Jun 22, 2015
1 parent 3bd5523 commit 4e0792c
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/bgp/bgp_attr.cc
Expand Up @@ -212,12 +212,12 @@ std::string PmsiTunnelSpec::ToString() const {
return oss.str();
}

uint32_t PmsiTunnelSpec::GetLabel() const {
return label >> 4;
uint32_t PmsiTunnelSpec::GetLabel(bool is_vni) const {
return (is_vni ? label : (label >> 4));
}

void PmsiTunnelSpec::SetLabel(uint32_t in_label) {
label = in_label << 4 | 0x01;
void PmsiTunnelSpec::SetLabel(uint32_t in_label, bool is_vni) {
label = (is_vni ? in_label : (in_label << 4 | 0x01));
}

Ip4Address PmsiTunnelSpec::GetIdentifier() const {
Expand Down Expand Up @@ -293,7 +293,7 @@ PmsiTunnel::PmsiTunnel(PmsiTunnelDB *pmsi_tunnel_db,
refcount_ = 0;
tunnel_flags = pmsi_spec_.tunnel_flags;
tunnel_type = pmsi_spec_.tunnel_type;
label = pmsi_spec_.GetLabel();
label = pmsi_spec_.label;
identifier = pmsi_spec_.GetIdentifier();
}

Expand Down
9 changes: 6 additions & 3 deletions src/bgp/bgp_attr.h
Expand Up @@ -212,8 +212,8 @@ struct PmsiTunnelSpec : public BgpAttribute {
virtual void ToCanonical(BgpAttr *attr);
virtual std::string ToString() const;

uint32_t GetLabel() const;
void SetLabel(uint32_t label);
uint32_t GetLabel(bool is_vni = false) const;
void SetLabel(uint32_t label, bool is_vni = false);
Ip4Address GetIdentifier() const;
void SetIdentifier(Ip4Address identifier);

Expand All @@ -237,6 +237,9 @@ class PmsiTunnel {
}

const PmsiTunnelSpec &pmsi_tunnel() const { return pmsi_spec_; }
uint32_t GetLabel(bool is_vni = false) const {
return (is_vni ? label : label >> 4);
}

friend std::size_t hash_value(const PmsiTunnel &pmsi_tunnel) {
size_t hash = 0;
Expand All @@ -246,14 +249,14 @@ class PmsiTunnel {

uint8_t tunnel_flags;
uint8_t tunnel_type;
uint32_t label;
Ip4Address identifier;

private:
friend int intrusive_ptr_add_ref(const PmsiTunnel *cpmsi_tunnel);
friend int intrusive_ptr_del_ref(const PmsiTunnel *cpmsi_tunnel);
friend void intrusive_ptr_release(const PmsiTunnel *cpmsi_tunnel);

uint32_t label;
mutable tbb::atomic<int> refcount_;
PmsiTunnelDB *pmsi_tunnel_db_;
PmsiTunnelSpec pmsi_spec_;
Expand Down
8 changes: 5 additions & 3 deletions src/bgp/bgp_route.cc
Expand Up @@ -338,13 +338,13 @@ static void FillOriginVnPathInfo(const OriginVnPath *ovnpath,
}
}

static void FillPmsiTunnelInfo(const PmsiTunnel *pmsi_tunnel,
static void FillPmsiTunnelInfo(const PmsiTunnel *pmsi_tunnel, bool label_is_vni,
ShowRoutePath *show_path) {
ShowPmsiTunnel spt;
spt.set_type(pmsi_tunnel->pmsi_tunnel().GetTunnelTypeString());
spt.set_ar_type(pmsi_tunnel->pmsi_tunnel().GetTunnelArTypeString());
spt.set_identifier(pmsi_tunnel->identifier.to_string());
spt.set_label(pmsi_tunnel->label);
spt.set_label(pmsi_tunnel->GetLabel(label_is_vni));
spt.set_flags(pmsi_tunnel->pmsi_tunnel().GetTunnelFlagsStrings());
show_path->set_pmsi_tunnel(spt);
}
Expand Down Expand Up @@ -410,7 +410,9 @@ void BgpRoute::FillRouteInfo(const BgpTable *table,
FillOriginVnPathInfo(attr->origin_vn_path(), &srp);
}
if (attr->pmsi_tunnel()) {
FillPmsiTunnelInfo(attr->pmsi_tunnel(), &srp);
const ExtCommunity *extcomm = attr->ext_community();
bool label_is_vni = extcomm && extcomm->ContainsTunnelEncapVxlan();
FillPmsiTunnelInfo(attr->pmsi_tunnel(), label_is_vni, &srp);
}
show_route_paths.push_back(srp);
}
Expand Down
5 changes: 4 additions & 1 deletion src/bgp/bgp_xmpp_channel.cc
Expand Up @@ -1617,6 +1617,7 @@ bool BgpXmppChannel::ProcessEnetItem(string vrf_name,
IpAddress nh_address(Ip4Address(0));
uint32_t label = 0;
uint32_t flags = 0;
bool label_is_vni = false;

if (add_change) {
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
Expand Down Expand Up @@ -1659,6 +1660,8 @@ bool BgpXmppChannel::ProcessEnetItem(string vrf_name,
TunnelEncap tun_encap(*it);
if (tun_encap.tunnel_encap() == TunnelEncapType::UNSPEC)
continue;
if (tun_encap.tunnel_encap() == TunnelEncapType::VXLAN)
label_is_vni = true;
no_valid_tunnel_encap = false;
if (i == 0) {
ext.communities.push_back(
Expand Down Expand Up @@ -1755,7 +1758,7 @@ bool BgpXmppChannel::ProcessEnetItem(string vrf_name,
}
pmsi_spec.SetIdentifier(nh_address.to_v4());
}
pmsi_spec.SetLabel(label);
pmsi_spec.SetLabel(label, label_is_vni);
attrs.push_back(&pmsi_spec);
}

Expand Down
15 changes: 12 additions & 3 deletions src/bgp/evpn/evpn_route.cc
Expand Up @@ -15,10 +15,10 @@ using std::vector;

const EvpnPrefix EvpnPrefix::kNullPrefix;

const uint32_t EvpnPrefix::kInvalidLabel = 0x100000;
const uint32_t EvpnPrefix::kInvalidLabel = 0x00100000;
const uint32_t EvpnPrefix::kNullTag = 0;
const uint32_t EvpnPrefix::kMaxTag = 0xFFFFFFFF;
const uint32_t EvpnPrefix::kMaxVni = 0xFFFFFF;
const uint32_t EvpnPrefix::kMaxVni = 0x00FFFFFF;

const size_t EvpnPrefix::kRdSize = RouteDistinguisher::kSize;
const size_t EvpnPrefix::kEsiSize = EthernetSegmentId::kSize;
Expand Down Expand Up @@ -213,7 +213,16 @@ int EvpnPrefix::FromProtoPrefix(BgpServer *server,
(pmsi_tunnel->tunnel_type == PmsiTunnelSpec::IngressReplication ||
pmsi_tunnel->tunnel_type ==
PmsiTunnelSpec::AssistedReplicationContrail)) {
*label = pmsi_tunnel->label;
const ExtCommunity *extcomm = attr ? attr->ext_community() : NULL;
if (extcomm && extcomm->ContainsTunnelEncapVxlan()) {
if (prefix->tag_ && prefix->tag_ <= kMaxVni) {
*label = prefix->tag_;
} else {
*label = pmsi_tunnel->GetLabel(true);
}
} else {
*label = pmsi_tunnel->GetLabel(false);
}
}
break;
}
Expand Down

0 comments on commit 4e0792c

Please sign in to comment.