@@ -796,6 +796,77 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
796
796
return true ;
797
797
}
798
798
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
+
799
870
/*
800
871
* VNet Orch class definitions
801
872
*/
@@ -1292,6 +1363,27 @@ bool VNetRouteOrch::doRouteTask<VNetBitmapObject>(const string& vnet, IpPrefix&
1292
1363
return true ;
1293
1364
}
1294
1365
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
+
1295
1387
bool VNetRouteOrch::handleRoutes (const Request& request)
1296
1388
{
1297
1389
SWSS_LOG_ENTER ();
@@ -1329,6 +1421,10 @@ bool VNetRouteOrch::handleRoutes(const Request& request)
1329
1421
{
1330
1422
return doRouteTask<VNetVrfObject>(vnet_name, ip_pfx, nh, op);
1331
1423
}
1424
+ else
1425
+ {
1426
+ return doRouteTask<VNetBitmapObject>(vnet_name, ip_pfx, nh, op);
1427
+ }
1332
1428
1333
1429
return true ;
1334
1430
}
0 commit comments