100% found this document useful (1 vote)
231 views15 pages

Assignment 3 PDF

The document describes simulating routing algorithms in NS3 by: 1) Configuring a topology with 10 nodes connected by links and assigning IP addresses 2) Installing network stacks on the nodes and setting up routing protocols 3) Generating traffic between two nodes by installing a UDP application and sink

Uploaded by

PArk100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
231 views15 pages

Assignment 3 PDF

The document describes simulating routing algorithms in NS3 by: 1) Configuring a topology with 10 nodes connected by links and assigning IP addresses 2) Installing network stacks on the nodes and setting up routing protocols 3) Generating traffic between two nodes by installing a UDP application and sink

Uploaded by

PArk100
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Department of Electrical Engineering

Sharif University of Technology

Experimenting Network Layer


with NS3
Goals
1) Become familiar with Network Simulator 3
2) Simulate routing algorithm in fixed wired network
3) Simulate routing algorithms for Ad hoc networks

Introduction
The network layer is concerned with getting packets from the source all the way to the destination.
Getting to the destination may require making many hops at intermediate routers along the way. This
function clearly contrasts with that of the data link layer, which has the more modest goal of just moving
frames from one end of a wire to the other.
To achieve its goals, the network layer must know about the topology of the communication subnet (i.e.,
the set of all routers) and choose appropriate paths through it. It must also take care to choose routes to
avoid overloading some of the communication lines and routers while leaving others idle. It is up to the
network layer to deal with them.
A router in the network needs to be able to look at a packets destination address and then determine
the output port which is the best choice to get the packet to that destination. The router makes this
decision by consulting a forwarding table. Routing algorithms are required to build the routing tables and
hence forwarding tables.
The basic problem of routing is to find the lowest-cost path between any two nodes, where the cost of a
path equals the sum of the costs of all the edges that make up the path.
Routing is achieved in most practical networks by running routing protocols among the nodes. The
protocols provide a distributed, dynamic way to solve the problem of finding the lowest-cost path in the
presence of link and node failures, and changing edge costs. In this exercise you will see some NS3
features to simulate routing.

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology

I) Routing in Fixed wired Networks


In this part we want to run a simulation to investigate the routing algorithm in the following topology. The
topology is the same as the example, the sink tree of which is calculated in the class based on Dijkstras
shortest path algorithm.
A

8
F

First thing you should know that NS3 code is in C++ syntax. In fact NS3 is a library for C++ .It consists of
several modules for different parts of network simulation. When you want to do a simulation you include
the modules you need and then you write your code.
For this part add these libraries:
#include
#include
#include
#include
#include
#include
#include
#include
#include

"ns3/core-module.h"
"ns3/network-module.h"
"ns3/internet-module.h"
"ns3/point-to-point-module.h"
"ns3/netanim-module.h"
"ns3/applications-module.h"
"ns3/animation-interface.h"
"ns3/point-to-point-layout-module.h"
"ns3/ipv4-static-routing-helper.h"

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
#include
#include
#include
#include
#include
#include
#include
#include
#include

"ns3/ipv4-list-routing-helper.h"
"ns3/ipv4-global-routing-helper.h"
"ns3/flow-monitor.h"
"ns3/flow-monitor-helper.h"
"ns3/flow-monitor-module.h"
<iostream>
<fstream>
<vector>
<string>

Next line will show that this project is implemented in a C++ namespace called ns3. using statement
introduces the ns-3 namespace into the current (global) declarative region. This is a fancy way of
saying that after this declaration, you will not have to type ns3:: scope resolution operator before all of
the ns-3 code in order to use it.
using namespace ns3;
The next line enables you in showing some messages while running the code:
NS_LOG_COMPONENT_DEFINE ("Lab3_part1");
Now you can start the main function of your program.
int main (int argc, char *argv[])
{
//add your codes here
}
First we declare some parameters for our simulation. You should write all other codes on your main
function.
uint32_t PacketSize = 512; // bytes
std::string DataRate ("1Mbps");
uint16_t num_Nodes = 10;
uint16_t UDPport = 9;
bool tracing = false;
CommandLine object allows the user to override any of the defaults at run-time:

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
CommandLine cmd;
cmd.AddValue ("PacketSize", "size of application packet sent", PacketSize);
cmd.AddValue ("DataRate", "rate of pacekts sent", DataRate);
cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
cmd.Parse (argc, argv);
Now you should configure an on/off application to generate data.
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue(PacketSize));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (DataRate));
Config::SetDefault ( "ns3::Ipv4GlobalRouting::RespondToInterfaceEvents",BooleanValue(true));

Now enable Packet Meta data for animator and the name of file for animation output:
ns3::PacketMetadata::Enable();
std::string animFile = "lab3_part1.xml" ;
Now lets create the network topology. Network nodes are stored in a container class called
NodeContainer.
NodeContainer nodes;
nodes.Create (num_Nodes);
Now you should group nodes to make links between them.
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer

AB
BC
CD
DE
EA
FH
GI
HJ
IF
JG
AF
BG
CH
DI
EJ

=
=
=
=
=
=
=
=
=
=
=
=
=
=
=

NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer
NodeContainer

(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get
(nodes.Get

(0),
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8),
(9),
(0),
(1),
(2),
(3),
(4),

nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get
nodes.Get

(1));
(2));
(3));
(4));
(0));
(7));
(8));
(9));
(5));
(6));
(5));
(6));
(7));
(8));
(9));

Now you should assign bandwidth and delay to each link.


PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
p2p.SetChannelAttribute ("Delay", StringValue ("10ms"));
NetDeviceContainer dAB = p2p.Install (AB);
Do it for other links with the values like link AB.
After that we should set Layer 3 settings. To implement ipv4 easily we use InternetStackHelper. This
helper uses static routing as its first priority algorithm for routing; therefore, we redefine the priority:
NS_LOG_INFO("Setting routing protocols");
Ipv4StaticRoutingHelper staticRouting;
Ipv4GlobalRoutingHelper globalRouting;
Ipv4ListRoutingHelper list;
list.Add(staticRouting,0);
list.Add(globalRouting,10);
// Install network stacks on the nodes
InternetStackHelper internet;
internet.SetRoutingHelper(list);
internet.Install(nodes);
Now you should assign IP to each node for routing and also assign the metric of each link to it.
Ipv4AddressHelper ipv4;
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer iAB = ipv4.Assign (dAB);
iAB.SetMetric(0,7);
iAB.SetMetric(1,7);
ipv4.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer iBC = ipv4.Assign (dBC);
iBC.SetMetric(0,4);
iBC.SetMetric(1,4);
ipv4.SetBase ("1.1.3.0", "255.255.255.0");
Ipv4InterfaceContainer iCD = ipv4.Assign (dCD);
iCD.SetMetric(0,6);
iCD.SetMetric(1,6);
ipv4.SetBase ("10.1.4.0", "255.255.255.0");
Ipv4InterfaceContainer iDE = ipv4.Assign (dDE);
iDE.SetMetric(0,3);
iDE.SetMetric(1,3);
ipv4.SetBase ("10.1.5.0", "255.255.255.0");
Ipv4InterfaceContainer iEA = ipv4.Assign (dEA);
iEA.SetMetric(0,3);
iEA.SetMetric(1,3);
ipv4.SetBase ("10.1.6.0", "255.255.255.0");
Ipv4InterfaceContainer iFH = ipv4.Assign (dFH);
iFH.SetMetric(0,5);

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
iFH.SetMetric(1,5);
ipv4.SetBase ("10.1.7.0", "255.255.255.0");
Ipv4InterfaceContainer iGI = ipv4.Assign (dGI);
iGI.SetMetric(0,3);
iGI.SetMetric(1,3);
ipv4.SetBase ("10.1.8.0", "255.255.255.0");
Ipv4InterfaceContainer iHJ = ipv4.Assign (dHJ);
iHJ.SetMetric(0,2);
iHJ.SetMetric(1,2);
ipv4.SetBase ("10.1.9.0", "255.255.255.0");
Ipv4InterfaceContainer iIF = ipv4.Assign (dIF);
iIF.SetMetric(0,7);
iIF.SetMetric(1,7);
ipv4.SetBase ("10.1.10.0", "255.255.255.0");
Ipv4InterfaceContainer iJG = ipv4.Assign (dJG);
iJG.SetMetric(0,6);
iJG.SetMetric(1,6);
ipv4.SetBase ("10.1.11.0", "255.255.255.0");
Ipv4InterfaceContainer iAF = ipv4.Assign (dAF);
iAF.SetMetric(0,8);
iAF.SetMetric(1,8);
ipv4.SetBase ("10.1.12.0", "255.255.255.0");
Ipv4InterfaceContainer iBG = ipv4.Assign (dBG);
iBG.SetMetric(0,3);
iBG.SetMetric(1,3);
ipv4.SetBase ("10.1.13.0", "255.255.255.0");
Ipv4InterfaceContainer iCH = ipv4.Assign (dCH);
iCH.SetMetric(0,5);
iCH.SetMetric(1,5);
ipv4.SetBase ("10.1.14.0", "255.255.255.0");
Ipv4InterfaceContainer iDI = ipv4.Assign (dDI);
iDI.SetMetric(0,2);
iDI.SetMetric(1,2);
ipv4.SetBase ("10.1.15.0", "255.255.255.0");
Ipv4InterfaceContainer iEJ = ipv4.Assign (dEJ);
iEJ.SetMetric(0,6);
iEJ.SetMetric(1,6);
Now, we add the following code to initialize routing database and set up the routing tables in the nodes:
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Now we want to show how to install UDP application on node A and D. First, copy the following code:

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
PacketSinkHelper UDPsink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (),
UDPport));
ApplicationContainer App;
NodeContainer SourceNode = NodeContainer (nodes.Get (0));
NodeContainer SinkNode = NodeContainer (nodes.Get (6));

