Gaurav WC
Gaurav WC
TECHNOLOGY
C-4, JANAKPURI, NEW DELHI-110058
WIRELESS COMMUNICATION
LAB
(ETEC-463)
---------------------------------------
Name GAURAV KUMAR
Branch B. TECH – IT-1(Morning)
Year 4th Year - 7 Sem
Enrollment Number 02515003120
Class Serial Number 23
Submitted to Dr. SONIKA MALIK
Assistant Professor,
IT Department
TABLE OF CONTENTS
Sr. No. Experiment Sign
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 1
THEORY:
Frequency reuse, or, frequency planning, is a technique of reusing frequencies and channels within
a communication system to improve capacity and spectral efficiency. Frequency reuse is one of the
fundamental concepts on which commercial wireless systems are based that involve the
partitioning of an RF radiating area into cells. The increased capacity in a commercial wireless
network, compared with a network with a single transmitter, comes from the fact that the same
radio frequency can be reused in a different area for a completely different transmission.
Frequency reuse in mobile cellular systems means that frequencies allocated to the service are
reused in a regular pattern of cells, each covered by one base station.
The repeating regular pattern of cells is called cluster. Since each cell is designed to use radio
frequencies only within its boundaries, the same frequencies can be reused in other cells not far
away without interference, in another cluster. Such cells are called ‘co-channel’ cells. The reuse of
frequencies enables a cellular system to handle a huge number of calls with a limited number of
channels. Figure 1 shows a frequency planning with cluster size of 7, showing the co-channels cells
in different clusters by the same letter. The closest distance between the co channel cells (in
different clusters) is determined by the choice of the cluster size and the layout of the cell cluster.
Consider a cellular system with S duplex channels available for use and let N be the number of cells
in a cluster.
If each cell is allotted K duplex channels with all being allotted unique and disjoint channel
groups we have S = KN under normal 2 circumstances. Now, if the cluster are repeated M times
within the total area, the total number of duplex channels, or, the total number of users in the
system would be T = MS = KMN. Clearly, if K and N remain constant, then
T∝M
and, if T and K remain constant, then
N ∝1/M
Hence the capacity gain achieved is directly proportional to the number of times a cluster is
repeated, as well as, for a fixed cell size, small N decreases the size of the cluster with in turn
results in the increase of the number of clusters and hence the capacity. However, for small N, co-
channel cells are located much closer and hence more interference. The value of N is determined by
calculating the amount of interference that can be tolerated for a sufficient quality communication.
Hence the smallest N having interference below the tolerated limit is used. However, the cluster
size N cannot take on any value and is given only by the following equation
GAURAV KUMAR(IT-1)
02515003120
N = i2 + ij + j2, i ≥ 0, j ≥ 0, (where i and j are integer numbers)
With the rapid increase in the number of mobile users, the mobile service providers had to follow
strategies which ensure the effective utilization of the limited radio spectrum. With increased
capacity and low interference being the prime objectives, a frequency reuse scheme was helpful in
achieving these objectives. A variety of channel assignment strategies have been followed to aid
these objectives. Channel assignment strategies are classified into two types: fixed and dynamic, as
discussed below.
In the fixed channel assignment strategy, each cell is allocated a fixed number of voice channels.
Any communication within the cell can only be made with the designated unused channels of that
particular cell. Suppose if all the channels are occupied, then the call is blocked and the subscriber
has to wait. This is simplest of the channel assignment strategies as it requires very simple circuitry
but provides worst channel utilization. Later there was another
approach in which the channels were borrowed from adjacent cells if all of its own designated
channels were occupied. This was named as a borrowing strategy. In such cases the MSC
supervises the borrowing process and ensures that none of the calls in progress are interrupted.
In dynamic channel assignment strategy channels are temporarily assigned for use in cells for the
duration of the call. Each time a call attempt is made from a cell the corresponding BS requests a
channel from MSC. The MSC then allocates a channel to the requesting BS. After the call is over
the channel is returned and kept in a central pool. To avoid co-channel interference any channel
that is in use in one cell can only be reassigned simultaneously to another cell in the system if the
distance between the two cells is larger than minimum reuse distance. When compared to the FCA,
DCA has reduced the likelihood of blocking and even increased the trunking capacity of the
network as all of the channels are available to all cells, i.e., good quality of service. But this type of
assignment strategy results in a heavy load on switching centers at heavy traffic conditions.
Co-channel interference is the cross talk between two different radio transmitters using the same
radio frequency as is the case with the co-channel cells. The reasons for CCI can be because of
either adverse weather conditions or poor frequency planning or overly crowded radio spectrum.
This is a different type of interference which is caused by adjacent channels i.e. channels in
adjacent cells. It is the signal impairment which occurs to one frequency due to presence of another
signal on a nearby frequency. This occurs when imperfect receiver filters allow nearby frequencies
to leak into the passband. This problem is enhanced if the adjacent channel user is transmitting in a
close range compared to the subscriber’s receiver while the receiver attempts to receive a base
station on the channel. This is called the near-far effect. The more adjacent channels are packed
into the channel block, the higher the spectral efficiency, provided that the performance degradation
GAURAV KUMAR(IT-1)
02515003120
can be tolerated in the system link budget. This effect can also occur if a mobile close to a base
station transmits on a channel close to one being used by a weak mobile. This problem might occur
if the base station has a problem in discriminating the
mobile user from the “bleed over” caused by the close adjacent channel mobile.
Cell-Splitting
Cell Splitting is based on the cell radius reduction and minimizes the need to modify the existing
cell parameters. Cell splitting involves the process of subdividing a congested cell into smaller
cells, each with its own base station and a corresponding reduction in antenna size and transmitting
power. This increases the capacity of a cellular system since it increases the number of times that
channels are reused. Since the new cells have smaller radii than the existing cells, inserting these
smaller cells, known as microcells, between the already existing cells results in an increase of
capacity due to the additional number of channels per unit area.
Sectoring
Sectoring is basically a technique which can increase the SIR without necessitating an increase in
the cluster size. Till now, it has been assumed that the base station is located in the center of a cell
and radiates uniformly in all the directions behaving as an omni-directional antenna. However, it
has been found that the co-channel interference in a cellular system may be decreased by replacing
a single omni-directional antenna at the base station by several directional antennas, each radiating
within a specified sector.
THEORY:
Code Division Multiple Access (CDMA) is a sort of multiplexing that facilitates various signals to
occupy a single transmission channel. It optimizes the use of available bandwidth. The technology
is commonly used in ultra-high frequency (UHF) cellular telephone systems, bands ranging
between the 80MHz and 1.9GHz. The CDMA system is very different from time and frequency
multiplexing. In this system, a user has access to the whole bandwidth for the entire duration. The
basic principle is that different CDMA codes are used to distinguish among the different users.
Technology generally used are direct sequence spread spectrum modulation (DS-CDMA),
frequency hopping or mixed CDMA detection (JDCDMA). Here, a signal is generated which
extends over a wide bandwidth. A code called spreading code is used to perform this action. Using
a group of codes, which are orthogonal to each other, it is possible to select a signal with a given
code in the presence of many other signals with different orthogonal codes.
SOURCE CODE:
import java.io.*;
class cdma1 {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int dataa,datab;
int keya[]=new int [6]; int keyb[]=new int [6]; int key1[]=new int [6];
int key2[]=new int [6]; int key3[]=new int[6];
int ina ,inb;
public void getdata()throws IOException {
System.out.println("A-Enter data bit");
ina=Integer.parseInt(br.readLine());
if(ina>1 ||ina<0)
System.out.println("Error enter binary");
System.out.println("B-Enter data bit");
inb=Integer.parseInt(br.readLine());
if(inb>1 ||inb<0)
Systemout.println("Error enter binary");
System.out.println("A-Enter the 6-bit binary key"); for(int i=0; i<6; i++) {
keya[i]=Integer.parseInt(br.readLine());
if(keya[i]>1 ||keya[i]<0)
System.out.println("Error enter binary");
}
System.out.println("B-Enter the 6 bit binary key"); for(int i=0;i<6;i++) {
keyb[i]=Integer.parseInt(br.readLine());
if(keyb[i]>1 ||keyb[i]<0)
System.out.println("Error enter binary");
}
}
public void compute()throws IOException { if (ina==0) dataa = -1;
else dataa=1;
if(inb==0) datab=-1;
else datab=1;
for(int i=0;i<6;i++) {
if(keya[i]==0) key1[i]= -1;
GAURAV KUMAR(IT-1)
02515003120
else key1[i]=1;
}
for(int i=0;i<6;i++) {
if(keyb[i]==0) key2[i]= -1;
else key2[i]=1;
}
for(int i=0;i<6;i++) {
keya[i]=key1[i]*dataa; keyb[i]=key2[i]*datab; key3[i]=keya[i]+keyb[i]; }
for(int i=0;i<6;i++) {
keya[i]=key3[i]*key1[i]; keyb[i]=key3[i]*key2[i]; }
int totala=0; int totalb=0;
for(int i=0;i<6;i++) {
totala=totala+keya[i];
totalb=totalb+keyb[i];
}
System.out.println("Transformed key a");
for(int i=0;i<6;i++)
System.out.print(key1[i]+" ");
System.out.println("Transformed key b");
for(int i=0;i<6;i++)
System.out.print(key2[i]+" ");
System.out.println("The sum of a is "+totala);
System.out.println("The sum of b is "+totalb);
if(totala>=0)
System.out.println("The data entered by A is 1");
else
System.out.println("The data entered by A is 0");
if(totalb>=0)
System.out.println("The data entered by B is 1");
else
System.out.println("The data entered by B is 0");
}
}
class cdma {
public static void main(String args[])throws IOException { cdma1 c=new cdma1();
c.getdata();
c.compute();
}
}
OUTPUT:
C:\jdk1.3\bin>javac cdma.java
C:\jdk1.3\bin>java cdma
A-Enter data bit 1
B-Enter data bit 0
A-Enter the 6bit binary key 0 1 0 0 1 1
B-Enter the 6bit binary key 1 1 0 1 0 1
Transformed key a: -1 1 -1 -1 1 1
Transformed key b: 1 1 -1 1 -1 1
The sum of a is 6
The sum of b is -6
The data entered by A is 1
The data entered by B is 0
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 3
THEORY:
Getting Online
By far the most important element of your home network is the router. After purchasing a router,
you need to get it connected and online. If your service provider gave you a modem when they
activated your internet service, this should be pretty simple. Just follow these steps:
● Turn off your modem.
● Unplug the modem’s Ethernet cable from the PC.
● Connect that cable to the WAN or Internet port on your new router.
● Power on your modem (wait for a minute or two).
● Next power on your router (wait for a minute or two).
● Now use another Ethernet cable to connect the PC to your router’s LAN port, and turn on your
PC.
By default, most consumer routers are set up to use DHCP to automatically assign an IP address to
your computer. So, if everything worked right, you should now be online.
With the router and PC physically connected, you can now begin customizing the router’s
configuration. Most routers these days are managed via a web browser and are shipped using a
default IP address, administrator account, and password. This default IP address will vary from
vendor to vendor, so check your documentation to find out yours. Once you have that information,
accessing the management console is easy.
● Launch your Web browser; it doesn’t matter which one you use.
● Enter the router’s IP address, which will look something like 192.168.0.1, into the browser’s
address bar and press Enter.
● You will see the router’s login screen asking for the default administrator username and
password. After your supply those credentials and press Enter, you should be looking at the
management console.
Next, it’s time to focus on your router’s LAN configuration. As I previously mentioned, DHCP,
which manages all the IP addresses on your network, is typically enabled by default on most
consumer routers. Your router uses the IP address, a numeric identifier, to locate your PC and route
the correct network traffic.
If the computer or mobile device does not already have an IP address, it will request one from the
network’s DHCP server, which is on the router. The DHCP server pulls an IP address from a pool
of available IP addresses (called a Scope) and assigns it to the device. When the device disconnects
from the network, or a certain amount of time has passed (referred to as a lease) the IP address
returns to the DHCP pool.
To set the DHCP scope, follow these steps:
● Log in to the router’s management console and look for a heading like LAN Setup (or something
similar). Here you should see your LAN’s IP address and subnet mask along with a section for
DHCP server.
GAURAV KUMAR(IT-1)
02515003120
● Assign a range of IP addresses for the DHCP server to use. Assuming your router’s IP address is
192.168.0.1 and you wanted to assign 50 IP addresses to the DHCP scope, you would set the
Starting IP address to 192.168.0.2 and the Ending address to 192.168.0.51.
With your network now properly configured you can move on to setting up your wireless network.
This is actually very simple and should only take you couple of minutes. When you do this, make
sure you use a computer that is connected to the network via an Ethernet cable. If you try to
configure Wi-Fi over wireless, you’ll lose the connection to the management console whenever
changes to the configuration are applied.
● Go into the router’s management console and locate the section titled Wireless Setup. It might be
labeled differently depending on your router, but it should be pretty obvious which one it is.
● The wireless network should be enabled by default, but if it isn’t, turn it on. If you have a
dual-band router, you should see the configuration settings for both the 2.4Gz and 5GHz networks.
Both need to be configured independently.
● Next make sure the Channel is set to Auto and leave the Mode in its default setting. You can
adjust these settings later if you feel the network is sluggish or if you’re experiencing dropped
connections.
● This brings us to the SSID. The SSID is the name of your wireless network. You can name the
network just about anything you want, and you definitely should not leave it set to the default
value. Something descriptive is always good. For instance, we might use something along the lines
of PCM24 and PCM50. PCM24 would be the name assigned to the 2,4GHz network and PCM50
would be the name assigned to the 5GHz network. PCM of course stands for PCMag.
● The final step is to set the encryption your Wi-Fi network will use. There are a few choices here.
The only one you’re interested in using is WPA2.
● There might be a few WPA2 options listed, but you want the one listed as WPA2- PSK [AES].
This is the highest level of wireless security currently available. Some routers still offer WEP. Do
not use it as it is vulnerable to brute-force attacks.
● Once you’ve set your encryption type to WPA2, assign a passphrase (aka passcode or key). This
Passphrase needs to be between 8 and 63 characters long and should be made up of both letters
(both uppercase and lowercase), numbers and characters ($@#%&). The longer the key, the more
secure. Passphrases made up of random characters, such as hy#Pnj!123 are the best, but if you have
to use a name or something else familiar, make sure to mix it up with some numbers and characters
as well (ex: P@assword20!5).
All that’s left now is to save your configuration changes and test the connection. Your wireless
devices should now be online.
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 4
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 5
SOURCE CODE:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/mobility-module.h"
#include "ns3/stats-module.h"
#include "ns3/wifi-module.h"
#include <iostream>
NS_LOG_COMPONENT_DEFINE ("Main");
using namespace ns3;
class Experiment {
public:
Experiment (); Experiment (std::string name);
Gnuplot2dDataset Run (const WifiHelper &wifi, const YansWifiPhyHelper &wifiPhy, const
NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel); private: void
ReceivePacket (Ptr<Socket> socket);
void SetPosition (Ptr<Node> node, Vector position);
Vector GetPosition (Ptr<Node> node);
void AdvancePosition (Ptr<Node> node);
Ptr<Socket> SetupPacketReceive (Ptr<Node> node);
uint32_t m_bytesTotal; Gnuplot2dDataset m_output;
};
Experiment::Experiment () {}
Experiment::Experiment (std::string name): m_output (name){
m_output.SetStyle (Gnuplot2dDataset::LINES);
}
void Experiment::SetPosition (Ptr<Node> node, Vector position){
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); mobility->SetPosition
(position);
}
Vector Experiment::GetPosition (Ptr<Node> node) {
Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> (); return mobility-
>GetPosition ();
}
void Experiment::AdvancePosition (Ptr<Node> node) {
Vector pos = GetPosition (node);
double mbs = ((m_bytesTotal * 8.0) / 1000000);
m_bytesTotal = 0; m_output.Add (pos.x, mbs);
pos.x += 1.0;
if (pos.x >= 210.0) { return; }
SetPosition (node, pos);
Simulator::Schedule (Seconds (1.0), &Experiment::AdvancePosition, this, node); }
void Experiment::ReceivePacket (Ptr<Socket> socket) {
Ptr<Packet> packet;
while ((packet = socket->Recv ())) { m_bytesTotal += packet->GetSize (); } }
Ptr<Socket>Experiment::SetupPacketReceive (Ptr<Node> node){
TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory"); Ptr<Socket> sink =
GAURAV KUMAR(IT-1)
02515003120
Socket::CreateSocket (node, tid);
sink->Bind ();
sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this)); return sink; }
Gnuplot2dDataset Experiment::Run (const WifiHelper &wifi, const YansWifiPhyHelper
&wifiPhy, const NqosWifiMacHelper &wifiMac, const YansWifiChannelHelper &wifiChannel) {
m_bytesTotal = 0; NodeContainer c; c.Create (2);
PacketSocketHelper packetSocket;
packetSocket.Install (c);
YansWifiPhyHelper phy = wifiPhy;
phy.SetChannel (wifiChannel.Create ());
NqosWifiMacHelper mac = wifiMac;
NetDeviceContainer devices = wifi.Install (phy, mac, c);
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);
PacketSocketAddress socket;
socket.SetSingleDevice (devices.Get (0)->GetIfIndex ());
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket)); onoff.SetConstantRate
(DataRate (60000000));
onoff.SetAttribute ("PacketSize", UintegerValue (2000));
ApplicationContainer apps = onoff.Install (c.Get (0));
apps.Start (Seconds (0.5));
apps.Stop (Seconds (250.0));
Simulator::Schedule (Seconds (1.5), &Experiment::AdvancePosition, this c.Get
(1)); Ptr<Socket> recvSink = SetupPacketReceive (c.Get (1));
Simulator::Run (); Simulator::Destroy (); return m_output;
}
int main (int argc, char *argv[]) {
Config::SetDefault ("ns3::FragmentationThreshold", StringValue ("2200")); Config::SetDefault
("ns3::RtsCtsThreshold", StringValue ("2200"));
CommandLine cmd; cmd.Parse (argc, argv);
Gnuplot gnuplot = Gnuplot ("reference-rates.png");
Experiment experiment;
WifiHelper wifi = WifiHelper::Default ();
wifi.SetStandard (WIFI_PHY_STANDARD_80211a);
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default (); Gnuplot2dDataset
dataset;
wifiMac.SetType ("ns3::AdhocWifiMac");
NS_LOG_DEBUG ("54");
experiment = Experiment ("54mb");
wifi.SetRemoteStationManager ("ns3::", “DataMode", StringValue ("OfdmRate54Mbps")); dataset
= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("48");
experiment = Experiment ("48mb");
wifi.SetRemoteStationManager ("ns3::", “DataMode", StringValue ("OfdmRate48Mbps")); dataset
GAURAV KUMAR(IT-1)
02515003120
= experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("36");
experiment = Experiment ("36mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate36Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("24");
experiment = Experiment ("24mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate24Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("18");
experiment = Experiment ("18mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate18Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("12");
experiment = Experiment ("12mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate12Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("9");
experiment = Experiment ("9mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue
("OfdmRate9Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("6");
experiment = Experiment ("6mb");
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode", StringValue ("OfdmRate6Mbps"));
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
gnuplot = Gnuplot ("rate-control.png");
wifi.SetStandard (WIFI_PHY_STANDARD_holland);
NS_LOG_DEBUG ("arf");
experiment = Experiment ("arf");
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("aarf");
experiment = Experiment ("aarf");
wifi.SetRemoteStationManager ("ns3::AarfWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("aarf-cd");
experiment = Experiment ("aarf-cd");
GAURAV KUMAR(IT-1)
02515003120
wifi.SetRemoteStationManager ("ns3::AarfcdWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("cara");
experiment = Experiment ("cara");
wifi.SetRemoteStationManager ("ns3::CaraWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel);
gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("rraa");
experiment = Experiment ("rraa");
wifi.SetRemoteStationManager ("ns3::RraaWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel); gnuplot.AddDataset (dataset);
NS_LOG_DEBUG ("ideal");
experiment = Experiment ("ideal");
wifi.SetRemoteStationManager ("ns3::IdealWifiManager");
dataset = experiment.Run (wifi, wifiPhy, wifiMac, wifiChannel); gnuplot.AddDataset (dataset);
gnuplot.GenerateOutput (std::cout);
return 0;
}
OUTPUT:
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 6
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 <bits/stdc++.h>
NS_LOG_COMPONENT_DEFINE ("WifiSimpleInfra");
using namespace ns3;
void ReceivePacket (Ptr<Socket> socket) {
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); Time
interPacketInterval = Seconds (interval);
Config::SetDefault
("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue (phyMode)); NodeContainer
c;
c.Create (2);
WifiHelper wifi;
if (verbose) { wifi.EnableLogComponents (); }
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
wifiPhy.Set ("RxGain", DoubleValue (0) );
wifiPhy.SetPcapDataLinkType (YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
GAURAV KUMAR(IT-1)
02515003120
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel","Rss",DoubleValue(rss));
wifiPhy.SetChannel (wifiChannel.Create ());
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager","DataMode",StringValue
(phyMode), "ControlMode",StringValue (phyMode));
Ssid ssid = Ssid ("wifi-default");
wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid), "ActiveProbing",
BooleanValue (false));
NetDeviceContainer staDevice = wifi.Install (wifiPhy, wifiMac, c.Get (0)); NetDeviceContainer
devices = staDevice;
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));
NetDeviceContainer apDevice = wifi.Install (wifiPhy, wifiMac, c.Get (1)); devices.Add
(apDevice);
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);
wifiPhy.EnablePcap ("wifi-simple-infra", devices);
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;
}
GAURAV KUMAR(IT-1)
02515003120
OUTPUT:
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 7
THEORY:
Wireshark is a third-party graphical user interface (GUI) network protocol analyzer that is used to
interactively dump and analyze network traffic. Similar to the snoop command, you can use
Wireshark to browse packet data on a live network or from a previously saved capture file. By
default, Wireshark uses the libpcap format for file captures, which is also used by the tcpdump
utility and other similar tools. A key advantage of using Wireshark is that it is capable of reading
and importing several other file formats besides the libpcap format.
Both TShark and Wireshark provide several unique features, including the following:
● Capable of assembling all of the packets in a TCP conversation and displaying the data in that
conversation in ASCU, EBCDIC or hex format
● Contain more filterable fields than in other network protocol analyzers Use a syntax that is richer
than other network protocol analyzers for eating filters.
Wireshark is a useful tool to determine the cause of slow network connections. The following
steps show you how to configure Wireshark:
Install Wireshark:
On Windows, download Wireshark and install with the default selections On Linux, enter the
commands:
yum search wireshark
yum install wireshark.x86_64k
1. yum install wireshark-gnome
Note: Replace "wireshark.x86_64" with the build that corresponds to your Linux workstation
platform.
2. If the Protocol field lists "UNKNOWN", select Analyze->Enabled Protocols->Enable All 3.
Configure the interface to be analyzed:
When starting, the "Welcome to Wireshark" screen will show a heading named "Capture". Choose
the interface with a graph activity.
4. Define filters
Suppose you want to monitor traffic to port 20182. At the top, click the Expression item
next to the Filter item
Choose Field Name TCP - Transmission Control Protocol and expand to select tcp.dstport -
Destination Port, Relation ==, Value 20182 where 20182 is the Helix server port number you are
connecting to. Click OK.
5. Capture Data
Click Capture -> Start from the Menu
Click tcp.destport == 20182 and press the enter key.
Run: p4 info
and check that you see an immediate response.
6. Launch the application you want to analyze and reproduce the issue. 7. Select the Capture |
Stop menu item when you have completed reproducing the issue. 8. Double-click any of the
packets to see the packet contents
9. To save the results, select the File | Save as... menu item to save the output as a .pcap file .
GAURAV KUMAR(IT-1)
02515003120
EXPERIMENT - 8
AIM: Experiment to capture, filter and inspect elements using WIRESHARK tool.
Wireshark, a network analysis tool formerly known as Ethereal, captures packets in real time and
displays them in human-readable format. Wireshark includes filters, color coding, and other
features that let you dig deep into network traffic and inspect individual packets. This tutorial will
get you up to speed with the basics of capturing packets, filtering them, and inspecting them. You
can use Wireshark to inspect a suspicious program’s network traffic, analyze the traffic flow on
your network, or troubleshoot network problems.
Getting Wireshark
You can download Wireshark for Windows or macOS from its official website. If you’re using
Linux or another UNIX-like system, you’ll probably find Wireshark in its package repositories. For
example, if you’re using Ubuntu, you’ll find Wireshark in the Ubuntu Software Center.
Just a quick warning: Many organizations don’t allow Wireshark and similar tools on their
networks. Don’t use this tool at work unless you have permission.
Capturing Packets
After downloading and installing Wireshark, you can launch it and double-click the name of a
network interface under Capture to start capturing packets on that interface. For example, if you
want to capture traffic on your wireless network, click your wireless interface. You can configure
advanced features by clicking Capture > Options, but this isn’t necessary for now.
GAURAV KUMAR(IT-1)
02515003120
As soon as you click the interface’s name, you’ll see the packets start to appear in real time.
Wireshark captures each packet sent to or from your system.
If you have promiscuous mode enabled—it’s enabled by default—you’ll also see all the other
packets on the network instead of only packets addressed to your network adapter. To check if
promiscuous mode is enabled, click Capture > Options and verify the “Enable promiscuous mode
on all interfaces” checkbox is activated at the bottom of this window.
Click the red “Stop” button near the top left corner of the window when you want to stop
capturing traffic.
GAURAV KUMAR(IT-1)
02515003120
Color Coding
You’ll probably see packets highlighted in a variety of different colors. Wireshark uses colors to
help you identify the types of traffic at a glance. By default, light purple is TCP traffic, light blue is
UDP traffic, and black identifies packets with errors—for example, they could have been delivered
out of order. To view exactly what the color codes mean, click View > Coloring Rules. You can
also customize and modify the coloring rules from here, if you like.
Sample Captures
If there’s nothing interesting on your own network to inspect, Wireshark’s wiki has you covered.
The wiki contains a page of sample capture files that you can load and inspect. Click File > Open in
Wireshark and browse for your downloaded file to open one. You can also save your own captures
in Wireshark and open them later. Click File > Save to save your captured packets.
GAURAV KUMAR(IT-1)
02515003120
Filtering Packets
If you’re trying to inspect something specific, such as the traffic a program sends when phoning
home, it helps to close down all other applications using the network so you can narrow down the
traffic. Still, you’ll likely have a large amount of packets to sift through. That’s where Wireshark’s
filters come in. The most basic way to apply a filter is by typing it into the filter box at the top of
the window and clicking Apply (or pressing Enter). For example, type “dns” and you’ll see only
DNS packets. When you start typing, Wireshark will help you autocomplete your filter.
You can also click Analyze > Display Filters to choose a filter from among the default filters
included in Wireshark. From here, you can add your own custom filters and save them to easily
access them in the future. For more information on Wireshark’s display filtering language, read the
Building display filter expressions page in the official Wireshark
documentation.
Another interesting thing you can do is right-click a packet and select Follow > TCP Stream.
You’ll see the full TCP conversation between the client and the server. You can also click other
protocols in the Follow menu to see the full conversations for other protocols, if applicable. Close
the window and you’ll find a filter has been applied automatically. Wireshark is showing you the
packets that make up the conversation.
Inspecting Packets
Click a packet to select it and you can dig down to view its details. You can also create filters from
here — just right-click one of the details and use the Apply as Filter submenu to create a filter
based on it.
GAURAV KUMAR(IT-1)
02515003120