1# SPDX-License-Identifier: BSD-3-Clause 2# Copyright(c) 2022 University of New Hampshire 3# Copyright(c) 2023 PANTHEON.tech s.r.o. 4 5"""NIC port model. 6 7Basic port information, such as location (the port are identified by their PCI address on a node), 8drivers and address. 9""" 10 11 12from dataclasses import dataclass 13 14from framework.config import PortConfig 15 16 17@dataclass(slots=True, frozen=True) 18class PortIdentifier: 19 """The port identifier. 20 21 Attributes: 22 node: The node where the port resides. 23 pci: The PCI address of the port on `node`. 24 """ 25 26 node: str 27 pci: str 28 29 30@dataclass(slots=True) 31class Port: 32 """Physical port on a node. 33 34 The ports are identified by the node they're on and their PCI addresses. The port on the other 35 side of the connection is also captured here. 36 Each port is serviced by a driver, which may be different for the operating system (`os_driver`) 37 and for DPDK (`os_driver_for_dpdk`). For some devices, they are the same, e.g.: ``mlx5_core``. 38 39 Attributes: 40 identifier: The PCI address of the port on a node. 41 os_driver: The operating system driver name when the operating system controls the port, 42 e.g.: ``i40e``. 43 os_driver_for_dpdk: The operating system driver name for use with DPDK, e.g.: ``vfio-pci``. 44 peer: The identifier of a port this port is connected with. 45 The `peer` is on a different node. 46 mac_address: The MAC address of the port. 47 logical_name: The logical name of the port. Must be discovered. 48 """ 49 50 identifier: PortIdentifier 51 os_driver: str 52 os_driver_for_dpdk: str 53 peer: PortIdentifier 54 mac_address: str = "" 55 logical_name: str = "" 56 57 def __init__(self, node_name: str, config: PortConfig): 58 """Initialize the port from `node_name` and `config`. 59 60 Args: 61 node_name: The name of the port's node. 62 config: The test run configuration of the port. 63 """ 64 self.identifier = PortIdentifier( 65 node=node_name, 66 pci=config.pci, 67 ) 68 self.os_driver = config.os_driver 69 self.os_driver_for_dpdk = config.os_driver_for_dpdk 70 self.peer = PortIdentifier(node=config.peer_node, pci=config.peer_pci) 71 72 @property 73 def node(self) -> str: 74 """The node where the port resides.""" 75 return self.identifier.node 76 77 @property 78 def pci(self) -> str: 79 """The PCI address of the port.""" 80 return self.identifier.pci 81 82 83@dataclass(slots=True, frozen=True) 84class PortLink: 85 """The physical, cabled connection between the ports. 86 87 Attributes: 88 sut_port: The port on the SUT node connected to `tg_port`. 89 tg_port: The port on the TG node connected to `sut_port`. 90 """ 91 92 sut_port: Port 93 tg_port: Port 94