marvis.network
A subnet.
Classes
A channel prototype defines all parameters for the channel creation and offers a method to add nodes. |
|
A network connects many nodes together and assigns IP addresses. |
- class marvis.network.Network(network_address, netmask=None, base=None, default_channel_type=<class 'marvis.channel.csma.CSMAChannel'>)[source]
Bases:
object
A network connects many nodes together and assigns IP addresses.
It can be compared to a subnet or so. It should also support IPv6 (untested!).
- Parameters
network_address (str) – The network base address (and optional subnet mask). An example for this parameter could be
"10.42.42.0/24"
.netmask (str) – The networks subnet mask. It can be used to provide a mask if not already given in the
network_address
parameter.base (str) – The base / start for the IP-addresses of this network. An IPv4 example for this parameter could be
"0.0.0.50"
.default_channel_type (class) – The default channel to use. This can be one of
CSMAChannel
orWiFiChannel
.
- channels
All the channels in the network.
- channels_prototypes
The prototypes for the future channels.
- default_channel_type
The channel type
- random_channel_names
The list of random generated channel names to avoid duplicates
- nodes
The list of the connected nodes
- allocated_ip_addresses
The list of already allocated ip addresses
- network
The network’s address (containing the subnet mask).
- netmask
The network’s netmask
- next_free_ip
The next potentially free ip address of that network moved by base
- color
The color of the network’s nodes in a visualization.
- create_channel(name=None, channel_type=None, **channel_kwargs)[source]
Adds one named channel prototype to the network.
- Parameters
name (str) – The name of the channel. If set to
None
, a random name will be generatedchannel_type (class) – The channel type. If set to
None
, the default channel type will be set.channel_kwargs (dict) – The arguments of the new channel
- block_ip_address(ip_addr)[source]
Blocks an IP address.
That IP address will not be assigned to any node.
- Parameters
ip_addr (str) – The IP address which will be blocked.
- get_free_ip_address()[source]
Get a free ip address.
This returns an ip address which is not already allocated or blocked.
- prepare(simulation, network_index)[source]
Prepares the network.
Warning: Don’t call this function manually.
- Parameters
simulation (
Simulation
) – The simulation to prepare the network for.network_index (int) – The index of the network (needed for coloring).
- set_delay(delay, channel_name=None)[source]
Sets the delay of a specific channel (if name is present) or all channels.
In case of WiFi-Channels, the distance between the nodes is important. The requested delay is configured at 100 meters distance. If the distance is smaller, the delay is smaller as well (for example half of the delay at 50 meters).
- Parameters
delay (str) – The new time for delay in the channel in seconds (10s) or milliseconds (10ms)
channel_name (str) – The name of a specific channel (or all channels if value is None)
- set_speed(speed, channel_name=None)[source]
Sets the speed of a specific channel (if name is present) or all channels.
Warning: So far this only has an effect before the simulation is started.
- Parameters
speed (str) – The new speed
channel_name (str) – The name of a specific channel (or all channels if value is None)
- class marvis.network.ChannelPrototype(network, name, channel_type, kwargs)[source]
Bases:
object
A channel prototype defines all parameters for the channel creation and offers a method to add nodes.
- Parameters
network (
Network
) – The network where the channel is located in.name (str) – The name of the channel.
channel_type (class) – The channel to use. This can be one of
CSMAChannel
orWiFiChannel
.kwargs (dict) – The parameters of the channel.
- connect(node, ip_addr=None, ifname=None)[source]
Adds one node to the channel.
Please note: Every node can only be added to one channel in the same network. Otherwise proper routing is not possible. Use SwitchNode to connect channels.
- Parameters
node (
Node
) – The node that should be connected to the network. It must be instance a subclass ofNode
.ip_addr (str) – The IP address of that node. If
None
an random IP from the network will be assigned. If notNone
the IP address have to be in the range of the network.ifname (str) – The name of the interface. If
None
a random name will be assigned. If notNone
the max. length isIFNAMSIZ
(system depended). This will not be checked.
- set_delay(delay)[source]
Sets the delay of a specific channel.
In case of WiFi-Channels, the distance between the nodes is important. The requested delay is configured at 100 meters distance. If the distance is smaller, the delay is smaller as well (for example half of the delay at 50 meters).
- Parameters
delay (str) – The new time for delay in the channel in seconds (10s) or milliseconds (10ms)
Inheritance Diagramm