Applicable Versions | NetSim Standard | NetSim Pro |
NetSim currently supports static routing for IPV4 addressing. In order to configure static routes for networks involving IPV6 addresses, users have to modify the source codes of the function configure_static_ip_route() in the IP_Routing.c file which is part of the IP project.
Follow the steps given below to modify configure_static_ip_route() for IPV6 based networks:
The steps involved may vary between different versions of NetSim. Choose the appropriate section of this article, as per the version of NetSim.
Applicable Releases | v11.1 | v12 | v13 |
1.Open NetSim source code in Visual Studio 2019 by clicking on the Open Code button present in NetSim Home Screen via Open Simulation->Workspace Options->Open Code.
2. Go to IP project through the solution explorer and open the file IP_Routing.c. Add/modify the lines of code highlighted in red as shown below:
void configure_static_ip_route(NETSIM_ID d, char* file)
{
.
.
.
.
.
if (_stricmp(f, "route"))
{
display_error("Not start with route", file, line);
continue;
}
f = find_word(&temp);
if (_stricmp(f, "add"))
{
display_error("Second word is not add", file, line);
continue;
}
f = find_word(&temp);
NETSIM_IPAddress dest = STR_TO_IP6(f);
f = find_word(&temp);
if (_stricmp(f, "mask"))
{
display_error("Fourth word is not mask", file, line);
continue;
}
f = find_word(&temp);
UINT mask = atoi(f);
f = find_word(&temp);
NETSIM_IPAddress gateway = STR_TO_IP6(f);
f = find_word(&temp);
.
.
.
.
if (table)
change_table(d, table, gateway, in, metric);
else
//add_table(d, dest, mask, gateway, in, metric);
iptable_add(IP_WRAPPER_GET(d), dest, NULL, mask, gateway, 1, &DEVICE_NWADDRESS(d, in), &in, metric, "STATIC");
}
}
3. Now right click on IP module in the solution explorer and select Rebuild.
4. After a successful build, NetSim will automatically take care of linking the modified source code with simulations performed.
Note: You will have to undo the changes done to IP protocol and rebuild the code to reset NetSim back to handle IPV4 based static routes.
Applicable Releases | v10.2 | v11.0 |
1. Open NetSim source code in Visual Studio 2015/2017 by double-clicking on the NetSim.sln file present in “<NetSim_Install_Directory>/src/Simulation” folder.
2. Go to IP project through the solution explorer and open the file IP_Routing.c. Add/modify the lines of code highlighted in red as shown below:
void configure_static_ip_route(NETSIM_ID d, char* file)
{
.
.
.
.
.
if (_stricmp(f, "route"))
{
display_error("Not start with route", file, line);
continue;
}
f = find_word(&temp);
if (_stricmp(f, "add"))
{
display_error("Second word is not add", file, line);
continue;
}
f = find_word(&temp);
NETSIM_IPAddress dest = STR_TO_IP6(f);
f = find_word(&temp);
if (_stricmp(f, "mask"))
{
display_error("Fourth word is not mask", file, line);
continue;
}
f = find_word(&temp);
UINT mask = atoi(f);
f = find_word(&temp);
NETSIM_IPAddress gateway = STR_TO_IP6(f);
f = find_word(&temp);
.
.
.
.
if (table)
change_table(d, table, gateway, in, metric);
else
//add_table(d, dest, mask, gateway, in, metric);
iptable_add(IP_WRAPPER_GET(d), dest, NULL, mask, gateway, 1, &DEVICE_NWADDRESS(d, in), &in, metric, "STATIC");
}
}
3. Now right click on IP module in the solution explorer and select Rebuild.
4. Upon successful build, you will get a new libIP.dll file in the “<NetSim_Install_Directory>/src/Simulation/DLL” folder.
5. Copy this newly built DLL file and replace it in the bin folder of NetSim after you rename the original libIP.dll file which is already existing there(as a backup).
Upon performing the above steps, NetSim is now set up to handle static routes for IPV6 based networks (IoT).
Note: You will have to replace the original DLL file back the bin folder to reset NetSim back to handle IPV4 based static routes.
IoT use case:
Following example demonstrates how you can configure static routes for packets with the destination in the same network and across the network:
The network shown above has an application configured between two sensors within the IPV6 based sensor network and another between a sensor node and a wired node in the external network.
Let's say we want to set static routes for Sensor A in such a way that packets from Sensor A will go via Sensor B.
Sensor A -> Sensor B -> next hop/destination
- Create your network scenario in NetSim GUI and Enable packet trace using the packet trace icon and save the network scenario created in the GUI to obtain the Configuration.netsim file.
- A separate Static routing file is required for each device for which you want to configure static routes. It is advised to save each file with the file-name containing the device name. For example the static routing file for Sensor A can be saved as SENSOR_A_STATIC_IP_ROUTE.txt.
- To statically route packets in the following way:
SENSOR A->SENSOR B
with the following IP address assignment:
Device Name | IP Address |
Sensor A | 21AF:435D:7F02:92B1:4219:F0BD:509E:7110 |
Sensor B | 21AF:435D:7F02:92B1:4219:1407:E06C:8339 |
Sensor C | 21AF:435D:7F02:92B1:4219:AA7A:292D:C383 |
Sensor D | 21AF:435D:7F02:92B1:4219:BB98:55D5:59C0 |
Sensor E | 21AF:435D:7F02:92B1:4219:6412:0C3E:D551 |
Low PAN Gateway F | 21AF:435D:7F02:92B1:4219:D1A9:8D46:AC05 |
Static routing file format:
route ADD <DESTINATION_ADDRESS> MASK <PREFIX_LENGTH> <GATEWAY_IP> METRIC <INTEGER_VALUE> IF <INTERFACE_ID>
Eg:
route ADD 0:0:0:0:0:0:0:0 MASK 0 21AF:435D:7F02:92B1:4219:1407:E06C:8339 METRIC 1 IF 1
We will have to create a static route text file for Sensor A
SENSOR_A_STATIC_IP_ROUTE.txt which contains the following static route table entries:
route ADD 21AF:435D:7F02:0:0:0:0:0 MASK 48 21AF:435D:7F02:92B1:4219:1407:E06C:8339 METRIC 1 IF 1
route ADD 0:0:0:0:0:0:0:0 MASK 0 21AF:435D:7F02:92B1:4219:1407:E06C:8339 METRIC 1 IF 1
Here the first route entry is for the packets within the network and the second is for the packets across the network.
- Open the Configuraiton.netsim file in the saved directory and in the properties of the sensor nodes where you want to perform static routing make the following changes(highlighted in red):
<LAYER TYPE="NETWORK_LAYER">
<ROUTING_PROTOCOL NAME="DSR" SETPROPERTY="TRUE">
<PROTOCOL_PROPERTY ACK_TYPE="LINK_LAYER_ACK"/>
</ROUTING_PROTOCOL>
<PROTOCOL NAME="IPV4" SETPROPERTY="true">
<PROTOCOL_PROPERTY STATIC_IP_ROUTE="SENSOR_A_STATIC_IP_ROUTE.txt"/>
</PROTOCOL>
</LAYER>
Here the variable "STATIC_IP_ROUTE" will contain the name of the text file containing the static routes for that specific sensor device.
- Save the Configuration file with the changes performed.
- Create a new folder and place the configuration file along with the static routing text files that were created for the sensor nodes.
- Run NetSim via CLI mode (ref section on running NetSim via CLI in NetSim User Manual) with iopath (input - output path) as the path of the new folder that was created in the previous step.
Upon simulation all the scenario related result files will get created in the new folder that you have created.
To access the packet_trace go to the temp path of Netsim (type %temp%\netsim in run).
Upon opening the Packet trace in excel use the 'Format as table' option for better visualization and filters.
Now filter only sensing/application related packets in the column PACKET_TYPE.
Upon observing the columns TRANSMITTER_ID and RECEIVER_ID you will be able to find that all data packets from SENSOR A/SENSOR-1 was sent to SENSOR B//SENSOR-2 as per the static routes configured.
For more information visit www.tetcos.com
Related articles:
how-to-configure-static-routes-for-sensors-in-netsim-