In this post, you can learn
Create a new packet structure that may be attached to the agent
Create a new packet queue
Know the Optimised Link State Routing (OLSR) protocol for wireless networks
8.1 - Introduction
NS2 can simulate almost all the wired and wireless networks. Also, it has the capacity to simulate other networks like satellite networks, multicasting, etc. This chapter will make the readers to write a new packet structure and add it to an agent and test the packet in a wireless network.
8.2 – Adding a New Agent
Creation of an agent in NS2 needs an understanding of the OTCL and C++ linkages that are described in previous posts. Creation of a packet also involves the linkages between Otcl and C++. The following source code tells about the creation of a new agent along with a new packet.
Listing 8.1 shows the code of a declaration of TSPAgent, which inherits the Agent class. It also has the inner class TSPTimer to deal with timeouts during an Event timeout interval.
Listing 8.2 shows the implementation of TSPAgent and implements the agent that acts upon the PT_TSP packet that will be introduced shortly in the next section of code.
This agent also has a binding variable value_ that has to be set in the ns-default.tcl file.
A PT_TSP packet will be sent if the Otcl command is “sendTo” and if the Otcl command is Hello, the C++ file will report as “Your Message is received”
8.3 – Addition of New Packet
Listing 8.3 shows the declaration of a new packet type, “TSPPacket” that can be implemented in NS as PT_TSP. It defines the Packet header, which contains the data to be received or sent and an offset.
Listing 8.4 implements the packet structure and implements the functions that can access the data.
To compile all the above files in NS2
Put all the files in ~ns-2.35/newpkt/
Open the ~ns-2.35/Makefile.in and make an entry in the OBJ_CC variable as given below
newpkt/TSPAgent.o newpkt/TSPPacket.o \
Make an entry in the ~ns-2.35/common/packet.h about the packet type as given below.
static const packet_t PT_TSP = 73;
static packet_t PT_NTYPE = 74; // This MUST be the LAST one
There are total 73 packet types that are already supported in ns2 and if we want to add a new packet it has to be added at the end with a number incremented. So, after adding our packet, the last packet value is 74. Older NS2 version different syntax for adding the new packet types. Refer [1] for more information.
name_[PT_TSP]="TSPHeader";
name_[PT_NTYPE]= "undefined";
Also, there is a binding variable called value_, the value of value_ has to be set in the ~ns-2.35/tcl/lib/ns-default.tcl, go to the end of the line and paste this line
Agent/TSPAgent set value_ 0 (if this line is not set, then a warning will be reported during the interpretation of Tcl)
Open the terminal and go to ~ns-2.35/ and execute the following for recompiling ns2
./configure
make
Once make is done, the codes above will be compiled and generate the object files and now its time to test our code (new agent and new packet)
The output of the above script will be
42
Hello
Your Message is Received
The following Listing 8.6 shows the Otcl code to test the new Packet and new Agent by testing it on a Wireless adhoc network
The output for the above script is given below
num_nodes is set 50
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
Agent 45 receives packet with value 75 from Agent 0
Agent 38 receives packet with value 75 from Agent 0
Agent 26 receives packet with value 75 from Agent 0
Agent 9 receives packet with value 75 from Agent 0
Agent 20 receives packet with value 75 from Agent 0
Agent 16 receives packet with value 75 from Agent 0
Agent 40 receives packet with value 75 from Agent 0
Agent 12 receives packet with value 75 from Agent 0
Agent 47 receives packet with value 75 from Agent 0
Agent 31 receives packet with value 75 from Agent 0
Agent 7 receives packet with value 75 from Agent 0
Agent 13 receives packet with value 75 from Agent 0
Agent 39 receives packet with value 75 from Agent 0
Agent 48 receives packet with value 75 from Agent 0
Agent 41 receives packet with value 75 from Agent 0
Agent 27 receives packet with value 75 from Agent 0
Agent 46 receives packet with value 75 from Agent 0
Agent 43 receives packet with value 75 from Agent 0
8.4 Adding a New Protocol
NS2 by default supports a huge number of routing protocols, network protocols, power-aware protocols, etc. But at times, we may need our own protocol to be implemented and tested in a simulator. NS2 supports the addition of a new protocol.
The addition of a new protocol in NS2 involves the following.
Implementation of a specific packet type in which the protocol is defined,
actual protocol implementation
any other information like logs, routing table, etc.
The following case study implements the OLSR (Optimised Link State Routing) protocol as applicable to wireless networks in NS2.
The readers are advised to learn more about the OLSR through the www.ietf.org
This topic is intended for the addition of any protocol (in case we take it as OLSR) and not the discussion of the OLSR protocol. However, here are the features of the OLSR protocol
It is a wireless network protocol
Proactive & Table-driven
Link State Routing
Utilises a technique to reduce message flooding using MultiPoint Relaying (MPR)
Each node
expands a spanning tree
can obtain the whole network topology
periodically updates the status of its links
Re-broadcasts link-state information received from its neighbours
Keeps track of link state information received from other nodes
uses the above information to determine the next hope for each destination
There are three main modules
Neighbour/link sensing
Provide topology information up to two hops
MPR selector information notification
(“A select B as A’s MPR” in HELLO message to B)
Multi-point Relaying (MPR) is a technique
Every node keeps a table of routes to all known destinations through its MPR nodes
Every node periodically broadcasts a list of its MPR Selectors (instead of the whole list of neighbours).
Upon receipt of MPR information, each node recalculates and updates routes to each known destination
Optimised flooding/forwarding
MPR set to cover all the two-hop neighbours
MPR selector set: a set of nodes that select me as one of their MPR set
OLSR messages from the MPR selector set are to be forwarded
Link-State messaging and route calculation
Topology table
Route table
Each node maintains a routing table to all known destinations in the network
The routing table is calculated from the Topological Table, taking the connected pairs
Routing table:
Destination address
Next Hop address
Distance
Routing Table is recalculated after every change in neighbourhood table or in topological table
Implementation of OLSR
List of Files. (The CD associated with this book carries the Code; readers are asked to download it also from [10]).
The header files
OLSR.h (contains the agent related declaration)
OLSR_pkt.h, (packet level classes)
OLSR_printer.h (printer related functions)
OLSR_repositories.h (related data structures)
OLSR_rtable.h (Routing Table)
OLSR_state.h (consists of the state of the node)
The C Source Files (the actual implementation of the OLSR protocol)
OLSR.cc (implementation of the agent and other related classes)
OLSR_printer.cc
OLSR_rtable.cc
OLSR_state.cc
The OLSR Agent Otcl Class
The output can be verified in the trace file generated, Node (0) details
Routing Table
P 10.000000 _0_ Routing Table
P dest next iface dist
P 1 1 0 1
P 2 1 0 2
P 3 4 0 2
P 4 4 0 1
Link Set
P 15.000000 _0_ Link Set
P local nb sym asym lost time
P 0 1 20.671089 20.671089 0.000000 26.671089
P 0 4 19.445169 19.445169 0.000000 25.445169
Neighbor Set
P 20.000000 _0_ Neighbor Set
P nb status willingness
P 1 1 3
P 4 1 3
Neighbor2hop Set
P 25.000000 _0_ Neighbor2hop Set
P nb nb2hop time
P 1 2 29.610521
P 1 3 29.610521
P 4 3 30.091939
MPR Set
P 30.000000 _0_ MPR Set
P nb
P 1
MPR Selector Set
P 35.000000 _0_ MPR Selector Set
P nb time
P 1 40.008076
P 4 40.165949
Topology Set
P 40.000000 _0_ Topology Set
P dest last seq time
P 0 1 2 52.864873
P 2 1 2 52.864873
P 3 1 2 52.864873
Installation of OLSR protocol in NS2.
Step 1: Copy all the files in the ~ns-2.35/olsr folder
Step 2: Make an entry in the ~ns-2.35/Makefile.in as given below in the OBJ_CC variable
olsr/OLSR.o olsr/OLSR_state.o olsr/OLSR_rtable.o olsr/OLSR_printer.o \
Step 3: Apply the patch file to the corresponding NS version, using the command given below
patch -p1 < olsr/um-olsr_ns-2.35_v1.0.patch
(For the patch to work successfully, patch it when a fresh installation of the ns-allinone-2.35 package is installed)
Step 4: Once the patching is done, execute the following commands
./configure
make
If the patch is not working, refer to the website http://www.nsnam.com for more detailed instructions.
Conclusion
This chapter deals with the simulation of various other protocols, agents, applications, etc. This chapter implements the addition of a new agent, a new protocol, a new packet and their application to run under a wireless network. This also briefs and describes the OLSR (Optimised Link State Routing) protocol to measure the routing performance metrics using a trace file.
Comments
Post a Comment