Networkng Full

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 54

SHAGUN DEOGHARKAR

FYMCA Roll No. 12

NETWORKING WITH
LINUX
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 1
Aim:Installation of NS-3 in Linux
Steps:

1.Sudo apt upgrade

2.Sudo apt update

3.sudo apt-get install g++ python


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
4.  sudo apt-get install g++ python3 python3-dev pkg-config
sqlite3

5. sudo apt-get install qt5-default mercurial

6. sudo apt-get install gir1.2-goocanvas-2.0 python-gi python-


gi-cairo python3-pygraphviz pyhton-gi python3-gi-cairo
python3-pygraphviz gir1.2-gtk-3.0
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
7. sudo apt-get install gdb valgrind

8. sudo apt-get install doxygen graphviz imagemagick

9. sudo apt install python3-pip

10. pip install ipython


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
11. sudo apt-get install texlive texlive-extra-utils texlive-
latex-extra texlive-font-utils dvipng latexmk

12. sudo apt-get install python3-sphinx dia

13. sudo apt-get install tcpdump


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
14. sudo apt-get install cmake libc6-dev libc6-dev-i386
libclang-6.0-dev llvm-6.0-dev automake python3-pip

15. pip install cxxfilt

16. mkdir workspace

17. cd workspace

18. download file from nsnam.org


(https://www.nsnam.org/releases/ns-3-32/) ns – 3.32 and move
it into workspace

19. tar jxvf ns-allinone-3.32.tar.bz2 (cmd to unzip folder)

20. cd ns-allinone-3.32

21. ./build.py --enable-examples --enable-tests

22. cd ns-3.32 23. ./test.py

Practical No 2
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Aim:Installation of NetAnim
1.sudo apt upgrade

2.sudo apt update

3.sudo ./waf configure

4. sudo ./waf build


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
5.cd netanim-3.108

6.ls

7.make clean

8.qmake NetAnim.pro

9./NetAnim

NetAnim
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 3
Aim:Installation of WireShark
Steps:

1.Sudo apt upgrade

2.Sudo apt update

3. sudo add-apt-repository ppa:wireshark-dev/stable

4.sudo apt install wireshark


SHAGUN DEOGHARKAR
FYMCA Roll No. 12

5.configuring wireshark click yes


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 4
Aim: Point to point topology with ns3.

Source Code:
#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"
#include "ns3/netanim-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"));
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
  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));

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

OUTPUT:Running the first file


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12

Practical No 5
Aim: Point to point topology with ns3 & Net-Anim.

Source Code:
#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"
#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;
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
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("Pract2.xml");
AnimationInterface::SetConstantPosition(nodes.Get(0),10,25);
AnimationInterface::SetConstantPosition(nodes.Get(1),40,25);
anim.EnablePacketMetadata(true);
pointToPoint.EnablePcapAll("Pract2");
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT: Running the second file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12

Practical No 6
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Aim: Star topology with ns3 & Net-Anim.

Source Code:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-star.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/mobility-module.h"
#include "ns3/onoff-application.h"
using namespace ns3;
//NS_LOG_COMPONENT_DEFINE ("Star");
NS_LOG_COMPONENT_DEFINE ("StarExample");
int
main (int argc, char *argv[])
{
// Set up some default values for the simulation.
Config::SetDefault ("ns3::OnOffApplication::PacketSize",
UintegerValue (137));
// ??? try and stick 15kb/s into the data rate
Config::SetDefault ("ns3::OnOffApplication::DataRate",
StringValue ("14kb/s"));
// Default number of nodes in the star. Overridable by command
line argument.
uint32_t nSpokes = 8;
CommandLine cmd (__FILE__);
cmd.AddValue ("nSpokes", "Number of nodes to place in the
star", nSpokes);
cmd.Parse (argc, argv);
LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO);
NS_LOG_INFO ("Build star topology.");
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));
PointToPointStarHelper star (nSpokes, pointToPoint);
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet;
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
star.InstallStack (internet);
NS_LOG_INFO ("Assign IP Addresses.");
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0",
"255.255.255.0"));
NS_LOG_INFO ("Create applications.");
// Create a packet sink on the star "hub" to receive packets.
uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress
(Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory",
hubLocalAddress);
ApplicationContainer hubApp = packetSinkHelper.Install
(star.GetHub ());
hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
// Create OnOff applications to send TCP to the hub, one on
each spoke node.
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetAttribute ("OnTime", StringValue
("ns3::ConstantRandomVariable[Constant=1]"));
onOffHelper.SetAttribute ("OffTime", StringValue
("ns3::ConstantRandomVariable[Constant=0]"));
ApplicationContainer spokeApps;
for (uint32_t i = 0; i < star.SpokeCount (); ++i)
{
AddressValue remoteAddress (InetSocketAddress
(star.GetHubIpv4Address (i), port));
onOffHelper.SetAttribute ("Remote", remoteAddress);
spokeApps.Add (onOffHelper.Install (star.GetSpokeNode (i)));
}
spokeApps.Start (Seconds (1.0));
spokeApps.Stop (Seconds (10.0));
NS_LOG_INFO ("Enable static global routing.");
// Turn on global static routing so we can actually be routed
across the star.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
NS_LOG_INFO ("Enable pcap tracing.");
//
// Do pcap tracing on all point-to-point devices on all nodes.
//
pointToPoint.EnablePcapAll ("star");
star.BoundingBox(1,1,100,100);
AnimationInterface anim("star.xml");
NS_LOG_INFO ("Run Simulation.");
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}

