A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nsclick-raw-wlan.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Authors: Lalith Suresh <suresh.lalith@gmail.com>
5 */
6
7// Scenario: node A (using Click) sends packets to node B (not using
8// Click)
9//
10// (Click) (non-Click)
11// A ))) WLAN ((( B
12// (172.16.1.1) (172.16.1.2)
13// (eth0)
14//
15
16#include "ns3/applications-module.h"
17#include "ns3/click-internet-stack-helper.h"
18#include "ns3/core-module.h"
19#include "ns3/internet-module.h"
20#include "ns3/log.h"
21#include "ns3/mobility-helper.h"
22#include "ns3/network-module.h"
23#include "ns3/wifi-module.h"
24
25using namespace ns3;
26
27void
29{
30 NS_LOG_UNCOND("Received one packet!");
31}
32
33int
34main(int argc, char* argv[])
35{
36 double rss = -80;
37 std::string clickConfigFolder = "src/click/examples";
38
39 CommandLine cmd(__FILE__);
40 cmd.AddValue("clickConfigFolder",
41 "Base folder for click configuration files",
42 clickConfigFolder);
43 cmd.Parse(argc, argv);
44
45 // Setup nodes
46 NodeContainer wifiNodes;
47 wifiNodes.Create(2);
48
49 // Get Wifi devices installed on both nodes.
50 // Adapted from examples/wireless/wifi-simple-adhoc.cc
51 std::string phyMode("DsssRate1Mbps");
52
53 // disable fragmentation for frames below 2200 bytes
54 Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
55 StringValue("2200"));
56 // turn off RTS/CTS for frames below 2200 bytes
57 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
58 // Fix non-unicast data rate to be the same as that of unicast
59 Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
60
62 wifi.SetStandard(WIFI_STANDARD_80211b);
63
64 YansWifiPhyHelper wifiPhy;
65 // This is one parameter that matters when using FixedRssLossModel
66 // set it to zero; otherwise, gain will be added
67 wifiPhy.Set("RxGain", DoubleValue(0));
68 // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
70
71 YansWifiChannelHelper wifiChannel;
72 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
73 // The below FixedRssLossModel will cause the rss to be fixed regardless
74 // of the distance between the two stations, and the transmit power
75 wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss", DoubleValue(rss));
76 wifiPhy.SetChannel(wifiChannel.Create());
77
78 // Add an upper mac and disable rate control
79 WifiMacHelper wifiMac;
80 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
81 "DataMode",
82 StringValue(phyMode),
83 "ControlMode",
84 StringValue(phyMode));
85 // Set it to adhoc mode
86 wifiMac.SetType("ns3::AdhocWifiMac");
87 NetDeviceContainer wifiDevices = wifi.Install(wifiPhy, wifiMac, wifiNodes);
88
89 // Setup mobility models
92 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
93 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
94 mobility.SetPositionAllocator(positionAlloc);
95 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
96 mobility.Install(wifiNodes);
97
98 // Install normal internet stack on node B
100 internet.Install(wifiNodes.Get(1));
101
102 // Install Click on node A
104 clickinternet.SetClickFile(wifiNodes.Get(0),
105 clickConfigFolder + "/nsclick-wifi-single-interface.click");
106 clickinternet.SetRoutingTableElement(wifiNodes.Get(0), "rt");
107 clickinternet.Install(wifiNodes.Get(0));
108
109 // Configure IP addresses
111 ipv4.SetBase("172.16.1.0", "255.255.255.0");
112 ipv4.Assign(wifiDevices);
113
114 // Setup traffic application and sockets
116 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", LocalAddress);
117 ApplicationContainer recvapp = packetSinkHelper.Install(wifiNodes.Get(1));
118 recvapp.Start(Seconds(5.0));
119 recvapp.Stop(Seconds(10.0));
120
121 OnOffHelper onOffHelper("ns3::TcpSocketFactory", Address());
122 onOffHelper.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
123 onOffHelper.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
124
126
128 onOffHelper.SetAttribute("Remote", remoteAddress);
129 appcont.Add(onOffHelper.Install(wifiNodes.Get(0)));
130
131 appcont.Start(Seconds(5.0));
132 appcont.Stop(Seconds(10.0));
133
134 // For tracing
135 wifiPhy.EnablePcap("nsclick-raw-wlan", wifiDevices);
136
139
141
142 return 0;
143}
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
helps to create WifiNetDevice objects
create MAC layers for a ns3::WifiNetDevice.
void SetType(std::string type, Args &&... args)
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
void Set(std::string name, const AttributeValue &v)
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
manage and create wifi channel objects for the YANS model.
void SetPropagationDelay(std::string name, Ts &&... args)
void AddPropagationLoss(std::string name, Ts &&... args)
Ptr< YansWifiChannel > Create() const
Make it easy to create and manage PHY objects for the YANS model.
void SetChannel(Ptr< YansWifiChannel > channel)
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
@ WIFI_STANDARD_80211b
Every class exported by the ns3 library is enclosed in the ns3 namespace.
wifi
Definition third.py:84
mobility
Definition third.py:92
void ReceivePacket(Ptr< Socket > socket)