Hi All, Our website moved to a new URL. Please bookmark the new link: https://ns2bloggers.blogspot.com/

Tuesday 24 June 2014

KEYBOARD SHORTCUTS FOR USING NAM

Most of the buttons in NAM have keyboard equivalents.We can use it in easy way and handle the network simulation easily. The commands are;

  1. <return> - Typing a <return> will pause nam if it's not already paused. If nam is paused, <return> will step the animation one simulated clock tick. (If your keyboard autorepeats, holding down <return> is a goodway to slow-step through the animation.)
  2. 'p' or 'P' - Pause but not step if paused.
  3. 'c' or 'C' - Continue after a pause.
  4. 'b' or 'B' - Decrease animation time for one screen update interval.
  5. 'r' or 'R' - Rewind.
  6. 'f' or 'F' - Fast Forward.
  7. 'n' or 'N' - Jump to time of next event in the tracefile.
  8. 'x' or 'X' - Undo the last rate change.
  9. 'u' or 'U' - Undo the last time slider drag.
  10. '>' or `.' - Increase the granularity (speed up) by 5%.
  11. '<' or ',' - Decrease the granularity (slow down) by 5%.
  12. <space bar> - Toggle the pause state of nam.
  13. 'q', 'Q' or <control-c> - Quit.
Note they only function when the mouse cursor is inside the nam window.

Monday 2 June 2014

NS2 MODULE FOR ANT COLONY OPTIMIZATION

In computer science and operations research, the ant colony optimization algorithm (ACO) is a probabilistic technique for solving computational problems which can be reduced to finding good paths through graphs.

This algorithm is a member of the ant colony algorithms family, in swarm intelligence methods, and it constitutes some metaheuristic optimizations. Initially proposed by Marco Dorigo in 1992 in his PhD thesis,the first algorithm was aiming to search for an optimal path in a graph, based on the behavior of ants seeking a path between their colony and a source of food. The original idea has since diversified to solve a wider class of numerical problems, and as a result, several problems have emerged, drawing on various aspects of the behavior of ants.

In the natural world, ants (initially) wander randomly, and upon finding food return to their colony while laying down pheromone trails. If other ants find such a path, they are likely not to keep travelling at random, but to instead follow the trail, returning and reinforcing it if they eventually find food.

Over time, however, the pheromone trail starts to evaporate, thus reducing its attractive strength. The more time it takes for an ant to travel down the path and back again, the more time the pheromones have to evaporate. A short path, by comparison, gets marched over more frequently, and thus the pheromone density becomes higher on shorter paths than longer ones. Pheromone evaporation also has the advantage of avoiding the convergence to a locally optimal solution. If there were no evaporation at all, the paths chosen by the first ants would tend to be excessively attractive to the following ones. In that case, the exploration of the solution space would be constrained.

Thus, when one ant finds a good (i.e., short) path from the colony to a food source, other ants are more likely to follow that path, and positive feedback eventually leads to all the ants' following a single path. The idea of the ant colony algorithm is to mimic this behavior with "simulated ants" walking around the graph representing the problem to solve.

This post contains extensions to NS-2 (versions 2.27 and 2.28) which enables the ACO behavior in WSNs. The module is adaptable to the current version of NS-2 since it is installed as a new routing protocol. Written mainly in C++ the ACO module (AntSense) produces the main attributes, however it was design in order to be used by any other technology supported by this simulator.

When designing a routing protocol for WSNs it is important to consider the packet length of each type of packets used by our protocol, since, as already explained communication is an energy-expensive function. In AntSense development, several approaches were used concerning types of packets and different lengths, the configuration illustrated in this section refers to the best pattern found by the results. In ACO approach ants are considered as packets that travel the network changing routing information in order to find the best path towards the anthill, in this case towards the sink-node. The ant packet structure is composed by:
  1. pkt_src: the node that originated the ant packet;
  2. antpath[3]: the three previous nodes visited by the ant;
  3. energy: the average energy per path;
  4. pheromone: the pheromone level that should be dropped by the return ant;
  5. toSinkNode: a boolean variable that informs if the ant is a forward or a return ant;

All the nodes that belong to the ant path are responsible to update the packet with the proper data, and should update also their internal information regarding the neighbor devices and pheromone levels always taking in consideration the direction of the s ant packet. As a normal protocol AntSense also requires a Hello type packets, in order for the nodes know which are the sensor nodes that are contactable with only one hop. The following structure were used in the hello packet:
  1. rp_src: the node that originated the hello packet;
  2. node_energy: the energy of the source node;

ANT Structure
It is important to emphasize that the node energy of the source is also exchange, this procedure allows a to increase the update rate in order to help ants to decide the best route based in available energy.

The AntSense file structure is divided in three different files (Figure): antsense.cc, queue.cc, and table.cc. The first one is the main file, where the routing protocol is written, functions like ant receive and ant forwards are describe here. This main file requires the functions described in the last two files, it uses the queue.cc to manage the data packet queuing, and table.cc to decide the best neighbor device to forward ant packets and data packets.

All the main and “hard” equations are described in the table.cc, where a routing table is kept and updated every time a ant packet is received.

The AntSense model in a first phase was build to behave as a normal ACO approach, however as the integration in WSNs was being designed the final solution reflects several aspects of the WSN integration, i.e. reduce the ant memory to three slots, which allows us to reduce communication time.

For Script, Click here
For More, Click here


Sunday 1 June 2014

PRINTING ROUTING TABLE IN TERMINAL

Here, we are going to generate routing tables IN  for tcl scripts by modifying AODV protocol. For that we have to modify following files in the AODV directory[for AODV directory look at ns2.35 folder];
  1. aodv.h 
  2. aodv.cc

1. aodv.h modification

First display aodv.h file and then add the following lines inside the class AODV in the protected scope Add the line after the rt_down() function.

void rt_print(nsaddr_t nodeid);




Save the aodv.h file and

2. aodv.cc modification

Now click on aodv.cc file and select display option,

Now add the following function rt_print to the aodv.cc file probably below rt_down function.

void  AODV::rt_print(nsaddr_t nodeid) {
aodv_rt_entry *rt;
printf("Node id \t time \t destination \t nexthop \t hop count \t seq.no\n");
for (rt=rtable.head();rt; rt = rt->rt_link.le_next) {
printf("NODE: %i \t %f \t %i \t %i \t \t %i \t \t %i \n", nodeid, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops, rt->rt_seqno);
}
}



Now finally we have to call the function that we written above,we can call it in any part of protocol. Here we are going to call inside recvReply() function.

For that we have to write following line inside if (ih->daddr() == index);

 rt_print(index);



After completing these steps.Open the terminal window and change the directory to the ns2.35 by using following command.

cd /home/user/Desktop/ns-allinone-2.35/ns-2.35 [change path as yours]

and now type 
                                                                     make clean 
then type
                                                                         make
then type
                                                               sudo make install

After successful completion of steps.Run a sample program.
For sample program,click here  and run the program using command ns filename.tcl

Screen shot