Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[subnet decap] Add subnet decap rule based on overlay ECMP #3153

Merged
merged 3 commits into from
May 31, 2024
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
50 changes: 48 additions & 2 deletions orchagent/vnetorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "neighorch.h"
#include "crmorch.h"
#include "routeorch.h"
#include "tunneldecaporch.h"
#include "flowcounterrouteorch.h"

extern sai_virtual_router_api_t* sai_virtual_router_api;
Expand All @@ -43,6 +44,7 @@ extern RouteOrch *gRouteOrch;
extern MacAddress gVxlanMacAddress;
extern BfdOrch *gBfdOrch;
extern SwitchOrch *gSwitchOrch;
extern TunnelDecapOrch *gTunneldecapOrch;
/*
* VRF Modeling and VNetVrf class definitions
*/
Expand Down Expand Up @@ -334,7 +336,7 @@ VNetVrfObject::~VNetVrfObject()
set<sai_object_id_t> vr_ent = getVRids();
for (auto it : vr_ent)
{
if (it != gVirtualRouterId)
if (it != gVirtualRouterId)
{
sai_status_t status = sai_virtual_router_api->remove_virtual_router(it);
if (status != SAI_STATUS_SUCCESS)
Expand Down Expand Up @@ -717,7 +719,8 @@ static bool update_route(sai_object_id_t vr_id, sai_ip_prefix_t& ip_pfx, sai_obj
}

VNetRouteOrch::VNetRouteOrch(DBConnector *db, vector<string> &tableNames, VNetOrch *vnetOrch)
: Orch2(db, tableNames, request_), vnet_orch_(vnetOrch), bfd_session_producer_(db, APP_BFD_SESSION_TABLE_NAME)
: Orch2(db, tableNames, request_), vnet_orch_(vnetOrch), bfd_session_producer_(db, APP_BFD_SESSION_TABLE_NAME),
app_tunnel_decap_term_producer_(db, APP_TUNNEL_DECAP_TERM_TABLE_NAME)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -1432,6 +1435,39 @@ bool VNetRouteOrch::updateTunnelRoute(const string& vnet, IpPrefix& ipPrefix,
return true;
}

inline void VNetRouteOrch::createSubnetDecapTerm(const IpPrefix &ipPrefix)
{
const SubnetDecapConfig &config = gTunneldecapOrch->getSubnetDecapConfig();
if (!config.enable || subnet_decap_terms_created_.find(ipPrefix) != subnet_decap_terms_created_.end())
{
return;
}
SWSS_LOG_NOTICE("Add subnet decap term for %s", ipPrefix.to_string().c_str());
static const vector<FieldValueTuple> data = {
{"term_type", "MP2MP"},
{"subnet_type", "vip"}
};
string tunnel_name = ipPrefix.isV4() ? config.tunnel : config.tunnel_v6;
string key = tunnel_name + ":" + ipPrefix.to_string();
app_tunnel_decap_term_producer_.set(key, data);
subnet_decap_terms_created_.insert(ipPrefix);
}

inline void VNetRouteOrch::removeSubnetDecapTerm(const IpPrefix &ipPrefix)
{
const SubnetDecapConfig &config = gTunneldecapOrch->getSubnetDecapConfig();
auto it = subnet_decap_terms_created_.find(ipPrefix);
if (it == subnet_decap_terms_created_.end())
{
return;
}
SWSS_LOG_NOTICE("Remove subnet decap term for %s", ipPrefix.to_string().c_str());
string tunnel_name = ipPrefix.isV4() ? config.tunnel : config.tunnel_v6;
string key = tunnel_name + ":" + ipPrefix.to_string();
app_tunnel_decap_term_producer_.del(key);
subnet_decap_terms_created_.erase(it);
}

template<>
bool VNetRouteOrch::doRouteTask<VNetVrfObject>(const string& vnet, IpPrefix& ipPrefix,
nextHop& nh, string& op)
Expand Down Expand Up @@ -2088,6 +2124,14 @@ void VNetRouteOrch::postRouteState(const string& vnet, IpPrefix& ipPrefix, NextH
removeRouteAdvertisement(prefix_to_use);
}
}
if (route_state == "active")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this code be in the if block at line#2115?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if block at LINE#2115 checks if the vnet is allowed to advertise prefix. The decap term should be added even if the vnet is not allowed to advertise prefix.

{
createSubnetDecapTerm(prefix_to_use);
}
else if (route_state == "inactive")
{
removeSubnetDecapTerm(prefix_to_use);
}
}

void VNetRouteOrch::removeRouteState(const string& vnet, IpPrefix& ipPrefix)
Expand All @@ -2101,11 +2145,13 @@ void VNetRouteOrch::removeRouteState(const string& vnet, IpPrefix& ipPrefix)
if(adv_prefix_refcount_[adv_pfx] == 1)
{
removeRouteAdvertisement(adv_pfx);
removeSubnetDecapTerm(adv_pfx);
}
}
else
{
removeRouteAdvertisement(ipPrefix);
removeSubnetDecapTerm(ipPrefix);
}
}

Expand Down
4 changes: 4 additions & 0 deletions orchagent/vnetorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ class VNetRouteOrch : public Orch2, public Subject, public Observer
void updateVnetTunnel(const BfdUpdate&);
void updateVnetTunnelCustomMonitor(const MonitorUpdate& update);
bool updateTunnelRoute(const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops, string& op);
void createSubnetDecapTerm(const IpPrefix &ipPrefix);
void removeSubnetDecapTerm(const IpPrefix &ipPrefix);

template<typename T>
bool doRouteTask(const string& vnet, IpPrefix& ipPrefix, NextHopGroupKey& nexthops, string& op, string& profile,
Expand All @@ -485,7 +487,9 @@ class VNetRouteOrch : public Orch2, public Subject, public Observer
std::map<std::string, VNetEndpointInfoTable> nexthop_info_;
std::map<IpPrefix, IpPrefix> prefix_to_adv_prefix_;
std::map<IpPrefix, int> adv_prefix_refcount_;
std::set<IpPrefix> subnet_decap_terms_created_;
ProducerStateTable bfd_session_producer_;
ProducerStateTable app_tunnel_decap_term_producer_;
unique_ptr<Table> monitor_session_producer_;
shared_ptr<DBConnector> state_db_;
shared_ptr<DBConnector> app_db_;
Expand Down
Loading
Loading