diff --git a/unittest/error-vxlan1.yaml b/unittest/error-vxlan1.yaml new file mode 100644 index 0000000..f126395 --- /dev/null +++ b/unittest/error-vxlan1.yaml @@ -0,0 +1,16 @@ +test: + description: "A VXLAN source and destination must be the same address family" + errors: + expected: + - "vxlan_tunnel .* local and remote are not the same address family" + count: 1 +--- +vxlan_tunnels: + vxlan_tunnel0: + local: 192.0.2.1 + remote: 2001:db8::1 + vni: 100 + +interfaces: + vxlan_tunnel0: + description: "My little tunnel" diff --git a/unittest/error-vxlan2.yaml b/unittest/error-vxlan2.yaml new file mode 100644 index 0000000..4a6a7a1 --- /dev/null +++ b/unittest/error-vxlan2.yaml @@ -0,0 +1,24 @@ +test: + description: "VXLAN VNIs must be unique" + errors: + expected: + - "vxlan_tunnel .* VNI .* is not unique" + count: 2 +--- +vxlan_tunnels: + vxlan_tunnel0: + local: 192.0.2.1 + remote: 192.0.2.2 + vni: 100 + + vxlan_tunnel1: + local: 2001:db8::1 + remote: 2001:db8::2 + vni: 100 + +interfaces: + vxlan_tunnel0: + description: "This tunnel has the same VNI as vxlan_tunnel1" + + vxlan_tunnel1: + description: "This tunnel has the same VNI as vxlan_tunnel0" diff --git a/validator/vxlan_tunnel.py b/validator/vxlan_tunnel.py index dae55f5..e614bdc 100644 --- a/validator/vxlan_tunnel.py +++ b/validator/vxlan_tunnel.py @@ -13,6 +13,7 @@ # import logging import validator.interface as interface +import ipaddress class NullHandler(logging.Handler): def emit(self, record): @@ -54,4 +55,14 @@ def validate_vxlan_tunnels(yaml): for ifname, iface in yaml['vxlan_tunnels'].items(): logger.debug("vxlan_tunnel %s: %s" % (ifname, iface)) + vni = iface['vni'] + if not vni_unique(yaml, vni): + msgs.append("vxlan_tunnel %s VNI %d is not unique" % (ifname, vni)) + result = False + local = ipaddress.ip_address(iface['local']) + remote = ipaddress.ip_address(iface['remote']) + if local.version != remote.version: + msgs.append("vxlan_tunnel %s local and remote are not the same address family" % (ifname)) + result = False + return result, msgs