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
36using namespace ns3;
37
38void
40{
41 NS_LOG_UNCOND("Received one packet!");
42}
43
44int
45main(int argc, char* argv[])
46{
47#ifdef NS3_CLICK
48 double rss = -80;
49 std::string clickConfigFolder = "src/click/examples";
50
51 CommandLine cmd(__FILE__);
52 cmd.AddValue("clickConfigFolder",
53 "Base folder for click configuration files",
54 clickConfigFolder);
55 cmd.Parse(argc, argv);
56
57 // Setup nodes
58 NodeContainer wifiNodes;
59 wifiNodes.Create(2);
60
61 // Get Wifi devices installed on both nodes.
62 // Adapted from examples/wireless/wifi-simple-adhoc.cc
63 std::string phyMode("DsssRate1Mbps");
64
65 // disable fragmentation for frames below 2200 bytes
66 Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",
67 StringValue("2200"));
68 // turn off RTS/CTS for frames below 2200 bytes
69 Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue("2200"));
70 // Fix non-unicast data rate to be the same as that of unicast
71 Config::SetDefault("ns3::WifiRemoteStationManager::NonUnicastMode", StringValue(phyMode));
72
74 wifi.SetStandard(WIFI_STANDARD_80211b);
75
76 YansWifiPhyHelper wifiPhy;
77 // This is one parameter that matters when using FixedRssLossModel
78 // set it to zero; otherwise, gain will be added
79 wifiPhy.Set("RxGain", DoubleValue(0));
80 // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
81 wifiPhy.SetPcapDataLinkType(WifiPhyHelper::DLT_IEEE802_11_RADIO);
82
83 YansWifiChannelHelper wifiChannel;
84 wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
85 // The below FixedRssLossModel will cause the rss to be fixed regardless
86 // of the distance between the two stations, and the transmit power
87 wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss", DoubleValue(rss));
88 wifiPhy.SetChannel(wifiChannel.Create());
89
90 // Add an upper mac and disable rate control
91 WifiMacHelper wifiMac;
92 wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager",
93 "DataMode",
94 StringValue(phyMode),
95 "ControlMode",
96 StringValue(phyMode));
97 // Set it to adhoc mode
98 wifiMac.SetType("ns3::AdhocWifiMac");
99 NetDeviceContainer wifiDevices = wifi.Install(wifiPhy, wifiMac, wifiNodes);
100
101 // Setup mobility models
103 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
104 positionAlloc->Add(Vector(0.0, 0.0, 0.0));
105 positionAlloc->Add(Vector(5.0, 0.0, 0.0));
106 mobility.SetPositionAllocator(positionAlloc);
107 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
108 mobility.Install(wifiNodes);
109
110 // Install normal internet stack on node B
111 InternetStackHelper internet;
112 internet.Install(wifiNodes.Get(1));
113
114 // Install Click on node A
115 ClickInternetStackHelper clickinternet;
116 clickinternet.SetClickFile(wifiNodes.Get(0),
117 clickConfigFolder + "/nsclick-wifi-single-interface.click");
118 clickinternet.SetRoutingTableElement(wifiNodes.Get(0), "rt");
119 clickinternet.Install(wifiNodes.Get(0));
120
121 // Configure IP addresses
123 ipv4.SetBase("172.16.1.0", "255.255.255.0");
124 ipv4.Assign(wifiDevices);
125
126 // Setup traffic application and sockets
127 Address LocalAddress(InetSocketAddress(Ipv4Address::GetAny(), 50000));
128 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", LocalAddress);
129 ApplicationContainer recvapp = packetSinkHelper.Install(wifiNodes.Get(1));
130 recvapp.Start(Seconds(5.0));
131 recvapp.Stop(Seconds(10.0));
132
133 OnOffHelper onOffHelper("ns3::TcpSocketFactory", Address());
134 onOffHelper.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
135 onOffHelper.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
136
137 ApplicationContainer appcont;
138
139 AddressValue remoteAddress(InetSocketAddress(Ipv4Address("172.16.1.2"), 50000));
140 onOffHelper.SetAttribute("Remote", remoteAddress);
141 appcont.Add(onOffHelper.Install(wifiNodes.Get(0)));
142
143 appcont.Start(Seconds(5.0));
144 appcont.Stop(Seconds(10.0));
145
146 // For tracing
147 wifiPhy.EnablePcap("nsclick-raw-wlan", wifiDevices);
148
149 Simulator::Stop(Seconds(20.0));
150 Simulator::Run();
151
152 Simulator::Destroy();
153#else
154 NS_FATAL_ERROR("Can't use ns-3-click without NSCLICK compiled in");
155#endif
156
157 return 0;
158}
a polymophic address class
Definition: address.h:92
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
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.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
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.
Hold variables of type string.
Definition: string.h:42
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
helps to create WifiNetDevice objects
Definition: wifi-helper.h:325
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
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:891
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
@ WIFI_STANDARD_80211b
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:33
wifi
Definition: third.py:88
mobility
Definition: third.py:96
void ReceivePacket(Ptr< Socket > socket)