Add MPLS config option and interface.is_mpls()

Also add tests and documentation
This commit is contained in:
Pim van Pelt
2023-06-10 15:31:09 +02:00
parent 85e553c437
commit 4681aec952
6 changed files with 28 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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"))

View File

@ -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

View File

@ -50,6 +50,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:
@ -60,6 +61,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)

View File

@ -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