WattsonNetworkNode#
- class wattson.cosimulation.simulators.network.components.wattson_network_node.WattsonNetworkNode(*, id: str, system_name: str | None = None, display_name: str | None = None, network_emulator: NetworkEmulator | None = None, emulation_instance: ~typing.Any | None = None, segment: str = 'main', config: dict = <factory>, _is_started: bool = False, logger: ~logging.Logger | None = None, interfaces: ~typing.List[WattsonNetworkInterface] = <factory>, priority: float = 4, _services: ~typing.Dict[int, ~wattson.services.wattson_service.WattsonService] = <factory>, _processes: ~typing.List[~subprocess.Popen] = <factory>, _min_interface_id: int = 0, _is_outside_namespace: bool = False)#
Bases:
WattsonNetworkEntity,NetworkNodeA WattsonNetworkNode is a WattsonNetworkEntity that serves as node. A node can have interfaces and run services. Switches, Routers and ordinary hosts are NetworkNodes.
Methods
add_dns_entryAdds an Interface and links it to this node.
add_roleAdds a service to this node.
delete_roleexecExecutes a file-system related command (e.g., mounting).
Checks whether the given file exists on this node
Returns the contents of a file on the file system of this node.
Writes the given content string to the file on the file system of this node specified by path.
Checks whether the given folder exists on this node
get_configget_free_interface_nameReturn the working directory of this node relative to this node.
Return the working directory of this node relative to the host machine running Wattson.
Returns the root folder of this network node.
get_interfacesReturns a list of all IP addresses of this node.
get_prefixget_python_executableget_rolesget_serviceget_service_by_nameget_servicesget_sysctlget_working_directoryReturns True iff the node's configuration already has a service section :return:
Set an interface down
Flush (remove) the IP address of an interface
Renames a physical interface on the node
Set the IP address for an interface
Set the MAC / hardware address for the given interface
Set an interface up
Returns a list of actual interfaces existing on the node.
is_outside_namespaceLoads and instantiates service instances from the (optional) 'services' list in the node's configuration.
manage_processmkdirMounts the target folder at the given mount point.
on_interface_startAttempts to open a terminal / konsole for the network node.
popenremove_fileremove_folderremove_interfaceset_configset_sysctlshutdown_processessocket_existsstartStart a packet capture on this node for the given interface.
stopStops a packet capture on this node for the given interface.
stop_serviceCreates a dictionary for synchronization with a RemoteNetworkEntity.
Transforms the given path to a node-specific path, i.e., relative paths are transformed to the in-node file system w.r.t.
Unmount the given mount point
update_configAttributes
class_identity_idospriorityinterfacesconfigid- __init__(*, id: str, system_name: str | None = None, display_name: str | None = None, network_emulator: NetworkEmulator | None = None, emulation_instance: ~typing.Any | None = None, segment: str = 'main', config: dict = <factory>, _is_started: bool = False, logger: ~logging.Logger | None = None, interfaces: ~typing.List[WattsonNetworkInterface] = <factory>, priority: float = 4, _services: ~typing.Dict[int, ~wattson.services.wattson_service.WattsonService] = <factory>, _processes: ~typing.List[~subprocess.Popen] = <factory>, _min_interface_id: int = 0, _is_outside_namespace: bool = False) None#
- add_interface(interface: WattsonNetworkInterface)#
Adds an Interface and links it to this node.
- Parameters:
interface ('NetworkInterface') – The interface instance
- add_service(service: WattsonService)#
Adds a service to this node. This does not start the service.
- Parameters:
service (WattsonServiceInterface) – The service to add to this node.
- exec_fs_cmd(cmd: List[str], **kwargs) int#
Executes a file-system related command (e.g., mounting). This does not necessarily belong to the network namespace in mixed-namespace environments
- Parameters:
cmd (List[str]) – The command to execute
**kwargs –
- Returns:
The command’s return code
- Return type:
int
- file_exists(file: Path) bool#
Checks whether the given file exists on this node
- Parameters:
file (Path) – The file path to check for
- Returns:
Whether the file exists (and is actually a file)
- Return type:
bool
- file_get_contents(path: Path) str | None#
Returns the contents of a file on the file system of this node.
- Parameters:
path (Path) – The path of the file to read.
- Returns:
The contents of the file or None if the file does not exist or is not readable.
- Return type:
Optional[str]
- file_put_contents(path: Path, contents: str) Tuple[bool, Path | None]#
Writes the given content string to the file on the file system of this node specified by path. Returns whether the operation succeeded.
- Parameters:
path (Path) – The path of the file to write to.
contents (str) – The contents of the file to write.
- Returns:
Whether the operation succeeded and the potentially transformed path of the target file.
- Return type:
Tuple[bool,Optional[Path]]
- folder_exists(folder: Path) bool#
Checks whether the given folder exists on this node
- Parameters:
folder (Path) – The folder path to check for
- Returns:
Whether the folder exists (and is actually a folder)
- Return type:
bool
- get_guest_folder() Path#
Return the working directory of this node relative to this node. This is just the host folder / artifact folder, except for nodes that use a different file system (e.g., Docker or VMs)
- Returns:
The working directory of this node relative to the node / guest.
- Return type:
Path
- get_host_folder(ensure_exists: bool = True) Path#
Return the working directory of this node relative to the host machine running Wattson.
- Parameters:
ensure_exists (bool, optional) – (Default value = True)
- Returns:
The working directory of this node relative to the host machine
- Return type:
Path
- get_host_root(ensure_exists: bool = True) Path#
Returns the root folder of this network node.
- Parameters:
ensure_exists (bool, optional) – (Default value = True)
- get_ip_addresses() List[str]#
Returns a list of all IP addresses of this node. Each IP is formatted as a string, indicating the IP itself in decimal notation and the prefix length. E.g.: 192.168.0.1/24 :return: A list of (formatted) IP addresses.
- has_services() bool#
Returns True iff the node’s configuration already has a service section :return:
- interface_down(interface: WattsonNetworkInterface) bool#
Set an interface down
- Parameters:
interface ('NetworkInterface') – The interface to set down
- Returns:
Whether the action has been successfully performed
- Return type:
bool
- interface_flush_ip(interface: WattsonNetworkInterface) bool#
Flush (remove) the IP address of an interface
- Parameters:
interface ('NetworkInterface') – The interface to flush the IP address of
- Returns:
Whether the action has been successfully performed
- Return type:
bool
- interface_rename(old_name: str, new_name: str) bool#
Renames a physical interface on the node
- Parameters:
old_name (str) – The original interface name
new_name (str) – The new interface name
- Returns:
Whether the action was successful
- Return type:
bool
- interface_set_ip(interface: WattsonNetworkInterface) bool#
Set the IP address for an interface
- Parameters:
interface ('NetworkInterface') – The interface to set the IP address of
- Returns:
Whether the action has been successfully performed
- Return type:
bool
- interface_set_mac(interface: WattsonNetworkInterface) bool#
Set the MAC / hardware address for the given interface
- Parameters:
interface ('NetworkInterface') – The interface to set the MAC address for
- Returns:
Whether the action has been successfully performed
- Return type:
bool
- interface_up(interface: WattsonNetworkInterface) bool#
Set an interface up
- Parameters:
interface ('NetworkInterface') – The interface to set up
- Returns:
Whether the action has been successfully performed
- Return type:
bool
- interfaces_list_existing(try_num: int = 0, max_tries: int = 10, retry_error_message: str = '') List[Dict]#
Returns a list of actual interfaces existing on the node. Each interface information consists of the interface’s name, its hardware address, ip addresses, and potential statistics.
- Returns:
A list of dictionaries containing interface information
- Return type:
List[Dict]
- load_services()#
Loads and instantiates service instances from the (optional) ‘services’ list in the node’s configuration. For each found service, a respective instance is created. :return:
- mount(mount_point: Path, target: Path, remove_file: bool = False, remove_folder: bool = False, bind: bool = False) bool#
Mounts the target folder at the given mount point.
- Parameters:
mount_point (Path) – The mount point
target (Path) – The target folder
remove_file (bool, optional) – Whether to remove the mount point if it is a file (Default value = False)
remove_folder (bool, optional) – Whether to remove the mount point if it is a folder (Default value = False)
bind (bool, optional) – Whether to mount via –bind (if applicable) (Default value = False)
- Returns:
Whether the mounting was successful
- Return type:
bool
- open_terminal() bool#
Attempts to open a terminal / konsole for the network node.
- start_pcap(interface: WattsonNetworkInterface | None = None) List[WattsonService]#
Start a packet capture on this node for the given interface. If the interface is None, all packets for all interfaces are captured.
- Parameters:
interface (Optional['NetworkInterface'], optional) – (Optional) interface to start the PCAP for (Default value = None)
- Returns:
A list of services that represent the packet capturing processes.
- Return type:
List[‘WattsonServiceInterface’]
- stop_pcap(interface: WattsonNetworkInterface | None = None)#
Stops a packet capture on this node for the given interface. If the interface is None, packet captures for all interfaces are stopped.
- Parameters:
interface (Optional['NetworkInterface'], optional) – (Optional) interface to stop the PCAP (Default value = None)
- to_remote_representation(force_state_synchronization: bool = True) RemoteNetworkEntityRepresentation#
Creates a dictionary for synchronization with a RemoteNetworkEntity.
- Parameters:
force_state_synchronization (bool, optional) – Whether to force a synchronization of the internal state with the actual state (Default value = True)
- Returns:
A dictionary representation of this WattsonNetworkEntity for synchronization with a RemoteNetworkEntity.
- Return type:
- transform_path(path: Path) Path#
Transforms the given path to a node-specific path, i.e., relative paths are transformed to the in-node file system w.r.t. the working directory.
- Parameters:
path (Path) – The path to transform
- Returns:
The transformed path
- Return type:
Path
- unmount(mount_point: Path, lazy: bool = False, force: bool = False) bool#
Unmount the given mount point
- Parameters:
mount_point (Path) – The mount point
lazy (bool, optional) – Use lazy unmounting (Default value = False)
force (bool, optional) – force unmounting (Default value = False)
- Returns:
Whether the unmounting was successful
- Return type:
bool