21 #include "ns3/trace-helper.h"
22 #include "yans-wifi-helper.h"
23 #include "ns3/error-rate-model.h"
24 #include "ns3/propagation-loss-model.h"
25 #include "ns3/propagation-delay-model.h"
26 #include "ns3/yans-wifi-channel.h"
27 #include "ns3/yans-wifi-phy.h"
28 #include "ns3/wifi-net-device.h"
29 #include "ns3/radiotap-header.h"
30 #include "ns3/pcap-file-wrapper.h"
31 #include "ns3/simulator.h"
32 #include "ns3/config.h"
33 #include "ns3/names.h"
34 #include "ns3/abort.h"
42 AsciiPhyTransmitSinkWithContext (
43 Ptr<OutputStreamWrapper> stream,
50 NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
55 AsciiPhyTransmitSinkWithoutContext (
56 Ptr<OutputStreamWrapper> stream,
67 AsciiPhyReceiveSinkWithContext (
68 Ptr<OutputStreamWrapper> stream,
80 AsciiPhyReceiveSinkWithoutContext (
81 Ptr<OutputStreamWrapper> stream,
117 factory.
Set (n0, v0);
118 factory.
Set (n1, v1);
119 factory.
Set (n2, v2);
120 factory.
Set (n3, v3);
121 factory.
Set (n4, v4);
122 factory.
Set (n5, v5);
123 factory.
Set (n6, v6);
124 factory.
Set (n7, v7);
125 m_propagationLoss.push_back (factory);
141 factory.
Set (n0, v0);
142 factory.
Set (n1, v1);
143 factory.
Set (n2, v2);
144 factory.
Set (n3, v3);
145 factory.
Set (n4, v4);
146 factory.
Set (n5, v5);
147 factory.
Set (n6, v6);
148 factory.
Set (n7, v7);
149 m_propagationDelay = factory;
157 for (std::vector<ObjectFactory>::const_iterator i = m_propagationLoss.begin (); i != m_propagationLoss.end (); ++i)
164 if (m_propagationLoss.begin () == i)
166 channel->SetPropagationLossModel (cur);
171 channel->SetPropagationDelayModel (delay);
178 return c->AssignStreams (stream);
226 m_errorRateModel.
Set (n0, v0);
227 m_errorRateModel.
Set (n1, v1);
228 m_errorRateModel.
Set (n2, v2);
229 m_errorRateModel.
Set (n3, v3);
230 m_errorRateModel.
Set (n4, v4);
231 m_errorRateModel.
Set (n5, v5);
232 m_errorRateModel.
Set (n6, v6);
233 m_errorRateModel.
Set (n7, v7);
241 phy->SetErrorRateModel (error);
242 phy->SetChannel (m_channel);
243 phy->SetMobility (node);
244 phy->SetDevice (device);
252 uint16_t channelFreqMhz,
253 uint16_t channelNumber,
255 bool isShortPreamble)
257 uint32_t dlt = file->GetDataLinkType ();
261 case PcapHelper::DLT_IEEE802_11:
264 case PcapHelper::DLT_PRISM_HEADER:
266 NS_FATAL_ERROR (
"PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
269 case PcapHelper::DLT_IEEE802_11_RADIO:
271 Ptr<Packet> p = packet->
Copy ();
272 RadiotapHeader header;
284 header.SetFrameFlags (frameFlags);
285 header.SetRate (rate);
287 uint16_t channelFlags = 0;
302 if (channelFreqMhz < 2500)
311 header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
313 p->AddHeader (header);
318 NS_ABORT_MSG (
"PcapSniffTxEvent(): Unexpected data link type " << dlt);
324 Ptr<PcapFileWrapper> file,
325 Ptr<const Packet> packet,
326 uint16_t channelFreqMhz,
327 uint16_t channelNumber,
329 bool isShortPreamble,
333 uint32_t dlt = file->GetDataLinkType ();
337 case PcapHelper::DLT_IEEE802_11:
340 case PcapHelper::DLT_PRISM_HEADER:
342 NS_FATAL_ERROR (
"PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
345 case PcapHelper::DLT_IEEE802_11_RADIO:
347 Ptr<Packet> p = packet->Copy ();
348 RadiotapHeader header;
360 header.SetFrameFlags (frameFlags);
361 header.SetRate (rate);
363 uint16_t channelFlags = 0;
378 if (channelFreqMhz < 2500)
387 header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
389 header.SetAntennaSignalPower (signalDbm);
390 header.SetAntennaNoisePower (noiseDbm);
392 p->AddHeader (header);
397 NS_ABORT_MSG (
"PcapSniffRxEvent(): Unexpected data link type " << dlt);
407 m_pcapDlt = PcapHelper::DLT_IEEE802_11;
410 m_pcapDlt = PcapHelper::DLT_PRISM_HEADER;
413 m_pcapDlt = PcapHelper::DLT_IEEE802_11_RADIO;
416 NS_ABORT_MSG (
"YansWifiPhyHelper::SetPcapFormat(): Unexpected format");
431 NS_LOG_INFO (
"YansWifiHelper::EnablePcapInternal(): Device " << &device <<
" not of type ns3::WifiNetDevice");
436 NS_ABORT_MSG_IF (phy == 0,
"YansWifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
440 std::string filename;
441 if (explicitFilename)
461 bool explicitFilename)
471 NS_LOG_INFO (
"YansWifiHelper::EnableAsciiInternal(): Device " << device <<
" not of type ns3::WifiNetDevice");
481 uint32_t nodeid = nd->GetNode ()->GetId ();
482 uint32_t deviceid = nd->GetIfIndex ();
483 std::ostringstream oss;
500 std::string filename;
501 if (explicitFilename)
518 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid <<
"/$ns3::WifiNetDevice/Phy/State/RxOk";
522 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid <<
"/$ns3::WifiNetDevice/Phy/State/Tx";
536 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid <<
"/$ns3::WifiNetDevice/Phy/State/RxOk";
537 Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyReceiveSinkWithContext, stream));
540 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid <<
"/$ns3::WifiNetDevice/Phy/State/Tx";
541 Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTransmitSinkWithContext, stream));
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())
Manage ASCII trace files for device models.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
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())
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, uint32_t dataLinkType, uint32_t snapLen=65535, int32_t tzCorrection=0)
Create and initialize a pcap file.
void SetNext(Ptr< PropagationLossModel > next)
Enables a chain of loss models to act on the signal.
Ptr< YansWifiChannel > Create(void) const
Make it easy to create and manage PHY objects for the yans model.
static YansWifiChannelHelper Default(void)
Hold a value for an Attribute.
Manage pcap files for device models.
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
#define NS_LOG_COMPONENT_DEFINE(name)
void SetPcapDataLinkType(enum SupportedPcapDataLinkTypes dlt)
void SetTypeId(TypeId tid)
virtual void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename)
Enable ascii trace output on the indicated net device.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits. ...
void Set(std::string name, const AttributeValue &v)
static YansWifiPhyHelper Default(void)
void Connect(std::string path, const CallbackBase &cb)
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the ascii trace helper figure out a reasonable filename to use for an ascii trace file associated...
#define NS_FATAL_ERROR(msg)
fatal error handling
the interface for Wifi's error models
void SetChannel(Ptr< YansWifiChannel > channel)
double GetSeconds(void) const
std::string GetFilenameFromDevice(std::string prefix, Ptr< NetDevice > device, bool useObjectNames=true)
Let the pcap helper figure out a reasonable filename to use for a pcap file associated with a device...
static void EnablePrinting(void)
Ptr< Object > Create(void) const
calculate a propagation delay.
Hold together all Wifi-related objects.This class holds together ns3::WifiChannel, ns3::WifiPhy, ns3::WifiMac, and, ns3::WifiRemoteStationManager.
Ptr< Packet > Copy(void) const
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
802.11 PHY layer modelThis PHY implements a model of 802.11a. The model implemented here is based on ...
virtual Ptr< WifiPhy > Create(Ptr< Node > node, Ptr< WifiNetDevice > device) const
virtual void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename)
Enable pcap output the indicated net device.
void Set(std::string name, const AttributeValue &value)
manage and create wifi channel objects for the yans model.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
instantiate subclasses of ns3::Object.
Modelize the propagation loss through a transmission medium.
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())
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if cond is true.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
SupportedPcapDataLinkTypes
int64_t AssignStreams(Ptr< YansWifiChannel > c, int64_t stream)