Step 3. Automatically assigning IP addresses to a subnet from a given range¶
Goals¶
Complex networks often contain several subnetworks, and the user may want to assign specific IP address ranges for them. This step demonstrates how to assign a range of IP addresses to subnets.
The model¶
This step uses the ConfiguratorA network, as in the previous two steps. One switch and the connected hosts as a group will be on the same subnet, and there are three such groups in the network.
The configuration is the following:
[Config Step3]
network = ConfiguratorA
description = "Automatically assigning IP addresses to a subnet from a given range"
*.configurator.config = xmldoc("step3.xml")
This time the XML configuration is supplied in an external file
(step3.xml), using the xmldoc()
function:
<config>
<interface hosts="host{0-2}" address="10.0.0.x"/>
<interface hosts="host{3-5}" address="10.0.1.x"/>
<interface hosts="host{6-8}" address="10.0.2.x"/>
<interface hosts="router0" towards="host0" address="10.0.0.x"/>
<interface hosts="router1" towards="host3" address="10.0.1.x"/>
<interface hosts="router2" towards="host6" address="10.0.2.x"/>
<interface hosts="router*" address="10.1.x.x"/>
</config>
A brief explanation:
The first three entries assign IP addresses with different network prefixes to hosts in the three different subnets.
The next three entries specify for each router that its interface that connects to a subnet should belong in that subnet. These entries use the
towards
selector, which selects the interfaces that are connected towards the specified host or hosts.The last entry sets the network prefix of interfaces of all routers to be 10.1.x.x. The routers’ interfaces facing the subnets were assigned addresses by the previous rules, so this rule only affects the interfaces facing the other routers.
These seven rules assign addresses to all interfaces in the network, thus, a default rule is not required.
Variations¶
The same effect can be achieved in more than one way. Here is an alternative XML configuration (step3alt1.xml) that results in the same address assignment:
<config>
<interface among="host{0-2} router0" address="10.0.0.x"/>
<interface among="host{3-5} router1" address="10.0.1.x"/>
<interface among="host{6-8} router2" address="10.0.2.x"/>
<interface hosts="router*" address="10.1.x.x"/>
</config>
The among
selector selects the interfaces of the specified hosts
towards the specified hosts (the statement among="X Y Z"
is the same
as hosts="X Y Z" towards="X Y Z"
).
Another alternative XML configuration is the following:
<config>
<interface hosts="host0" address="10.0.0.x"/>
<interface hosts="host3" address="10.0.1.x"/>
<interface hosts="host6" address="10.0.2.x"/>
<interface among="router*" address="10.1.x.x"/>
<interface hosts='**' address='10.x.x.x' netmask='255.x.x.x'/>
</config>
This one assigns an address to one host in each of the three subnets. It
assigns addresses o the interfaces of the routers facing the other
routers, and includes a copy of the default configuration. Because
assignDisjunctSubnetAddresses=true
, the configurator puts the
unspecified hosts, and the subnet facing router interfaces into the same
subnet as the specified host.
Results¶
The assigned addresses are shown in the following image.
The addresses are assigned as intended. This is useful because it is easy to recognize which group a node belongs to just by looking at its address (e.g. in the logs.)
Sources: omnetpp.ini
,
ConfiguratorA.ned