Where instead of source node and sink node above (0 and 6), you should insert the two last non-equal digits
of your student ID.
To Create a UDP packet sink to receive these packets use the following codes:
App = UDPsink.Install (SinkNode);
App.Start (Seconds (0.0));
App.Stop (Seconds (10.0));
Address Sink_Address(InetSocketAddress(iHD.GetAddress (1), UDPport));
To Create a UDP packet source to send these packets type the following codes:
OnOffHelper UDPsource ("ns3::UdpSocketFactory", Sink_Address);
UDPsource.SetAttribute ("OnTime",
StringValue("ns3::ConstantRandomVariable[Constant=1]"));
UDPsource.SetAttribute ("OffTime",
StringValue("ns3::ConstantRandomVariable[Constant=0]"));
App = UDPsource.Install(SourceNode);
App.Start (Seconds (1.0));
App.Stop (Seconds (10.0));
You should determine your nodes places for NetAnim. Do it with these codes:
AnimationInterface anim (animFile);
Ptr<Node> n = nodes.Get (0);
anim.SetConstantPosition (n, 100, 10);
n = nodes.Get (1);
anim.SetConstantPosition (n, 187, 73);
n = nodes.Get (2);
anim.SetConstantPosition (n, 154, 172);
n = nodes.Get (3);
anim.SetConstantPosition (n, 47, 172);
n = nodes.Get (4);
anim.SetConstantPosition (n, 14, 73);
n = nodes.Get (5);
anim.SetConstantPosition (n, 100, 56);
n = nodes.Get (6);

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
anim.SetConstantPosition
n = nodes.Get (7);
anim.SetConstantPosition
n = nodes.Get (8);
anim.SetConstantPosition
n = nodes.Get (9);
anim.SetConstantPosition

(n, 143, 86);


(n, 127, 136);
(n, 73, 136);
(n, 56, 86);

NS3 has two types of text output: Pcap files which are standard files in network programs. You can read
them with wireshark or winpcap. The second type is NS3s trace files that you can parse it yourself (in
MATLAB for example).
if (tracing == true)
{
AsciiTraceHelper ascii;
p2p.EnableAsciiAll (ascii.CreateFileStream ("Lab3_part1.tr"));
p2p.EnablePcap ("Lab3_part1");
}
To print routing tables you should add the following codes:
Ptr<OutputStreamWrapper> stream1 = Create<OutputStreamWrapper> ("Table2", std::ios::out);
Ipv4GlobalRoutingHelper helper2;
helper2.PrintRoutingTableAllAt(Seconds(2.0),stream1);

And the last thing to do is to define the simulation time and run the simulation. After everything is done,
we destroy the simulator object we have created, and then end the main function.
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
To run the simulation save the code with .cc extension in scratch folder in ns3 directory. Then open a
terminal and cd to ns-allinone-3.x/ns-3.x/ and enter:
./waf run scratch/myfile (without .cc)
Do the simulation and compare the result with what calculated in the class.
Now try to change the metric of an arbitrary link, such that the path created by Dijksta's shortest path
aloghrithm changes. Again do the simulation and investigate how the path for sending packets has been

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology
changed.
In all above parts, you should take some snapshots from NetAnim to compare the results obtained by
simulation with what you calculate manually by the method mentioned in the class.
To see .xml output file with NetAnim open a terminal and cd to the netanim folder (cd netanim) and enter:
./NetAnim
A program will be opened and then click on Open XML trace file and select the .xml output of your program.
You can find all of the outputs of the simulation such as trace file, routing table, .xml file and pcap files in
the following folder:
ns-allinone-3.x/ns-3.x/

