Applicable Versions
NetSim Standard
NetSim Pro


Applicable Releases
v11.0
v12
v13


Location Aware Routing (LAR):

Routing for an ad-hoc wireless network is challenging, many routing strategies have been proposed in the literature. With the availability of affordable Global Position System-equipped devices, Location-Aware Routing provides a promising foundation for developing an efficient and practical solution for routing in the ad-hoc wireless network.


Most Forward within Fixed Radius R (MFR):

MFR protocol is a geographic Location-Aware Routing protocol. MFR forwards packets to the neighbor nodes within a set radius of the current node (not the route source) that makes the most forward progress (or the least backward progress) along the line drawn from the current node to the destination. Progress is calculated as the cosine of the distance from the current node to the neighbor node projected back onto the line from the current node to the destination.

                                       

Figure: MFR Protocol Implementation

Here,

  • S(N1) is the source node and D(N6) is the destination node.
  • N2 and N3 are in the transmission radius of S(N1).
  • So, according to the MFR protocol, d1, and d2 are the projected distances of N2 and N3 respectively on the line drawn from the current node i.e., S(N1) and the destination node D(N6):
  • d2 > d1, therefore the next route hop node will be N3.
  • N4, N5, and S(N1) are in the transmission radius of N3.  Since S (N1) is already present in the route list, skip it.
  • So, according to MFR protocol, d3, and d4 are the projected distances of N5 and N4 respectively on the line drawn from the current node i.e., N3 and the destination node D(N6):
  • d4 > d3, therefore the next route hop node will be N4.
  • N5, D(N6), and N3 are in the transmission radius of N3.  Since N3 is already present in the route list, skip it.
  • So, according to MFR protocol, d5, and d6 are the projected distances of N5 and D(N6) respectively on the line drawn from the current node i.e., N4 and the destination node D(N6):
  • d6 > d5, therefore the next route hop node will be D(N6).
  • Route according to MFR :  S(N1) -> N3 -> N4 -> D(N6)


Real-Time Interaction in NetSim:

NetSim allows users to interact with the simulation at runtime via a socket or through a file. User Interactions make the simulation more realistic by allowing command execution to view/modify certain device parameters during runtime. 


Python socket interface:

Python interfacing is a method to interface custom protocols like routing-based protocols with the NetSim engine. In this project, we input NetSimCore.exe with routes generated via our routing protocol i.e., Most Forward within Fixed Radius R (MFR) which is a geographic location-aware routing protocol. The interaction between the routing protocol and the NetSimCore.exe is happening via socket programming.

The Real-Time Interaction has to be turned ‘True’ before running the simulation of the scenario. This lets the NetSimCore.exe (server) to wait for the client (Python script) to connect using the socket port. After the connection is established, we compute the routes based on our custom MFR protocol. These routes are passed as static routes to the NetSimCore.exe server by the python script.


Python Script:

The code has been divided into 2 separate files: Socket programming code (socketInterface.py) and MFR protocol code (mfrProtocol.py). The protocols are written in a separate script file like here.


socketInterface.py:

  • Include the protocol file name to import at the top of the code.
  • from mfrProtocol import*
  • The function _ipaddr() has the device names and their respective IP addresses.
  • We create a socket and connect it to port 8999 since NetSimCore.exe runs on this port.
  • The ‘route add’ command :

            route ADD 11.1.1.6 MASK 255.255.255.255 + _ipaddr(route[each+1]) + METRIC 1 IF 1

Here 11.1.1.6 is the Destination IP and 255.255.255.255 is the Subnet Mask to denote ‘all packets’ from the Source. The Metric is 1 and the Interface (IF) is also 1 as there is only one wireless interface.


