0% found this document useful (0 votes)
85 views12 pages

Practical 5

1. The program simulates a wireless network topology using ns-3 and its modules. It creates nodes for an access point, clients, and wired devices and connects them using Wi-Fi and point-to-point links. 2. IP addresses are assigned to the interfaces and an UDP echo server-client application is run between a wired and wireless node to simulate network traffic. 3. The nodes are placed in a grid layout and their positions animated using the NetAnim module for visualization of the wireless network topology.

Uploaded by

panaspa1993
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)
85 views12 pages

Practical 5

1. The program simulates a wireless network topology using ns-3 and its modules. It creates nodes for an access point, clients, and wired devices and connects them using Wi-Fi and point-to-point links. 2. IP addresses are assigned to the interfaces and an UDP echo server-client application is run between a wired and wireless node to simulate network traffic. 3. The nodes are placed in a grid layout and their positions animated using the NetAnim module for visualization of the wireless network topology.

Uploaded by

panaspa1993
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/ 12

ATHARVA KALE PRACTICAL NO.

5 ROLL NO: 27

AIM: Program to simulate Wireless Network Topology using


netanim and pyviz.

 THEORY:
1. A Wireless network is a type of the computer network that uses the wireless
connections for connecting network nodes for data transfer.
2. Wireless network topology shows how the computers connect each other when
there is no physical connection. The computers communicate each using the
wireless devices.
3. The wireless networks are very useful, inexpensive, popular and widely used.
They are easy setup and do not require the cables installation.
4. Stations:
a. All components that can connect into a wireless medium in a network are
referred to as stations.
b. All stations are equipped with wireless network interface controllers.
Wireless stations fall into two categories: wireless access points (WAPs),
and clients.
5. Access Point(AP):
a. In computer networking, a wireless access point (WAP), or more
generally just access point (AP), is a networking hardware device that
allows other Wi-Fi devices to connect to a wired network.
b. Wireless devices communicate with the wired LAN through a base station
known as an access point (AP) or wireless access point (WAP).
6. Classes Used In Code:
a. Following different classes are used in code:
i. Node Class:
1. In ns-3 the basic computing device abstraction is called the
node. This abstraction is represented in C++ by the class Node.
2. This abstraction is represented in C++ by the class Node.
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

3. The Node class provides methods for managing the


representations of computing devices in simulations.
ii. PointToPointHelper Class:
1. PointToPointNetDevice class specializes the NetDevice
abstract base class.
2. Together with a PointToPointChannel the class models,
with some level of abstraction, a generic point-to-point or
serial link. Key parameters or objects that can be specified
for this device include a queue, data rate, and interframe
transmission gap.
iii. NetDevice Class:
1. Net device abstraction covers both the software driver and
the simulated hardware. The net device abstraction is
represented in C++ by the class NetDevice.
2. The NetDevice class provides methods for managing
connections to Node and Channel objects; and may be
specialized by developers in the object-oriented
programming sense.
iv. Ipv4AddressHelper Class:
1. A helper class to make life easier while doing simple IPv4
address assignment in scripts.
2. This class is a very simple IPv4 address generator. You can
think of it as a simple local number incrementer. It has no
notion that IP addresses are part of a global address space.
3. If you have a complicated address assignment situation
you may want to look at the Ipv4AddressGenerator which
does recognize that IP address and network number
generation is part of a global problem. Ipv4AddressHelper
is a simple class to make simple problems easy to handle.
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

A) Write a program to simulate wireless network topology.

 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 10.1.3.0
// AP
// * * * *
// | | | | 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");
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

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


// 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);
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);


}

NodeContainer p2pNodes;
p2pNodes.Create (2);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
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 ();


ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

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),
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

"LayoutType", StringValue ("RowFirst"));

mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNode);
AnimationInterface::SetConstantPosition (p2pNodes.Get (1), 10, 30);
AnimationInterface::SetConstantPosition (csmaNodes.Get (1), 10, 33);
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);


ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

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 ("third");
phy.EnablePcap ("third", apDevices.Get (0));
csma.EnablePcap ("third", csmaDevices.Get (0), true);
}
AnimationInterface anim ("wireless-animation.xml");
for (uint32_t i = 0; i < wifiStaNodes.GetN (); ++i)
{
anim.UpdateNodeDescription (wifiStaNodes.Get (i), "STA"); // Optional
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

anim.UpdateNodeColor (wifiStaNodes.Get (i), 255, 0, 0); // Optional


}
for (uint32_t i = 0; i < wifiApNode.GetN (); ++i)
{
anim.UpdateNodeDescription (wifiApNode.Get (i), "AP"); // Optional
anim.UpdateNodeColor (wifiApNode.Get (i), 0, 255, 0); // Optional
}
for (uint32_t i = 0; i < csmaNodes.GetN (); ++i)
{

anim.UpdateNodeDescription (csmaNodes.Get (i), "CSMA"); // Optional


anim.UpdateNodeColor (csmaNodes.Get (i), 0, 0, 255); // Optional
}
anim.EnablePacketMetadata (); // Optional
anim.EnableIpv4RouteTracking ("routingtable-wireless.xml", Seconds (0), Seconds
(5), Seconds (0.25)); //Optional
anim.EnableWifiMacCounters (Seconds (0), Seconds (10)); //Optional
anim.EnableWifiPhyCounters (Seconds (0), Seconds (10)); //Optional
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

 OUTPUT:

o ./waf output:

o Python Visualizer:
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

o NetAnim Output:
ATHARVA KALE PRACTICAL NO.5 ROLL NO: 27

o Wireshark

 CONCLUSION:
Hence we successfully simulated Wireless Network Topology.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy