Skip to content

Commit

Permalink
Add support for parsing L3 label in EVPN Type 2 routes
Browse files Browse the repository at this point in the history
Change-Id: Iefe4aa83235b83c2e8e3b0746b43a26157797b2f
Partial-Bug: 1636654
  • Loading branch information
Nischal Sheth committed Mar 10, 2017
1 parent 9c8347e commit aaa8759
Show file tree
Hide file tree
Showing 21 changed files with 998 additions and 251 deletions.
3 changes: 2 additions & 1 deletion src/bgp/bgp_peer.cc
Expand Up @@ -1586,9 +1586,10 @@ void BgpPeer::ProcessNlri(Address::Family family, DBRequest::DBOperation oper,
PrefixT prefix;
BgpAttrPtr new_attr(attr);
uint32_t label = 0;
uint32_t l3_label = 0;
int result = PrefixT::FromProtoPrefix(server_, **it,
(oper == DBRequest::DB_ENTRY_ADD_CHANGE ? attr.get() : NULL),
&prefix, &new_attr, &label);
&prefix, &new_attr, &label, &l3_label);
if (result) {
BGP_LOG_PEER_WARNING(Message, this,
BGP_LOG_FLAG_ALL, BGP_PEER_DIR_IN,
Expand Down
3 changes: 2 additions & 1 deletion src/bgp/bgp_route.h
Expand Up @@ -62,7 +62,8 @@ class BgpRoute : public Route {

virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
const BgpAttr *attr = NULL,
uint32_t label = 0) const {
uint32_t label = 0,
uint32_t l3_label = 0) const {
}
virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
IpAddress nexthop) const {
Expand Down
5 changes: 3 additions & 2 deletions src/bgp/ermvpn/ermvpn_route.cc
Expand Up @@ -84,7 +84,8 @@ int ErmVpnPrefix::FromProtoPrefix(const BgpProtoPrefix &proto_prefix,
int ErmVpnPrefix::FromProtoPrefix(BgpServer *server,
const BgpProtoPrefix &proto_prefix,
const BgpAttr *attr, ErmVpnPrefix *prefix,
BgpAttrPtr *new_attr, uint32_t *label) {
BgpAttrPtr *new_attr, uint32_t *label,
uint32_t *l3_label) {
return FromProtoPrefix(proto_prefix, prefix);
}

Expand Down Expand Up @@ -296,7 +297,7 @@ void ErmVpnRoute::SetKey(const DBRequestKey *reqkey) {
}

void ErmVpnRoute::BuildProtoPrefix(BgpProtoPrefix *prefix,
const BgpAttr *attr, uint32_t label) const {
const BgpAttr *attr, uint32_t label, uint32_t l3_label) const {
prefix_.BuildProtoPrefix(prefix);
}

Expand Down
6 changes: 4 additions & 2 deletions src/bgp/ermvpn/ermvpn_route.h
Expand Up @@ -40,7 +40,8 @@ class ErmVpnPrefix {
static int FromProtoPrefix(BgpServer *server,
const BgpProtoPrefix &proto_prefix,
const BgpAttr *attr, ErmVpnPrefix *prefix,
BgpAttrPtr *new_attr, uint32_t *label);
BgpAttrPtr *new_attr, uint32_t *label,
uint32_t *l3_label);
static ErmVpnPrefix FromString(const std::string &str,
boost::system::error_code *errorp = NULL);

Expand Down Expand Up @@ -81,7 +82,8 @@ class ErmVpnRoute : public BgpRoute {
virtual void SetKey(const DBRequestKey *reqkey);
virtual void BuildProtoPrefix(BgpProtoPrefix *prefix,
const BgpAttr *attr = NULL,
uint32_t label = 0) const;
uint32_t label = 0,
uint32_t l3_label = 0) const;
virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
IpAddress nexthop) const;

Expand Down
26 changes: 19 additions & 7 deletions src/bgp/evpn/evpn_route.cc
Expand Up @@ -200,9 +200,12 @@ EvpnPrefix::EvpnPrefix(const RouteDistinguisher &rd, uint32_t tag,

int EvpnPrefix::FromProtoPrefix(BgpServer *server,
const BgpProtoPrefix &proto_prefix, const BgpAttr *attr,
EvpnPrefix *prefix, BgpAttrPtr *new_attr, uint32_t *label) {
EvpnPrefix *prefix, BgpAttrPtr *new_attr, uint32_t *label,
uint32_t *l3_label) {
*new_attr = attr;
*label = 0;
if (l3_label)
*l3_label = 0;
prefix->type_ = proto_prefix.type;
size_t nlri_size = proto_prefix.prefix.size();

Expand Down Expand Up @@ -253,6 +256,10 @@ int EvpnPrefix::FromProtoPrefix(BgpServer *server,
prefix->ReadIpAddress(proto_prefix, ip_offset, ip_size, ip_size);
size_t label_offset = ip_offset + ip_size;
*label = ReadLabel(proto_prefix, attr, label_offset, prefix->tag_);
size_t l3_label_offset = label_offset + kLabelSize;
if (l3_label && nlri_size >= l3_label_offset + kLabelSize) {
*l3_label = ReadLabel(proto_prefix, attr, l3_label_offset);
}
break;
}
case InclusiveMulticastRoute: {
Expand Down Expand Up @@ -369,9 +376,8 @@ int EvpnPrefix::FromProtoPrefix(BgpServer *server,
// must be obtained from the BgpAttr. The BgpAttr is NULL and label is
// 0 when withdrawing the route.
//
void EvpnPrefix::BuildProtoPrefix(const BgpAttr *attr, uint32_t label,
BgpProtoPrefix *proto_prefix) const {
assert(attr != NULL || label == 0);
void EvpnPrefix::BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
const BgpAttr *attr, uint32_t label, uint32_t l3_label) const {
proto_prefix->type = type_;
proto_prefix->prefix.clear();

Expand All @@ -395,7 +401,9 @@ void EvpnPrefix::BuildProtoPrefix(const BgpAttr *attr, uint32_t label,
}
case MacAdvertisementRoute: {
size_t ip_size = GetIpAddressSize();
size_t nlri_size = kMinMacAdvertisementRouteSize + kLabelSize + ip_size;
size_t nlri_size = kMinMacAdvertisementRouteSize + ip_size + kLabelSize;
if (l3_label)
nlri_size += kLabelSize;
proto_prefix->prefixlen = nlri_size * 8;
proto_prefix->prefix.resize(nlri_size, 0);

Expand All @@ -420,6 +428,10 @@ void EvpnPrefix::BuildProtoPrefix(const BgpAttr *attr, uint32_t label,
WriteIpAddress(proto_prefix, ip_offset);
size_t label_offset = ip_offset + ip_size;
WriteLabel(proto_prefix, attr, label_offset, label);
if (l3_label) {
size_t l3_label_offset = label_offset + kLabelSize;
WriteLabel(proto_prefix, attr, l3_label_offset, l3_label);
}
break;
}
case InclusiveMulticastRoute: {
Expand Down Expand Up @@ -959,8 +971,8 @@ void EvpnRoute::SetKey(const DBRequestKey *reqkey) {
}

void EvpnRoute::BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
const BgpAttr *attr, uint32_t label) const {
prefix_.BuildProtoPrefix(attr, label, proto_prefix);
const BgpAttr *attr, uint32_t label, uint32_t l3_label) const {
prefix_.BuildProtoPrefix(proto_prefix, attr, label, l3_label);
}

void EvpnRoute::BuildBgpProtoNextHop(vector<uint8_t> &nh,
Expand Down
10 changes: 6 additions & 4 deletions src/bgp/evpn/evpn_route.h
Expand Up @@ -66,12 +66,13 @@ class EvpnPrefix {
EvpnPrefix(const RouteDistinguisher &rd, uint32_t tag,
const IpAddress &ip_address, uint8_t ip_prefixlen);

void BuildProtoPrefix(const BgpAttr *attr, uint32_t label,
BgpProtoPrefix *proto_prefix) const;
void BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
const BgpAttr *attr, uint32_t label, uint32_t l3_label = 0) const;

static int FromProtoPrefix(BgpServer *server,
const BgpProtoPrefix &proto_prefix, const BgpAttr *attr,
EvpnPrefix *evpn_prefix, BgpAttrPtr *new_attr, uint32_t *label);
EvpnPrefix *evpn_prefix, BgpAttrPtr *new_attr, uint32_t *label,
uint32_t *l3_label = NULL);
static EvpnPrefix FromString(const std::string &str,
boost::system::error_code *errorp = NULL);
std::string ToString() const;
Expand Down Expand Up @@ -127,7 +128,8 @@ class EvpnRoute : public BgpRoute {
virtual void SetKey(const DBRequestKey *reqkey);

virtual void BuildProtoPrefix(BgpProtoPrefix *proto_prefix,
const BgpAttr *attr = NULL, uint32_t label = 0) const;
const BgpAttr *attr = NULL, uint32_t label = 0,
uint32_t l3_label = 0) const;
virtual void BuildBgpProtoNextHop(std::vector<uint8_t> &nh,
IpAddress nexthop) const;

Expand Down

0 comments on commit aaa8759

Please sign in to comment.