A Discrete-Event Network Simulator
API
nsclick-raw-wlan.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation;
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * Authors: Lalith Suresh <suresh.lalith@gmail.com>
16  */
17 
18 // Scenario: node A (using Click) sends packets to node B (not using
19 // Click)
20 //
21 // (Click) (non-Click)
22 // A ))) WLAN ((( B
23 // (172.16.1.1) (172.16.1.2)
24 // (eth0)
25 //
26 
27 #include "ns3/applications-module.h"
28 #include "ns3/click-internet-stack-helper.h"
29 #include "ns3/core-module.h"
30 #include "ns3/internet-module.h"
31 #include "ns3/log.h"
32 #include "ns3/mobility-helper.h"
33 #include "ns3/network-module.h"
34 #include "ns3/wifi-module.h"
35 
36 using namespace ns3;
37 
38 void
40 {
41  NS_LOG_UNCOND("Received one packet!");
42 }
43 
44 int
45 main(int argc, char* argv[])
46 {
47  double rss = -80;
48  std::string clickConfigFolder = "src/click/examples";
49 
50  CommandLine cmd(__FILE__);
51  cmd.AddValue("clickConfigFolder",
52  "Base folder for click configuration files",
54  cmd.Parse(argc, argv);
55 
56  // Setup nodes
57  NodeContainer wifiNodes;
58  wifiNodes.Create(2);
59 
60  // Get Wifi devices installed on both nodes.
61  // Adapted from examples/wireless/wifi-simple-adhoc.cc
62  std::string phyMode("DsssRate1Mbps");
63 
64  // disable fragmentation for frames below 2200 bytes
65  Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
66  StringValue("2200"));
67  // turn off RTS/CTS for frames below 2200 bytes
68  Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
69  // Fix non-unicast data rate to be the same as that of unicast
70  Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
71 
73  wifi.SetStandard(WIFI_STANDARD_80211b);
74 
75  YansWifiPhyHelper wifiPhy;
76  // This is one parameter that matters when using FixedRssLossModel
77  // set it to zero; otherwise, gain will be added
78  wifiPhy.Set("RxGain", DoubleValue(0));
79  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
81 
82  YansWifiChannelHelper wifiChannel;
83  wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
84  // The below FixedRssLossModel will cause the rss to be fixed regardless
85  // of the distance between the two stations, and the transmit power
86  wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss", DoubleValue(rss));
87  wifiPhy.SetChannel(wifiChannel.Create());
88 
89  // Add an upper mac and disable rate control
90  WifiMacHelper wifiMac;
91  wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
92  "DataMode",
93  StringValue(phyMode),
94  "ControlMode",
95  StringValue(phyMode));
96  // Set it to adhoc mode
97  wifiMac.SetType("ns3::AdhocWifiMac");
98  NetDeviceContainer wifiDevices = wifi.Install(wifiPhy, wifiMac, wifiNodes);
99 
100  // Setup mobility models
102  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
103  positionAlloc->Add(Vector(0.0, 0.0, 0.0));
104  positionAlloc->Add(Vector(5.0, 0.0, 0.0));
105  mobility.SetPositionAllocator(positionAlloc);
106  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
107  mobility.Install(wifiNodes);
108 
109  // Install normal internet stack on node B
111  internet.Install(wifiNodes.Get(1));
112 
113  // Install Click on node A
115  clickinternet.SetClickFile(wifiNodes.Get(0),
116  clickConfigFolder + "/nsclick-wifi-single-interface.click");
117  clickinternet.SetRoutingTableElement(wifiNodes.Get(0), "rt");
118  clickinternet.Install(wifiNodes.Get(0));
119 
120  // Configure IP addresses
122  ipv4.SetBase("172.16.1.0", "255.255.255.0");
123  ipv4.Assign(wifiDevices);
124 
125  // Setup traffic application and sockets
127  PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", LocalAddress);
128  ApplicationContainer recvapp = packetSinkHelper.Install(wifiNodes.Get(1));
129  recvapp.Start(Seconds(5.0));
130  recvapp.Stop(Seconds(10.0));
131 
132  OnOffHelper onOffHelper("ns3::TcpSocketFactory", Address());
133  onOffHelper.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
134  onOffHelper.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
135 
137 
138  AddressValue remoteAddress(InetSocketAddress(Ipv4Address("172.16.1.2"), 50000));
139  onOffHelper.SetAttribute("Remote", remoteAddress);
140  appcont.Add(onOffHelper.Install(wifiNodes.Get(0)));
141 
142  appcont.Start(Seconds(5.0));
143  appcont.Stop(Seconds(10.0));
144 
145  // For tracing
146  wifiPhy.EnablePcap("nsclick-raw-wlan", wifiDevices);
147 
148  Simulator::Stop(Seconds(20.0));
149  Simulator::Run();
150 
152 
153  return 0;
154 }
a polymophic address class
Definition: address.h:101
holds a vector of ns3::Application pointers.
aggregate Click/IP/TCP/UDP functionality to existing Nodes.
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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.
Definition: ipv4-address.h:42
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.
Definition: on-off-helper.h:44
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.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
helps to create WifiNetDevice objects
Definition: wifi-helper.h:324
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.
Definition: wifi-helper.cc:543
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:163
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:178
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:890
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
@ WIFI_STANDARD_80211b
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:40
wifi
Definition: third.py:95
mobility
Definition: third.py:105
void ReceivePacket(Ptr< Socket > socket)