Network Simulator-3 (NS-3) Practical Lab Manual
ISBN 9788119221820

Highlights

Notes

  

Practical 7:: Defualt Network Topology (Point-to-Point)

/* -*- Mode:C++; c-file-style:”gnu”; indent-tabs-mode:nil; -*- */

/*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License version 2 as

* published by the Free Software Foundation;

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

*/

#include “ns3/core-module.

h” #include “ns3/network-module.

h” #include “ns3/internet-module.h”

#include “ns3/point-to-point-module.

h” #include “ns3/applications-module.h”

//netAnimation

#include “ns3/netanim-module.

h” #include “ns3/mobility-module.h”

// Default Network Topology

//

// 10.1.1.0

// n0 n1

// point-to-point

//

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“FirstScriptExample”); int

main (int argc, char *argv[])

{

CommandLine cmd ( FILE );

cmd.Parse (argc, argv);

Time::SetResolution (Time::NS);

LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);

LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);

NodeContainer nodes;

nodes.Create (2);

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes);

InternetStackHelper stack;

stack.Install (nodes);

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (devices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));MobilityHelper mobility;

mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

mobility.Install(nodes);

AnimationInterface anim(“first.xml”);

AnimationInterface::SetConstantPosition (nodes.Get(0), 10, 25);

AnimationInterface::SetConstantPosition(nodes.Get(1), 40,25);

anim.EnablePacketMetadata(true);

pointToPoint.EnablePcapAll(“first”);

Simulator::Run ();Simulator::Destroy ();return 0;

}

Output:

To Generate the Graph refer data.txt file

20

1

10080

4480

0.444444444444444

0.711796246648794

100

1

177457

36594

0.206213336188485

0.427518656716418

200

1

615864

107739

0.174939597053895

0.307852186936455

300

1

1264802

195851

0.154847161848258

0.264189805352033

400

3

2036278

254648

0.125055616178145

0.218597530952615

500

3

3142241

341094

0.108551190058306

0.193741027075484

gplot.plt file to Generate Graph

set terminal png

set output “Lalit.png”

set title “Point to Point Toplogy end to end delay” set xlabel “nodes”

set ylabel “end to end delay”

plot “data.txt” using 1: 5 with linespoint title “TimeDelay” lw 4,”data.txt” using 1: 6 with linespoint title “DBR “ lw 2

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