Finding the Node Position, speed and Velocity of a Node while using AODV

Finding the Node Position, speed and Velocity of a Node while using AODV

Steps
1. ~ns-2.34/aodv/aodv.h
include the following header line in aodv.h

   1: #include<mobilenode.h>
2.In protected scope declare the variables you would be using to store the node parameters.


   1: double xpos;
   2: double ypos;
   3: double zpos;
   4: double iEnergy;
   5: int node_speed;
   6: MobileNode *iNode;
   7: FILE *fp;

3.In aodv.cc initialize the declared variables.



   1: xpos = 0.0;
   2: ypos = 0.0;
   3: zpos = 0.0;
   4: node_speed = 0;
   5: iEnergy=0.0;
   6: fp=fopen("pradeep.csv","w");
   7: MobileNode *iNode;

4.Finally access the required functions from mobilenode.h. Paste the following lines in the AODV::forward() function


//Code by pradeepkumar
/***This code retrieves node 
position*****/
fprintf(fp,"Position is, X, Y, Z, Velocity is, X, Y, Z, 
Velocity, Node Speed, Energy \n");
iNode = (MobileNode*) 
(Node::get_node_by_address(index));
((MobileNode *) 
iNode)->getLoc(&xpos,&ypos,&zpos);
//Position of %d , X, Y, 
Z
fprintf(fp,"%d,%f,%f,%f,", index, xpos, ypos, zpos);
/***This code retrieves the nodes velocity*****/
iNode = (MobileNode*) 
(Node::get_node_by_address(index));
((MobileNode *) 
iNode)->getVelo(&xpos, &ypos, &zpos);
//Velocity of %d , X, Y, 
Z
fprintf(fp,"%d,%f,%f,%f,", index, xpos, ypos, zpos);
/***This code retrieves the nodes speed*****/
iNode = (MobileNode*) 
(Node::get_node_by_address(index));
node_speed = ((MobileNode *) 
iNode)->speed();
iEnergy=iNode->energy_model()->energy();
//Velocity 
of %d , Node Speed in m/s Energy in joules 
fprintf(fp,"%d,%d,%f,", index, 
node_speed,iEnergy);

Promiscuous Mode in AODV (ns 2.34)

In a network, promiscuous mode allows a network device to intercept and read each network packet that arrives in its entirety. This mode of operation is sometimes given to a network snoop server that captures and saves all packets for analysis (for example, for monitoring network usage). Its often used to
monitor network activity

Files to be changed
1. ~ns-2.34/aodv/aodv.h
2. ~ns-2.34/aodv/aodv.cc
3. ~ns-2.34/lib/tcl/ns-mobilenode.tcl

1. Make AODV agent a child class of Tap (you should have a member function tap), and define the Mac variable

   1: #include <mac.h>
   2: class AODV: public Tap, public Agent {
   3: public:
   4: void tap(const Packet *p);
   5: ......
   6: protected:
   7: Mac *mac_;
   8: ......
   9: }

2. Modify aodv/aodv.cc
Define TCL command "install-tap" and implement AODV::tap()


   1: int AODV::command(int argc, const char*const* argv) {
   2:  
   3: ......
   4:  
   5: else if(argc == 3) {
   6:  
   7: ......
   8:  
   9: else if (strcmp(argv[1], "install-tap") == 0) {
  10: mac_ = (Mac*)TclObject::lookup(argv[2]);
  11: if (mac_ == 0) return TCL_ERROR;
  12: mac_->installTap(this);
  13: return TCL_OK;
  14: }
  15:  
  16: } 
  17: return Agent::command(argc, argv);
  18:  
  19:  
  20: }
  21:  
  22: void AODV::tap(const Packet *p) {
  23: //put your code here
  24: fprintf(stdout,"Node in Promiscuous Mode");
  25: } 
  26:  


3. Modify tcl/lib/ns-mobilenode.tcl


   1: Node/MobileNode instproc add-target { agent port } {
   2: $self instvar dmux_ imep_ toraDebug_ mac_
   3: ......
   4: # Special processing for AODV
   5: set aodvonly [string first "AODV" [$agent info class]] 
   6: if {$aodvonly != -1 } {
   7: $agent if-queue [$self set ifq_(0)] ; # ifq between LL and MAC
   8: $agent install-tap $mac_(0)
   9: ......
  10: }

Network Simulators for Education and Research

There are various real hardware tools and emulators are available in the market for measuring the performance of a network, wireless network. But one cannot invest much in terms of money and time. Hence there should be some tools that helps the researchers to do their research to measure the performance and find the results. Here are some of the tools that are free and easily avaialble to everyone at the cost of Time (you need to invest time thats what a researcher is supposed to do)
1. Network Simulator 2 (NS2)
Link : http://www.isi.edu/nsnam/ns/
Ns is a discrete event simulator targeting for networking research. This simulator provides support for simulation of Wired networks like TCP, routing, and multicast protocols over wired and wireless  networks. In short it is called as NS2.
Languages Used: Tcl, OTcl, C++, Simple AWK Script to analyze the results (freely available in the web)
Pros:
  • It is free and Open Source 
  • Simulate almost any type of networks which are in great demand by the industry/Academia
  • It runs on all Operating Systems like Linux, Solaris, Windows (using cygwin), MacOS and FreeBSD
  • Possible for deeper insights and need to make some assumptions.
  • There are huge number of helping hands(forums) to help.
  • Documentation is perfect and there are some books from leading publishers like Springer, etc.
Cons:
  • Should know the Concepts of TCL/TK and C++
  • Should be strong enough in C++ and its Object oriented Concepts
To know more about NS2, visit http://pradeepkumar.org/category/network-simulator-2
Installation of Network Simulator 2 in Fedora 12, Audio by Pradeepkumar
2. GloMoSim
Link: http://pcl.cs.ucla.edu/projects/glomosim/
GloMoSim is just Global Mobile Simulator, which says that it is targeting mainly for wireless networks, but the wired and hybrid network capability will be added soon. This is developed based on the PARSEC Compiler. Glomosim Supports various layers like Mobility, Radio Propagation, Radio Model, Packet reception models, Data Link, Network (Routing), Transport, Application.
The software can be obtained based on the request, it is free only for Academic Research. For others, QualNet has to be purchased.
Languages Used: Basic knowledge on Parsec, C programming
Pros
  • It is free for educational and academic research
  • It supports almost all the OSI layers with limited benefits
Cons
  • Parsec support for Redhat 7.2 which is outdated
  • The team is targeting mainly on QualNet which is the commercial Version GloMoSim
3. OpNet
Link: http://www.opnet.com/
Opnet is a graduate project of Alain Cohen while he was at MIT. Now the entire product is commercialized. This tool performs the performance comparison of for computer networks and applications. This tool addresses application performance management, network performance management and Research & Development in Network
Pros
  • used to enhance existing protocols
  • to develop proprietary protocol
  • test and demonstrate technology designs
Cons
  • Cost of the product is high

(Source: http://campus.murraystate.edu)
4. Omnet++
Link: http://www.omnetpp.org/
Omnet++ is a discrete event simulator that concentrates on wired and wireless networks. Languages used are Java, C++, SystemC.
Pros
  • It is free for academics
  • useful for wired and wireless networks
  • Recently a new horizon, a parallel simulation extension of Omnet++ for multicore/multiprocessor is developed and released.
  • So many frameworks free to download
  • Best documentation
Cons
  • some of the frameworks are version compatible (if a framework developed for 3.3 version, it may not work under version 4.0)

(Source: cs.uni-paderborn.de)
5. NS3
Link: http://www.nsnam.org/
This is also a discrete event simulator that concentrates on network research. It is written in C++ and Python. So a basic knowledge of python is needed to learn this tool. It supports Linux, Windows (cygwin) and also under visual studio 2010.
Pros:
  • Proper documentation is available
  • it is free
  • support for wired and wireless networks
Cons
  • to learn a new scripting python
  • online forums are there much

(source: http://www.nsnam.org)
6. QualNet
Link: http://www.scalable-networks.com/products/qualnet/
QualNet Developer is a network evaluation software that analyze the performance of wired, wireless and hybrid network. QualNet supports thousands of nodes for simulation and also supports for 64 bit Operating system.
It works on Unix, Linux, MacOS and even can be deployed in live networks.
This tool is an extension of GloMoSim which is being commercialized. They have separate licenses for Academics and others. Refer the link above for pricing and support.
7. NetSim
Link: http://tetcos.com/software.html
NetSim is a comprehensive tool for studying computer networks. NetSim features state of the art network simulation technology, and comes with additional offerings that enhance and quicken students’ learning, and prepare them better for their career.
  • Model networks with various technologies, protocols, devices and traffic types.
  • Study Performance metrics at network, link by link and packet levels
  • Analyze and graph, inter and intra protocol performance by varying modeling attributes
  • Learn from detailed simulation lab experiments
C/C++ is supported. Only a demo version is available for download, contact the above link for pricing and support for academic or standard
8. TOSSIM
Link:http://www.cs.berkeley.edu/~pal/research/tossim.html
This simulator is mainly for sensor networks. TOSSIM is an extension for TinyOS Mote SIMulator.
  • It is free of cost and can scale upto 1000 of nodes
  • one can test the algorithm as well as implementation (validation can also be done)
  • It includes physical layer design to application layer design
  • Hardware in the loop is possible
  • it also has a GUI called TinyViz which can be visualized for running simulations of sensor networks.
(Source: tinyos.net)
and there are more number of tools in the market either for Free or limited Cost.

Creating a New Agent in Network Simulator 2

How to create a new agent in NS2. You can use any version of the Simulator. The following codes will make you to understand the writing of a sample agent.

Requirements:

  • NS2 Simulator
  • A tcl file to test the compiled agent

If any two values are supplied from the TCL file, the agent computes the Surface area of the Cylinder which is nothing but (2* PI * r * h).  The supplied values from TCL file are r and h.

How to do that.

1. Copy the newagent.cc (given below ) file in ~ns-allinone-2.34/ns-2.34/newfolder
2. Make an entry in the ~ns-2.34/Makefile.in
    Make an entry in the OBJ_CC =
            newfolder/newagent.o \
3. in the shell prompt, go to ~ns-2.34 and give the command
./configure
make
4. run the file agent_new.tcl (given below)
you can see the output

Here is the C++ code to be written and compiled

//Name of the file is newagent.cc and put it in a folder inside ~ns-2.34/newfolder/
#include <stdio.h>
#include <string.h>
#include "agent.h"
class TSPAgent : public Agent {
public:
        TSPAgent();
protected:
        int command(int argc, const char*const* argv);
private:
        int    tsp_var1;
        double tsp_var2;
        void   TSPPrivFunc(void);
};

static class TSPAgentClass : public TclClass {
public:
       TSPAgentClass() : TclClass("Agent/TSPAgentOtcl") {}
        TclObject* create(int, const char*const*) {
                return(new TSPAgent());
        }
} class_tsp_agent;

TSPAgent::TSPAgent() : Agent(PT_UDP) {
       bind("tsp_var1_otcl", &tsp_var1);
       bind("tsp_var2_otcl", &tsp_var2);
}
int TSPAgent::command(int argc, const char*const* argv) {
      if(argc == 2) {
           if(strcmp(argv[1], "call-tsp-priv-func") == 0) {
                  TSPPrivFunc();
                  return(TCL_OK);
           }
      }
     return(Agent::command(argc, argv));
}

void TSPAgent::TSPPrivFunc(void) {
      Tcl& tcl = Tcl::instance();
      tcl.eval("puts \"Message From TSPPrivFunc\"");
      tcl.evalf("puts \"     Area of the Cylinder is = %f\"", tsp_var1*tsp_var2*2*3.14);
}

TCL Code to Test the above C++ Program (Agent)

# Create MyAgent (This will give two warning messages that
set myagent [new Agent/TSPAgentOtcl]

# Set configurable parameters of MyAgent
$myagent set tsp_var1_otcl 2
$myagent set tsp_var2_otcl 6.5

# Give a command to MyAgent
$myagent call-tsp-priv-func