0% found this document useful (0 votes)
49 views27 pages

Linux Lab 4 Assignment

The document describes a lab assignment to simulate a hybrid network topology in NS-3 and perform some tasks. The tasks include changing the number of CSMA nodes to 15 using command line arguments, performing network animation by setting node positions, and modifying log levels to LOG_LEVEL_ALL and another option. Code snippets are provided to demonstrate completing the tasks.

Uploaded by

s1062230092
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
0% found this document useful (0 votes)
49 views27 pages

Linux Lab 4 Assignment

The document describes a lab assignment to simulate a hybrid network topology in NS-3 and perform some tasks. The tasks include changing the number of CSMA nodes to 15 using command line arguments, performing network animation by setting node positions, and modifying log levels to LOG_LEVEL_ALL and another option. Code snippets are provided to demonstrate completing the tasks.

Uploaded by

s1062230092
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

Name: Shaikh Inamul Hasan

Roll no: 100

Lab Assignment 4: Write a Program to simulate Hybridtopology

1. Change csma node to 15 through command line analyze the changes 1 ./waf -

-run scratch/[Link]
Output:-

2 ./waf --run “scratch/[Link] --nCsma=15”

Output:-

2. Perform animation through NetAnim

AnimationInterface anim(“[Link]”);
Name: Shaikh Inamul Hasan
Roll no: 100

And set the position for each node


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"
#include "ns3/netanim-module.h"

// Default Network Topology


//
// Wifi [Link]
// AP
// * * * *
// | | | | [Link]
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

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 );


[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] ("nWifi", "Number of wifi STA devices", nWifi);


[Link] ("verbose", "Tell echo applications to log if true", verbose);
[Link] ("tracing", "Enable pcap tracing", tracing);

[Link] (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;
[Link] (2);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);
Name: Shaikh Inamul Hasan
Roll no: 100

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

NodeContainer wifiStaNodes;
wifi[Link] (nWifi);
NodeContainer wifiApNode = [Link] (0);

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();


YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); [Link]
([Link] ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
[Link] ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

[Link] ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

MobilityHelper mobility;

[Link] ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
Name: Shaikh Inamul Hasan
Roll no: 100

"DeltaX", DoubleValue (5.0),


"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));

[Link] ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
[Link] (wifiStaNodes);

[Link] ("ns3::ConstantPositionMobilityModel");
[Link] (wifiApNode);

InternetStackHelper stack; [Link]


(csmaNodes); [Link]
(wifiApNode); [Link]
(wifiStaNodes);

Ipv4AddressHelper address;

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

[Link] ("[Link]", "[Link]");


[Link] (staDevices);
[Link] (apDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


Name: Shaikh Inamul Hasan
Roll no: 100

[Link] ("MaxPackets", UintegerValue (1));


[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps =
[Link] (wifi[Link] (nWifi - 1)); [Link]
(Seconds (2.0));
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (10.0));

if (tracing == true)
{
[Link] ("third");
[Link] ("third", [Link] (0));
[Link] ("third", [Link] (0), true);
}

std::string animFile = "[Link]";


AnimationInterface anim(animFile);
[Link]([Link](0), 0, 0);
[Link]([Link](1), 50, 100);

Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Output:-
Name: Shaikh Inamul Hasan
Roll no: 100

3. Replace LOG_LEVEL_INFO with any two of the following


LOG_LEVEL_ALL
LOG_PREFIX_FUN
C
LOG_PREFIX_TIM
E
LOG_PREFIX_NOD
E
LOG_PREFIX_LEV
EL
LOG_PREFIX_ALL
Code(For LOG_LEVEL_ALL ):

#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"
#include "ns3/netanim-module.h"

// Default Network Topology


Name: Shaikh Inamul Hasan
Roll no: 100

//
// Wifi [Link]
// AP
// * * * *
// | | | | [Link]
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

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 );


[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
[Link] ("nWifi", "Number of wifi STA devices", nWifi);
[Link] ("verbose", "Tell echo applications to log if true", verbose);
[Link] ("tracing", "Enable pcap tracing", tracing);

[Link] (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)


{
Name: Shaikh Inamul Hasan
Roll no: 100

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_ALL );
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_ALL );
}

NodeContainer p2pNodes;
[Link] (2);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

NodeContainer wifiStaNodes;
wifi[Link] (nWifi);
NodeContainer wifiApNode = [Link] (0);

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();


YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] ([Link] ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
[Link] ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

[Link] ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

MobilityHelper mobility;

[Link] ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));

[Link] ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
[Link] (wifiStaNodes);

[Link] ("ns3::ConstantPositionMobilityModel");
[Link] (wifiApNode);

InternetStackHelper stack;
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] (csmaNodes); [Link]


(wifiApNode); [Link]
(wifiStaNodes);

Ipv4AddressHelper address;

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

[Link] ("[Link]", "[Link]");


[Link] (staDevices);
[Link] (apDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (1));
[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps =
[Link] (wifi[Link] (nWifi - 1)); [Link]
(Seconds (2.0));
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (10.0));


Name: Shaikh Inamul Hasan
Roll no: 100

if (tracing == true)
{
[Link] ("third");
[Link] ("third", [Link] (0));
[Link] ("third", [Link] (0), true);
}
/*
std::string animFile = "[Link]";
AnimationInterface anim(animFile);
[Link]([Link](0), 0, 0);
[Link]([Link](1), 50, 100);
*/

Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Output:-(For LOG_LEVEL_ALL ):

Code(For LOG_PREFIX_FUNC ):-


#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"
Name: Shaikh Inamul Hasan
Roll no: 100

#include "ns3/csma-module.h" #include


"ns3/internet-module.h" #include "ns3/yans-
wifi-helper.h"#include "ns3/ssid.h"
#include "ns3/netanim-module.h"

// Default Network Topology


//
// Wifi [Link]
// AP
// * * * *
// | | | | [Link]
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

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 );


[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
[Link] ("nWifi", "Number of wifi STA devices", nWifi);
[Link] ("verbose", "Tell echo applications to log if true", verbose);
[Link] ("tracing", "Enable pcap tracing", tracing);

[Link] (argc,argv);

// The underlying restriction of 18 is due to the grid position


Name: Shaikh Inamul Hasan
Roll no: 100

// 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_PREFIX_FUNC );
LogComponentEnable ("UdpEchoServerApplication", LOG_PREFIX_FUNC );
}

NodeContainer p2pNodes;
[Link] (2);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);
Name: Shaikh Inamul Hasan
Roll no: 100

NodeContainer wifiStaNodes;
wifi[Link] (nWifi);
NodeContainer wifiApNode = [Link] (0);

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();


YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); [Link]
([Link] ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
[Link] ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

[Link] ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

MobilityHelper mobility;

[Link] ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));

[Link] ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] (wifiStaNodes);

[Link] ("ns3::ConstantPositionMobilityModel");
[Link] (wifiApNode);

InternetStackHelper stack; [Link]


(csmaNodes); [Link]
(wifiApNode); [Link]
(wifiStaNodes);

Ipv4AddressHelper address;

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

[Link] ("[Link]", "[Link]");


[Link] (staDevices);
[Link] (apDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (1));
[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps =
[Link] (wifi[Link] (nWifi - 1)); [Link]
(Seconds (2.0));
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (10.0));

if (tracing == true)
{
[Link] ("third");
[Link] ("third", [Link] (0));
[Link] ("third", [Link] (0), true);
}
/*
std::string animFile = "[Link]";
AnimationInterface anim(animFile);
[Link]([Link](0), 0, 0);
[Link]([Link](1), 50, 100);
*/

Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Output:(For LOG_PREFIX_FUNC ):-

Code(For LOG_PREFIX_TIME):-
#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"
Name: Shaikh Inamul Hasan
Roll no: 100

#include "ns3/ssid.h"
#include "ns3/netanim-module.h"

// Default Network Topology


//
// Wifi [Link]
// AP
// * * * *
// | | | | [Link]
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

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 );


[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
[Link] ("nWifi", "Number of wifi STA devices", nWifi);
[Link] ("verbose", "Tell echo applications to log if true", verbose);
[Link] ("tracing", "Enable pcap tracing", tracing);

[Link] (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.
Name: Shaikh Inamul Hasan
Roll no: 100

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_PREFIX_TIME );
LogComponentEnable ("UdpEchoServerApplication", LOG_PREFIX_TIME );
}

NodeContainer p2pNodes;
[Link] (2);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices;
p2pDevices = [Link] (p2pNodes);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

NodeContainer wifiStaNodes;
wifi[Link] (nWifi);
NodeContainer wifiApNode = [Link] (0);
Name: Shaikh Inamul Hasan
Roll no: 100

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();


YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); [Link]
([Link] ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
[Link] ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

[Link] ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

MobilityHelper mobility;

[Link] ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));

[Link] ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
[Link] (wifiStaNodes);

[Link] ("ns3::ConstantPositionMobilityModel");
Name: Shaikh Inamul Hasan
Roll no: 100

[Link] (wifiApNode);

InternetStackHelper stack; [Link]


(csmaNodes); [Link]
(wifiApNode); [Link]
(wifiStaNodes);

Ipv4AddressHelper address;

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

[Link] ("[Link]", "[Link]");


[Link] (staDevices);
[Link] (apDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (1));
[Link] ("Interval", TimeValue (Seconds (1.0)));
[Link] ("PacketSize", UintegerValue (1024));

ApplicationContainer clientApps =
[Link] (wifi[Link] (nWifi - 1)); [Link]
(Seconds (2.0));
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Name: Shaikh Inamul Hasan
Roll no: 100

Simulator::Stop (Seconds (10.0));

if (tracing == true)
{
[Link] ("third");
[Link] ("third", [Link] (0));
[Link] ("third", [Link] (0), true);
}
/*
std::string animFile = "[Link]";
AnimationInterface anim(animFile);
[Link]([Link](0), 0, 0);
[Link]([Link](1), 50, 100);
*/

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

Output:(For LOG_PREFIX_TIME ):-

4. Send 4 packets from client to server through cmd


Get IP address information through Wireshark tool.(Linux/Windows)
Create a Trace file (.tr file) and read information through TraceMetric Tool/tcpdump
⇒ Steps to download TraceMetric Tool
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"
Name: Shaikh Inamul Hasan
Roll no: 100

#include "ns3/internet-module.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/netanim-module.h"

// Default Network Topology


//
/ Wifi [Link]
// AP
// * * * *
/ | | | | [Link]
// n5 n6 n7 n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN [Link]

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 );


[Link] ("nCsma", "Number of \"extra\" CSMA nodes/devices", nCsma);
[Link] ("nWifi", "Number of wifi STA devices", nWifi);
[Link] ("verbose", "Tell echo applications to log if true", verbose);
[Link] ("tracing", "Enable pcap tracing", tracing);

[Link] (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.
Name: Shaikh Inamul Hasan
Roll no: 100

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_PREFIX_TIME );
LogComponentEnable ("UdpEchoServerApplication", LOG_PREFIX_TIME );
}

NodeContainer p2pNodes;
[Link] (2);

PointToPointHelper pointToPoint;
[Link] ("DataRate", StringValue ("5Mbps"));
[Link] ("Delay", StringValue ("2ms"));

NetDeviceContainer p2pDevices; p2pDevices =


[Link] (p2pNodes);

NodeContainer csmaNodes;
[Link] ([Link] (1));
[Link] (nCsma);

CsmaHelper csma;
[Link] ("DataRate", StringValue ("100Mbps"));
[Link] ("Delay", TimeValue (NanoSeconds (6560)));

NetDeviceContainer csmaDevices;
csmaDevices = [Link] (csmaNodes);

NodeContainer wifiStaNodes;
wifi[Link] (nWifi);
NodeContainer wifiApNode = [Link] (0);
Name: Shaikh Inamul Hasan
Roll no: 100

YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();


YansWifiPhyHelper phy = YansWifiPhyHelper::Default (); [Link]
([Link] ());

WifiHelper wifi;
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");

WifiMacHelper mac;
Ssid ssid = Ssid ("ns-3-ssid");
[Link] ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));

NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);

[Link] ("ns3::ApWifiMac", "Ssid",


SsidValue (ssid));

NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);

MobilityHelper mobility;

[Link] ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue ("RowFirst"));

[Link] ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
[Link] (wifiStaNodes);

[Link] ("ns3::ConstantPositionMobilityModel"); [Link]


(wifiApNode);
Name: Shaikh Inamul Hasan
Roll no: 100

InternetStackHelper stack; [Link]


(csmaNodes); [Link]
(wifiApNode); [Link]
(wifiStaNodes);

Ipv4AddressHelper address; [Link]

("[Link]", "[Link]");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = [Link] (p2pDevices);

[Link] ("[Link]", "[Link]");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = [Link] (csmaDevices);

[Link] ("[Link]", "[Link]");


[Link] (staDevices);
[Link] (apDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = [Link] ([Link] (nCsma));


[Link] (Seconds (1.0));
[Link] (Seconds (10.0));

UdpEchoClientHelper echoClient ([Link] (nCsma), 9);


[Link] ("MaxPackets", UintegerValue (1)); [Link]
("Interval", TimeValue (Seconds (1.0))); [Link] ("PacketSize",
UintegerValue (1024));

ApplicationContainer clientApps = [Link]


(wifi[Link] (nWifi - 1));
[Link] (Seconds (2.0));
[Link] (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

Simulator::Stop (Seconds (10.0));


Name: Shaikh Inamul Hasan
Roll no: 100

if (tracing == true)
{
[Link] ("third"); [Link]
("third", [Link] (0)); [Link] ("third",
[Link] (0), true);
}
/*
std::string animFile = "[Link]";
AnimationInterface anim(animFile);
[Link]([Link](0), 0, 0);
[Link]([Link](1), 50, 100);
*/

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

Output:-

Download TraceMetrics From SourceForge


[Link]

Follow Steps from :


[Link] metrics-
tool-an-elementary-trace-analysis-solution-for-ns-3/

You might also like