II) Routing in Ad hoc networks


In this part, we want to analyze the routing in the ad hoc networks. These networks are quite different
from fixed wired network. What makes ad hoc networks different from wired networks is that all the usual
rules about fixed topologies, fixed and known neighbors, fixed relationship between IP address and
location are not more applicable. Routers can come and go or appear in new places at the drop of a bit.
With a wired network, if a router has a valid path to some destination, that path continues to be valid
indefinitely (barring a failure somewhere in the system). With an ad hoc network, the topology may be
changing all the time, so desirability and even validity of paths can change spontaneously, without
warning. Needless to say, these circumstances make routing in ad hoc networks quite different from
routing in their fixed counterparts.
A variety of routing algorithms for ad hoc networks have been proposed. In this part, we want to become
familiar with OLSR, AODV and DSDV routing algorithms. To do so, we consider the following topology in
which each node only has access to its neighbors.

Data Networks
Dr. M. R. Pakravan

Department of Electrical Engineering


Sharif University of Technology

10

Due to the wireless nature of the topology, we cannot use the codes mentioned in the first part. First, we
should add these header files for further use:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

"ns3/core-module.h"
"ns3/network-module.h"
"ns3/internet-module.h"
"ns3/mobility-module.h"
"ns3/config-store-module.h"
"ns3/applications-module.h"
"ns3/wifi-module.h"
"ns3/internet-module.h"
"ns3/olsr-helper.h"
"ns3/dsdv-helper.h"
"ns3/aodv-helper.h"
"ns3/point-to-point-layout-module.h"
"ns3/ipv4-static-routing-helper.h"
"ns3/ipv4-list-routing-helper.h"
"ns3/ipv4-global-routing-helper.h"
"ns3/flow-monitor.h"
"ns3/flow-monitor-helper.h"
"ns3/flow-monitor-module.h"
"ns3/animation-interface.h"
"ns3/netanim-module.h"
<iostream>
<fstream>
<vector>
<string>

Data Networks
Dr. M. R. Pakravan

10

Department of Electrical Engineering


Sharif University of Technology
Likewise the part one, we add these codes:
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("WifiAdhoc_Routing");

Then add these codes to the main function:


std::string phyMode ("DsssRate1Mbps");
uint32_t PacketSize = 512; // bytes
std::string DataRate ("1Mbps"); // Kbytes per second
uint16_t num_Nodes = 8;
uint16_t UDPport = 9;
bool verbose = false;
bool tracing = false;
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (PacketSize));
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (DataRate));
//"CommandLine object allows the user to override any of the defaults at run-time
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("PacketSize", "size of application packet sent", PacketSize);
cmd.AddValue ("DataRate", "rate of pacekts sent", DataRate);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
cmd.AddValue ("tracing", "turn on ascii and pcap tracing", tracing);
cmd.Parse (argc, argv);
ns3::PacketMetadata::Enable();
std::string animFile = "Lab3_part2.xml" ;

Now lets create the network topology, network nodes are stored in a container class called
NodeContainer:
NodeContainer Nodes;
Nodes.Create (num_Nodes);
The below set of helpers will help us to put together the wifi NICs we want, also some logging switches
are set here:
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}

Data Networks
Dr. M. R. Pakravan

11

Department of Electrical Engineering


Sharif University of Technology
Here we set up the physical layer properties:
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.Set ("RxGain", DoubleValue (-12) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
And the wireless channel properties:
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::FriisPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());
Add a non-QoS upper mac, and disable rate control:
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager","DataMode",StringValue(phyMode),
"ControlMode",StringValue (phyMode));

Set it to adhoc mode:


wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer Devices;
Devices = wifi.Install (wifiPhy, wifiMac, Nodes);
Using MobilityHelper, we set the positions of the nodes:
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator","MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),"DeltaX", DoubleValue (5.0), "DeltaY", DoubleValue
(10.0),"GridWidth", UintegerValue (3), "LayoutType", StringValue ("RowFirst"));
int x[num_Nodes] = {0, 500, 0, 1000, 1500, 500, 1000, 1500,
1000, 1500,
500};
int y[num_Nodes] = {0, 0, 500, 500, 500, 1000, 1000, 1000,
1500, 1500,
500};
int z[num_Nodes] = {0, 0, 0, 0, 0,
0, 0, 0 , 0, 0, 0};
Ptr<ListPositionAllocator> positionAlloc = CreateObject <ListPositionAllocator>();
for(int i = 0; i < num_Nodes; i++)
{
positionAlloc->Add(Vector(x[i], y[i], z[i]));
}
mobility.SetPositionAllocator(positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

Data Networks
Dr. M. R. Pakravan

12

Department of Electrical Engineering


Sharif University of Technology
mobility.Install (Nodes);

Now we enable OLSR routing for the network. The procedure for AODV and DSDV is similar to OLSR.
OlsrHelper olsr;
Ipv4StaticRoutingHelper staticRouting;
Ipv4ListRoutingHelper list;
list.Add (staticRouting, 0);
list.Add (olsr, 10);
InternetStackHelper internet;
internet.SetRoutingHelper (list); // has effect on the next Install ()
internet.Install (Nodes);
Then we assign the IP addresses to the nodes:
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("192.168.1.0", "255.255.255.0");
Ipv4InterfaceContainer i;
i = ipv4.Assign (Devices);

Now, we should create a UDP application between node 0 and node 8:


PacketSinkHelper UDPsink ("ns3::UdpSocketFactory",
InetSocketAddres(Ipv4Address::GetAny (), UDPport));
ApplicationContainer App;
NodeContainer SourceNode = NodeContainer (Nodes.Get (0));
NodeContainer SinkNode = NodeContainer (Nodes.Get (8));
//To Create a UDP packet sink
App = UDPsink.Install(SinkNode);
App.Start (Seconds (30.0));
App.Stop (Seconds (60.0));
//To Create a UDP packet source
OnOffHelper UDPsource ("ns3::UdpSocketFactory",
InetSocketAddress(i.GetAddress(8,0), UDPport));
UDPsource.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
UDPsource.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
App = UDPsource.Install(SourceNode);
App.Start (Seconds (30.0));
App.Stop (Seconds (60.0));

Data Networks
Dr. M. R. Pakravan

13

Department of Electrical Engineering


Sharif University of Technology
OLSR needs time to converge and therefore we should give it some time to converge before starting the
data flow. Also you can add the following codes to print the routing tables meanwhile the simulation:
Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("moh-olsrroutes", std::ios::out);
olsr.PrintRoutingTableAllEvery (Seconds (1), routingStream);

And the last thing to do is to define the simulation time and run the simulation and after everything is done
you should destroy the simulator object as explained in the first part.
For this part of assignment, first run the simulation for each of the routing algorithms (OLSR, AODV and
DSDV). Explain what the parameters are in the tables of each algorithm. What are the differences between
the algorithms?
Second, check the routing table of node 0 and determine when the table converges and when a path
between node 0 and node 8 is established.

At last, set down node 6 at second
+ 40. In this case, the previous path will
10

be no more valid, and a new path should be established. Check the routing table of node 0 and determine
when a new path is created? (You should check the destination with IP address: 192.168.1.9 and see
which node is the interface).

III) Flow Monitor


In this part, we want to become familiar with flow monitor, by means of which you can see the throughput
of each flow easily. To do so, you can add the following codes to your main function:
// 1. Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
// 2. Run simulation for 60 seconds
Simulator::Stop (Seconds (60));
Simulator::Run ();
// 3. Print per flow statistics
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier >
(flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin ();
i != stats.end (); ++i)
{

Data Networks
Dr. M. R. Pakravan

14

Department of Electrical Engineering


Sharif University of Technology
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
std::cout << "Flow " << i->first - 1 << " (" << t.sourceAddress << " -> " <<
t.destinationAddress
<< ")\n";std::cout << " Tx Bytes: " << i->second.txBytes << "\n";
std::cout << " Rx Bytes: " << i->second.rxBytes << "\n";
std::cout << " Throughput: " << i->second.rxBytes * 8.0 /(i>second.timeLastRxPacket.GetSeconds()- i>second.timeFirstTxPacket.GetSeconds()) / 1024 / 1024 << " Mbps \n";
}

IV) Experiment Report:


You should prepare a proper explanatory report for this assignment. Then you should pack this report,
as well as the scripts and output files (.xml) for each part, zip them and upload one file in the courseware.
The received folder should contain:

The scripts written for each part,


The output files (routing tables and .xml files) for each part,
Your report (both MS word and PDF format) that contains the results of the simulations in the form
of plots and some snapshots from NetAnim output. Please kindly that for each part, you should
analyze the results you have found and explain how they are related to the theories discussed in
the class.

Data Networks
Dr. M. R. Pakravan

15

You might also like