Skip to content

Commit

Permalink
Vxlan external ip feature (#330)
Browse files Browse the repository at this point in the history
* add vxlan external ip attribute

* add fragment file

* bugfix deleting vxlan should check external ip

* fix sanity test error
  • Loading branch information
xhan-dell authored Feb 2, 2024
1 parent b5613f2 commit 9e1cb5d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- sonic_vxlans - Add support for the "external_ip" vxlan option (https://github.com/ansible-collections/dellemc.enterprise_sonic/pull/330).
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, **kwargs):
'name': {'required': True, 'type': 'str'},
'source_ip': {'type': 'str'},
'primary_ip': {'type': 'str'},
'external_ip': {'type': 'str'},
'vlan_map': {
'elements': 'dict',
'options': {
Expand Down
29 changes: 28 additions & 1 deletion plugins/module_utils/network/sonic/config/vxlans/vxlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def get_delete_all_vxlan_request(self, have):
vlan_map_requests = []
src_ip_requests = []
primary_ip_requests = []
external_ip_requests = []
evpn_nvo_requests = []
tunnel_requests = []

Expand All @@ -291,6 +292,7 @@ def get_delete_all_vxlan_request(self, have):
vrf_map_list = conf.get('vrf_map', [])
src_ip = conf.get('source_ip', None)
primary_ip = conf.get('primary_ip', None)
external_ip = conf.get('external_ip', None)
evpn_nvo = conf.get('evpn_nvo', None)

if vrf_map_list:
Expand All @@ -301,6 +303,8 @@ def get_delete_all_vxlan_request(self, have):
src_ip_requests.extend(self.get_delete_src_ip_request(conf, conf, name, src_ip))
if primary_ip:
primary_ip_requests.extend(self.get_delete_primary_ip_request(conf, conf, name, primary_ip))
if external_ip:
external_ip_requests.extend(self.get_delete_external_ip_request(conf, conf, name, external_ip))
if evpn_nvo:
evpn_nvo_requests.extend(self.get_delete_evpn_request(conf, conf, evpn_nvo))
tunnel_requests.extend(self.get_delete_tunnel_request(conf, conf, name))
Expand All @@ -315,6 +319,8 @@ def get_delete_all_vxlan_request(self, have):
requests.extend(primary_ip_requests)
if evpn_nvo_requests:
requests.extend(evpn_nvo_requests)
if external_ip_requests:
requests.extend(external_ip_requests)
if tunnel_requests:
requests.extend(tunnel_requests)

Expand All @@ -331,6 +337,7 @@ def get_delete_vxlan_request(self, configs, have):
src_ip_requests = []
evpn_nvo_requests = []
primary_ip_requests = []
external_ip_requests = []
tunnel_requests = []

# Need to delete in the reverse order of creation.
Expand All @@ -342,6 +349,7 @@ def get_delete_vxlan_request(self, configs, have):
src_ip = conf.get('source_ip', None)
evpn_nvo = conf.get('evpn_nvo', None)
primary_ip = conf.get('primary_ip', None)
external_ip = conf.get('external_ip', None)
vlan_map_list = conf.get('vlan_map', None)
vrf_map_list = conf.get('vrf_map', None)

Expand All @@ -358,7 +366,8 @@ def get_delete_vxlan_request(self, configs, have):

is_delete_full = False
if (name and vlan_map_list is None and vrf_map_list is None and
src_ip is None and evpn_nvo is None and primary_ip is None):
src_ip is None and evpn_nvo is None and primary_ip is None and
external_ip is None):
is_delete_full = True
vrf_map_list = matched.get("vrf_map", [])
vlan_map_list = matched.get("vlan_map", [])
Expand All @@ -384,6 +393,8 @@ def get_delete_vxlan_request(self, configs, have):
evpn_nvo_requests.extend(self.get_delete_evpn_request(conf, matched, evpn_nvo))
if primary_ip:
primary_ip_requests.extend(self.get_delete_primary_ip_request(conf, matched, name, primary_ip))
if external_ip:
external_ip_requests.extend(self.get_delete_external_ip_request(conf, matched, name, external_ip))
if is_delete_full:
tunnel_requests.extend(self.get_delete_tunnel_request(conf, matched, name))

Expand All @@ -397,6 +408,8 @@ def get_delete_vxlan_request(self, configs, have):
requests.extend(evpn_nvo_requests)
if primary_ip_requests:
requests.extend(primary_ip_requests)
if external_ip_requests:
requests.extend(external_ip_requests)
if tunnel_requests:
requests.extend(tunnel_requests)

Expand Down Expand Up @@ -439,6 +452,8 @@ def build_create_tunnel_payload(self, conf):
vtep_ip_dict['src_ip'] = conf['source_ip']
if conf.get('primary_ip', None):
vtep_ip_dict['primary_ip'] = conf['primary_ip']
if conf.get('external_ip', None):
vtep_ip_dict['external_ip'] = conf['external_ip']

payload_url['sonic-vxlan:VXLAN_TUNNEL'] = {'VXLAN_TUNNEL_LIST': [vtep_ip_dict]}

Expand Down Expand Up @@ -584,6 +599,18 @@ def get_delete_primary_ip_request(self, conf, matched, name, del_primary_ip):

return requests

def get_delete_external_ip_request(self, conf, matched, name, external_ip):
requests = []
url = "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST={name}/external_ip"

if matched:
matched_external_ip = matched.get('external_ip', None)
if matched_external_ip and matched_external_ip == external_ip:
request = {"path": url.format(name=name), "method": DELETE}
requests.append(request)

return requests

def get_delete_vlan_map_request(self, conf, matched, name, del_vlan_map_list):
# Create URL and payload
requests = []
Expand Down
1 change: 1 addition & 0 deletions plugins/module_utils/network/sonic/facts/vxlans/vxlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def fill_tunnel_source_ip(self, vxlans, vxlan_tunnels, vxlans_evpn_nvo_list):
vxlan['name'] = each_tunnel['name']
vxlan['source_ip'] = each_tunnel.get('src_ip', None)
vxlan['primary_ip'] = each_tunnel.get('primary_ip', None)
vxlan["external_ip"] = each_tunnel.get('external_ip', None)
vxlan['evpn_nvo'] = None
evpn_nvo = next((nvo_map['name'] for nvo_map in vxlans_evpn_nvo_list if nvo_map['source_vtep'] == vxlan['name']), None)
if evpn_nvo:
Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/sonic_vxlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
primary_ip:
description: 'The vtep mclag primary ip address for this node'
type: str
external_ip:
description: 'The vtep mclag external ip address for this node'
type: str
vlan_map:
description: 'The list of VNI map of VLAN.'
type: list
Expand Down
5 changes: 5 additions & 0 deletions tests/regression/roles/sonic_vxlan/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tests_cli:
- name: vtep1
source_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
evpn_nvo: nvo5
vlan_map:
- vni: 101
Expand All @@ -56,6 +57,7 @@ tests:
- name: vtep1
source_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
- name: test_case_03
description: Update VRF properties
state: merged
Expand Down Expand Up @@ -94,6 +96,7 @@ tests:
- name: vtep2
source_ip: 3.3.3.3
primary_ip: 4.4.4.4
external_ip: 5.5.5.5
evpn_nvo: nvo5
vlan_map:
- vni: 101
Expand All @@ -108,6 +111,7 @@ tests:
- name: vtep2
source_ip: 5.5.5.5
primary_ip: 6.6.6.6
external_ip: 7.7.7.7
evpn_nvo: nvo6
vlan_map:
- vni: 101
Expand All @@ -126,6 +130,7 @@ tests:
- name: vtep2
source_ip: 5.5.5.5
primary_ip: 6.6.6.6
external_ip: 7.7.7.7
evpn_nvo: nvo6
vlan_map:
- vni: 101
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/modules/network/sonic/fixtures/sonic_vxlans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ merged_01:
- name: vteptest1
source_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
evpn_nvo: nvo1
vlan_map:
- vni: 101
Expand Down Expand Up @@ -52,6 +53,7 @@ merged_01:
- name: vteptest1
src_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL_MAP"
method: "patch"
data:
Expand Down Expand Up @@ -102,6 +104,7 @@ deleted_01:
- name: vteptest1
src_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
VXLAN_TUNNEL_MAP:
VXLAN_TUNNEL_MAP_LIST:
- name: vteptest1
Expand All @@ -128,6 +131,9 @@ deleted_01:
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST=vteptest1/src_ip"
method: "delete"
data:
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST=vteptest1/external_ip"
method: "delete"
data:
- path: "data/sonic-vxlan:sonic-vxlan/EVPN_NVO/EVPN_NVO_LIST=nvo1"
method: "delete"
data:
Expand All @@ -145,6 +151,7 @@ deleted_02:
- name: vteptest1
source_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
evpn_nvo: nvo1
vlan_map:
- vni: 101
Expand Down Expand Up @@ -184,6 +191,7 @@ deleted_02:
- name: vteptest1
src_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
VXLAN_TUNNEL_MAP:
VXLAN_TUNNEL_MAP_LIST:
- name: vteptest1
Expand All @@ -210,6 +218,9 @@ deleted_02:
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST=vteptest1/src_ip"
method: "delete"
data:
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL/VXLAN_TUNNEL_LIST=vteptest1/external_ip"
method: "delete"
data:
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL_MAP/VXLAN_TUNNEL_MAP_LIST=vteptest1,map_101_Vlan11"
method: "delete"
data:
Expand All @@ -224,6 +235,7 @@ replaced_02:
- name: vteptest1
source_ip: 1.1.1.9
primary_ip: 2.2.2.9
external_ip: 3.3.3.9
evpn_nvo: nvo1
vlan_map:
- vni: 101
Expand Down Expand Up @@ -265,6 +277,7 @@ replaced_02:
- name: vteptest1
src_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
VXLAN_TUNNEL_MAP:
VXLAN_TUNNEL_MAP_LIST:
- name: vteptest1
Expand Down Expand Up @@ -298,6 +311,7 @@ replaced_02:
- name: vteptest1
src_ip: 1.1.1.9
primary_ip: 2.2.2.9
external_ip: 3.3.3.9
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL_MAP"
method: "patch"
data:
Expand All @@ -324,6 +338,7 @@ overridden_02:
- name: vteptest1
source_ip: 1.1.1.9
primary_ip: 2.2.2.9
external_ip: 3.3.3.9
evpn_nvo: nvo1
vlan_map:
- vni: 101
Expand Down Expand Up @@ -365,6 +380,7 @@ overridden_02:
- name: vteptest1
src_ip: 1.1.1.1
primary_ip: 2.2.2.2
external_ip: 3.3.3.3
VXLAN_TUNNEL_MAP:
VXLAN_TUNNEL_MAP_LIST:
- name: vteptest1
Expand Down Expand Up @@ -398,6 +414,7 @@ overridden_02:
- name: vteptest1
src_ip: 1.1.1.9
primary_ip: 2.2.2.9
external_ip: 3.3.3.9
- path: "data/sonic-vxlan:sonic-vxlan/VXLAN_TUNNEL_MAP"
method: "patch"
data:
Expand Down

0 comments on commit 9e1cb5d

Please sign in to comment.