0% found this document useful (0 votes)
18 views52 pages

WC File Print

The document outlines the Wireless Communication Lab (ETEC-463) at Maharaja Agrasen Institute of Technology, detailing its vision, mission, program outcomes, and educational objectives. It includes practical experiments using Network Simulator 3 (NS3) for various wireless communication applications, emphasizing hands-on learning and technical proficiency. The lab aims to enhance students' understanding of networking concepts and prepare them for real-world challenges in the field of Information Technology.
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)
18 views52 pages

WC File Print

The document outlines the Wireless Communication Lab (ETEC-463) at Maharaja Agrasen Institute of Technology, detailing its vision, mission, program outcomes, and educational objectives. It includes practical experiments using Network Simulator 3 (NS3) for various wireless communication applications, emphasizing hands-on learning and technical proficiency. The lab aims to enhance students' understanding of networking concepts and prepare them for real-world challenges in the field of Information Technology.
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/ 52

WIRELESS COMMUNICATION LAB

(ETEC-463)

Faculty Name: Dr. Shikha Gupta Student Name.: Khushi Chaudhary


Roll No.: 20714803120
Semester: 7th
Group: 7I-8

Maharaja Agrasen Institute of Technology, PSP Area,


Sector – 22, Rohini, New Delhi – 110086
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY

VISION
To nurture young minds in a learning environment of high academic value and imbibe spiritual and
ethical values with technological and management competence.

MISSION
The Institute shall endeavor to incorporate the following basic missions in the teaching methodology:

Engineering Hardware – Software Symbiosis

Practical exercises in all Engineering and Management disciplines shall be carried out by Hardware
equipment as well as the related software enabling deeper understanding of basic concepts and
encouraging inquisitive nature.

Life – Long Learning

The Institute strives to match technological advancements and encourage students to keep updating
their knowledge for enhancing their skills and inculcating their habit of continuous learning.

Liberalization and Globalization

The Institute endeavors to enhance technical and management skills of students so that they are
intellectually capable and competent professionals with Industrial Aptitude to face the challenges of
globalization.

Diversification

The Engineering, Technology and Management disciplines have diverse fields of studies with different
attributes. The aim is to create a synergy of the above attributes by encouraging analytical thinking.

Digitization of Learning Processes

The Institute provides seamless opportunities for innovative learning in all Engineering and
Management disciplines through digitization of learning processes using analysis, synthesis,
simulation, graphics, tutorials and related tools to create a platform for multi- disciplinary approach.

Entrepreneurship
The Institute strives to develop potential Engineers and Managers by enhancing their skills and
research capabilities so that they become successfully entrepreneurs and responsible citizens.
MAHARAJA AGRASEN INSTITUTE OF TECHNOLOGY
Department of Information Technology

Vision of the Department

To establish a center of excellence promoting Information Technology related education and research
thus producing technocrats and entrepreneurs with ethical values.

Mission of the Department

To provide an open, diverse and collaborative environment to achieve global technological excellence
producing world-class engineers to solve real-world problems fulfilling the needs of the society.

Program Specific Outcomes (PSOs)

PSO1: Proficient at discerning suitable data structures and algorithms for designing, executing, and
validating efficient solutions for research-oriented challenges.

PSO 2: Attaining excellence in programming, technical projects and handling technical challenges.

PSO 3: Acquiring adequate knowledge in Information Technology for a successful professional life,
entrepreneurship and higher education.

Program Educational Objectives (PEOs)

PEO1: Our graduates will succeed in their career pursuits by applying their technical skills for higher
degrees.

PEO2: Our graduates will be able to devise innovative solutions for real-world problems by applying
Information Technology principles.

PEO3: Our graduates will exhibit high standards of professionalism, demonstrate strong interpersonal
and collaborative abilities with adherence to professional ethics.

PEO4: Our graduates will be able to use research opportunities, and thrive as successful entrepreneurs.

Program Outcomes (POs)


Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,


and an engineering specialization to the solution of complex engineering problems.

2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.

4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information
to provide valid conclusions.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.

6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.

7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.

10 .Communication: Communicate effectively on complex engineering activities with the engineering


community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.

11. Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.

12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change
Rubrics Evaluation
WIRELESS COMMUNICATION LAB
PRACTICAL RECORD

PAPER CODE : ETEC-463

Name of the student : KHUSHI CHAUDHARY

University Roll No. : 20714803120

Branch : Information Technology

Section/ Group : 7I-8

PRACTICAL DETAILS

a) Experiments according to the list provided by GGSIPU

Experiment Experiment Name Date Marks (0-3) Total Signature


No. Marks
(15)
R1 R2 R3 R4 R5
1. Installation, configuration, and study
of Network Simulator 3 (NS3)

2. Program in NS3 to connect WIFI to


BUS (CDMA)

3. Program in NS3 to create WIFI


SIMPLE INFRASTRUCTURE
MODE

4. Program in NS3 to create WIFI


SIMPLE ADHOC MODE

5 Program in NS3 to connect WIFI to


WIRED BRIDGING

6 Program in NS3 to create WIFI to


LTE (4G) CONNECTION

7 Program in NS3 to create A


SIMPLE WIFI ADHOC GRID

8. Introduction to GSM Architecture


EXPERIMENT – 1

AIM: Installation, configuration, and study of Network Simulator 3 (NS3).

