Skip to content

[neighbor_advertiser] Use existing tunnel if present for creating tunnel mappings #1589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions scripts/neighbor_advertiser
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ def get_loopback_addr(ip_ver):
def get_vlan_interfaces():
vlan_info = config_db.get_table('VLAN')
vlan_interfaces = []

vlan_intfs = config_db.get_table('VLAN_INTERFACE')
# Skip L2 VLANs
for vlan_name in vlan_info:
vlan_interfaces.append(vlan_name)
if vlan_name in vlan_intfs:
vlan_interfaces.append(vlan_name)

return vlan_interfaces

Expand Down Expand Up @@ -502,6 +504,14 @@ def reset_mirror_tunnel():
# Set vxlan tunnel
#

def check_existing_tunnel():
vxlan_tunnel = config_db.get_table('VXLAN_TUNNEL')
if len(vxlan_tunnel):
global VXLAN_TUNNEL_NAME
VXLAN_TUNNEL_NAME = list(vxlan_tunnel.keys())[0]
return True
return False

def add_vxlan_tunnel(dst_ipv4_addr):
vxlan_tunnel_info = {
'src_ip': get_loopback_addr(4),
Expand All @@ -517,12 +527,12 @@ def add_vxlan_tunnel_map():
'vni': get_vlan_interface_vxlan_id(vlan_intf_name),
'vlan': vlan_intf_name
}

config_db.set_entry('VXLAN_TUNNEL_MAP', (VXLAN_TUNNEL_NAME, VXLAN_TUNNEL_MAP_PREFIX + str(index)), vxlan_tunnel_map_info)


def set_vxlan_tunnel(ferret_server_ip):
add_vxlan_tunnel(ferret_server_ip)
if not check_existing_tunnel():
add_vxlan_tunnel(ferret_server_ip)
add_vxlan_tunnel_map()
log.log_info('Finish setting vxlan tunnel; Ferret: {}'.format(ferret_server_ip))

Expand Down
9 changes: 9 additions & 0 deletions tests/neighbor_advertiser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ def test_neighbor_advertiser_slice(self, set_up):
}
)
assert output == expected_output

def test_set_vxlan(self, set_up):
assert(neighbor_advertiser.check_existing_tunnel())
neighbor_advertiser.add_vxlan_tunnel_map()
tunnel_mapping = neighbor_advertiser.config_db.get_table('VXLAN_TUNNEL_MAP')
expected_mapping = {("vtep1", "map_1"): {"vni": "1000", "vlan": "Vlan1000"}, ("vtep1", "map_2"): {"vni": "2000", "vlan": "Vlan2000"}}
for key in expected_mapping.keys():
assert(key in tunnel_mapping.keys())
assert(expected_mapping[key] == tunnel_mapping[key])