diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/vpp/interface/gre.py | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/python/vyos/vpp/interface/gre.py b/python/vyos/vpp/interface/gre.py index 20a7ae9d4..65559f294 100644 --- a/python/vyos/vpp/interface/gre.py +++ b/python/vyos/vpp/interface/gre.py @@ -30,20 +30,58 @@ def show(): class GREInterface: - def __init__(self, ifname, source_address, remote, kernel_interface: str = ''): + """ + Class representing a GRE (Generic Routing Encapsulation) interface. + + Attributes: + ifname (str): The interface name. + source_address (str): The source IP address for the GRE tunnel. + remote (str): The remote IP address for the GRE tunnel. + tunnel_type (str): The type of GRE tunnel. Defaults to 'l3'. + kernel_interface (str): The associated kernel interface. Defaults to an empty string. + instance (int): The instance number derived from the interface name. + vpp (VPPControl): An instance of the VPPControl class for interacting with the VPP API. + """ + + # Mapping of tunnel types https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api#L25-L35 + TUNNEL_TYPE_MAP = { + "l3": 0, + "teb": 1, + "erspan": 2, + } + + def __init__( + self, + ifname, + source_address, + remote, + tunnel_type: str = 'l3', + kernel_interface: str = '', + ): + """ + Initialize a GREInterface instance. + + Args: + ifname (str): The interface name. + source_address (str): The source IP address for the GRE tunnel. + remote (str): The remote IP address for the GRE tunnel. + tunnel_type (str): The type of GRE tunnel. Defaults to 'l3'. + kernel_interface (str): The associated kernel interface. Defaults to an empty string. + """ self.instance = int(ifname.removeprefix('gre')) self.ifname = ifname self.src_address = source_address self.dst_address = remote + self.tunnel_type = self.TUNNEL_TYPE_MAP[tunnel_type] self.kernel_interface = kernel_interface self.vpp = VPPControl() def add(self): """Create GRE interface - https://github.com/FDio/vpp/blob/stable/2306/src/plugins/gre/gre.api + https://github.com/FDio/vpp/blob/stable/2406/src/plugins/gre/gre.api Example: from vyos.vpp.interface import GREInterface - a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25') + a = GREInterface(ifname='gre0', source_address='192.0.2.1', remote='203.0.113.25', tunnel_type='l3') a.add() """ self.vpp.api.gre_tunnel_add_del( @@ -52,6 +90,7 @@ class GREInterface: 'src': self.src_address, 'dst': self.dst_address, 'instance': self.instance, + 'type': self.tunnel_type, }, ) |
