Skip to content

Commit

Permalink
Community attribute to avoid re-orignating the routes
Browse files Browse the repository at this point in the history
Refer to https://bugs.launchpad.net/juniperopenstack/+bug/1500698

Changes made:
    1. Schema changes to add new property for community list and
       add this property to static routes
    2. XMPP message schema changes to add community to route entry
    3. Handling community in Rx/Tx on bgp_xmpp_channel
    4. Introduce new type for Community.
    5. Avoid service chaining routes which are tagged with "no-reoriginate" community
    6. UT for CommunityType, Rx/Tx of community in Xmpp messages and service chain

Change-Id: If57c005fd0e6c0b9705491db2f1da81bb0920000
Related-bug:#1500698
  • Loading branch information
bailkeri committed Nov 9, 2015
1 parent afcc00c commit a2298b7
Show file tree
Hide file tree
Showing 22 changed files with 719 additions and 77 deletions.
7 changes: 4 additions & 3 deletions src/bgp/bgp_table.cc
Expand Up @@ -13,6 +13,7 @@
#include "bgp/routing-instance/path_resolver.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/rtarget_group_mgr.h"
#include "net/community_type.h"

using std::map;
using std::make_pair;
Expand Down Expand Up @@ -143,12 +144,12 @@ UpdateInfo *BgpTable::GetUpdateInfo(RibOut *ribout, BgpRoute *route,
if (attr->community() != NULL &&
attr->community()->communities().size()) {
BOOST_FOREACH(uint32_t value, attr->community()->communities()) {
if (value == Community::NoAdvertise)
if (value == CommunityType::NoAdvertise)
return NULL;

if ((ribout->peer_type() == BgpProto::EBGP) &&
((value == Community::NoExport) ||
(value == Community::NoExportSubconfed))) {
((value == CommunityType::NoExport) ||
(value == CommunityType::NoExportSubconfed))) {
return NULL;
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/bgp/bgp_xmpp_channel.cc
Expand Up @@ -24,6 +24,7 @@
#include "bgp/scheduling_group.h"
#include "bgp/security_group/security_group.h"
#include "bgp/tunnel_encap/tunnel_encap.h"
#include "net/community_type.h"
#include "schema/xmpp_multicast_types.h"
#include "schema/xmpp_enet_types.h"
#include "xml/xml_pugi.h"
Expand All @@ -43,6 +44,7 @@ using autogen::McastTunnelEncapsulationListType;
using autogen::ItemType;
using autogen::NextHopListType;
using autogen::SecurityGroupListType;
using autogen::CommunityTagListType;
using autogen::TunnelEncapsulationListType;

using boost::system::error_code;
Expand Down Expand Up @@ -1078,6 +1080,7 @@ bool BgpXmppChannel::ProcessItem(string vrf_name,
uint32_t label = 0;
uint32_t flags = 0;
ExtCommunitySpec ext;
CommunitySpec comm;

if (add_change) {
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
Expand Down Expand Up @@ -1155,6 +1158,18 @@ bool BgpXmppChannel::ProcessItem(string vrf_name,
if (med.med != 0)
attrs.push_back(&med);

// Process community tags
const CommunityTagListType &ict_list = item.entry.community_tag_list;
for (CommunityTagListType::const_iterator cit = ict_list.begin();
cit != ict_list.end(); ++cit) {
error_code error;
uint32_t rt_community =
CommunityType::CommunityFromString(*cit, &error);
if (error)
continue;
comm.communities.push_back(rt_community);
}

BgpAttrNextHop nexthop(nh_address.to_v4().to_ulong());
attrs.push_back(&nexthop);

Expand All @@ -1180,6 +1195,9 @@ bool BgpXmppChannel::ProcessItem(string vrf_name,
if (!load_balance.IsDefault())
ext.communities.push_back(load_balance.GetExtCommunityValue());

if (!comm.communities.empty())
attrs.push_back(&comm);

if (!ext.communities.empty())
attrs.push_back(&ext);

Expand Down Expand Up @@ -1272,6 +1290,7 @@ bool BgpXmppChannel::ProcessInet6Item(string vrf_name,
uint32_t label = 0;
uint32_t flags = 0;
ExtCommunitySpec ext;
CommunitySpec comm;

if (add_change) {
req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
Expand Down Expand Up @@ -1352,6 +1371,18 @@ bool BgpXmppChannel::ProcessInet6Item(string vrf_name,
if (med.med != 0)
attrs.push_back(&med);

// Process community tags
const CommunityTagListType &ict_list = item.entry.community_tag_list;
for (CommunityTagListType::const_iterator cit = ict_list.begin();
cit != ict_list.end(); ++cit) {
error_code error;
uint32_t rt_community =
CommunityType::CommunityFromString(*cit, &error);
if (error)
continue;
comm.communities.push_back(rt_community);
}

BgpAttrNextHop nexthop(nh_address.to_v4().to_ulong());
attrs.push_back(&nexthop);

Expand All @@ -1377,6 +1408,9 @@ bool BgpXmppChannel::ProcessInet6Item(string vrf_name,
if (!load_balance.IsDefault())
ext.communities.push_back(load_balance.GetExtCommunityValue());

if (!comm.communities.empty())
attrs.push_back(&comm);

if (!ext.communities.empty()) {
attrs.push_back(&ext);
}
Expand Down
21 changes: 2 additions & 19 deletions src/bgp/community.cc
Expand Up @@ -12,6 +12,7 @@
#include "base/string_util.h"
#include "bgp/bgp_proto.h"
#include "bgp/tunnel_encap/tunnel_encap.h"
#include "net/community_type.h"

using std::sort;
using std::string;
Expand Down Expand Up @@ -77,25 +78,7 @@ bool Community::ContainsValue(uint32_t value) const {

void Community::BuildStringList(vector<string> *list) const {
BOOST_FOREACH(uint32_t community, communities_) {
string name;
switch (community) {
case AcceptOwn:
name = "accept-own";
break;
case NoExport:
name = "no-export";
break;
case NoAdvertise:
name = "no-advertise";
break;
case NoExportSubconfed:
name = "no-export-subconfed";
break;
default:
name = integerToString(community / 65536) + ":" +
integerToString(community % 65536);
break;
}
string name = CommunityType::CommunityToString(community);
list->push_back(name);
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/bgp/community.h
Expand Up @@ -43,13 +43,6 @@ struct CommunitySpec : public BgpAttribute {

class Community {
public:
enum WellKnownCommunity {
AcceptOwn = 0xFFFF0001,
NoExport = 0xFFFFFF01,
NoAdvertise = 0xFFFFFF02,
NoExportSubconfed = 0xFFFFFF03,
};

explicit Community(CommunityDB *comm_db)
: comm_db_(comm_db) {
refcount_ = 0;
Expand Down
8 changes: 6 additions & 2 deletions src/bgp/routing-instance/service_chaining.cc
Expand Up @@ -18,6 +18,7 @@
#include "bgp/origin-vn/origin_vn.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/service_chaining_types.h"
#include "net/community_type.h"

using boost::bind;
using boost::system::error_code;
Expand Down Expand Up @@ -158,8 +159,11 @@ bool ServiceChain<T>::Match(BgpServer *server, BgpTable *table, BgpRoute *route,
} else {
const BgpAttr *attr = route->BestPath()->GetAttr();
const Community *comm = attr ? attr->community() : NULL;
if (comm && comm->ContainsValue(Community::NoAdvertise))
if (comm) {
if ((comm->ContainsValue(CommunityType::NoAdvertise)) ||
(comm->ContainsValue(CommunityType::NoReOriginate)))
deleted = true;
}

int vn_index = GetOriginVnIndex(table, route);
int src_vn_index = src_->virtual_network_index();
Expand Down Expand Up @@ -418,7 +422,7 @@ void ServiceChain<T>::AddServiceChainRoute(PrefixT prefix,
BgpAttrDB *attr_db = server->attr_db();
CommunityDB *comm_db = server->comm_db();
CommunityPtr new_community =
comm_db->AppendAndLocate(orig_community, Community::AcceptOwn);
comm_db->AppendAndLocate(orig_community, CommunityType::AcceptOwn);
ExtCommunityDB *extcomm_db = server->extcomm_db();
PeerRibMembershipManager *membership_mgr = server->membership_mgr();
OriginVnPathDB *ovnpath_db = server->ovnpath_db();
Expand Down
3 changes: 2 additions & 1 deletion src/bgp/routing-instance/static_route.cc
Expand Up @@ -16,6 +16,7 @@
#include "bgp/l3vpn/inetvpn_route.h"
#include "bgp/routing-instance/routing_instance.h"
#include "bgp/routing-instance/static_route_types.h"
#include "net/community_type.h"

using boost::assign::list_of;
using boost::system::error_code;
Expand Down Expand Up @@ -431,7 +432,7 @@ void StaticRoute<T>::AddStaticRoute(NexthopPathIdList *old_path_ids) {
const Community *orig_community =
nexthop_route_path->GetAttr()->community();
CommunityPtr new_community =
comm_db->AppendAndLocate(orig_community, Community::AcceptOwn);
comm_db->AppendAndLocate(orig_community, CommunityType::AcceptOwn);
new_attr =
attr_db->ReplaceCommunityAndLocate(new_attr.get(), new_community);

Expand Down
17 changes: 9 additions & 8 deletions src/bgp/test/bgp_attr_test.cc
Expand Up @@ -13,6 +13,7 @@
#include "bgp/extended-community/mac_mobility.h"
#include "bgp/origin-vn/origin_vn.h"
#include "control-node/control_node.h"
#include "net/community_type.h"

using boost::assign::list_of;
using boost::system::error_code;
Expand Down Expand Up @@ -314,10 +315,10 @@ TEST_F(BgpAttrTest, CommunityCompare2) {
TEST_F(BgpAttrTest, CommunityBuildStringList1) {
CommunitySpec spec;
spec.communities.push_back(0xFFFF0000);
spec.communities.push_back(Community::AcceptOwn);
spec.communities.push_back(Community::NoExport);
spec.communities.push_back(Community::NoAdvertise);
spec.communities.push_back(Community::NoExportSubconfed);
spec.communities.push_back(CommunityType::AcceptOwn);
spec.communities.push_back(CommunityType::NoExport);
spec.communities.push_back(CommunityType::NoAdvertise);
spec.communities.push_back(CommunityType::NoExportSubconfed);
Community comm(comm_db_, spec);

vector<string> expected_list = list_of("65535:0")("accept-own")
Expand All @@ -329,10 +330,10 @@ TEST_F(BgpAttrTest, CommunityBuildStringList1) {

TEST_F(BgpAttrTest, CommunityBuildStringList2) {
CommunitySpec spec;
spec.communities.push_back(Community::NoExportSubconfed);
spec.communities.push_back(Community::NoAdvertise);
spec.communities.push_back(Community::NoExport);
spec.communities.push_back(Community::AcceptOwn);
spec.communities.push_back(CommunityType::NoExportSubconfed);
spec.communities.push_back(CommunityType::NoAdvertise);
spec.communities.push_back(CommunityType::NoExport);
spec.communities.push_back(CommunityType::AcceptOwn);
spec.communities.push_back(0xFFFF0000);
Community comm(comm_db_, spec);

Expand Down
19 changes: 10 additions & 9 deletions src/bgp/test/bgp_table_export_test.cc
Expand Up @@ -9,6 +9,7 @@
#include "bgp/test/bgp_server_test_util.h"
#include "bgp/xmpp_message_builder.h"
#include "control-node/control_node.h"
#include "net/community_type.h"

using namespace std;

Expand Down Expand Up @@ -397,7 +398,7 @@ TEST_P(BgpTableExportParamTest1, NoFeasiblePath) {
//
TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise1) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(Community::NoAdvertise);
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportReject();
Expand All @@ -411,7 +412,7 @@ TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise1) {
//
TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise2) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(Community::NoAdvertise);
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportReject();
Expand All @@ -425,7 +426,7 @@ TEST_P(BgpTableExportParamTest1, CommunityNoAdvertise2) {
//
TEST_P(BgpTableExportParamTest1, CommunityNoExport) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(Community::NoExport);
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportReject();
Expand All @@ -439,7 +440,7 @@ TEST_P(BgpTableExportParamTest1, CommunityNoExport) {
//
TEST_P(BgpTableExportParamTest1, CommunityNoExportSubconfed) {
CreateRibOut(BgpProto::EBGP, RibExportPolicy::BGP, 300);
SetAttrCommunity(Community::NoExportSubconfed);
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportReject();
Expand Down Expand Up @@ -622,7 +623,7 @@ class BgpTableExportParamTest3 :
//
TEST_P(BgpTableExportParamTest3, CommunityNoExport) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(Community::NoExport);
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportAccept();
Expand All @@ -636,7 +637,7 @@ TEST_P(BgpTableExportParamTest3, CommunityNoExport) {
//
TEST_P(BgpTableExportParamTest3, CommunityNoExportSubconfed) {
CreateRibOut(BgpProto::IBGP, RibExportPolicy::BGP, LocalAsNumber());
SetAttrCommunity(Community::NoExportSubconfed);
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportAccept();
Expand Down Expand Up @@ -840,7 +841,7 @@ TEST_P(BgpTableExportParamTest4b, AttrNoChange) {
// Intent: NoAdvertise community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoAdvertise) {
SetAttrCommunity(Community::NoAdvertise);
SetAttrCommunity(CommunityType::NoAdvertise);
AddPath();
RunExport();
VerifyExportAccept();
Expand All @@ -854,7 +855,7 @@ TEST_P(BgpTableExportParamTest4b, CommunityNoAdvertise) {
// Intent: NoExport community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoExport) {
SetAttrCommunity(Community::NoExport);
SetAttrCommunity(CommunityType::NoExport);
AddPath();
RunExport();
VerifyExportAccept();
Expand All @@ -868,7 +869,7 @@ TEST_P(BgpTableExportParamTest4b, CommunityNoExport) {
// Intent: NoExportSubconfed community is ignored if RibOut is XMPP.
//
TEST_P(BgpTableExportParamTest4b, CommunityNoExportSubconfed) {
SetAttrCommunity(Community::NoExportSubconfed);
SetAttrCommunity(CommunityType::NoExportSubconfed);
AddPath();
RunExport();
VerifyExportAccept();
Expand Down

0 comments on commit a2298b7

Please sign in to comment.