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 }
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())
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:73
hold variables of type string
Definition: string.h:19
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. ...
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())
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
Set the data link type of PCAP traces to be used.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
Create a phy helper in a default working state.
int main(int argc, char *argv[])
helps to create WifiNetDevice objects
Definition: wifi-helper.h:88
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
a 3d vector
Definition: vector.h:31
Include Radiotap link layer information.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
virtual NetDeviceContainer Install(const WifiPhyHelper &phy, const WifiMacHelper &mac, NodeContainer c) const
Definition: wifi-helper.cc:102
a polymophic address class
Definition: address.h:86
void SetChannel(Ptr< YansWifiChannel > channel)
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
holds a vector of ns3::NetDevice pointers
virtual void SetStandard(enum WifiPhyStandard standard)
Definition: wifi-helper.cc:96
static NqosWifiMacHelper Default(void)
Create a mac helper in a default working state.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
create non QoS-enabled MAC layers for a ns3::WifiNetDevice.
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
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)
Definition: log.h:377
manage and create wifi channel objects for the yans model.
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:38
hold objects of type ns3::Address
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...
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void ReceivePacket(Ptr< Socket > socket)
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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...
Hold a floating point type.
Definition: double.h:41
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.