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

MCLab Exp 5

The document outlines Experiment 5 of the CSL603 Mobile Computing Lab, focusing on the setup and configuration of a Wireless Access Point (AP) using NS3. The objective is to analyze Wi-Fi communication range between the AP and a static base station (BS) and determine the maximum communication distance. Students are expected to learn about wireless communication through practical coding and simulation exercises.

Uploaded by

amishav2004
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)
11 views6 pages

MCLab Exp 5

The document outlines Experiment 5 of the CSL603 Mobile Computing Lab, focusing on the setup and configuration of a Wireless Access Point (AP) using NS3. The objective is to analyze Wi-Fi communication range between the AP and a static base station (BS) and determine the maximum communication distance. Students are expected to learn about wireless communication through practical coding and simulation exercises.

Uploaded by

amishav2004
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/ 6

CSL603 Mobile Computing Lab

Sem VI
Name: Amisha Verma
Roll no :66

EXPERIMENT 5

Title To setup & configuration of Wireless Access Point (AP) using NS3. Analyze the Wi-Fi
communication range in the presence of the access point (AP) and the base station
(BS). Consider BS and AP are static. Find out the maximum distance to which two
way communications is possible. Try multiple iterations by adjusting its distance in
the code and test it
Pre requisite Computer Networks-NS2

Mapping with CO CSL603.4

Objective To understand wireless communication

Outcome Students learned wireless communication using NS3

Deliverables NS3

Colab #include "ns3/command-line.h"


Link/Program #include "ns3/config.h"
code with output #include "ns3/boolean.h"
#include "ns3/string.h"
#include "ns3/yans-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/mobility-helper.h"
#include "ns3/on-off-helper.h"
#include "ns3/yans-wifi-channel.h"
#include "ns3/mobility-model.h"
#include "ns3/packet-socket-helper.h"
#include "ns3/packet-socket-address.h"
#include "ns3/athstats-helper.h"
using namespace ns3;
3 Program:
static bool g_verbose = true;
void
DevTxTrace (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
std::cout << " TX p: " << *p << std::endl;
}
}
void
DevRxTrace (std::string context, Ptr<const Packet> p)
{
if (g_verbose)
{
std::cout << " RX p: " << *p << std::endl;
}
}
void
PhyRxOkTrace (std::string context, Ptr<const Packet> packet,
double snr, WifiMode mode, WifiPreamble preamble)
{
if (g_verbose)
{
std::cout << "PHYRXOK mode=" << mode << " snr=" << snr <<""<<
*packet <<
std::endl;
}
}
void
PhyRxErrorTrace (std::string context, Ptr<const Packet>
packet, double snr)
{
if (g_verbose)
{
std::cout << "PHYRXERROR snr=" << snr << " " << *packet
<< std::endl;
}
}
void
PhyTxTrace (std::string context, Ptr<const Packet> packet,
WifiMode mode, WifiPreamble preamble, uint8_t txPower)
{
if (g_verbose)
{
std::cout << "PHYTX mode=" << mode << " " << *packet << std::endl;}
}
void
PhyStateTrace (std::string context, Time start,
Time duration, WifiPhyState state)
{
if (g_verbose)
{
std::cout << " state=" << state << " start=" << start <<" duration=" <<
duration
<< std::endl;
}
}
static void
SetPosition (Ptr<Node> node, Vector position)
{
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel>
(); mobility->SetPosition (position);
}
static Vector
GetPosition (Ptr<Node> node)
{
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel>
(); return mobility->GetPosition ();
}
static void
AdvancePosition (Ptr<Node> node)
{
Vector pos = GetPosition (node);
pos.x += 5.0;
if (pos.x >= 210.0)
{
return;
}
SetPosition (node, pos);
Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
}
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.AddValue ("verbose", "Print trace
information if true", g_verbose);
cmd.Parse (argc, argv);
Packet::EnablePrinting ();
WifiHelper wifi;
MobilityHelper mobility;
NodeContainer stas;
NodeContainer ap;
NetDeviceContainer staDevs;
PacketSocketHelper packetSocket;
stas.Create (2);
ap.Create (1);
/ give packet socket powers to
nodes. packetSocket.Install (stas);
packetSocket.Install (ap);
WifiMacHelper wifiMac;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel =
YansWifiChannelHelper::Default();
wifiPhy.SetChannel (wifiChannel.Create ());
Ssid ssid = Ssid ("wifi-default");
wifi.SetRemoteStationManager
("ns3::ArfWifiManager"); // setup stas.
wifiMac.SetType ("ns3::StaWifiMac", "ActiveProbing", BooleanValue
(true),
"Ssid", SsidValue (ssid));
staDevs = wifi.Install (wifiPhy, wifiMac,
stas); // setup ap.
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
wifi.Install (wifiPhy, wifiMac, ap);
/ mobility.
mobility.Install (stas);
mobility.Install (ap);
Simulator::Schedule (Seconds (1.0), &AdvancePosition,
ap.Get(0));PacketSocketAddress socket;
socket.SetSingleDevice (staDevs.Get (0)->GetIfIndex ());
socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress
()); socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address
(socket)); onoff.SetConstantRate (DataRate ("500kb/s"));
ApplicationContainer apps = onoff.Install (stas.Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (43.0));
Simulator::Stop (Seconds (44.0));
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacTx",
MakeCallback (&DevTxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Mac/MacRx",
MakeCallback (&DevRxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxOk",
MakeCallback (&PhyRxOkTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/RxError",
MakeCallback (&PhyRxErrorTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/Tx",
MakeCallback (&PhyTxTrace));
Config::Connect ("/NodeList/*/DeviceList/*/Phy/State/State",
MakeCallback (&PhyStateTrace));
AthstatsHelper athstats;
athstats.EnableAthstats ("athstats-sta", stas);
athstats.EnableAthstats ("athstats-ap", ap);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Conclusion In this experiment, wireless access point (AP) using NS3 is configured
and setup and analysed the Wi-Fi communication range in the
presence of the access point (AP) and the base station (BS).
References NS-3 Official Documentation
NS-3 Wi-Fi Module Guide
DOI: 10.1109/ACCESS.2019.2906223

You might also like