Skip to content

Commit b96ee54

Browse files
authored
[vnetorch] Advertise vnet tunnel routes (sonic-net#2058)
What I did Advertise active vnet tunnel routes. Why I did it The overlay routes programmed on the device need to be advertised to BGP peers. This PR aims to meet this requirement. How I verified it Add an entry in ADVERTISE_NETWORK_TABLE for active overlay routes
1 parent 6dae6b8 commit b96ee54

File tree

3 files changed

+328
-11
lines changed

3 files changed

+328
-11
lines changed

orchagent/vnetorch.cpp

+34-2
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ bool VNetOrch::addOperation(const Request& request)
396396
sai_attribute_t attr;
397397
vector<sai_attribute_t> attrs;
398398
set<string> peer_list = {};
399-
bool peer = false, create = false;
399+
bool peer = false, create = false, advertise_prefix = false;
400400
uint32_t vni=0;
401401
string tunnel;
402402
string scope;
@@ -427,6 +427,10 @@ bool VNetOrch::addOperation(const Request& request)
427427
{
428428
scope = request.getAttrString("scope");
429429
}
430+
else if (name == "advertise_prefix")
431+
{
432+
advertise_prefix = request.getAttrBool("advertise_prefix");
433+
}
430434
else
431435
{
432436
SWSS_LOG_INFO("Unknown attribute: %s", name.c_str());
@@ -453,7 +457,7 @@ bool VNetOrch::addOperation(const Request& request)
453457

454458
if (it == std::end(vnet_table_))
455459
{
456-
VNetInfo vnet_info = { tunnel, vni, peer_list, scope };
460+
VNetInfo vnet_info = { tunnel, vni, peer_list, scope, advertise_prefix };
457461
obj = createObject<VNetVrfObject>(vnet_name, vnet_info, attrs);
458462
create = true;
459463

@@ -645,6 +649,7 @@ VNetRouteOrch::VNetRouteOrch(DBConnector *db, vector<string> &tableNames, VNetOr
645649

646650
state_db_ = shared_ptr<DBConnector>(new DBConnector("STATE_DB", 0));
647651
state_vnet_rt_tunnel_table_ = unique_ptr<Table>(new Table(state_db_.get(), STATE_VNET_RT_TUNNEL_TABLE_NAME));
652+
state_vnet_rt_adv_table_ = unique_ptr<Table>(new Table(state_db_.get(), STATE_ADVERTISE_NETWORK_TABLE_NAME));
648653

649654
gBfdOrch->attach(this);
650655
}
@@ -1563,12 +1568,39 @@ void VNetRouteOrch::postRouteState(const string& vnet, IpPrefix& ipPrefix, NextH
15631568
fvVector.emplace_back("state", route_state);
15641569

15651570
state_vnet_rt_tunnel_table_->set(state_db_key, fvVector);
1571+
1572+
if (vnet_orch_->getAdvertisePrefix(vnet))
1573+
{
1574+
if (route_state == "active")
1575+
{
1576+
addRouteAdvertisement(ipPrefix);
1577+
}
1578+
else
1579+
{
1580+
removeRouteAdvertisement(ipPrefix);
1581+
}
1582+
}
15661583
}
15671584

15681585
void VNetRouteOrch::removeRouteState(const string& vnet, IpPrefix& ipPrefix)
15691586
{
15701587
const string state_db_key = vnet + state_db_key_delimiter + ipPrefix.to_string();
15711588
state_vnet_rt_tunnel_table_->del(state_db_key);
1589+
removeRouteAdvertisement(ipPrefix);
1590+
}
1591+
1592+
void VNetRouteOrch::addRouteAdvertisement(IpPrefix& ipPrefix)
1593+
{
1594+
const string key = ipPrefix.to_string();
1595+
vector<FieldValueTuple> fvs;
1596+
fvs.push_back(FieldValueTuple("", ""));
1597+
state_vnet_rt_adv_table_->set(key, fvs);
1598+
}
1599+
1600+
void VNetRouteOrch::removeRouteAdvertisement(IpPrefix& ipPrefix)
1601+
{
1602+
const string key = ipPrefix.to_string();
1603+
state_vnet_rt_adv_table_->del(key);
15721604
}
15731605

15741606
void VNetRouteOrch::update(SubjectType type, void *cntx)

orchagent/vnetorch.h

+24-7
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ extern sai_object_id_t gVirtualRouterId;
2727
const request_description_t vnet_request_description = {
2828
{ REQ_T_STRING },
2929
{
30-
{ "src_mac", REQ_T_MAC_ADDRESS },
31-
{ "vxlan_tunnel", REQ_T_STRING },
32-
{ "vni", REQ_T_UINT },
33-
{ "peer_list", REQ_T_SET },
34-
{ "guid", REQ_T_STRING },
35-
{ "scope", REQ_T_STRING },
30+
{ "src_mac", REQ_T_MAC_ADDRESS },
31+
{ "vxlan_tunnel", REQ_T_STRING },
32+
{ "vni", REQ_T_UINT },
33+
{ "peer_list", REQ_T_SET },
34+
{ "guid", REQ_T_STRING },
35+
{ "scope", REQ_T_STRING },
36+
{ "advertise_prefix", REQ_T_BOOL},
3637
},
3738
{ "vxlan_tunnel", "vni" } // mandatory attributes
3839
};
@@ -57,6 +58,7 @@ struct VNetInfo
5758
uint32_t vni;
5859
set<string> peers;
5960
string scope;
61+
bool advertise_prefix;
6062
};
6163

6264
typedef map<VR_TYPE, sai_object_id_t> vrid_list_t;
@@ -83,7 +85,8 @@ class VNetObject
8385
tunnel_(vnetInfo.tunnel),
8486
peer_list_(vnetInfo.peers),
8587
vni_(vnetInfo.vni),
86-
scope_(vnetInfo.scope)
88+
scope_(vnetInfo.scope),
89+
advertise_prefix_(vnetInfo.advertise_prefix)
8790
{ }
8891

8992
virtual bool updateObj(vector<sai_attribute_t>&) = 0;
@@ -113,13 +116,19 @@ class VNetObject
113116
return scope_;
114117
}
115118

119+
bool getAdvertisePrefix() const
120+
{
121+
return advertise_prefix_;
122+
}
123+
116124
virtual ~VNetObject() noexcept(false) {};
117125

118126
private:
119127
set<string> peer_list_ = {};
120128
string tunnel_;
121129
uint32_t vni_;
122130
string scope_;
131+
bool advertise_prefix_;
123132
};
124133

