Skip to content

Commit

Permalink
[subnet decap] Add subnet decap rule based on overlay ECMP (#3153)
Browse files Browse the repository at this point in the history
* [subnet decap] Add subnet decap rule based on overlay ECMP vxlan tunnel route
What I did
Support dynamic decap rule generation based on the Vxlan tunnel route of Overlay ECMP.
This depends on: #3117

Why I did it
To enable SONiC with the capability to decap IPinIP packets with dest IP in the Overlay ECMP Vxlan tunnel route prefix.
  • Loading branch information
lolyu authored May 31, 2024
1 parent 8e8fc66 commit 1f12a8d
Show file tree
Hide file tree
Showing 3 changed files with 376 additions and 2 deletions.
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")
{
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

0 comments on commit 1f12a8d

Please sign in to comment.