Skip to content

Commit 3b34b21

Browse files
Volodymyr Samotiyprsunny
Volodymyr Samotiy
authored andcommitted
[vnetorch]: Add support of local routes for Bitmap VNET implementation (sonic-net#801)
Signed-off-by: Volodymyr Samotiy <[email protected]>
1 parent 62b7ca4 commit 3b34b21

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

orchagent/vnetorch.cpp

+96
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,77 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
796796
return true;
797797
}
798798

799+
bool VNetBitmapObject::addRoute(IpPrefix& ipPrefix, nextHop& nh)
800+
{
801+
SWSS_LOG_ENTER();
802+
803+
sai_status_t status;
804+
sai_attribute_t attr;
805+
vector<sai_attribute_t> attrs;
806+
sai_ip_prefix_t pfx;
807+
sai_object_id_t tunnelRouteTableEntryId;
808+
uint32_t peerBitmap = vnet_id_;
809+
Port port;
810+
811+
if ((!gPortsOrch->getPort(nh.ifname, port) || (port.m_rif_id == SAI_NULL_OBJECT_ID)))
812+
{
813+
SWSS_LOG_WARN("Port/RIF %s doesn't exist", nh.ifname.c_str());
814+
return false;
815+
}
816+
817+
for (const auto& vnet : getPeerList())
818+
{
819+
uint32_t id = getBitmapId(vnet);
820+
if (id == 0)
821+
{
822+
SWSS_LOG_WARN("Peer vnet %s not ready", vnet.c_str());
823+
return false;
824+
}
825+
peerBitmap |= id;
826+
}
827+
828+
/* Local route */
829+
copy(pfx, ipPrefix);
830+
831+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ACTION;
832+
attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_LOCAL;
833+
attrs.push_back(attr);
834+
835+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY;
836+
attr.value.u32 = getFreeTunnelRouteTableOffset();
837+
attrs.push_back(attr);
838+
839+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_KEY;
840+
attr.value.u64 = 0;
841+
attrs.push_back(attr);
842+
843+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_IN_RIF_METADATA_MASK;
844+
attr.value.u64 = ~peerBitmap;
845+
attrs.push_back(attr);
846+
847+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_DST_IP_KEY;
848+
attr.value.ipprefix = pfx;
849+
attrs.push_back(attr);
850+
851+
attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_ROUTER_INTERFACE;
852+
attr.value.oid = port.m_rif_id;
853+
attrs.push_back(attr);
854+
855+
status = sai_bmtor_api->create_table_bitmap_router_entry(
856+
&tunnelRouteTableEntryId,
857+
gSwitchId,
858+
(uint32_t)attrs.size(),
859+
attrs.data());
860+
861+
if (status != SAI_STATUS_SUCCESS)
862+
{
863+
SWSS_LOG_ERROR("Failed to create local VNET route entry, SAI rc: %d", status);
864+
throw std::runtime_error("VNet route creation failed");
865+
}
866+
867+
return true;
868+
}
869+
799870
/*
800871
* VNet Orch class definitions
801872
*/
@@ -1292,6 +1363,27 @@ bool VNetRouteOrch::doRouteTask<VNetBitmapObject>(const string& vnet, IpPrefix&
12921363
return true;
12931364
}
12941365

1366+
template<>
1367+
bool VNetRouteOrch::doRouteTask<VNetBitmapObject>(const string& vnet, IpPrefix& ipPrefix, nextHop& nh, string& op)
1368+
{
1369+
SWSS_LOG_ENTER();
1370+
1371+
if (!vnet_orch_->isVnetExists(vnet))
1372+
{
1373+
SWSS_LOG_WARN("VNET %s doesn't exist", vnet.c_str());
1374+
return false;
1375+
}
1376+
1377+
auto *vnet_obj = vnet_orch_->getTypePtr<VNetBitmapObject>(vnet);
1378+
1379+
if (op == SET_COMMAND)
1380+
{
1381+
return vnet_obj->addRoute(ipPrefix, nh);
1382+
}
1383+
1384+
return true;
1385+
}
1386+
12951387
bool VNetRouteOrch::handleRoutes(const Request& request)
12961388
{
12971389
SWSS_LOG_ENTER();
@@ -1329,6 +1421,10 @@ bool VNetRouteOrch::handleRoutes(const Request& request)
13291421
{
13301422
return doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, nh, op);
13311423
}
1424+
else
1425+
{
1426+
return doRouteTask<VNetBitmapObject>(vnet_name, ip_pfx, nh, op);
1427+
}
13321428

13331429
return true;
13341430
}

orchagent/vnetorch.h

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ class VNetBitmapObject: public VNetObject
181181

182182
virtual bool addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp);
183183

184+
virtual bool addRoute(IpPrefix& ipPrefix, nextHop& nh);
185+
184186
void setVniInfo(uint32_t vni);
185187

186188
bool updateObj(vector<sai_attribute_t>&);

0 commit comments

Comments
 (0)