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 “”.
- configure_src_mac_by_src_ip(tap_name: str, src_ip_addr: str, src_mac_addr: str | None = None, on_off=True) bool
Configures/Clears how the source MAC address of Ethernet frames should be modified for traffic from a specified IP address on a particular TAP device (requires packet manipulation to be enabled).
- Args:
tap_name (str): Name of the TAP device over which the manipulation is required src_ip_addr (str): Source IP Address for the frames to be manipulated src_mac_addr (str, optional): Desired source MAC address to be set for the frames to be manipulated on_off (bool): Indicates whether the configuration should be enabled or disabled.
Set to True to apply (set) the configuration, or False to remove (clear) it.
- Returns:
bool: True if src mac set to be manipulated for all frames with the desired source ip address.
- configure_vlans_by_src_ip(tap_name: str, src_ip_addr: str, inner_vlan: VlanTag | None = None, outer_vlan: VlanTag | None = None, on_off=True) bool
Configures/Clears how the Inner and Outer Vlans of Ethernet frames should be modified for traffic from a specified IP address on a particular TAP device (requires packet manipulation to be enabled).
- Args:
tap_name (str): name of the TAP device over which the manipulation is required src_ip_addr (str): Source IP Address for the frames to be manipulated inner_vlan (str, Optional): Desired Inner vlan tag to be set for the Ethernet frames. outer_vlan (str, Optional): Desired Outer vlan tag to be set for the Ethernet frames. on_off (bool): Indicates whether the configuration should be enabled or disabled.
Set to True to apply (set) the configuration, or False to remove (clear) it.
- Returns:
bool: True if the Inner and Outer Vlans set to be manipulated for all frames with the desired source ip address.
- configure_multicast_vlans_by_src_ip(tap_name: str, src_ip_addr: str, inner_vlan: VlanTag | None = None, outer_vlan: VlanTag | None = None, on_off=True) bool
- Configures/Clears how the Inner and Outer Multicast Vlans of Ethernet frames should be modified for traffic from a specified IP address
on a particular TAP device (requires packet manipulation to be enabled).
- Note:
if a default VLAN is already provided or set (throw configure_vlans_by_src_ip), the configured VLANs will not be taken into consideration during handling of the packets.
- Args:
tap_name (str): name of the TAP device over which the manipulation is required src_ip_addr (str): Source IP Address for the frames to be manipulated inner_vlan (str, Optional): Desired Inner vlan tag to be set for the Ethernet frames. outer_vlan (str, Optional): Desired Outer vlan tag to be set for the Ethernet frames. on_off (bool): Indicates whether the configuration should be enabled or disabled.
Set to True to apply (set) the configuration, or False to remove (clear) it.
- Returns:
bool: True if the Inner and Outer Vlans set to be manipulated for all frames with the desired source ip address.
- configure_vlans_for_ip_pair(tap_name: str, src_ip_addr: str, dst_ip_addr: str, inner_vlan: VlanTag | None = None, outer_vlan: VlanTag | None = None, on_off=True) bool
- Configures/Clears how the Inner and Outer VLAN tags of Ethernet frames should be modified for traffic sent from a specific
source IP address to a specific unicast destination IP address on a particular TAP device (requires packet manipulation to be enabled).
- Note:
if a default VLAN is already provided or set (throw configure_vlans_by_src_ip), the configured VLANs will not be taken into consideration during handling of the packets.
- Args:
tap_name (str): name of the TAP device over which the manipulation is required src_ip_addr (str): Source IP Address for the frames to be manipulated inner_vlan (str, Optional): Desired Inner vlan tag to be set for the Ethernet frames. outer_vlan (str, Optional): Desired Outer vlan tag to be set for the Ethernet frames. on_off (bool): Indicates whether the configuration should be enabled or disabled.
Set to True to apply (set) the configuration, or False to remove (clear) it.
- Returns:
bool: True if the Inner and Outer Vlans set to be manipulated for all frames with the desired source ip address.
- 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.