OUTPUT: Running the star topology and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 7
Aim: Bus topology with ns3 & Pyviz.

Source Code:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
// Default Network Topology
//
//10.1.1.0
// n0 -------------- n1 n2 n3 n4
//point-to-point | | |
//|
//================
//LAN 10.1.2.0
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 5;
CommandLine cmd (__FILE__);
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA
nodes/devices", nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if
true", verbose);
cmd.Parse (argc,argv);
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO);
}
nCsma = nCsma == 0 ? 1 : nCsma;
NodeContainer p2pNodes;
p2pNodes.Create (2);
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("10Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("5ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue
("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds
(6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
InternetStackHelper stack;
stack.Install (p2pNodes.Get (0));
stack.Install (csmaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install
(csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress
(nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds
(1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install
(p2pNodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
pointToPoint.EnablePcapAll ("second");
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
csma.EnablePcap ("second", csmaDevices.Get (1), true);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT: Running the Bus topology and visualising it.
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 8
Aim: Introduction to Wireshark with point-to-point topology.

Source Code:
#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"
#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);
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
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("pract5.xml");
AnimationInterface::SetConstantPosition(nodes.Get(0),10,25);
AnimationInterface::SetConstantPosition(nodes.Get(1),40,25);
anim.EnablePacketMetadata(true);
pointToPoint.EnablePcapAll("pract5");
Simulator::Run ();
Simulator::Destroy ();
return 0; }
SHAGUN DEOGHARKAR
FYMCA Roll No. 12

OUTPUT: Running the Wireshark file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 9
Aim: Introduction to YANS with Wi-Fi Access point.

Source Code:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
// Default Network Topology
// Wifi 10.1.3.0
// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
//
//point-to-point |
//
//| | |
//================
//LAN 10.1.2.0
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = false;
CommandLine cmd (__FILE__);
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA
nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if
true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
// The underlying restriction of 18 is due to the grid
position
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
// allocator's configuration; the grid layout will exceed the
// bounding box if more than 18 nodes are provided.
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid
layout exceeds the bounding box" <<
std::endl;
return 1;
}
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO);
}
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("10Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue
("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds
(6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default
();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
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"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel
("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
address.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install
(csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress
(nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds
(1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
if (tracing == true)
{
pointToPoint.EnablePcapAll ("pract6");
phy.EnablePcap ("pract6", apDevices.Get (0));
csma.EnablePcap ("pract6", csmaDevices.Get (0), true);
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT: Running the file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 10
Aim: Visualization of Wi-Fi Access point (YANS) with PyViz.

Source Code:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
// Default Network Topology
// Wifi 10.1.3.0
//
// *

// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
//
//point-to-point |
//
//
//| | |
//================
//LAN 10.1.2.0
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = false;
CommandLine cmd (__FILE__);
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA
nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if
true", verbose);
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
// The underlying restriction of 18 is due to the grid
position
// allocator's configuration; the grid layout will exceed the
// bounding box if more than 18 nodes are provided.
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid
layout exceeds the bounding box" <<
std::endl;
return 1;
}
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO);
}
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("10Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue
("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds
(6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default
();
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
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"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel
("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
address.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
ApplicationContainer serverApps = echoServer.Install
(csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress
(nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds
(1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
if (tracing == true)
{
pointToPoint.EnablePcapAll ("pract7");
phy.EnablePcap ("pract7", apDevices.Get (0));
csma.EnablePcap ("pract7", csmaDevices.Get (0), true);
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT: Running the file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 11
Aim: Visualization of Wi-Fi Access point (YANS) with PyViz.

Source Code:
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
// Default Network Topology
// Wifi 10.1.3.0
// | | | | 10.1.1.0
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
//
//point-to-point |
//| | |
//================
//LAN 10.1.2.0
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nCsma = 3;
uint32_t nWifi = 3;
bool tracing = true;
CommandLine cmd (__FILE__);
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA
nodes/devices", nCsma);
cmd.AddValue ("nWifi", "Number of wifi STA devices", nWifi);
cmd.AddValue ("verbose", "Tell echo applications to log if
true", verbose);
cmd.AddValue ("tracing", "Enable pcap tracing", tracing);
cmd.Parse (argc,argv);
// The underlying restriction of 18 is due to the grid
position
// allocator's configuration; the grid layout will exceed the
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
// bounding box if more than 18 nodes are provided.
if (nWifi > 18)
{
std::cout << "nWifi should be 18 or less; otherwise grid
layout exceeds the bounding box" <<
std::endl;
return 1;
}
if (verbose) {
LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO); }
NodeContainer p2pNodes;
p2pNodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("10Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
csmaNodes.Create (nCsma);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue
("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds
(6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default
();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
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"));
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel
("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
InternetStackHelper stack;
stack.Install (csmaNodes);
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
address.SetBase ("10.1.3.0", "255.255.255.0");
address.Assign (staDevices);
address.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install
(csmaNodes.Get (nCsma));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress
(nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
echoClient.SetAttribute ("Interval", TimeValue (Seconds
(1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps =
echoClient.Install (wifiStaNodes.Get (nWifi - 1));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
if (tracing == true)
{
pointToPoint.EnablePcapAll ("pract8");
phy.EnablePcap ("pract8", apDevices.Get (0));
csma.EnablePcap ("pract8", csmaDevices.Get (0), true);
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT: Running the file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 12
Aim: Animate three way handshake for TCP Connection using
NetAnim.

Source Code:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/ipv4-global-routing-helper.h"
//Inculding Header File
#include "ns3/netanim-module.h"

// Default Network Topology


//
//   10.1.1.0
// n0 -------------- n1   n2   n3   n4
// point-to-point  | | | |
//                ================
//                  LAN 10.1.2.0
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");

int
main (int argc, char *argv[])
{
  bool verbose = true;
  uint32_t nCsma = 3;

  CommandLine cmd (__FILE__);


  cmd.AddValue ("nCsma", "Number of \"extra\" CSMA
nodes/devices", nCsma);
  cmd.AddValue ("verbose", "Tell echo applications to log if
true", verbose);

  cmd.Parse (argc,argv);

  if (verbose)
{
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
   LogComponentEnable ("UdpEchoClientApplication",
LOG_LEVEL_INFO);
   LogComponentEnable ("UdpEchoServerApplication",
LOG_LEVEL_INFO);
}

  nCsma = nCsma == 0 ? 1 : nCsma;

  NodeContainer p2pNodes;
  p2pNodes.Create (2);

  NodeContainer csmaNodes;
  csmaNodes.Add (p2pNodes.Get (1));
  csmaNodes.Create (nCsma);

  PointToPointHelper pointToPoint;
  pointToPoint.SetDeviceAttribute ("DataRate", StringValue
("5Mbps"));
  pointToPoint.SetChannelAttribute ("Delay", StringValue
("2ms"));

  NetDeviceContainer p2pDevices;
  p2pDevices = pointToPoint.Install (p2pNodes);

  CsmaHelper csma;
  csma.SetChannelAttribute ("DataRate", StringValue
("100Mbps"));
  csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds
(6560)));

  NetDeviceContainer csmaDevices;
  csmaDevices = csma.Install (csmaNodes);

  InternetStackHelper stack;
  stack.Install (p2pNodes.Get (0));
  stack.Install (csmaNodes);

  Ipv4AddressHelper address;
  address.SetBase ("10.1.1.0", "255.255.255.0");
  Ipv4InterfaceContainer p2pInterfaces;
  p2pInterfaces = address.Assign (p2pDevices);

  address.SetBase ("10.1.2.0", "255.255.255.0");


  Ipv4InterfaceContainer csmaInterfaces;
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
  csmaInterfaces = address.Assign (csmaDevices);

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install


(csmaNodes.Get (nCsma));
  serverApps.Start (Seconds (1.0));
  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress


(nCsma), 9);
  echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
  echoClient.SetAttribute ("Interval", TimeValue (Seconds
(1.0)));
  echoClient.SetAttribute ("PacketSize", UintegerValue
(1024));

  ApplicationContainer clientApps = echoClient.Install


(p2pNodes.Get (0));
  clientApps.Start (Seconds (2.0));
  clientApps.Stop (Seconds (10.0));

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  pointToPoint.EnablePcapAll ("pract9");
  csma.EnablePcap ("pact9", csmaDevices.Get (1), true);
  //Including Animation
  AnimationInterface anim("pract9.xml");

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

OUTPUT: Running the file and visualising it.


SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
Practical No 13
Aim:Analyze the Network traffic using wireshark
Step:-Considering en2s0 network

2.arp
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
3.Graph

4.TCP
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
SHAGUN DEOGHARKAR
FYMCA Roll No. 12

Practical No 14
Aim:Analyze the performance parameter of the network using
Wireshark.
Steps:

1.ssl

2.TCP
SHAGUN DEOGHARKAR
FYMCA Roll No. 12
3.ARP

4.ICMP
SHAGUN DEOGHARKAR
FYMCA Roll No. 12

5.Tcp.port==80

You might also like