Skip to content

Commit

Permalink
[subnet_decap] Add subnet decap (#3117)
Browse files Browse the repository at this point in the history
What I did
Add subnet decap feature:

Enable TunnelDecapOrch to subsribe to the tunnel and decap term table to create/remove tunnel and decap terms.
Allow MP2MP decap term creation/removal.
Enable TunnelDecapOrch to subscribe to subnet decap table and respond to source IP change by changing the source IPs of the decap terms related to the subnet decap.
Enhance tunnelmgrd to adapt to the tunnel/decap term db schema change
Microsoft ADO (number only): 27768412
  • Loading branch information
lolyu committed May 28, 2024
1 parent 3ee7361 commit 353ab92
Show file tree
Hide file tree
Showing 15 changed files with 1,669 additions and 296 deletions.
29 changes: 28 additions & 1 deletion cfgmgr/tunnelmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ static int cmdIpTunnelRouteDel(const std::string& pfx, std::string & res)
TunnelMgr::TunnelMgr(DBConnector *cfgDb, DBConnector *appDb, const std::vector<std::string> &tableNames) :
Orch(cfgDb, tableNames),
m_appIpInIpTunnelTable(appDb, APP_TUNNEL_DECAP_TABLE_NAME),
m_appIpInIpTunnelDecapTermTable(appDb, APP_TUNNEL_DECAP_TERM_TABLE_NAME),
m_cfgPeerTable(cfgDb, CFG_PEER_SWITCH_TABLE_NAME),
m_cfgTunnelTable(cfgDb, CFG_TUNNEL_TABLE_NAME)
{
Expand Down Expand Up @@ -223,6 +224,7 @@ bool TunnelMgr::doTunnelTask(const KeyOpFieldsValuesTuple & t)

const std::string & tunnelName = kfvKey(t);
const std::string & op = kfvOp(t);
std::string src_ip;
TunnelInfo tunInfo;

for (auto fieldValue : kfvFieldsValues(t))
Expand All @@ -237,6 +239,10 @@ bool TunnelMgr::doTunnelTask(const KeyOpFieldsValuesTuple & t)
{
tunInfo.type = value;
}
else if (field == "src_ip")
{
src_ip = value;
}
}

if (op == SET_COMMAND)
Expand All @@ -260,7 +266,27 @@ bool TunnelMgr::doTunnelTask(const KeyOpFieldsValuesTuple & t)
*/
if (m_tunnelReplay.find(tunnelName) == m_tunnelReplay.end())
{
m_appIpInIpTunnelTable.set(tunnelName, kfvFieldsValues(t));
/* Create the tunnel */
std::vector<FieldValueTuple> fvs;
std::copy_if(kfvFieldsValues(t).cbegin(), kfvFieldsValues(t).cend(),
std::back_inserter(fvs),
[](const FieldValueTuple & fv) {
return fvField(fv) != "dst_ip";
});
m_appIpInIpTunnelTable.set(tunnelName, fvs);

/* Create the decap term */
fvs.clear();
if (!src_ip.empty())
{
fvs.emplace_back("src_ip", src_ip);
fvs.emplace_back("term_type", "P2P");
}
else
{
fvs.emplace_back("term_type", "P2MP");
}
m_appIpInIpTunnelDecapTermTable.set(tunnelName + DEFAULT_KEY_SEPARATOR + tunInfo.dst_ip, fvs);
}
}
m_tunnelReplay.erase(tunnelName);
Expand All @@ -279,6 +305,7 @@ bool TunnelMgr::doTunnelTask(const KeyOpFieldsValuesTuple & t)
tunInfo = it->second;
if (tunInfo.type == IPINIP)
{
m_appIpInIpTunnelDecapTermTable.del(tunnelName + DEFAULT_KEY_SEPARATOR + tunInfo.dst_ip);
m_appIpInIpTunnelTable.del(tunnelName);
}
else
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/tunnelmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class TunnelMgr : public Orch
void finalizeWarmReboot();