125134
struct nextHop
@@ -223,6 +232,11 @@ class VNetOrch : public Orch2
223232
return vnet_table_.at(name)->getTunnelName();
224233
}
225234

235+
bool getAdvertisePrefix(const std::string& name) const
236+
{
237+
return vnet_table_.at(name)->getAdvertisePrefix();
238+
}
239+
226240
bool isVnetExecVrf() const
227241
{
228242
return (vnet_exec_ == VNET_EXEC::VNET_EXEC_VRF);
@@ -338,6 +352,8 @@ class VNetRouteOrch : public Orch2, public Subject, public Observer
338352
void delEndpointMonitor(const string& vnet, NextHopGroupKey& nexthops);
339353
void postRouteState(const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops);
340354
void removeRouteState(const string& vnet, IpPrefix& ipPrefix);
355+
void addRouteAdvertisement(IpPrefix& ipPrefix);
356+
void removeRouteAdvertisement(IpPrefix& ipPrefix);
341357

342358
void updateVnetTunnel(const BfdUpdate&);
343359
bool updateTunnelRoute(const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops, string& op);
@@ -362,6 +378,7 @@ class VNetRouteOrch : public Orch2, public Subject, public Observer
362378
ProducerStateTable bfd_session_producer_;
363379
shared_ptr<DBConnector> state_db_;
364380
unique_ptr<Table> state_vnet_rt_tunnel_table_;
381+
unique_ptr<Table> state_vnet_rt_adv_table_;
365382
};
366383

367384
class VNetCfgRouteOrch : public Orch

0 commit comments

Comments
 (0)