Ns2 Code for Shortest Path Routing

Learn to how to implement Ns2 code for shortest Path Routing

When to use Shortest Path routing?

An algorithm that is designed essentially to find a path of minimum length between two specified vertices of a connected weighted graph


General procedure to find out shortest path:

  • Initialize the array smallestWeight so that smallestWeight[u] = weights[vertex, u].
  • Set smallestWeight[vertex] = 0.
  • Find the vertex, v, that is closest to vertex for which the shortest path has not been determined.
  • Mark v as the (next) vertex for which the smallest weight is found.
  • For each vertex w in G, such that the shortest path from vertex to w has not been determined and an edge (v, w) exists, if the weight of the path to w via v is smaller than its current weight, update the weight of w to the weight of v + the weight of the edge (v, w).

NS2 Projects Video Output

See our Latest Video Output of Ns2 Projects on Various Domain.

Ns2 Projects

Customized NS2 Projects for B.E/B.Tech/M.E/M.Tech/Ms/PhD Scholars.

Ns2 Projects Screen Shots

Ns2 Projects Screen Shots.Regular Update of NS2 Projects Screenshots here!

Sample code for shortest path routing:

This code contains main function of dijikstra’s routing algorithm.

int main()
Node N0(0);
Node N1(1);
Node N2(2);
Node N3(3);
Node N4(4);
RoutingVec_t NextHop;
RoutingVec_t Parent;

N0.AddAdj(1, 10);
N0.AddAdj(2, 5);

N1.AddAdj(3, 1);
N1.AddAdj(2, 2);

N2.AddAdj(4, 2);
N2.AddAdj(1, 3);
N2.AddAdj(3, 9);

N3.AddAdj(4, 4);

N4.AddAdj(0, 7);
N4.AddAdj(3, 6);


for (nodeid_t i = 0; i < Nodes.size(); i++)
{ // Get shortest path for each root node
printf("\nFrom root %ld\n", i);
Dijkstra(Nodes, i, NextHop, Parent);
for (unsigned int k = 0; k < Nodes.size(); k++)
printf("Next hop for node %d is %ld\n", k, NextHop[k]);
printf("Printing paths\n");
for (nodeid_t j = 0; j < Nodes.size(); j++)
PrintRoute(i, j, Parent);

Journal Support for Research Scholars
NS2 Projects Journal support
Ns2 Projects Work Progress
  • MANET – Mobile Ad Hoc Network 95%
  • VANET – Vechicle Ad Hoc Netwok 97%
  • LTE – Long Term Evolution 78%
  • IoT – Internet of Things 90%
  • Wireless Sensor Network 89%
  • Network Security 89%
  • Ns2 Attacks 96%
  • Cognitive Radio Network 85%
  • Parallel and Distributed Computing 73%
  • SDN – Software Defined Networking 95%
  • P2P , Video Streaming , Peersim 96%
  • IPV4 , IPV6 88%
  • 4G Network , 5G Network 80%
  • Visual , Underwater Sensor Network 79%
  • Multicasting Communication 84%
  • Wimax, WiFi 90%
  • OFDMA 94%
Our Achievements – Ns2 Projects
Ns2 Projects Achievements