Remote Network Emulator
The RemoteNetworkEmulator
is the Remote Representation of the WattsonNetworkEmulator
.
It allows entities, e.g., the User or custom components, to interact with the running network emulation, retrieve its state and manipulate its behavior. The implementation is available here.
It provides a set of Getters for network entities, e.g., hosts, switches or links. All returned entities are instances of the RemoteNetworkEntity
class, e.g., a RemoteNetworkHost
. They then offer an interface following the default NetworkEntity
, e.g., the WattsonNetworkHost
.
Instantiating the RemoteNetworkEmulator
from wattson.cosimulation.control.interface.wattson_client import WattsonClient
from wattson.cosimulation.simulators.network.remote_network_emulator import RemoteNetworkEmulator
# Create client and connect
wattson_client = WattsonClient(wattson_socket_ip="10.0.0.1", name="custom-client")
wattson_client.require_connection()
wattson_client.register()
# Create the RemoteNetworkEmulator
remote_network_emulator = RemoteNetworkEmulator(wattson_client=wattson_client)
PythonListing Entities
# Get all Network Nodes
nodes: List[RemoteNetworkNode] = remote_network_emulator.get_nodes()
## Get all hosts
hosts: List[RemoteNetworkHost] = remote_network_emulator.get_hosts()
## Get all routers
routers: List[RemoteNetworkRouter] = remote_network_emulator.get_routers()
## Get all switches
switches: List[RemoteNetworkSwitch] = remote_network_emulator.get_switches()
# Get all Network Links
links: List[RemoteNetworkLink] = remote_network_emulator.get_links()
# Get all Interfacesfind_nodes_by_ip_address
interfaces: List[RemoteNetworkInterface] = remote_network_emulator.get_interfaces()
# Get all entities (nodes + links + interfaces)
entities: List[RemoteNetworkEntity] = remote_network_emulator.get_entities()
# List all entity IDs of nodes
for node in nodes:
print(node.entity_id)
PythonGetting individual Entities
Each Network Entity has a unique entity ID. It allows to address each entity by a string.
from wattson.cosimulation.exceptions import NetworkNodeNotFoundException
try:
host1: RemoteNetworkHost = remote_network_emulator.get_host(host="hostId")
except NetworkNodeNotFoundException:
print("Host not found")
# You can also search for hosts by a role
firewalls: List[RemoteNetworkNode] = remote_network_emulator.find_nodes_by_role(role="firewall")
# ... or by IP address
host_by_ip: List[RemoteNetworkNode] = remote_network_emulator.find_node_by_ip(ip="172.16.2.1")
PythonCreating a new Host
Creating a new host via the RemoteNetworkEmulator follows a slightly different process compared to the default NetworkEmulator.
Instead of creating a Host object and pass it to the emulator, the creation process follows a procedural approach since to ensure that each RemoteNetworkHost
has a corresponding NetworkHost
.
# Arguments are passed to the constructor of the NetworkHost.
# The config is set as the host configuration.
# The entity_id must not exists!
host: RemoteNetworkHost = remote_network_emulator.create_host(entity_id="new-host", arguments=[], config={})
# Create a new switch
switch: RemoteNetworkSwitch = remote_network_emulator.create_switch(entity_id="new-switch")
# Connect both nodes and set an IP address for the host
interface_a, link, interface_b = remote_network_emulator.connect_nodes(
node_a=host,
node_b=switch,
interface_a_options={"ip": "172.16.2.1", prefix_length=24}
interface_b_options={},
link_options={},
)
Python