@@ -266,7 +266,7 @@ std::bitset<VNET_TUNNEL_SIZE> VNetBitmapObject::tunnelIdOffsets_;
266
266
map<string, uint32_t > VNetBitmapObject::vnetIds_;
267
267
map<uint32_t , VnetBridgeInfo> VNetBitmapObject::bridgeInfoMap_;
268
268
map<tuple<MacAddress, sai_object_id_t >, VnetNeighInfo> VNetBitmapObject::neighInfoMap_;
269
- map<tuple<IpAddress, sai_object_id_t >, uint16_t > VNetBitmapObject::endpointMap_;
269
+ map<tuple<IpAddress, sai_object_id_t >, TunnelEndpointInfo > VNetBitmapObject::endpointMap_;
270
270
271
271
VNetBitmapObject::VNetBitmapObject (const std::string& vnet, const VNetInfo& vnetInfo,
272
272
vector<sai_attribute_t >& attrs) : VNetObject(vnetInfo)
@@ -960,12 +960,12 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
960
960
auto *tunnel = vxlan_orch->getVxlanTunnel (getTunnelName ());
961
961
auto endpoint = make_tuple (endp.ip , tunnel->getTunnelId ());
962
962
uint16_t tunnelIndex = 0 ;
963
+ TunnelEndpointInfo endpointInfo;
963
964
if (endpointMap_.find (endpoint) == endpointMap_.end ())
964
965
{
965
966
tunnelIndex = getFreeTunnelId ();
966
967
vector<sai_attribute_t > vxlan_attrs;
967
968
968
- sai_object_id_t tunnelL3VxlanEntryId;
969
969
attr.id = SAI_TABLE_META_TUNNEL_ENTRY_ATTR_ACTION;
970
970
attr.value .s32 = SAI_TABLE_META_TUNNEL_ENTRY_ACTION_TUNNEL_ENCAP;
971
971
vxlan_attrs.push_back (attr);
@@ -983,7 +983,7 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
983
983
vxlan_attrs.push_back (attr);
984
984
985
985
status = sai_bmtor_api->create_table_meta_tunnel_entry (
986
- &tunnelL3VxlanEntryId ,
986
+ &endpointInfo. metaTunnelEntryId ,
987
987
gSwitchId ,
988
988
(uint32_t )vxlan_attrs.size (),
989
989
vxlan_attrs.data ());
@@ -994,11 +994,14 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
994
994
throw std::runtime_error (" VNet route creation failed" );
995
995
}
996
996
997
- endpointMap_.emplace (endpoint, tunnelIndex);
997
+ endpointInfo.tunnelIndex = tunnelIndex;
998
+ endpointInfo.use_count = 1 ;
999
+ endpointMap_.emplace (endpoint, endpointInfo);
998
1000
}
999
1001
else
1000
1002
{
1001
- tunnelIndex = endpointMap_.at (endpoint);
1003
+ tunnelIndex = endpointMap_.at (endpoint).tunnelIndex ;
1004
+ endpointMap_.at (endpoint).use_count ++;
1002
1005
}
1003
1006
1004
1007
/* Tunnel route */
@@ -1049,6 +1052,8 @@ bool VNetBitmapObject::addTunnelRoute(IpPrefix& ipPrefix, tunnelEndpoint& endp)
1049
1052
1050
1053
tunnelRouteInfo.vni = endp.vni == 0 ? getVni () : endp.vni ;
1051
1054
tunnelRouteInfo.mac = mac;
1055
+ tunnelRouteInfo.ip = endp.ip ;
1056
+ tunnelRouteInfo.tunnelId = tunnel->getTunnelId ();
1052
1057
tunnelRouteMap_.emplace (ipPrefix, tunnelRouteInfo);
1053
1058
1054
1059
return true ;
@@ -1081,6 +1086,16 @@ bool VNetBitmapObject::removeTunnelRoute(IpPrefix& ipPrefix)
1081
1086
throw std::runtime_error (" VNET tunnel route removal failed" );
1082
1087
}
1083
1088
1089
+ auto endpoint = make_tuple (tunnelRouteInfo.ip , tunnelRouteInfo.tunnelId );
1090
+
1091
+ if (endpointMap_.find (endpoint) == endpointMap_.end ())
1092
+ {
1093
+ SWSS_LOG_ERROR (" Tunnel endpoint doesn't exist for tunnel route %s" , ipPrefix.to_string ().c_str ());
1094
+ throw std::runtime_error (" VNET tunnel route removal failed" );
1095
+ }
1096
+
1097
+ auto endpointInfo = endpointMap_.at (endpoint);
1098
+
1084
1099
sai_status_t status;
1085
1100
1086
1101
status = sai_bmtor_api->remove_table_bitmap_router_entry (tunnelRouteInfo.tunnelRouteTableEntryId );
@@ -1090,6 +1105,23 @@ bool VNetBitmapObject::removeTunnelRoute(IpPrefix& ipPrefix)
1090
1105
throw std::runtime_error (" VNET tunnel route removal failed" );
1091
1106
}
1092
1107
1108
+ if (endpointInfo.use_count > 1 )
1109
+ {
1110
+ endpointInfo.use_count --;
1111
+ }
1112
+ else
1113
+ {
1114
+ status = sai_bmtor_api->remove_table_meta_tunnel_entry (endpointInfo.metaTunnelEntryId );
1115
+ if (status != SAI_STATUS_SUCCESS)
1116
+ {
1117
+ SWSS_LOG_ERROR (" Failed to remove meta tunnel entry for VNET tunnel route, SAI rc: %d" , status);
1118
+ throw std::runtime_error (" VNET tunnel route removal failed" );
1119
+ }
1120
+
1121
+ recycleTunnelId (endpointInfo.tunnelIndex );
1122
+ endpointMap_.erase (endpoint);
1123
+ }
1124
+
1093
1125
status = sai_next_hop_api->remove_next_hop (tunnelRouteInfo.nexthopId );
1094
1126
if (status != SAI_STATUS_SUCCESS)
1095
1127
{
@@ -1108,7 +1140,6 @@ bool VNetBitmapObject::removeTunnelRoute(IpPrefix& ipPrefix)
1108
1140
}
1109
1141
1110
1142
recycleTunnelRouteTableOffset (tunnelRouteInfo.offset );
1111
-
1112
1143
tunnelRouteMap_.erase (ipPrefix);
1113
1144
1114
1145
return true ;
0 commit comments