A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
49  // Setup nodes
50  NodeContainer wifiNodes;
51  wifiNodes.Create (2);
52 
53  // Get Wifi devices installed on both nodes.
54  // Adapted from examples/wireless/wifi-simple-adhoc.cc
55  std::string phyMode ("DsssRate1Mbps");
56 
57  // disable fragmentation for frames below 2200 bytes
58  Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold", StringValue ("2200"));
59  // turn off RTS/CTS for frames below 2200 bytes
60  Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", StringValue ("2200"));
61  // Fix non-unicast data rate to be the same as that of unicast
62  Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
63  StringValue (phyMode));
64 
65  WifiHelper wifi;
67 
69  // This is one parameter that matters when using FixedRssLossModel
70  // set it to zero; otherwise, gain will be added
71  wifiPhy.Set ("RxGain", DoubleValue (0) );
72  // ns-3 supports RadioTap and Prism tracing extensions for 802.11b
74 
75  YansWifiChannelHelper wifiChannel;
76  wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
77  // The below FixedRssLossModel will cause the rss to be fixed regardless
78  // of the distance between the two stations, and the transmit power
79  wifiChannel.AddPropagationLoss ("ns3::FixedRssLossModel","Rss",DoubleValue (rss));
80  wifiPhy.SetChannel (wifiChannel.Create ());
81 
82  // Add a non-QoS upper mac, and disable rate control
84  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
85  "DataMode",StringValue (phyMode),
86  "ControlMode",StringValue (phyMode));
87  // Set it to adhoc mode
88  wifiMac.SetType ("ns3::AdhocWifiMac");
89  NetDeviceContainer wifiDevices = wifi.Install (wifiPhy, wifiMac, wifiNodes);
90 
91  // Setup mobility models
92  MobilityHelper mobility;
93  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
94  positionAlloc->Add (Vector (0.0, 0.0, 0.0));
95  positionAlloc->Add (Vector (5.0, 0.0, 0.0));
96  mobility.SetPositionAllocator (positionAlloc);
97  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
98  mobility.Install (wifiNodes);
99 
100  // Install normal internet stack on node B
101  InternetStackHelper internet;
102  internet.Install (wifiNodes.Get (1));
103 
104  // Install Click on node A
105  ClickInternetStackHelper clickinternet;
106  clickinternet.SetClickFile (wifiNodes.Get (0), "src/click/examples/nsclick-wifi-single-interface.click");
107  clickinternet.SetRoutingTableElement (wifiNodes.Get (0), "rt");
108  clickinternet.Install (wifiNodes.Get (0));
109 
110  // Configure IP addresses
111  Ipv4AddressHelper ipv4;
112  ipv4.SetBase ("172.16.1.0", "255.255.255.0");
113  ipv4.Assign (wifiDevices);
114 
115  // Setup traffic application and sockets
116  Address LocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 50000));
117  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", LocalAddress);
118  ApplicationContainer recvapp = packetSinkHelper.Install (wifiNodes.Get (1));
119  recvapp.Start (Seconds (5.0));
120  recvapp.Stop (Seconds (10.0));
121 
122  OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
123  onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
124  onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
125 
126  ApplicationContainer appcont;
127 
128  AddressValue remoteAddress (InetSocketAddress (Ipv4Address ("172.16.1.2"), 50000));
129  onOffHelper.SetAttribute ("Remote", remoteAddress);
130  appcont.Add (onOffHelper.Install (wifiNodes.Get (0)));
131 
132  appcont.Start (Seconds (5.0));
133  appcont.Stop (Seconds (10.0));
134 
135  // For tracing
136  wifiPhy.EnablePcap ("nsclick-raw-wlan", wifiDevices);
137 
138  Simulator::Stop (Seconds (20.0));
139  Simulator::Run ();
140 
142  return 0;
143 #else
144  NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in");
145 #endif
146 }