THEORY: ns-3 is a discrete-event network simulator, targeted primarily for research and
educational use. ns-3 is free software, licensed under the GNU GPLv2 license, and is publicly
available for research, development, and use.
The goal of the ns-3 project is to develop a preferred, open simulation environment for
networking research: it should be aligned with the simulation needs of modern networking
research and should encourage community contribution, peer review, and validation of the
software.

Simulation Models
The ns-3 project is committed to building a solid simulation core that is well documented, easy
to use and debug, and that caters to the needs of the entire simulation workflow, from
simulation configuration to trace collection and analysis.
Furthermore, the ns-3 software infrastructure encourages the development of simulation
models which are sufficiently realistic to allow ns-3 to be used as a real-time network emulator,
interconnected with the real world and which allows many existing real-world protocol
implementations to be reused within ns-3.
The ns-3 simulation core supports research on both IP and non-IP based networks. However,
most of its users focuses on wireless/IP simulations which involve models for Wi-Fi, WiMAX,
or LTE for layers 1 and 2 and a variety of static or dynamic routing protocols such as OLSR
and AODV for IP-based applications.
ns-3 also supports a real-time scheduler that facilitates several “simulation-in-the-loop” use
cases for interacting with real systems. For instance, users can emit and receive ns-3-generated
packets on real network devices, and ns-3 can serve as an interconnection framework to add
link effects between virtual machines.
Another emphasis of the simulator is on the reuse of real application and kernel code.
Frameworks for running unmodified applications or the entire Linux kernel networking stack
within ns-3 are presently being tested and evaluated.
Community Involvement
Because creating a network simulator that sports enough high-quality validated, and
maintained models requires a lot of work, ns-3 attempts to spread this workload over a large
community of users and developers.
Every three months, we ship a new stable version of ns-3 with new models developed,
documented, validated, and maintained by enthusiastic researchers. We encourage the open
validation of these models by third parties on our mailing-lists to ensure that the models we
ship are and stay of the highest quality possible.
DOWNLOAD
There are two main options:
1. Download a release tarball. This will unpack to a directory such as ns-allinone-3.40
containing ns-3 and some other programs. Below is a command-line download using wget, but
a browser download will also work:

2. Clone ns-3 from the Git repository. The ns-3-allinone can be cloned, as well as ns-3-dev by
itself. Below, we illustrate the latter:

Note that if you select option 1), your directory name will contain the release number. If you
clone ns-3, your directory will be named ns-3-dev. By default, Git will check out the ns-3
master branch, which is a development branch. All ns-3 releases are tagged in Git, so if you
would then like to check out a past release, you can do so as follows:

In this quick-start, we are omitting download and build instructions for optional ns-3 modules,
the NetAnim animator, Python bindings, and NetSimulyzer. The ns-3 Tutorial has some
instructions on optional components, or else the documentation associated with the extension
should be consulted. Moreover, in this guide we will assume that you are using ns-3.36 or later.
Earlier versions had different configuration, build, and run command and options.

BUILDING AND TESTING


Once you have obtained the source either by downloading a release or by cloning a Git
repository, the next step is to configure the build using the CMake build system. The below
commands make use of a Python wrapper around CMake, called ns3, that simplifies the
command-line syntax, resembling Waf syntax. There are several options to control the build,
but enabling the example programs and the tests, for a default build profile (with asserts enabled
and support for ns-3 logging) is what is usually done at first:

Depending on how fast your CPU is, the configuration command can take anywhere from a
few seconds to a minute. Then, use the ns3 program to build the ns-3 module libraries and
executables:

Build times vary based on the number of CPU cores, the speed of the CPU and memory, and
the mode of the build (whether debug mode, which is faster, or the default or optimized modes,
which are slower). Additional configuration (not covered here) can be used to limit the scope
of the build, and the ccache, if installed, can speed things up. In general, plan on the build
taking a few minutes on faster workstations.
You should see some output such as below, if successful:

Once complete, you can run the unit tests to check your build:

This command should run several hundred-unit tests. If they pass, you have made a successful
initial build of ns-3. Read further in this manual for instructions about building optional
components, or else consult the ns-3 Tutorial or other documentation to get started with the
base ns-3.
If you prefer to code with a code editor, consult the documentation in the ns-3 Manual on
Working with CMake, since CMake enables ns-3 integration with a variety of code editors,
including:
• JetBrains’s CLion
• Microsoft Visual Studio and Visual Studio Code
• Apple’s Xcode
• CodeBlocks
• Eclipse CDT4

INSTALLATION
Most users do not install ns-3 libraries to typical system library directories; they instead just
leave the libraries in the build directory, and the ns3 Python program will find these libraries.
However, it is possible to perform an installation step– ns3 install– with the following caveats.
The location of the installed libraries is set by the --prefix option specified at the configure
step. The prefix defaults to /usr/local. For a given --prefix=$PREFIX, the installation step will
install headers to a $PREFIX/ include directory, libraries and pkgconfig files to a $PREFIX/lib
directory, and a few binaries to a $PREFIX/ libexec directory. For example, ./ns3 configure --
prefix=/tmp, followed by ./ns3 build and ./ ns3 install, will lead to files being installed in
/tmp/include, /tmp/lib, and /tmp/libexec.
Note that the ns3 script prevents running the script as root (or as a sudo user). As a result, with
the default prefix of /usr/local, the installation will fail unless the user has written privileges in
that directory. Attempts to force this with sudo ./ns3 install will fail due to a check in the ns3
program that prevents running as root. This check was installed by ns-3 maintainers for the
safety of novice users who may run ./ns3 in a root shell and later in a normal shell, and become
confused about errors resulting in lack of privileges to modify files. For users who know what
they are doing and who want to install to a privileged directory, users can comment out the
statement refuse_run_as_root() in the ns3 program (around line 1400), and then run sudo ./ns3
install.
EXPERIMENT – 2

AIM: Program in NS3 to connect WIFI to BUS (CDMA).

THEORY:

Integrating Wi-Fi connectivity on a bus through a CDMA (Code Division Multiple Access)
network is a sophisticated solution aimed at enhancing the overall passenger experience and
providing reliable internet access during transit. This deployment involves equipping the bus
with a cellular modem or router that supports CDMA technology, serving as the gateway to
establish a high-speed internet connection while the bus is in motion. To authenticate the bus
on the CDMA network, a Subscriber Identity Module (SIM) card is inserted into the cellular
modem or router, allowing it to access data services and connect to the internet. Additionally,
the cellular modem or router functions as a Wi-Fi access point, creating a local Wi-Fi network
within the bus. Passengers and onboard devices can connect to this Wi-Fi network, enabling
them to access the internet or communicate with each other during the journey. The network
configuration includes implementing security measures such as WPA2 or WPA3 to ensure the
privacy and integrity of transmitted data. Quality of Service (QoS) settings may also be applied
to prioritize specific types of data traffic, optimizing overall network performance.

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/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
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;
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);
// Check for valid number of csma or wifi nodes
// 250 should be enough, otherwise IP addresses
// soon become an issue
if (nWifi > 250 || nCsma > 250)
{
std::cout << "Too many wifi or csma nodes, no more than 250 each." << 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 ("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 ();
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);
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);
}
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT:
EXPERIMENT – 3

AIM: Program in NS3 to create WIFI SIMPLE INFRASTRUCTURE MODE.

THEORY:

In the deployment of a basic Wi-Fi infrastructure mode, the establishment of a wireless network
is initiated through the utilization of an access point (AP) or router. The initial step involves
ensuring the proper setup of the router or access point, and its connection to the internet is
facilitated by means of an Ethernet cable. Access to the router's web interface is achieved
through a browser, typically by entering its IP address (e.g., 192.168.0.1 or 192.168.1.1), where
authentication with administrator credentials is requisite. Within the wireless settings section
of the interface, the configuration entails the assignment of an SSID (Service Set Identifier) or
network name, along with the selection of a security mode, such as WPA2 or WPA3, thereby
necessitating the formulation of a robust password for heightened network security.
Subsequently, on user devices like laptops or smartphones, the identification and selection of
the network from the available options, coupled with the entry of the designated password,
establish a connection. The ensuing communication between devices transpires through the
access point, thereby facilitating internet access. In instances where a more sophisticated
network architecture is sought, considerations such as the allocation of static IP addresses and
the implementation of specific security measures may be warranted. It is imperative to consult
the user manual or documentation pertinent to the specific router or access point for nuanced
and device-specific instructions

SOURCE CODE:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("WifiSimpleInfra");
void ReceivePacket (Ptr<Socket> socket)
{
while (socket->Recv ())
{
NS_LOG_UNCOND ("Received one packet!");
}
}
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount-1, pktInterval);
}
else
{
socket->Close ();
}
}
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double rss = -80; // -dBm
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
double interval = 1.0; // seconds
bool verbose = false;
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
cmd.AddValue ("numPackets", "number of packets generated", numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets", interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);
// disable fragmentation for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
StringValue ("2200"));
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));
NodeContainer c;
c.Create (2);
// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (0) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed regardless
// of the distance between the two stations, and the transmit power
wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a mac and disable rate control
WifiMacHelper wifiMac;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Setup the rest of the mac
Ssid ssid = Ssid ("wifi-default");
// setup sta.
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMac, c.Get (0));
NetDeviceContainer devices = staDevice;
// setup ap.
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, c.Get (1));
devices.Add (apDevice);
// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
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));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
InternetStackHelper internet;
internet.Install (c);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
source->SetAllowBroadcast (true);
source->Connect (remote);
// Tracing
wifiPhy.EnablePcap ("wifi-simple-infra", devices);
// Output what we are doing
NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss
);
Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
Seconds (1.0), &GenerateTraffic,
source, packetSize, numPackets, interPacketInterval);
Simulator::Stop (Seconds (30.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;}
OUTPUT:
EXPERIMENT – 4

AIM: Program in NS3 to create WIFI SIMPLE ADHOC MODE.

THEORY:

The implementation of a basic Wi-Fi ad-hoc mode involves the establishment of a direct
communication network among devices, bypassing the necessity for a central access point or
router. In this setup, devices within the network communicate with each other peer-to-peer.
The initiation of such a network typically requires users to access their device's network
settings and configure the Wi-Fi connection to operate in ad-hoc mode. Upon configuring the
ad-hoc network, devices within its vicinity can identify and connect directly to this network
without the need for a pre-existing infrastructure. This mode is particularly advantageous in
scenarios where the establishment of a traditional network infrastructure is impractical or when
a temporary network is required, such as during collaborative projects, presentations, or in
settings where conventional networking equipment is unavailable. However, it's crucial to note
that ad-hoc networks may have limitations in terms of range and scalability compared to
infrastructure mode. Devices in ad-hoc mode need to be within each other's range for effective
communication. Additionally, security considerations become more critical in ad-hoc mode,
and users should employ robust security protocols, such as WPA2 or WPA3, to protect the
network from unauthorized access

SOURCE CODE:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");
void ReceivePacket (Ptr<Socket> socket)
{
while (socket->Recv ())
{
NS_LOG_UNCOND ("Received one packet!");
}
}
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount-1, pktInterval);
}
else
{
socket->Close ();
}
}
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double rss = -80; // -dBm
uint32_t packetSize = 1000; // bytes
uint32_t numPackets = 1;
double interval = 1.0; // seconds
bool verbose = false;
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("rss", "received signal strength", rss);
cmd.AddValue ("packetSize", "size of application packet sent", packetSize);
cmd.AddValue ("numPackets", "number of packets generated", numPackets);
cmd.AddValue ("interval", "interval (seconds) between packets", interval);
cmd.AddValue ("verbose", "turn on all WifiNetDevice log components", verbose);
cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);
// disable fragmentation for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
StringValue ("2200"));
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
("2200"));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
StringValue (phyMode));
NodeContainer c;
c.Create (2);
// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
if (verbose)
{
wifi.EnableLogComponents (); // Turn on all Wifi logging
}
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// This is one parameter that matters when using FixedRssLossModel
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (0) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
// The below FixedRssLossModel will cause the rss to be fixed regardless
// of the distance between the two stations, and the transmit power
wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a mac and disable rate control
WifiMacHelper wifiMac;
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
// Note that with FixedRssLossModel, the positions below are not
// used for received signal strength.
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));
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
InternetStackHelper internet;
internet.Install (c);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
Ptr<Socket> recvSink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
Ptr<Socket> source = Socket::CreateSocket (c.Get (1), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address ("255.255.255.255"), 80);
source->SetAllowBroadcast (true);
source->Connect (remote);
// Tracing
wifiPhy.EnablePcap ("wifi-simple-adhoc", devices);
// Output what we are doing
NS_LOG_UNCOND ("Testing " << numPackets << " packets sent with receiver rss " << rss
);
Simulator::ScheduleWithContext (source->GetNode ()->GetId (),
Seconds (1.0), &GenerateTraffic,
source, packetSize, numPackets, interPacketInterval);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

