TunnelController

class mtf.network_port.tunnel_controller.TunnelController

A controller class for managing network tunneling operations.

__init__(channel_name: str)
set_vlan(tap_name: str = '', inner_vlan: c_ulong = 0, outer_vlan: c_ulong = 0, inner_vlan_ethertype: c_ushort = 33024, outer_vlan_ethertype: c_ushort = 37120, inner_priority_tag: c_ubyte = 0, outer_priority_tag: c_ubyte = 0, inner_cfi: c_bool = False, outer_cfi: c_bool = False) None

Configures VLAN settings for a specified network interface (tap).

Args:

tap_name (str): The name of the tap interface to configure. Default is an empty string. inner_vlan (c_uint32): The inner VLAN ID to be set. Default is 0. outer_vlan (c_uint32): The outer VLAN ID to be set. Default is 0. inner_vlan_ethertype (c_uint16): The ethertype for the inner VLAN. Default is 0x8100. outer_vlan_ethertype (c_uint16): The ethertype for the outer VLAN. Default is 0x9100. inner_priority_tag (c_ubyte): The priority tag for the inner VLAN. Default is 0. outer_priority_tag (c_ubyte): The priority tag for the outer VLAN. Default is 0. inner_cfi (c_bool): The inner VLAN CFI (Canonical Format Indicator). Default is False. outer_cfi (c_bool): The CFI for the outer VLAN. Default is False.

set_physical_callback(callback_function=None, filter: mtf_eth_filter | None = None) None

Sets a callback function to handle physical layer events.

Args:
callback_function (function, optional): A function to handle physical layer events.

If no function is provided, the callback is not set.

filter (mtf_eth_filter, optional): Select a filter that is applied to incoming packets.

Only packets that match this filter will be forwareded to python. All other packets will be left alone

remove_physical_callback() None

Remove the registered physical callback method

set_virtual_callback(tap_name: str = '', callback_function=None, filter: mtf_eth_filter | None = None) None

Sets a callback function to handle virtual layer events for a specified tap.

Args:
tap_name (str, optional): The name of the virtual tap for which the callback

will be set. If no name is provided, the callback is set for all taps.

callback_function (function, optional): A function to handle virtual layer events.

If no function is provided, the callback is not set.

filter (mtf_eth_filter, optional): Select a filter that is applied to incoming packets.

Only packets that match this filter will be forwareded to python. All other packets will be left alone

remove_virtual_callback(tap_name: str = '') None

Remove the registered virtual callback method

If no tap name is specified, the virtual callbacks of all tabs are removed

Args:

tap_name (str, optional): The tap name to remove it from. Defaults to “”.

start() None

Starts the tunnel controller.

stop() None

Stop the tunnel controller.

clean_up() bool

Implementation of the Controler Base cleanup method

Returns:

bool: True if cleanup was successsful

static __new__(cls, *args, **kwargs)

Initializes a new instance of the ControllerBase.

The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.

Note:

Do not override this method in subclasses to maintain this functionality.

Args:

*args: Suitable arguments passed to the constructor of the ControllerBase class. **kwargs: keywords passed to the constructor of the ControllerBase class.

Returns:

instance(ControllerBase): The new instance of the class that has been created.

classmethod controllers_cleanup()

Cleans up all controller instances.

It Calls the clean_up() method for each instance, since it iterates through the list of controllers to realize any needed cleanup which can fail so an error will be raised. Then, the remaining instances will continue processing.

Returns:

bool: True indicating that all the controllers are successfully cleaned up, otherwise False when an error occurred during the operation of the cleanup.