Skip to content

Commit

Permalink
[vxlan] Remove tunnel map objects on VNET tunnel removal (sonic-net#2150
Browse files Browse the repository at this point in the history
)

* [vxlan] Remove tunnel map objects on VNET tunnel removal
Signed-off-by: Volodymyr Samotiy <volodymyrs@nvidia.com>
  • Loading branch information
volodymyrsamotiy authored Mar 28, 2022
1 parent 20dde0c commit 680c539
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
28 changes: 6 additions & 22 deletions orchagent/vxlanorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,28 +1542,12 @@ bool VxlanTunnelOrch::removeVxlanTunnelMap(string tunnelName, uint32_t vni)
tunnel_obj->vlan_vrf_vni_count--;
if (tunnel_obj->vlan_vrf_vni_count == 0)
{
auto tunnel_term_id = vxlan_tunnel_table_[tunnelName].get()->getTunnelTermId();
try
{
remove_tunnel_termination(tunnel_term_id);
}
catch(const std::runtime_error& error)
{
SWSS_LOG_ERROR("Error removing tunnel term entry. Tunnel: %s. Error: %s", tunnelName.c_str(), error.what());
return false;
}

auto tunnel_id = vxlan_tunnel_table_[tunnelName].get()->getTunnelId();
try
{
removeTunnelFromFlexCounter(tunnel_id, tunnelName);
remove_tunnel(tunnel_id);
}
catch(const std::runtime_error& error)
{
SWSS_LOG_ERROR("Error removing tunnel entry. Tunnel: %s. Error: %s", tunnelName.c_str(), error.what());
return false;
}
uint8_t mapper_list = 0;

TUNNELMAP_SET_VLAN(mapper_list);
TUNNELMAP_SET_VRF(mapper_list);

tunnel_obj->deleteTunnelHw(mapper_list, TUNNEL_MAP_USE_DEDICATED_ENCAP_DECAP);
}

SWSS_LOG_NOTICE("Vxlan map entry deleted for tunnel '%s' with vni '%d'", tunnelName.c_str(), vni);
Expand Down
27 changes: 27 additions & 0 deletions tests/test_vnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def create_vxlan_tunnel(dvs, name, src_ip):
attrs,
)

def delete_vxlan_tunnel(dvs, name):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
delete_entry_tbl(conf_db, "VXLAN_TUNNEL", name)

def create_vxlan_tunnel_map(dvs, tunnel_name, tunnel_map_entry_name, vlan, vni_id):
conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -621,6 +624,18 @@ def check_vxlan_tunnel(self, dvs, tunnel_name, src_ip):
self.tunnel_map_map[tunnel_name] = tunnel_map_id
self.tunnel[tunnel_name] = tunnel_id

def check_del_vxlan_tunnel(self, dvs):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)

old_tunnel = get_deleted_entries(asic_db, self.ASIC_TUNNEL_TABLE, self.tunnel_ids, 1)
check_deleted_object(asic_db, self.ASIC_TUNNEL_TABLE, old_tunnel[0])
self.tunnel_ids.remove(old_tunnel[0])

old_tunnel_maps = get_deleted_entries(asic_db, self.ASIC_TUNNEL_MAP, self.tunnel_map_ids, 4)
for old_tunnel_map in old_tunnel_maps:
check_deleted_object(asic_db, self.ASIC_TUNNEL_MAP, old_tunnel_map)
self.tunnel_map_ids.remove(old_tunnel_map)

def check_vxlan_tunnel_entry(self, dvs, tunnel_name, vnet_name, vni_id):
asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
app_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -1049,6 +1064,9 @@ def test_vnet_orch_1(self, dvs, testlog):
delete_vnet_entry(dvs, 'Vnet_2000')
vnet_obj.check_del_vnet_entry(dvs, 'Vnet_2000')

delete_vxlan_tunnel(dvs, tunnel_name)
vnet_obj.check_del_vxlan_tunnel(dvs)

'''
Test 2 - Two VNets, One HSMs per VNet
'''
Expand Down Expand Up @@ -1175,6 +1193,9 @@ def test_vnet_orch_2(self, dvs, testlog):
delete_vnet_entry(dvs, 'Vnet_2')
vnet_obj.check_del_vnet_entry(dvs, 'Vnet_2')

delete_vxlan_tunnel(dvs, tunnel_name)
vnet_obj.check_del_vxlan_tunnel(dvs)

'''
Test 3 - Two VNets, One HSMs per VNet, Peering
'''
Expand Down Expand Up @@ -1255,6 +1276,9 @@ def test_vnet_orch_3(self, dvs, testlog):
delete_vnet_entry(dvs, 'Vnet_20')
vnet_obj.check_del_vnet_entry(dvs, 'Vnet_20')

delete_vxlan_tunnel(dvs, tunnel_name)
vnet_obj.check_del_vxlan_tunnel(dvs)

'''
Test 4 - IPv6 Vxlan tunnel test
'''
Expand Down Expand Up @@ -1396,6 +1420,9 @@ def test_vnet_orch_4(self, dvs, testlog):
delete_vnet_entry(dvs, 'Vnet3001')
vnet_obj.check_del_vnet_entry(dvs, 'Vnet3001')

delete_vxlan_tunnel(dvs, tunnel_name)
vnet_obj.check_del_vxlan_tunnel(dvs)

'''
Test 5 - Default VNet test
'''
Expand Down

0 comments on commit 680c539

Please sign in to comment.