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 
50  CommandLine cmd (__FILE__);
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 
71  wifi.SetStandard (WIFI_STANDARD_80211b);
72 
73  YansWifiPhyHelper wifiPhy;
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 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::InetSocketAddress
an Inet address class
Definition: inet-socket-address.h:41
ns3::YansWifiPhyHelper
Make it easy to create and manage PHY objects for the YANS model.
Definition: yans-wifi-helper.h:161
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::ListPositionAllocator::Add
void Add(Vector v)
Add a position to the list of positions.
Definition: position-allocator.cc:70
ns3::YansWifiChannelHelper::SetPropagationDelay
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())
Definition: yans-wifi-helper.cc:74
ns3::PcapHelperForDevice::EnablePcap
void EnablePcap(std::string prefix, Ptr< NetDevice > nd, bool promiscuous=false, bool explicitFilename=false)
Enable pcap output the indicated net device.
Definition: trace-helper.cc:401
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ApplicationContainer::Stop
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Definition: application-container.cc:107
ns3::WifiHelper
helps to create WifiNetDevice objects
Definition: wifi-helper.h:327
ns3::Ipv4AddressHelper
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Definition: ipv4-address-helper.h:48
ns3::AddressValue
AttributeValue implementation for Address.
Definition: address.h:278
ns3::YansWifiChannelHelper::AddPropagationLoss
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())
Definition: yans-wifi-helper.cc:50
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
ns3::WifiPhyHelper::DLT_IEEE802_11_RADIO
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
Definition: wifi-helper.h:180
ns3::YansWifiPhyHelper::SetChannel
void SetChannel(Ptr< YansWifiChannel > channel)
Definition: yans-wifi-helper.cc:134
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::ApplicationContainer::Add
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Definition: application-container.cc:67
ns3::Ipv4AddressHelper::SetBase
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Definition: ipv4-address-helper.cc:64
third.wifi
wifi
Definition: third.py:96
ns3::Ptr< Socket >
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::YansWifiChannelHelper::Create
Ptr< YansWifiChannel > Create(void) const
Definition: yans-wifi-helper.cc:98
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::Address
a polymophic address class
Definition: address.h:91
ns3::InternetStackHelper::Install
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Definition: internet-stack-helper.cc:366
ns3::OnOffHelper
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:43
ReceivePacket
void ReceivePacket(Ptr< Socket > socket)
Definition: nsclick-raw-wlan.cc:39
ns3::WIFI_STANDARD_80211b
@ WIFI_STANDARD_80211b
Definition: wifi-standards.h:128
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition: node-container.cc:93
second.cmd
cmd
Definition: second.py:35
NS_LOG_UNCOND
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Definition: log-macros-enabled.h:269
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::PacketSinkHelper
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Definition: packet-sink-helper.h:36
ns3::WifiPhyHelper::SetPcapDataLinkType
void SetPcapDataLinkType(SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
Definition: wifi-helper.cc:573
ns3::Ipv4Address::GetAny
static Ipv4Address GetAny(void)
Definition: ipv4-address.cc:395
ns3::ApplicationContainer::Start
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Definition: application-container.cc:87
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Ipv4AddressHelper::Assign
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Definition: ipv4-address-helper.cc:135
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::ApplicationContainer
holds a vector of ns3::Application pointers.
Definition: application-container.h:43
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::WifiMacHelper::SetType
void SetType(std::string type, Args &&... args)
Definition: wifi-mac-helper.h:130
ns3::YansWifiChannelHelper
manage and create wifi channel objects for the YANS model.
Definition: yans-wifi-helper.h:37
ns3::WifiMacHelper
create MAC layers for a ns3::WifiNetDevice.
Definition: wifi-mac-helper.h:48
ns3::Config::SetDefault
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
ns3::InternetStackHelper
aggregate IP/TCP/UDP functionality to existing Nodes.
Definition: internet-stack-helper.h:88
ns3::WifiPhyHelper::Set
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:140
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108