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
37using namespace ns3;
38
40{
41 NS_LOG_UNCOND ("Received one packet!");
42}
43
44int 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
78 wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11_RADIO);
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
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
146 Simulator::Destroy ();
147 return 0;
148#else
149 NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in");
150#endif
151}
a polymophic address class
Definition: address.h:91
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:229
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
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:41
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:43
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:41
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
helps to create WifiNetDevice objects
Definition: wifi-helper.h:323
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:574
void Set(std::string name, const AttributeValue &v)
Definition: wifi-helper.cc:141
manage and create wifi channel objects for the YANS model.
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())
Ptr< YansWifiChannel > Create(void) const
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())
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:849
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
@ WIFI_STANDARD_80211b
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:35
wifi
Definition: third.py:99
mobility
Definition: third.py:107
void ReceivePacket(Ptr< Socket > socket)