ProducerStateTable m_appIpInIpTunnelTable;
ProducerStateTable m_appIpInIpTunnelDecapTermTable;
Table m_cfgPeerTable;
Table m_cfgTunnelTable;

Expand Down
13 changes: 10 additions & 3 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Srv6Orch *gSrv6Orch;
FlowCounterRouteOrch *gFlowCounterRouteOrch;
DebugCounterOrch *gDebugCounterOrch;
MonitorOrch *gMonitorOrch;
TunnelDecapOrch *gTunneldecapOrch;

bool gIsNatSupported = false;
event_handle_t g_events_handle;
Expand Down Expand Up @@ -224,7 +225,13 @@ bool OrchDaemon::init()
gCbfNhgOrch = new CbfNhgOrch(m_applDb, APP_CLASS_BASED_NEXT_HOP_GROUP_TABLE_NAME);

gCoppOrch = new CoppOrch(m_applDb, APP_COPP_TABLE_NAME);
TunnelDecapOrch *tunnel_decap_orch = new TunnelDecapOrch(m_applDb, APP_TUNNEL_DECAP_TABLE_NAME);

vector<string> tunnel_tables = {
APP_TUNNEL_DECAP_TABLE_NAME,
APP_TUNNEL_DECAP_TERM_TABLE_NAME
};
gTunneldecapOrch = new TunnelDecapOrch(m_applDb, m_stateDb, m_configDb, tunnel_tables);
gDirectory.set(gTunneldecapOrch);

VxlanTunnelOrch *vxlan_tunnel_orch = new VxlanTunnelOrch(m_stateDb, m_applDb, APP_VXLAN_TUNNEL_TABLE_NAME);
gDirectory.set(vxlan_tunnel_orch);
Expand Down Expand Up @@ -380,7 +387,7 @@ bool OrchDaemon::init()
CFG_MUX_CABLE_TABLE_NAME,
CFG_PEER_SWITCH_TABLE_NAME
};
MuxOrch *mux_orch = new MuxOrch(m_configDb, mux_tables, tunnel_decap_orch, gNeighOrch, gFdbOrch);
MuxOrch *mux_orch = new MuxOrch(m_configDb, mux_tables, gTunneldecapOrch, gNeighOrch, gFdbOrch);
gDirectory.set(mux_orch);

MuxCableOrch *mux_cb_orch = new MuxCableOrch(m_applDb, m_stateDb, APP_MUX_CABLE_TABLE_NAME);
Expand Down Expand Up @@ -409,7 +416,7 @@ bool OrchDaemon::init()
* when iterating ConsumerMap. This is ensured implicitly by the order of keys in ordered map.
* For cases when Orch has to process tables in specific order, like PortsOrch during warm start, it has to override Orch::doTask()
*/
m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, tunnel_decap_orch, sflow_orch, gDebugCounterOrch, gMacsecOrch, bgp_global_state_orch, gBfdOrch, gSrv6Orch, mux_orch, mux_cb_orch, gMonitorOrch};
m_orchList = { gSwitchOrch, gCrmOrch, gPortsOrch, gBufferOrch, gFlowCounterRouteOrch, gIntfsOrch, gNeighOrch, gNhgMapOrch, gNhgOrch, gCbfNhgOrch, gRouteOrch, gCoppOrch, gQosOrch, wm_orch, gPolicerOrch, gTunneldecapOrch, sflow_orch, gDebugCounterOrch, gMacsecOrch, bgp_global_state_orch, gBfdOrch, gSrv6Orch, mux_orch, mux_cb_orch, gMonitorOrch};

bool initialize_dtel = false;
if (platform == BFN_PLATFORM_SUBSTRING || platform == VS_PLATFORM_SUBSTRING)
Expand Down
Loading

0 comments on commit 353ab92

Please sign in to comment.