A Discrete-Event Network Simulator
API
nsclick-raw-wlan.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Authors: Lalith Suresh <suresh.lalith@gmail.com>
17  */
18 
19 // Scenario: node A (using Click) sends packets to node B (not using
20 // Click)
21 //
22 // (Click) (non-Click)
23 // A ))) WLAN ((( B
24 // (172.16.1.1) (172.16.1.2)
25 // (eth0)
26 //
27 
28 #include "ns3/core-module.h"
29 #include "ns3/network-module.h"
30 #include "ns3/internet-module.h"
31 #include "ns3/applications-module.h"
32 #include "ns3/wifi-module.h"
33 #include "ns3/click-internet-stack-helper.h"
34 #include "ns3/log.h"
35 #include "ns3/mobility-helper.h"
36 
37 using namespace ns3;
38 
40 {
41  NS_LOG_UNCOND ("Received one packet!");
42 }
43 
44 int main (int argc, char *argv[])
45 {
46 #ifdef NS3_CLICK
47  double rss = -80;
48  std::string clickConfigFolder = "src/click/examples";
49 
51  cmd.AddValue ("clickConfigFolder", "Base folder for click configuration files", clickConfigFolder);
52  cmd.Parse (argc, argv);
53 
54  // Setup nodes
55  NodeContainer wifiNodes;
56  wifiNodes.Create (2);
57 
58  // Get Wifi devices installed on both nodes.
59  // Adapted from examples/wireless/wifi-simple-adhoc.cc
60  std::string phyMode ("DsssRate1Mbps");
61 
62  // disable fragmentation for frames below 2200 bytes
63  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
64  // turn off RTS/CTS for frames below 2200 bytes
65  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
66  // Fix non-unicast data rate to be the same as that of unicast
67  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
68  StringValue (phyMode));
69 
72 
74  // This is one parameter that matters when using FixedRssLossModel
75  // set it to zero; otherwise, gain will be added
76  wifiPhy.Set ("RxGain", DoubleValue (0) );
77  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
79 
80  YansWifiChannelHelper wifiChannel;
81  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
82  // The below FixedRssLossModel will cause the rss to be fixed regardless
83  // of the distance between the two stations, and the transmit power
84  wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
85  wifiPhy.SetChannel (wifiChannel.Create ());
86 
87  // Add an upper mac and disable rate control
88  WifiMacHelper wifiMac;
89  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
90  "DataMode",StringValue (phyMode),
91  "ControlMode",StringValue (phyMode));
92  // Set it to adhoc mode
93  wifiMac.SetType ("ns3::AdhocWifiMac");
94  NetDeviceContainer wifiDevices = wifi.Install (wifiPhy, wifiMac, wifiNodes);
95 
96  // Setup mobility models
98  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
99  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
100  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
101  mobility.SetPositionAllocator (positionAlloc);
102  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
103  mobility.Install (wifiNodes);
104 
105  // Install normal internet stack on node B
106  InternetStackHelper internet;
107  internet.Install (wifiNodes.Get (1));
108 
109  // Install Click on node A
110  ClickInternetStackHelper clickinternet;
111  clickinternet.SetClickFile (wifiNodes.Get (0), clickConfigFolder + "/nsclick-wifi-single-interface.click");
112  clickinternet.SetRoutingTableElement (wifiNodes.Get (0), "rt");
113  clickinternet.Install (wifiNodes.Get (0));
114 
115  // Configure IP addresses
116  Ipv4AddressHelper ipv4;
117  ipv4.SetBase ("172.16.1.0", "255.255.255.0");
118  ipv4.Assign (wifiDevices);
119 
120  // Setup traffic application and sockets
121  Address LocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 50000));
122  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", LocalAddress);
123  ApplicationContainer recvapp = packetSinkHelper.Install (wifiNodes.Get (1));
124  recvapp.Start (Seconds (5.0));
125  recvapp.Stop (Seconds (10.0));
126 
127  OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
128  onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
129  onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
130 
131  ApplicationContainer appcont;
132 
133  AddressValue remoteAddress (InetSocketAddress (Ipv4Address ("172.16.1.2"), 50000));
134  onOffHelper.SetAttribute ("Remote", remoteAddress);
135  appcont.Add (onOffHelper.Install (wifiNodes.Get (0)));
136 
137  appcont.Start (Seconds (5.0));
138  appcont.Stop (Seconds (10.0));
139 
140  // For tracing
141  wifiPhy.EnablePcap ("nsclick-raw-wlan", wifiDevices);
142 
143  Simulator::Stop (Seconds (20.0));
144  Simulator::Run ();
145 
147  return 0;
148 #else
149  NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in");
150 #endif
151 }
void AddPropagationLoss(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:112
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
Ptr< YansWifiChannel > Create(void) const
void SetRemoteStationManager(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition: wifi-helper.cc:683
Hold variables of type string.
Definition: string.h:41
Make it easy to create and manage PHY objects for the yans model.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
helps to create WifiNetDevice objects
Definition: wifi-helper.h:231
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
tuple cmd
Definition: second.py:35
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:530
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:712
a polymophic address class
Definition: address.h:90
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:706
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
manage and create wifi channel objects for the yans model.
create MAC layers for a ns3::WifiNetDevice.
virtual void SetType(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue())
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
AttributeValue implementation for Address.
Definition: address.h:278
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:495
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:209
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
void Add(Vector v)
Add a position to the list of positions.
void ReceivePacket(Ptr< Socket > socket)
void Parse(int argc, char *argv[])
Parse the program arguments.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
tuple wifi
Definition: third.py:89
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPropagationDelay(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
Include Radiotap link layer information.
Definition: wifi-helper.h:117
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.