Skip to content

Commit be974bf

Browse files
authored
[neighbor_advertiser] Use existing tunnel if present for creating tunnel mappings (sonic-net#1589)
1 parent 9492eab commit be974bf

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

scripts/neighbor_advertiser

+14-4
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ def get_loopback_addr(ip_ver):
169169
def get_vlan_interfaces():
170170
vlan_info = config_db.get_table('VLAN')
171171
vlan_interfaces = []
172-
172+
vlan_intfs = config_db.get_table('VLAN_INTERFACE')
173+
# Skip L2 VLANs
173174
for vlan_name in vlan_info:
174-
vlan_interfaces.append(vlan_name)
175+
if vlan_name in vlan_intfs:
176+
vlan_interfaces.append(vlan_name)
175177

176178
return vlan_interfaces
177179

@@ -502,6 +504,14 @@ def reset_mirror_tunnel():
502504
# Set vxlan tunnel
503505
#
504506

507+
def check_existing_tunnel():
508+
vxlan_tunnel = config_db.get_table('VXLAN_TUNNEL')
509+
if len(vxlan_tunnel):
510+
global VXLAN_TUNNEL_NAME
511+
VXLAN_TUNNEL_NAME = list(vxlan_tunnel.keys())[0]
512+
return True
513+
return False
514+
505515
def add_vxlan_tunnel(dst_ipv4_addr):
506516
vxlan_tunnel_info = {
507517
'src_ip': get_loopback_addr(4),
@@ -517,12 +527,12 @@ def add_vxlan_tunnel_map():
517527
'vni': get_vlan_interface_vxlan_id(vlan_intf_name),
518528
'vlan': vlan_intf_name
519529
}
520-
521530
config_db.set_entry('VXLAN_TUNNEL_MAP', (VXLAN_TUNNEL_NAME, VXLAN_TUNNEL_MAP_PREFIX + str(index)), vxlan_tunnel_map_info)
522531

523532

524533
def set_vxlan_tunnel(ferret_server_ip):
525-
add_vxlan_tunnel(ferret_server_ip)
534+
if not check_existing_tunnel():
535+
add_vxlan_tunnel(ferret_server_ip)
526536
add_vxlan_tunnel_map()
527537
log.log_info('Finish setting vxlan tunnel; Ferret: {}'.format(ferret_server_ip))
528538

tests/neighbor_advertiser_test.py

+9
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,12 @@ def test_neighbor_advertiser_slice(self, set_up):
5757
}
5858
)
5959
assert output == expected_output
60+
61+
def test_set_vxlan(self, set_up):
62+
assert(neighbor_advertiser.check_existing_tunnel())
63+
neighbor_advertiser.add_vxlan_tunnel_map()
64+
tunnel_mapping = neighbor_advertiser.config_db.get_table('VXLAN_TUNNEL_MAP')
65+
expected_mapping = {("vtep1", "map_1"): {"vni": "1000", "vlan": "Vlan1000"}, ("vtep1", "map_2"): {"vni": "2000", "vlan": "Vlan2000"}}
66+
for key in expected_mapping.keys():
67+
assert(key in tunnel_mapping.keys())
68+
assert(expected_mapping[key] == tunnel_mapping[key])

0 commit comments

Comments
 (0)