mfrProtocol.py:

  • This python script reads the device coordinate input from a file device_log.txt having data in the following format:

            Wirless_Node_1    49.760000    100.160000

  • The protocol script has 4 functions to ultimately find the projected distance _projDist() on the line drawn from the current node to the destination.
  • Mention the device_log.txt file name in the python script in File I/P section:

            with open('device_log.txt','r') as f:

  • In the Declarations of MFR, change the Transmission range (meters),  Source, and Destination device names accordingly:
    • source = 'Wirless_Node_1'
    • dest = 'Wirless_Node_6'
    • tx = 110

        Note: The Transmission range is set to 110 based on the channel conditions and device properties for this example. This may vary if any network other than the one discussed in this example is considered.



Network Configuration:

A MANET network configuration with 6 Wireless nodes is considered for this example as shown below:

  • Traffic is configured between Node 1 and Node 6.
  • By default nodes have the DSR protocol set as the routing protocol in the network layer. 
  • The wireless channel characteristics are set to Path loss only with the log distance path loss model (n=3.5) as shown below:

Note: In Netsim v12 and v13, the path loss exponent value is set to 3.8


Running Simulations using DSR:

  • Download the attached zip folder and extract it (Python-SDN-Interface file for v11 of Netsim and Python-SDN-Interface-v12 for v12 of Netsim and similarly for v13, Python-SDN-Interface-v13).
  • In NetSim and open the Configuration.netsim file present in the Config_file directory (for v13, import either the configuration file or the .netsim_exp file). 
  • Run the simulation for 100 seconds with the DSR protocol configured in the Network layer.
  • Upon running simulations with this configuration, DSR forms a route from source to destination as shown below:

           S(N1) -> N3 -> N5 -> D(N6)



NetSim Packet Animation to visualize packet flow in the network:



Procedure to perform routing using python interface in NetSim:

  • For the python interface to interact with NetSim during the simulation, Interactive Simulation parameters has to be set to 'True' under the Real-Time Interaction tab, before running the simulation.

  • This lets the NetSimCore.exe (server) to wait for the client (Python script) to connect using the socket port. After the connection is established, we compute the routes based on our custom MFR protocol. These routes are passed as static routes to the NetSimCore.exe server by the python script.
  • Run the simulation for 100 seconds. NetSim Simulation Console starts and waits for a client application to connect as shown below:

  • The socket client code to connect to NetSimCore.exe is written in socketInterface.py. And the MFR protocol code is written in mfrProtocol.c
  • Open Command Prompt in the directory where the python codes are present and run the command python socketInterface.py

  • Python interface interacts with NetSim Simulation and routes the packets from source to destination based on MFR protocol.

  • Simulation continues and packets are routed from source to destination based on MFR protocol as shown below:

           S(N1) -> N3 -> N4 -> D(N6)


NetSim Packet Animation to visualize packet flow in the network:


Analyzing the device route tables in NetSim Results Dashboard:

  • NetSim Results Window contains route tables for each device from which we can identify the routes updated by the python interface as per MFR protocol. Since the route that is formed is from   S(N1) -> N3 -> N4 -> D(N6), route entries for packets with destination 11.1.1.6 are added in the nodes N1, N3, and N4 to forward packets to N3, N4, and N6 respectively. In the nodes N1, N3, and N4 static route entries added based on MFR protocol by the python socket program can be found as shown below:


The static route entry for N1(Wireless_Node_1 specifies the next hop as N3 (Wireless_Node_3) which has the IP 11.1.1.3.

The static route entry for N3 (Wireless_Node_3) specifies the next hop as N4 (Wireless_Node_4) which has the IP 11.1.1.4.

The static route entry for N4 (Wireless_Node_4) specifies the next hop as the destination node N6 (Wireless_Node_6) which has the IP 11.1.1.6.


Using NetSim Packet Trace to identify the route taken by packets from the source to the destination:

NetSim Packet trace log file can be obtained by enabling the packet trace option in NetSim GUI before running the simulation. 

Upon running the simulation with packet trace enabled, the packet trace log file can be accessed from the NetSim Results Window using the Open Packet Trace link.

Once the packet trace log file is loaded you can filter a specific packet id in the PACKET_ID column to view the path that the packet has taken.

Upon filtering the Packet with id 1, we can observe the following in the packet trace:

In the case of DSR:

In the case of MFR: