0% found this document useful (0 votes)
3 views6 pages

Exam Linux Lab

The document contains two NS3 simulation programs: the first animates a wireless topology with three nodes using NetAnim, while the second analyzes network traffic in a star topology with 16 spokes connected to a hub. The first program sets up WiFi connections and mobility for nodes, and the second establishes point-to-point connections with UDP echo applications to generate traffic. Both programs utilize NS3 modules to simulate network behavior and generate output files for analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Exam Linux Lab

The document contains two NS3 simulation programs: the first animates a wireless topology with three nodes using NetAnim, while the second analyzes network traffic in a star topology with 16 spokes connected to a hub. The first program sets up WiFi connections and mobility for nodes, and the second establishes point-to-point connections with UDP echo applications to generate traffic. Both programs utilize NS3 modules to simulate network behavior and generate output files for analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q A ) WRITE A PROGRAM TO ANIMATE THE WIRELESS TOPOLOGY WITH USING NS3 AND

NETANIM.

#include "ns3/core-module.h"

#include "ns3/network-module.h"

#include "ns3/mobility-module.h"

#include "ns3/wifi-module.h"

#include "ns3/internet-module.h"

#include "ns3/netanim-module.h"

using namespace ns3;

int main (int argc, char *argv[])

NodeContainer nodes;

[Link](3);

WifiHelper wifi;

[Link](WIFI_PHY_STANDARD_80211b);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();

[Link] ([Link] ());

WifiMacHelper wifiMac;

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

NetDeviceContainer devices = [Link] (wifiPhy, wifiMac, nodes);


MobilityHelper mobility;

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add(Vector(0.0, 0.0, 0.0));

positionAlloc->Add(Vector(5.0, 0.0, 0.0));

positionAlloc->Add(Vector(10.0, 0.0, 0.0));

[Link](positionAlloc);

[Link] ("ns3::RandomWalk2dMobilityModel",

"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));

[Link](nodes);

InternetStackHelper internet;

[Link](nodes);

Ipv4AddressHelper ipv4;

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

Ipv4InterfaceContainer interfaces = [Link](devices);

AnimationInterface anim ("[Link]");

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

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

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

[Link]([Link](0), 255, 0, 0);

[Link]([Link](1), 0, 255, 0);


[Link]([Link](2), 0, 0, 255);

Simulator::Stop (Seconds (20.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

OUTPUT : -

Q B ) Analyze the network traffic using wireshark on star topology with 16 spokes.

#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"

using namespace ns3;

int main(int argc, char *argv[])

CommandLine cmd;

[Link](argc, argv);

NodeContainer hub;

[Link](1);

NodeContainer spokes;

[Link](16);

InternetStackHelper internet;

[Link](hub);

[Link](spokes);

PointToPointHelper p2p;

[Link]("DataRate", StringValue("5Mbps"));

[Link]("Delay", StringValue("2ms"));

Ipv4AddressHelper ipv4;

// Connect each spoke to hub

for (uint32_t i = 0; i < 16; i++)


{

NodeContainer pair([Link](0), [Link](i));

NetDeviceContainer devices = [Link](pair);

std::ostringstream subnet;

subnet << "10.1." << (i+1) << ".0";

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

[Link](devices);

// Enable PCAP tracing (generates .pcap files)

[Link]("star_topology_spoke_" + std::to_string(i+1), [Link](0), true);

[Link]("star_topology_spoke_" + std::to_string(i+1), [Link](1), true);

// Setup simple UDP Echo applications for some traffic

uint16_t echoPort = 9;

UdpEchoServerHelper echoServer(echoPort);

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

[Link](Seconds(1.0));

[Link](Seconds(10.0));

for (uint32_t i = 0; i < 16; i++)

UdpEchoClientHelper echoClient(Ipv4Address("[Link]"), echoPort); // Hub IP on subnet


[Link]

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

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

[Link]("PacketSize", UintegerValue(1024));
ApplicationContainer clientApps = [Link]([Link](i));

[Link](Seconds(2.0 + i));

[Link](Seconds(10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables();

Simulator::Stop(Seconds(11.0));

Simulator::Run();

Simulator::Destroy();

return 0;

You might also like