diff --git a/docs/config-guide.md b/docs/config-guide.md index b7fd14f..97c1fb1 100644 --- a/docs/config-guide.md +++ b/docs/config-guide.md @@ -306,6 +306,8 @@ exist as a PHY in VPP (ie. `HundredGigabitEthernet12/0/0`) or as a specified `Bo If it is not specified, the link is considered admin 'up'. * ***device-type***: An optional interface type in VPP. Currently the only supported vlaue is `dpdk`, and it is used to generate correct mock interfaces if the `--novpp` flag is used. +* ***mpls***: An optional boolean that configures MPLS on the interface or sub-interface. The + default value is `false`, if the field is not specified, which means MPLS will not be enabled. Further, top-level interfaces, that is to say those that do not have an encapsulation, are permitted to have any number of sub-interfaces specified by `subid`, an integer between [0,2G), which further @@ -330,6 +332,7 @@ interfaces: lcp: "ice0" mtu: 9000 addresses: [ 192.0.2.1/30, 2001:db8:1::1/64 ] + mpls: true sub-interfaces: 1234: mtu: 9000 @@ -338,6 +341,7 @@ interfaces: 1235: mtu: 1500 lcp: "ice0.qinq" + mpls: true addresses: [ 192.0.2.9/30, 2001:db8:3::1/64 ] encapsulation: dot1q: 1234 diff --git a/vppcfg/config/interface.py b/vppcfg/config/interface.py index 5d73560..ac77adf 100644 --- a/vppcfg/config/interface.py +++ b/vppcfg/config/interface.py @@ -701,3 +701,14 @@ def validate_interfaces(yaml): result = False return result, msgs + + +def is_mpls(yaml, ifname): + """Returns True if the interface exists and has mpls enabled. Returns false otherwise.""" + ifname, iface = get_by_name(yaml, ifname) + try: + if iface["mpls"] == True: + return True + except: + pass + return False diff --git a/vppcfg/config/test_interface.py b/vppcfg/config/test_interface.py index c677874..3d765c4 100644 --- a/vppcfg/config/test_interface.py +++ b/vppcfg/config/test_interface.py @@ -277,3 +277,10 @@ class TestInterfaceMethods(unittest.TestCase): self.assertFalse( interface.get_admin_state(self.cfg, "GigabitEthernet1/0/0.102") ) + + def test_is_mpls(self): + self.assertTrue(interface.is_mpls(self.cfg, "GigabitEthernet1/0/1")) + self.assertTrue(interface.is_mpls(self.cfg, "GigabitEthernet1/0/1.101")) + self.assertFalse(interface.is_mpls(self.cfg, "GigabitEthernet1/0/0")) + self.assertFalse(interface.is_mpls(self.cfg, "GigabitEthernet1/0/0.100")) + self.assertFalse(interface.is_mpls(self.cfg, "notexist")) diff --git a/vppcfg/example.yaml b/vppcfg/example.yaml index a5990d8..b735c49 100644 --- a/vppcfg/example.yaml +++ b/vppcfg/example.yaml @@ -20,7 +20,8 @@ interfaces: lcp: "ice12-0-0" mac: f2:01:00:12:00:00 mtu: 9000 - addresses: [ 192.0.2.17/30, 2001:DB8:3::1/64 ] + addresses: [ 192.0.2.17/30, 2001:db8:3::1/64 ] + mpls: true sub-interfaces: 1234: mtu: 1200 diff --git a/vppcfg/schema.yaml b/vppcfg/schema.yaml index 5bd935e..cd7f6df 100644 --- a/vppcfg/schema.yaml +++ b/vppcfg/schema.yaml @@ -52,6 +52,7 @@ interface: sub-interfaces: map(include('sub-interface'),key=int(min=1,max=4294967295),required=False) l2xc: str(required=False) state: enum('up', 'down', required=False) + mpls: bool(required=False) device-type: enum('dpdk', required=False) --- sub-interface: @@ -62,6 +63,7 @@ sub-interface: encapsulation: include('encapsulation',required=False) l2xc: str(required=False) state: enum('up', 'down', required=False) + mpls: bool(required=False) --- encapsulation: dot1q: int(min=1,max=4095,required=False) diff --git a/vppcfg/unittest/test_interface.yaml b/vppcfg/unittest/test_interface.yaml index 648c2eb..b48811c 100644 --- a/vppcfg/unittest/test_interface.yaml +++ b/vppcfg/unittest/test_interface.yaml @@ -23,6 +23,7 @@ interfaces: mtu: 9216 lcp: "e1" addresses: [ "192.0.2.1/30", "2001:db8:1::1/64" ] + mpls: true sub-interfaces: 100: lcp: "foo" @@ -33,6 +34,7 @@ interfaces: exact-match: True lcp: "e1.100" addresses: [ "10.0.2.1/30" ] + mpls: true 102: encapsulation: dot1ad: 100