diff --git a/orchagent/vnetorch.cpp b/orchagent/vnetorch.cpp index 00b7494e02..8fe1731d21 100644 --- a/orchagent/vnetorch.cpp +++ b/orchagent/vnetorch.cpp @@ -335,11 +335,20 @@ void VNetBitmapObject::recycleBitmapId(const string& vnet) } } -uint32_t VNetBitmapObject::getFreeTunnelRouteTableOffset() +uint32_t VNetBitmapObject::getFreeTunnelRouteTableOffset(IpPrefix ipPfx) { SWSS_LOG_ENTER(); - for (uint32_t i = 0; i < tunnelOffsets_.size(); i++) + uint32_t offsetStart = VNET_ROUTE_FULL_MASK_OFFSET_MAX + 1; + uint32_t offsetEnd = tunnelOffsets_.size(); + + if (ipPfx.isFullMask()) + { + offsetStart = 0; + offsetEnd = VNET_ROUTE_FULL_MASK_OFFSET_MAX; + } + + for (uint32_t i = offsetStart; i < offsetEnd; i++) { if (tunnelOffsets_[i] == false) { @@ -958,7 +967,7 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp) attr.value.s32 = SAI_TABLE_BITMAP_ROUTER_ENTRY_ACTION_TO_NEXTHOP; tr_attrs.push_back(attr); - tunnelRouteInfo.offset = getFreeTunnelRouteTableOffset(); + tunnelRouteInfo.offset = getFreeTunnelRouteTableOffset(ipPrefix); attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY; attr.value.u32 = tunnelRouteInfo.offset; tr_attrs.push_back(attr); @@ -1175,7 +1184,7 @@ bool VNetBitmapObject::addRoute(IpPrefix& ipPrefix, nextHop& nh) return true; } - routeInfo.offset = getFreeTunnelRouteTableOffset(); + routeInfo.offset = getFreeTunnelRouteTableOffset(ipPrefix); attr.id = SAI_TABLE_BITMAP_ROUTER_ENTRY_ATTR_PRIORITY; attr.value.u32 = routeInfo.offset; attrs.push_back(attr); diff --git a/orchagent/vnetorch.h b/orchagent/vnetorch.h index 1827e8af76..a58fae41ed 100644 --- a/orchagent/vnetorch.h +++ b/orchagent/vnetorch.h @@ -15,6 +15,7 @@ #define VNET_BITMAP_SIZE 32 #define VNET_TUNNEL_SIZE 40960 +#define VNET_ROUTE_FULL_MASK_OFFSET_MAX 3000 #define VNET_NEIGHBOR_MAX 0xffff #define VXLAN_ENCAP_TTL 128 #define VNET_BITMAP_RIF_MTU 9100 @@ -266,7 +267,7 @@ class VNetBitmapObject: public VNetObject static uint32_t getBitmapId(const string& name); static void recycleBitmapId(const string& name); - static uint32_t getFreeTunnelRouteTableOffset(); + static uint32_t getFreeTunnelRouteTableOffset(IpPrefix ipPfx); static void recycleTunnelRouteTableOffset(uint32_t offset); static uint16_t getFreeTunnelId();