OUTPUT:
EXPERIMENT – 5

AIM: Program in NS3 to connect WIFI to WIRED BRIDGING.

THEORY:

Wireless bridging serves as a pivotal solution for seamlessly integrating wired devices into a
wireless network infrastructure. The primary objective of this technology is to eliminate the
reliance on physical cables, extending the flexibility and reach of network connectivity. The
wireless bridge acts as an intermediary device, linking the wired and wireless segments of the
network. This is achieved through the configuration of two main components: the wireless
bridge itself and an associated access point or wireless router. The bridge, equipped with both
wireless and wired interfaces, establishes a connection with the existing Wi-Fi network,
effectively bridging the gap between the wireless and wired domains. To initiate the bridging
process, users typically access the configuration settings of the wireless bridge device. Within
these settings, essential parameters such as the SSID (Service Set Identifier) and security
credentials are configured to align with those of the target Wi-Fi network. Once established,
the bridge engages in wireless communication with the access point or router, effectively
joining the wireless network. Wired devices, connected to the bridge via Ethernet cables,
seamlessly become part of the wireless network as if physically connected to the access point.
This functionality is particularly advantageous in scenarios where running cables is impractical
or cost-prohibitive.

SOURCE CODE:

#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/bridge-helper.h"
#include <vector>
#include <stdint.h>
#include <sstream>
#include <fstream>
using namespace ns3;
int main (int argc, char *argv[])
{
uint32_t nWifis = 2;
uint32_t nStas = 2;
bool sendIp = true;
bool writeMobility = false;
CommandLine cmd;
cmd.AddValue ("nWifis", "Number of wifi networks", nWifis);
cmd.AddValue ("nStas", "Number of stations per wifi network", nStas);
cmd.AddValue ("SendIp", "Send Ipv4 or raw packets", sendIp);
cmd.AddValue ("writeMobility", "Write mobility trace", writeMobility);
cmd.Parse (argc, argv);
NodeContainer backboneNodes;
NetDeviceContainer backboneDevices;
Ipv4InterfaceContainer backboneInterfaces;
std::vector<NodeContainer> staNodes;
std::vector<NetDeviceContainer> staDevices;
std::vector<NetDeviceContainer> apDevices;
std::vector<Ipv4InterfaceContainer> staInterfaces;
std::vector<Ipv4InterfaceContainer> apInterfaces;
InternetStackHelper stack;
CsmaHelper csma;
Ipv4AddressHelper ip;
ip.SetBase ("192.168.0.0", "255.255.255.0");
backboneNodes.Create (nWifis);
stack.Install (backboneNodes);
backboneDevices = csma.Install (backboneNodes);
double wifiX = 0.0;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
for (uint32_t i = 0; i < nWifis; ++i)
{
// calculate ssid for wifi subnetwork
std::ostringstream oss;
oss << "wifi-default-" << i;
Ssid ssid = Ssid (oss.str ());
NodeContainer sta;
NetDeviceContainer staDev;
NetDeviceContainer apDev;
Ipv4InterfaceContainer staInterface;
Ipv4InterfaceContainer apInterface;
MobilityHelper mobility;
BridgeHelper bridge;
WifiHelper wifi;
WifiMacHelper wifiMac;
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
sta.Create (nStas);
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (wifiX),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (5.0),
"GridWidth", UintegerValue (1),
"LayoutType", StringValue ("RowFirst"));
// setup the AP.
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (backboneNodes.Get (i));
wifiMac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
apDev = wifi.Install (wifiPhy, wifiMac, backboneNodes.Get (i));
NetDeviceContainer bridgeDev;
bridgeDev = bridge.Install (backboneNodes.Get (i), NetDeviceContainer (apDev,
backboneDevices.Get (i)));
// assign AP IP address to bridge, not wifi
apInterface = ip.Assign (bridgeDev);
// setup the STAs
stack.Install (sta);
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
"Mode", StringValue ("Time"),
"Time", StringValue ("2s"),
"Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"),
"Bounds", RectangleValue (Rectangle (wifiX, wifiX+5.0,0.0,
(nStas+1)*5.0)));
mobility.Install (sta);
wifiMac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
staDev = wifi.Install (wifiPhy, wifiMac, sta);
staInterface = ip.Assign (staDev);
// save everything in containers.
staNodes.push_back (sta);
apDevices.push_back (apDev);
apInterfaces.push_back (apInterface);
staDevices.push_back (staDev);
staInterfaces.push_back (staInterface);
wifiX += 20.0;
}
Address dest;
std::string protocol;
if (sendIp)
{
dest = InetSocketAddress (staInterfaces[1].GetAddress (1), 1025);
protocol = "ns3::UdpSocketFactory";
}
else
{
PacketSocketAddress tmp;
tmp.SetSingleDevice (staDevices[0].Get (0)->GetIfIndex ());
tmp.SetPhysicalAddress (staDevices[1].Get (0)->GetAddress ());
tmp.SetProtocol (0x807);
dest = tmp;
protocol = "ns3::PacketSocketFactory";
}
OnOffHelper onoff = OnOffHelper (protocol, dest);
onoff.SetConstantRate (DataRate ("500kb/s"));
ApplicationContainer apps = onoff.Install (staNodes[0].Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (3.0));
wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[0]);
wifiPhy.EnablePcap ("wifi-wired-bridging", apDevices[1]);
if (writeMobility)
{
AsciiTraceHelper ascii;
MobilityHelper::EnableAsciiAll (ascii.CreateFileStream ("wifi-wired-bridging.mob"));
}
Simulator::Stop (Seconds (5.0));
Simulator::Run ();
Simulator::Destroy ();
}
OUTPUT:
EXPERIMENT – 6

