|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
27 #include "ns3/command-line.h"
28 #include "ns3/config.h"
29 #include "ns3/string.h"
30 #include "ns3/yans-wifi-helper.h"
31 #include "ns3/spectrum-wifi-helper.h"
33 #include "ns3/mobility-helper.h"
34 #include "ns3/internet-stack-helper.h"
35 #include "ns3/ipv4-address-helper.h"
36 #include "ns3/udp-client-server-helper.h"
37 #include "ns3/packet-sink-helper.h"
38 #include "ns3/on-off-helper.h"
39 #include "ns3/packet-sink.h"
40 #include "ns3/yans-wifi-channel.h"
41 #include "ns3/multi-model-spectrum-channel.h"
42 #include "ns3/propagation-loss-model.h"
43 #include "ns3/waveform-generator.h"
44 #include "ns3/waveform-generator-helper.h"
45 #include "ns3/non-communicating-net-device.h"
46 #include "ns3/wifi-net-device.h"
107 uint16_t channelFreqMhz,
129 bandInfo.
fc = 5180e6;
130 bandInfo.
fl = 5180e6 - 10e6;
131 bandInfo.
fh = 5180e6 + 10e6;
134 bands.push_back (bandInfo);
147 bandInfo.
fc = 5190e6;
148 bandInfo.
fl = 5190e6 - 10e6;
149 bandInfo.
fh = 5190e6 + 10e6;
152 bands.push_back (bandInfo);
159 int main (
int argc,
char *argv[])
162 double distance = 50;
163 double simulationTime = 10;
164 uint16_t index = 256;
165 std::string wifiType =
"ns3::SpectrumWifiPhy";
166 std::string errorModelType =
"ns3::NistErrorRateModel";
168 const uint32_t tcpPacketSize = 1448;
169 double waveformPower = 0;
172 cmd.AddValue (
"simulationTime",
"Simulation time in seconds", simulationTime);
173 cmd.AddValue (
"udp",
"UDP if set to 1, TCP otherwise", udp);
174 cmd.AddValue (
"distance",
"meters separation between nodes", distance);
175 cmd.AddValue (
"index",
"restrict index to single value between 0 and 31", index);
176 cmd.AddValue (
"wifiType",
"select ns3::SpectrumWifiPhy or ns3::YansWifiPhy", wifiType);
177 cmd.AddValue (
"errorModelType",
"select ns3::NistErrorRateModel or ns3::YansErrorRateModel", errorModelType);
178 cmd.AddValue (
"enablePcap",
"enable pcap output",
enablePcap);
179 cmd.AddValue (
"waveformPower",
"Waveform power (linear W)", waveformPower);
180 cmd.Parse (argc,argv);
182 uint16_t startIndex = 0;
183 uint16_t stopIndex = 31;
190 std::cout <<
"wifiType: " << wifiType <<
" distance: " << distance <<
"m; time: " << simulationTime <<
"; TxPower: 16 dBm (40 mW)" << std::endl;
191 std::cout << std::setw (5) <<
"index" <<
192 std::setw (6) <<
"MCS" <<
193 std::setw (13) <<
"Rate (Mb/s)" <<
194 std::setw (12) <<
"Tput (Mb/s)" <<
195 std::setw (10) <<
"Received " <<
196 std::setw (12) <<
"Signal (dBm)" <<
197 std::setw (12) <<
"Noi+Inf(dBm)" <<
198 std::setw (9) <<
"SNR (dB)" <<
200 for (uint16_t i = startIndex; i <= stopIndex; i++)
202 uint32_t payloadSize;
218 interferingNode.
Create (1);
223 uint16_t frequency = (i <= 15 ? 5180 : 5190);
224 if (wifiType ==
"ns3::YansWifiPhy")
227 channel.AddPropagationLoss (
"ns3::FriisPropagationLossModel",
229 channel.SetPropagationDelay (
"ns3::ConstantSpeedPropagationDelayModel");
233 else if (wifiType ==
"ns3::SpectrumWifiPhy")
236 = CreateObject<MultiModelSpectrumChannel> ();
238 = CreateObject<FriisPropagationLossModel> ();
243 = CreateObject<ConstantSpeedPropagationDelayModel> ();
424 wifi.SetRemoteStationManager (
"ns3::ConstantRateWifiManager",
"DataMode",
DataRate,
430 if (wifiType ==
"ns3::YansWifiPhy")
432 mac.SetType (
"ns3::StaWifiMac",
434 staDevice =
wifi.Install (
phy,
mac, wifiStaNode);
435 mac.SetType (
"ns3::ApWifiMac",
440 else if (wifiType ==
"ns3::SpectrumWifiPhy")
442 mac.SetType (
"ns3::StaWifiMac",
444 staDevice =
wifi.Install (spectrumPhy,
mac, wifiStaNode);
445 mac.SetType (
"ns3::ApWifiMac",
452 Config::Set (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported",
BooleanValue (
false));
454 else if (i > 7 && i <= 15)
456 Config::Set (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported",
BooleanValue (
true));
458 else if (i > 15 && i <= 23)
460 Config::Set (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported",
BooleanValue (
false));
464 Config::Set (
"/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/HtConfiguration/ShortGuardIntervalSupported",
BooleanValue (
true));
471 positionAlloc->
Add (Vector (0.0, 0.0, 0.0));
472 positionAlloc->
Add (Vector (distance, 0.0, 0.0));
473 positionAlloc->
Add (Vector (distance, distance, 0.0));
474 mobility.SetPositionAllocator (positionAlloc);
476 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
485 stack.Install (wifiStaNode);
488 address.SetBase (
"192.168.1.0",
"255.255.255.0");
492 staNodeInterface =
address.Assign (staDevice);
493 apNodeInterface =
address.Assign (apDevice);
502 serverApp = server.Install (wifiStaNode.
Get (0));
507 client.SetAttribute (
"MaxPackets",
UintegerValue (4294967295u));
508 client.SetAttribute (
"Interval",
TimeValue (
Time (
"0.0001")));
509 client.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
517 uint16_t
port = 50000;
520 serverApp = packetSinkHelper.Install (wifiStaNode.
Get (0));
525 onoff.SetAttribute (
"OnTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=1]"));
526 onoff.SetAttribute (
"OffTime",
StringValue (
"ns3::ConstantRandomVariable[Constant=0]"));
527 onoff.SetAttribute (
"PacketSize",
UintegerValue (payloadSize));
530 onoff.SetAttribute (
"Remote", remoteAddress);
539 *wgPsd = waveformPower / 20e6;
542 if (wifiType ==
"ns3::SpectrumWifiPhy")
545 waveformGeneratorHelper.
SetChannel (spectrumChannel);
561 std::stringstream ss;
562 ss <<
"wifi-spectrum-per-example-" << i;
563 phy.EnablePcap (ss.str (), apDevice);
576 "Error: Channel width must be 20 MHz if MCS index <= 15");
578 "Error: Wi-Fi nodes must be tuned to 5180 MHz to match the waveform generator");
583 "Error: Channel width must be 40 MHz if MCS index > 15");
585 "Error: Wi-Fi nodes must be tuned to 5190 MHz to match the waveform generator");
591 double throughput = 0;
592 uint64_t totalPacketsThrough = 0;
596 totalPacketsThrough = DynamicCast<UdpServer> (serverApp.
Get (0))->GetReceived ();
597 throughput = totalPacketsThrough * payloadSize * 8 / (simulationTime * 1000000.0);
602 uint64_t totalBytesRx = DynamicCast<PacketSink> (serverApp.
Get (0))->GetTotalRx ();
603 totalPacketsThrough = totalBytesRx / tcpPacketSize;
604 throughput = totalBytesRx * 8 / (simulationTime * 1000000.0);
606 std::cout << std::setw (5) << i <<
607 std::setw (6) << (i % 8) <<
608 std::setprecision (2) << std::fixed <<
609 std::setw (10) << datarate <<
610 std::setw (12) << throughput <<
611 std::setw (8) << totalPacketsThrough;
612 if (totalPacketsThrough > 0)
621 std::cout << std::setw (12) <<
"N/A" <<
622 std::setw (12) <<
"N/A" <<
623 std::setw (12) <<
"N/A" <<
void SetPropagationDelayModel(Ptr< PropagationDelayModel > delay)
Set the propagation delay model to be used.
holds a vector of ns3::NetDevice pointers
@ WIFI_STANDARD_80211n_5GHZ
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
double noise
noise power in dBm
AttributeValue implementation for DataRate.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
double Integral(const SpectrumValue &arg)
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Make it easy to create and manage PHY objects for the YANS model.
Parse command-line arguments.
void Add(Vector v)
Add a position to the list of positions.
void Set(std::string path, const AttributeValue &value)
AttributeValue implementation for Boolean.
void AddPropagationLossModel(Ptr< PropagationLossModel > loss)
Add the single-frequency propagation loss model to be used.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
helps to create WifiNetDevice objects
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
AttributeValue implementation for Address.
uint16_t GetFrequency(void) const
@ DLT_IEEE802_11_RADIO
Include Radiotap link layer information.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
void SetErrorRateModel(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())
The building block of a SpectrumModel.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
AttributeValue implementation for Ssid.
SignalNoiseDbm structure.
The IEEE 802.11 SSID Information Element.
This class implements a device which does not communicate, in the sense that it does not interact wit...
Hold together all Wifi-related objects.
Create a server application which waits for input UDP packets and uses the information carried into t...
double fl
lower limit of subband
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Class for representing data rates.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Ptr< Object > GetPhy() const
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
a polymophic address class
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
void SetFrequency(double frequency)
static_SpectrumModelWifi5180MHz_initializer()
class static_SpectrumModelWifi5190MHz_initializer static_SpectrumModelWifi5190MHz_initializer_instance
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
void MonitorSniffRx(Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise, uint16_t staId)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
double fc
center frequency
static_SpectrumModelWifi5190MHz_initializer()
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static void Run(void)
Run the simulation.
Hold variables of type string.
double fh
upper limit of subband
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
U * GetPointer(const Ptr< U > &p)
static Ipv4Address GetAny(void)
std::vector< BandInfo > Bands
Container of BandInfo.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Time Seconds(double value)
Construct a Time in the indicated unit.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
holds a vector of ns3::Application pointers.
AttributeValue implementation for Time.
uint16_t GetChannelWidth(void) const
keep track of a set of node pointers.
Ptr< SpectrumModel > SpectrumModelWifi5180MHz
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
class static_SpectrumModelWifi5180MHz_initializer static_SpectrumModelWifi5180MHz_initializer_instance
Hold an unsigned integer type.
manage and create wifi channel objects for the YANS model.
create MAC layers for a ns3::WifiNetDevice.
void SetDefault(std::string name, const AttributeValue &value)
double signal
signal strength in dBm
void SetChannel(Ptr< SpectrumChannel > channel)
aggregate IP/TCP/UDP functionality to existing Nodes.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
void Set(std::string name, const AttributeValue &v)
Helper class used to assign positions and mobility models to nodes.
Ptr< SpectrumModel > SpectrumModelWifi5190MHz
Make it easy to create and manage PHY objects for the spectrum model.