Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ bool VNetOrch::addOperation(const Request& request)
sai_attribute_t attr;
vector<sai_attribute_t> attrs;
set<string> peer_list = {};
bool peer = false, create = false;
bool peer = false, create = false, advertise_prefix = false;
uint32_t vni=0;
string tunnel;
string scope;
Expand Down Expand Up @@ -427,6 +427,10 @@ bool VNetOrch::addOperation(const Request& request)
{
scope = request.getAttrString("scope");
}
else if (name == "advertise_prefix")
{
advertise_prefix = request.getAttrBool("advertise_prefix");
}
else
{
SWSS_LOG_INFO("Unknown attribute: %s", name.c_str());
Expand All @@ -453,7 +457,7 @@ bool VNetOrch::addOperation(const Request& request)

if (it == std::end(vnet_table_))
{
VNetInfo vnet_info = { tunnel, vni, peer_list, scope };
VNetInfo vnet_info = { tunnel, vni, peer_list, scope, advertise_prefix };
obj = createObject<VNetVrfObject>(vnet_name, vnet_info, attrs);
create = true;

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

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

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

state_vnet_rt_tunnel_table_->set(state_db_key, fvVector);

if (vnet_orch_->getAdvertisePrefix(vnet))
{
if (route_state == "active")
{
addRouteAdvertisement(ipPrefix);
}
else
{
removeRouteAdvertisement(ipPrefix);
}
}
}

void VNetRouteOrch::removeRouteState(const string& vnet, IpPrefix& ipPrefix)
{
const string state_db_key = vnet + state_db_key_delimiter + ipPrefix.to_string();
state_vnet_rt_tunnel_table_->del(state_db_key);
removeRouteAdvertisement(ipPrefix);
}

void VNetRouteOrch::addRouteAdvertisement(IpPrefix& ipPrefix)
{
const string key = ipPrefix.to_string();
vector<FieldValueTuple> fvs;
fvs.push_back(FieldValueTuple("", ""));
state_vnet_rt_adv_table_->set(key, fvs);
}

void VNetRouteOrch::removeRouteAdvertisement(IpPrefix& ipPrefix)
{
const string key = ipPrefix.to_string();
state_vnet_rt_adv_table_->del(key);
}

void VNetRouteOrch::update(SubjectType type, void *cntx)
Expand Down
31 changes: 24 additions & 7 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ extern sai_object_id_t gVirtualRouterId;
const request_description_t vnet_request_description = {
{ REQ_T_STRING },
{
{ "src_mac", REQ_T_MAC_ADDRESS },
{ "vxlan_tunnel", REQ_T_STRING },
{ "vni", REQ_T_UINT },
{ "peer_list", REQ_T_SET },
{ "guid", REQ_T_STRING },
{ "scope", REQ_T_STRING },
{ "src_mac", REQ_T_MAC_ADDRESS },
{ "vxlan_tunnel", REQ_T_STRING },
{ "vni", REQ_T_UINT },
{ "peer_list", REQ_T_SET },
{ "guid", REQ_T_STRING },
{ "scope", REQ_T_STRING },
{ "advertise_prefix", REQ_T_BOOL},
},
{ "vxlan_tunnel", "vni" } // mandatory attributes
};
Expand All @@ -57,6 +58,7 @@ struct VNetInfo
uint32_t vni;
set<string> peers;
string scope;
bool advertise_prefix;
};

typedef map<VR_TYPE, sai_object_id_t> vrid_list_t;
Expand All @@ -83,7 +85,8 @@ class VNetObject
tunnel_(vnetInfo.tunnel),
peer_list_(vnetInfo.peers),
vni_(vnetInfo.vni),
scope_(vnetInfo.scope)
scope_(vnetInfo.scope),
advertise_prefix_(vnetInfo.advertise_prefix)
{ }

virtual bool updateObj(vector<sai_attribute_t>&) = 0;
Expand Down Expand Up @@ -113,13 +116,19 @@ class VNetObject
return scope_;
}

bool getAdvertisePrefix() const
{
return advertise_prefix_;
}

virtual ~VNetObject() noexcept(false) {};

private:
set<string> peer_list_ = {};
string tunnel_;
uint32_t vni_;
string scope_;
bool advertise_prefix_;
};

struct nextHop
Expand Down Expand Up @@ -223,6 +232,11 @@ class VNetOrch : public Orch2
return vnet_table_.at(name)->getTunnelName();
}

bool getAdvertisePrefix(const std::string& name) const
{
return vnet_table_.at(name)->getAdvertisePrefix();
}

bool isVnetExecVrf() const
{
return (vnet_exec_ == VNET_EXEC::VNET_EXEC_VRF);
Expand Down Expand Up @@ -338,6 +352,8 @@ class VNetRouteOrch : public Orch2, public Subject, public Observer
void delEndpointMonitor(const string& vnet, NextHopGroupKey& nexthops);
void postRouteState(const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops);
void removeRouteState(const string& vnet, IpPrefix& ipPrefix);
void addRouteAdvertisement(IpPrefix& ipPrefix);
void removeRouteAdvertisement(IpPrefix& ipPrefix);

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

class VNetCfgRouteOrch : public Orch
Expand Down
Loading