AIM: Program in NS3 to create WIFI to LTE (4G) CONNECTION.

THEORY:

In scenarios where a Wi-Fi connection is either unavailable or insufficient, the integration of


LTE (4G) connectivity provides a viable solution to ensure uninterrupted internet access. This
technology facilitates the seamless transition from Wi-Fi to cellular networks, offering users
the flexibility to maintain connectivity on the go or in areas with limited Wi-Fi coverage. To
initiate a Wi-Fi to LTE connection, devices need to be equipped with the necessary hardware,
typically a cellular modem or a smartphone with hotspot capabilities. In this setup, the device
establishes a connection with the LTE network, functioning as a gateway for internet
access. Users can configure their devices to prioritize LTE connectivity when Wi-Fi is either
absent or encounters connectivity issues. This configuration ensures a smooth transition
between the two networks, guaranteeing a reliable internet connection in diverse
environments. The integration of LTE technology introduces benefits such as enhanced
mobility and accessibility. Devices can seamlessly switch between Wi-Fi and LTE networks,
allowing users to stay connected in various settings, including during travel, in remote areas,
or when faced with Wi-Fi outages. Moreover, LTE technology often provides faster internet
speeds and lower latency compared to some Wi-Fi networks, contributing to an improved
online experience.

SOURCE CODE:

