Skip to content

Network Interface

The Network Interface is used to manage network configurations using nmcli.

Main network interface management class.

NetworkInterface

Interface for managing network configurations using nmcli.

This interface is designed for HIL (Hardware-in-the-Loop) testing environments where network configurations need to be dynamically changed. It specifically targets USB-to-Ethernet interfaces (with 'enp' prefix) and never modifies eth0 which is reserved for the HIL gateway connection.

Safety Features: - Automatically prevents modification of eth0 interface - Validates interface names before operations - Provides rollback capability through reset_to_default()

Methods:

Name Description
__enter__

Context manager entry.

__exit__

Context manager exit with cleanup.

__init__

Initialize the network interface manager.

cleanup

Clean up any network configurations created by this interface.

configure_nat_mode

Configure the interface to provide NAT (Network Address Translation).

discover_usb_ethernet_interfaces

Discover available USB-to-Ethernet interfaces.

get_interface_name

Get the name of the managed interface.

get_interface_status

Get current status and configuration of the interface.

get_network_statistics

Get network interface statistics and performance metrics.

reset_to_default

Reset the interface to its original configuration.

test_connectivity

Test network connectivity from this interface.

__enter__()

Context manager entry.

__exit__(exc_type, exc_val, exc_tb)

Context manager exit with cleanup.

__init__(interface_name=None)

Initialize the network interface manager.

Parameters:

Name Type Description Default
interface_name Optional[str]

Specific interface name to manage. If None, will use the first discovered USB-to-Ethernet interface.

None

cleanup()

Clean up any network configurations created by this interface.

configure_nat_mode(ip_pool_start='192.168.100.90', pool_size=1)

Configure the interface to provide NAT (Network Address Translation).

This creates a NAT gateway allowing connected devices to access the internet through the specified upstream interface. By default, provides a single IP (192.168.100.90) to ensure the DUT always gets the same IP address.

Parameters:

Name Type Description Default
ip_pool_start str

Starting IP address for DHCP pool (default: 192.168.100.90)

'192.168.100.90'
pool_size int

Number of IPs in the DHCP pool (default: 1 for consistent DUT IP)

1

discover_usb_ethernet_interfaces() staticmethod

Discover available USB-to-Ethernet interfaces.

Returns:

Type Description
List[str]

List of interface names that appear to be USB-to-Ethernet adapters

get_interface_name()

Get the name of the managed interface.

get_interface_status()

Get current status and configuration of the interface.

Returns:

Type Description
Dict[str, Any]

Dictionary containing interface status information

get_network_statistics()

Get network interface statistics and performance metrics.

Returns:

Type Description
Dict[str, Any]

Dictionary containing network statistics

reset_to_default()

Reset the interface to its original configuration.

test_connectivity(target_host='8.8.8.8', count=3, timeout=5)

Test network connectivity from this interface.

Parameters:

Name Type Description Default
target_host str

Host to ping for connectivity test

'8.8.8.8'
count int

Number of ping packets to send

3
timeout int

Timeout in seconds for the ping test

5

Returns:

Type Description
Dict[str, Any]

Dictionary containing connectivity test results