Virtual Local Area Network¶
The TestFramework depends heavily on the possibilities of VLANs. Each router has its own VLAN with its VLAN ID to separate it from others routers. For this functionality you need a network switch with VLAN capabilities.
- Important python packages:
- pyroute2
- paramiko
(the documentation is here not complete because the auto including function is corrupted by the pyroute2 module)
Class NetworkCtrl¶
-
class
network.network_ctrl.NetworkCtrl(remote_system: network.remote_system.RemoteSystem)¶ The NetworkCtrl manages the SSH-Connection between RemoteSystem and PI, using paramiko. Features:
- Open a SSH-Connection to a RemoteSystem
- Sending Commands that are executed on the RemoteSystem
- Sending data with scp
- Cause the RemoteSystem to download data from a started Web-Server
- Close a SSH-Connection
-
connect_with_remote_system()¶ Connects to the remote_system via SSH(Paramiko). Ignores a missing signature.
Raises Exception: If connecting fails
-
exit()¶ Close the SSHClient from paramiko.
-
remote_system_wget(file: str, remote_path: str, web_server_ip: str)¶ The RemoteSystem downloads the file from the PI and stores it at remote_file. Therefore this function starts a webserver in a new thread.
Parameters: - file – Like ‘/root/TestFramework/firmware/.../<firmware>.bin’
- remote_path – Like ‘/tmp/’
- web_server_ip – IP-address of the PI
-
send_command(command: str, timeout: int=90) → typing.List¶ Sends the given command via SSH to the RemoteSystem.
Parameters: - command – Like ‘ping 8.8.8.8’
- timeout – Timeout in seconds
Returns: The output of the command inside a list. Each output-line is a list-element
Raises: - TimeoutError – If the timeout-limit is reached
- Exception – If sending the command fails
-
send_data(local_file: str, remote_file: str)¶ Sends Data via sftp to the RemoteSystem.
Parameters: - local_file – Path to the local file
- remote_file – Path on the Router, where the file should be saved
-
test_connection() → bool¶ Sends a ‘Ping’ to the RemoteSystem.
Returns: ‘True’ if successful package-transmission
Class Namespace¶
-
class
network.namespace.Namespace(ipdb: pyroute2.ipdb.IPDB, nsp_name: str)¶ A Network-Namespace is logically another copy of the network stack, with its own routes, firewall rules, and network devices.
By default a process inherits its Network-Namespace from its parent. Initially all the processes share the same default Network-Namespace from the init process.
-
encapsulate_interface(iface_name: str)¶ Encapsulate the the given Network-Interface inside the Namespace.
Parameters: iface_name – Name of the selected Network-Interface
-
ipdb_get_ip(ipdb: bool, iface_name: str, not_this_ip: str=None)¶ Reads the ‘first’ IP from the IPDB or if intended from IPDN_NETNS.
Parameters: - ipdb – If ‘True’ IPDB is used, ‘False’ IPDB_NETNS is used
- iface_name – Name of the selected Network-Interface
- not_this_ip – If we know the first IP and are searching for another
Returns: IP with the format ip/mask
-
remove()¶ Removes the Namespace and all included Network-Interfaces.
-
Class NVAssistent¶
-
class
network.nv_assist.NVAssistent(link_iface_name: str)¶ - The NVAssistent (NamespaceVlanAssistent) provides the following Features:
- Creates a IPDB: stores the Network-Interfaces
- Creates VLANs and Namespaces
- Encapsulates the VLANs inside the Namespaces
- Delete VLANs and Namespaces
- IPDB: Is a transactional database, containing records, representing network stack objects.
- Any change in the database is not reflected immidiately in OS, but waits until commit() is called.
If we want to use VLANs for Systems (with identical IPs) on the network, we need Namespaces. Each Namespace encapsulate one VLAN for the current process. The Namespace only contains the given VLAN and the ‘lo’-interface. If we want to use a physical interface (like ‘eth0’) we have to create a bridge that connects the physical interface with Namespace by the ‘veth’-interfaces.
-
close()¶ Deletes all VLANs and Namespaces and releases the IPDB.
-
create_namespace_vlan(remote_system: network.remote_system.RemoteSystem)¶ Creats a Namespace and a VLAN. Encapsulate the VLAN inside the Namespace.
Parameters: remote_system – Router-Obj or Powerstrip-Obj with which we want to connect to.
-
delete_namespace(namespace_name: str)¶ Removes the given Namespace.
Parameters: namespace_name – Namespace_name
-
delete_vlan(vlan_iface_name: str)¶ Removes the given VLAN.
Parameters: vlan_iface_name – VLAN_name
-
get_ip_address(namespace_name: str, vlan_iface_name: str) -> (<class 'str'>, <class 'int'>)¶ Returns the the first IP of the VLAN in the IPDB of the Namespace
Parameters: - namespace_name – Namespace_name
- vlan_iface_name – VLAN_name
Returns: IP address (ip/mask)