#include "ns3/lte-helper.h"
#include "ns3/epc-helper.h"
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/wifi-module.h"
#include "ns3/csma-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wimax-module.h"
#include "ns3/internet-module.h"
#include "ns3/global-route-manager.h"
#include "ns3/ipcs-classifier-record.h"
#include "ns3/service-flow.h"
#include <iostream>
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/mobility-module.h"
#include "ns3/lte-module.h"
#include "ns3/point-to-point-helper.h"
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
NS_LOG_COMPONENT_DEFINE ("WimaxSimpleExample");
using namespace ns3;
int main (int argc, char *argv[])
{
Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
bool verbose = false;
int duration = 500, schedType = 0;
uint16_t numberOfUEs=2; //Default number of ues attached to each eNodeB
Ptr<LteHelper> lteHelper; //Define LTE
Ptr<EpcHelper> epcHelper; //Define EPC
NodeContainer remoteHostContainer; //Define the Remote Host
NetDeviceContainer internetDevices; //Define the Network Devices in the Connection
between EPC and the remote host
Ptr<Node> pgw; //Define the Packet Data Network Gateway(P-GW)
Ptr<Node> remoteHost; //Define the node of remote Host
InternetStackHelper internet; //Define the internet stack
PointToPointHelper p2ph; //Define Connection between EPC and the
Remote Host
Ipv4AddressHelper ipv4h; //Ipv4 address helper
Ipv4StaticRoutingHelper ipv4RoutingHelper; //Ipv4 static routing helper
Ptr<Ipv4StaticRouting> remoteHostStaticRouting;
Ipv4InterfaceContainer internetIpIfaces; //Ipv4 interfaces
CommandLine cmd;
cmd.AddValue ("scheduler", "type of scheduler to use with the network devices", schedType);
cmd.AddValue ("duration", "duration of the simulation in seconds", duration);
cmd.AddValue ("verbose", "turn on all WimaxNetDevice log components", verbose);
cmd.Parse (argc, argv);
LogComponentEnable ("UdpClient", LOG_LEVEL_INFO);
LogComponentEnable ("UdpServer", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
//LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer ssNodes;
NodeContainer bsNodes;
ssNodes.Create (2);
bsNodes.Create (1);
uint32_t nCsma = 3;
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 wifiApNode = p2pNodes.Get (0);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, ssNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNode);
MobilityHelper mobility1;
mobility1.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"));
mobility1.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility1.Install (wifiApNode);
(wifiApNode.Get(0) -> GetObject<ConstantPositionMobilityModel>()) ->
SetPosition(Vector(100.0, 501.0, 0.0));
InternetStackHelper stack1;
stack1.Install (csmaNodes);
stack1.Install (wifiApNode);
stack1.Install (ssNodes);
Ipv4AddressHelper address1;
address1.SetBase ("11.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address1.Assign (p2pDevices);
address1.SetBase ("11.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address1.Assign (csmaDevices);
address1.SetBase ("11.1.3.0", "255.255.255.0");
address1.Assign (staDevices);
address1.Assign (apDevices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps1 = echoServer.Install (csmaNodes.Get (nCsma));
serverApps1.Start (Seconds (1.0));
serverApps1.Stop (Seconds (duration+0.1));
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1000));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps1 =
echoClient.Install (ssNodes.Get (0));
clientApps1.Start (Seconds (2.0));
clientApps1.Stop (Seconds (duration+0.1));
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//pointToPoint.EnablePcapAll ("third");
phy.EnablePcap ("third", apDevices.Get (0));
//csma.EnablePcap ("third", csmaDevices.Get (0), true);
lteHelper = CreateObject<LteHelper> ();
epcHelper = CreateObject<EpcHelper> ();
lteHelper->SetEpcHelper (epcHelper);
lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
lteHelper->SetAttribute ("PathlossModel",
StringValue ("ns3::FriisPropagationLossModel"));
pgw = epcHelper->GetPgwNode ();
remoteHostContainer.Create (1);
remoteHost = remoteHostContainer.Get (0);
internet.Install (remoteHostContainer);
p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
internetDevices = p2ph.Install (pgw, remoteHost);
ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
internetIpIfaces = ipv4h.Assign (internetDevices);
remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4>
());
remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"),
1);
std::cout << "2. Installing LTE+EPC+remotehost. Done!" << std::endl;
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc;
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 500.0, 0.0)); //STA
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
mobility.Install(ssNodes.Get(0));
Ptr<ConstantVelocityMobilityModel> cvm = ssNodes.Get(0)-
>GetObject<ConstantVelocityMobilityModel>();
cvm->SetVelocity(Vector (5, 0, 0)); //move to left to right 10.0m/s
positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (0.0, 500.0, 10.0)); //MAG1AP
positionAlloc->Add (Vector (0.0, 510.0, 0.0)); //MAG2AP
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (NodeContainer(bsNodes.Get(0),ssNodes.Get(1)));
NetDeviceContainer ssDevs, bsDevs;
bsDevs = lteHelper->InstallEnbDevice (bsNodes);
ssDevs=lteHelper->InstallUeDevice (ssNodes);
for (uint16_t j=0; j < numberOfUEs; j++)
{
lteHelper->Attach (ssDevs.Get(j), bsDevs.Get(0));
}
Ipv4InterfaceContainer iueIpIface;
iueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ssDevs));
lteHelper->ActivateEpsBearer (ssDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT),
EpcTft::Default ());
UdpServerHelper udpServer;
ApplicationContainer serverApps;
UdpClientHelper udpClient;
ApplicationContainer clientApps;
udpServer = UdpServerHelper (100);
serverApps = udpServer.Install (ssNodes.Get (0));
serverApps.Start (Seconds (6));
serverApps.Stop (Seconds (duration));
udpClient = UdpClientHelper (iueIpIface.GetAddress (0), 100);
udpClient.SetAttribute ("MaxPackets", UintegerValue (200000));
udpClient.SetAttribute ("Interval", TimeValue (Seconds (0.004)));
udpClient.SetAttribute ("PacketSize", UintegerValue (1024));
clientApps = udpClient.Install (remoteHost);
clientApps.Start (Seconds (6));
clientApps.Stop (Seconds (duration));
lteHelper->EnableTraces ();
NS_LOG_INFO ("Starting simulation.....");
Simulator::Stop(Seconds(duration));
Simulator::Run ();
Simulator::Destroy ();
NS_LOG_INFO ("Done.");
return 0;
}
OUTPUT:
EXPERIMENT – 7

AIM: Program in NS3 to create A SIMPLE WIFI ADHOC GRID.

THEORY:

The concept of a Wi-Fi ad-hoc grid involves the creation of a decentralized network where
devices connect with each other directly, forming a grid-like structure without relying on a
central access point. Unlike traditional Wi-Fi infrastructure modes that necessitate a central
hub for communication, ad-hoc grids allow devices to establish peer-to-peer connections,
fostering flexibility and adaptability in various settings. In this arrangement, devices within the
ad-hoc grid communicate with each other without the need for a pre-existing network
infrastructure. Users can configure their devices to operate in ad-hoc mode, enabling them to
identify and connect directly to other devices within the grid. This type of network is
particularly advantageous in situations where a spontaneous and temporary network is
required, such as collaborative work environments, conferences, or ad-hoc events. Ad-hoc
grids are characterized by their simplicity and ease of setup. Users can quickly establish
connections between devices without the need for complex network configurations. However,
it's essential to consider the limitations of ad-hoc networks, such as potential security concerns
and limited range compared to traditional infrastructure modes.

SOURCE CODE:

#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/config-store-module.h"
#include "ns3/wifi-module.h"
#include "ns3/internet-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/flow-monitor-module.h"
#include "myapp.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
NS_LOG_COMPONENT_DEFINE ("Lab5");
using namespace ns3;
uint32_t MacTxDropCount, PhyTxDropCount, PhyRxDropCount;
void
MacTxDrop(Ptr<const Packet> p)
{
NS_LOG_INFO("Packet Drop");
MacTxDropCount++;
}
void
PrintDrop()
{
std::cout << Simulator::Now().GetSeconds() << "\t" << MacTxDropCount << "\t"<<
PhyTxDropCount << "\t" << PhyRxDropCount << "\n";
Simulator::Schedule(Seconds(5.0), &PrintDrop);
}
void
PhyTxDrop(Ptr<const Packet> p)
{
NS_LOG_INFO("Packet Drop");
PhyTxDropCount++;
}
void
PhyRxDrop(Ptr<const Packet> p)
{
NS_LOG_INFO("Packet Drop");
PhyRxDropCount++;
}
int main (int argc, char *argv[])
{
std::string phyMode ("DsssRate1Mbps");
double distance = 500; // m
uint32_t numNodes = 25; // by default, 5x5
double interval = 0.001; // seconds
uint32_t packetSize = 600; // bytes
uint32_t numPackets = 10000000;
std::string rtslimit = "1500";
CommandLine cmd;
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
cmd.AddValue ("distance", "distance (m)", distance);
cmd.AddValue ("packetSize", "distance (m)", packetSize);
cmd.AddValue ("rtslimit", "RTS/CTS Threshold (bytes)", rtslimit);
cmd.Parse (argc, argv);
// Convert to time object
Time interPacketInterval = Seconds (interval);
// turn off RTS/CTS for frames below 2200 bytes
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue
(rtslimit));
// Fix non-unicast data rate to be the same as that of unicast
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue
(phyMode));
NodeContainer c;
c.Create (numNodes);
// The below set of helpers will help us to put together the wifi NICs we want
WifiHelper wifi;
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
// set it to zero; otherwise, gain will be added
wifiPhy.Set ("RxGain", DoubleValue (-10) );
// ns-3 supports RadioTap and Prism tracing extensions for 802.11b
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
wifiPhy.SetChannel (wifiChannel.Create ());
// Add a non-QoS upper mac, and disable rate control
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue (phyMode));
// Set it to adhoc mode
wifiMac.SetType ("ns3::AdhocWifiMac");
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, c);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (distance),
"DeltaY", DoubleValue (distance),
"GridWidth", UintegerValue (5),
"LayoutType", StringValue ("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (c);
// Enable OLSR
OlsrHelper olsr;
Ipv4ListRoutingHelper list;
list.Add (olsr, 10);
InternetStackHelper internet;
internet.SetRoutingHelper (list); // has effect on the next Install ()
internet.Install (c);
Ipv4AddressHelper ipv4;
NS_LOG_INFO ("Assign IP Addresses.");
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer ifcont = ipv4.Assign (devices);
// Create Apps
uint16_t sinkPort = 6; // use the same for all apps
// UDP connection from N0 to N24
Address sinkAddress1 (InetSocketAddress (ifcont.GetAddress (24), sinkPort)); // interface of
n24
PacketSinkHelper packetSinkHelper1 ("ns3::UdpSocketFactory", InetSocketAddress
(Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps1 = packetSinkHelper1.Install (c.Get (24)); //n2 as sink
sinkApps1.Start (Seconds (0.));
sinkApps1.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket1 = Socket::CreateSocket (c.Get (0),
UdpSocketFactory::GetTypeId ()); //source at n0
// Create UDP application at n0
Ptr<MyApp> app1 = CreateObject<MyApp> ();
app1->Setup (ns3UdpSocket1, sinkAddress1, packetSize, numPackets, DataRate ("1Mbps"));
c.Get (0)->AddApplication (app1);
app1->SetStartTime (Seconds (31.));
app1->SetStopTime (Seconds (100.));
// UDP connection from N10 to N14
Address sinkAddress2 (InetSocketAddress (ifcont.GetAddress (14), sinkPort)); // interface of
n14
PacketSinkHelper packetSinkHelper2 ("ns3::UdpSocketFactory", InetSocketAddress
(Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps2 = packetSinkHelper2.Install (c.Get (14)); //n14 as sink
sinkApps2.Start (Seconds (0.));
sinkApps2.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket2 = Socket::CreateSocket (c.Get (10),
UdpSocketFactory::GetTypeId ()); //source at n10
// Create UDP application at n10
Ptr<MyApp> app2 = CreateObject<MyApp> ();
app2->Setup (ns3UdpSocket2, sinkAddress2, packetSize, numPackets, DataRate ("1Mbps"));
c.Get (10)->AddApplication (app2);
app2->SetStartTime (Seconds (31.5));
app2->SetStopTime (Seconds (100.));
// UDP connection from N20 to N4
Address sinkAddress3 (InetSocketAddress (ifcont.GetAddress (4), sinkPort)); // interface of
n4
PacketSinkHelper packetSinkHelper3 ("ns3::UdpSocketFactory", InetSocketAddress
(Ipv4Address::GetAny (), sinkPort));
ApplicationContainer sinkApps3 = packetSinkHelper3.Install (c.Get (4)); //n2 as sink
sinkApps3.Start (Seconds (0.));
sinkApps3.Stop (Seconds (100.));
Ptr<Socket> ns3UdpSocket3 = Socket::CreateSocket (c.Get (20),
UdpSocketFactory::GetTypeId ()); //source at n20
// Create UDP application at n20
Ptr<MyApp> app3 = CreateObject<MyApp> ();
app3->Setup (ns3UdpSocket3, sinkAddress3, packetSize, numPackets, DataRate
("1Mbps"));
c.Get (20)->AddApplication (app3);
app3->SetStartTime (Seconds (32.));
app3->SetStopTime (Seconds (100.));
// Install FlowMonitor on all nodes
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
// Trace Collisions

Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx
Drop", MakeCallback(&MacTxDrop));

Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyRxD
rop", MakeCallback(&PhyRxDrop));

Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/PhyTxD
rop", MakeCallback(&PhyTxDrop));
Simulator::Schedule(Seconds(5.0), &PrintDrop);
Simulator::Stop (Seconds (100.0));
Simulator::Run ();
PrintDrop();
// Print per flow statistics
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>
(flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator iter = stats.begin (); iter !=
stats.end (); ++iter)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (iter->first);
if ((t.sourceAddress == Ipv4Address("10.1.1.1") && t.destinationAddress ==
Ipv4Address("10.1.1.25"))
|| (t.sourceAddress == Ipv4Address("10.1.1.11") && t.destinationAddress ==
Ipv4Address("10.1.1.15"))
|| (t.sourceAddress == Ipv4Address("10.1.1.21") && t.destinationAddress ==
Ipv4Address("10.1.1.5")))
{
NS_LOG_UNCOND("Flow ID: " << iter->first << " Src Addr " << t.sourceAddress
<< " Dst Addr " << t.destinationAddress);
NS_LOG_UNCOND("Tx Packets = " << iter->second.txPackets);
NS_LOG_UNCOND("Rx Packets = " << iter->second.rxPackets);
NS_LOG_UNCOND("Throughput: " << iter->second.rxBytes * 8.0 / (iter-
>second.timeLastRxPacket.GetSeconds()-iter->second.timeFirstTxPacket.GetSeconds()) / 1024
<< " Kbps");
}
}
monitor->SerializeToXmlFile("lab-5.flowmon", true, true);
Simulator::Destroy ();
return 0;
}
OUTPUT:
EXPERIMENT – 8

AIM: Introduction to GSM Architecture.

System Architecture
• A GSM network consists of several functional entities, whose functions and interfaces are
defined. The GSM network can be divided into following broad parts.
 The Mobile Station (MS)
 The Base Station Subsystem (BSS)
 The Network Switching Subsystem (NSS)
 The Operation Support Subsystem OSS)

• A GSM Public Land Mobile Network (PLMN) consists of at least one Service Area controlled
by a Mobile Switching Center (MSC) connected to the Public Switched Telephone Network
(PSTN)

• The architecture of a GSM Public Land Mobile Network (PLMN)

• A Base Station Subsystem (BSS) consists of o A Base Station Controller (BSC)


 At least one radio access point or Base Transceiver Station (BTS) for Mobile Stations
(MS), which are mobile phones or another handheld device (for example PDA
computers) with phone interface.
• A BTS, with its aerial and associated radio frequency components, is the actual transmission
and reception component. A Network Cell is the area of radio coverage by one BTS. One or
more BTSs are in turn managed by a BSC. A network cell cluster covered by one or several
BSSs can be managed as a Location Area (LA). All these BSSs must however be controlled by
a single MSC.

• Figure shows three LAs of 3, 4 and 4 cells respectively with a MS moving across cell and LA
boundaries where a MS moving across cell and LA boundaries. 3 LAs consisting of 4 and 5
cells respectively are shown.

• A more detailed architecture of a single MSC controlled Service Area is outlined in figure
below.
• components of the tree GSM network subsystems

• Radio Subsystem (RSS) consisting of the BSSs and all BSS connected MS devices.
 Network and Switching Subsystem (NSS)
 Operation Subsystem (OSS)

• Specified in GSM 01.02 (‘General description of a GSM Public Land Mobile Network
(PLMN)’) and the GSM components are,

ME = Mobile Equipment
BTS = Base Receiving Station
BSC = Base Station Controller
MSC = Mobile Switching Center
VLR = Visitor Location Register
OMC = Operation and Maintenance Center
AuC = Authentication Center
HLR = Home Location Register
EIR = Equipment Identity Register
SMSC = Short Message Service Centre

• A MSC is also through a Gateway MSC (GMSC) connected to other MSCs and to the Public
Switched Telephone Network (PSTN) with the Integrated Services Digital Network (ISDN)
option. The Inter-Working Function (IWF) of GMSC connects the circuit switched data paths
of a GSM network with the PSTN/ISDN. A GMSC is usually integrated in an MSC.

• Basic GSM network components

You might also like