13#include "ns3/lr-wpan-csmaca.h"
14#include "ns3/lr-wpan-error-model.h"
15#include "ns3/lr-wpan-net-device.h"
16#include "ns3/mobility-model.h"
17#include "ns3/multi-model-spectrum-channel.h"
19#include "ns3/single-model-spectrum-channel.h"
89 return std::string(
"BUSY");
91 return std::string(
"BUSY_RX");
93 return std::string(
"BUSY_TX");
95 return std::string(
"FORCE_TRX_OFF");
97 return std::string(
"IDLE");
99 return std::string(
"INVALID_PARAMETER");
101 return std::string(
"RX_ON");
103 return std::string(
"SUCCESS");
105 return std::string(
"TRX_OFF");
107 return std::string(
"TX_ON");
109 return std::string(
"UNSUPPORTED_ATTRIBUTE");
111 return std::string(
"READ_ONLY");
113 return std::string(
"UNSPECIFIED");
115 return std::string(
"INVALID");
125 return std::string(
"MAC_IDLE");
127 return std::string(
"CHANNEL_ACCESS_FAILURE");
129 return std::string(
"CHANNEL_IDLE");
131 return std::string(
"SET_PHY_TX_ON");
133 return std::string(
"INVALID");
171 m_channel->SetPropagationDelayModel(delay);
175 if (!
m_channel->GetPropagationDelayModel())
177 NS_FATAL_ERROR(
"No propagation delay model added to the channel");
179 if (!
m_channel->GetPropagationLossModel())
186 for (
auto i = c.
Begin(); i != c.
End(); i++)
192 node->AddDevice(netDevice);
193 netDevice->SetNode(node);
196 devices.Add(netDevice);
223 int64_t currentStream = stream;
225 for (
auto i = c.
Begin(); i != c.
End(); ++i)
231 currentStream +=
lrwpan->AssignStreams(currentStream);
234 return (currentStream - stream);
242 uint8_t idBuf[2] = {0, 0};
243 uint8_t idBuf2[8] = {0, 0, 0, 0, 0, 0, 0, 0};
249 for (
auto i = c.
Begin(); i != c.
End(); i++)
251 if (id < 0x0001 || id > 0xFFFD)
253 NS_ABORT_MSG(
"Only 65533 addresses supported. Range [00:01]-[FF:FD]");
259 idBuf[0] = (
id >> 8) & 0xff;
260 idBuf[1] = (
id >> 0) & 0xff;
263 idBuf2[6] = (
id >> 8) & 0xff;
264 idBuf2[7] = (
id >> 0) & 0xff;
267 if (address64 ==
Mac64Address(
"00:00:00:00:00:00:00:01"))
270 coordShortAddr = address16;
271 coordExtAddr = address64;
276 device->GetMac()->SetExtendedAddress(address64);
277 device->SetPanAssociation(panId, coordExtAddr, coordShortAddr, address16);
289 uint8_t idBuf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
292 for (
auto i = c.
Begin(); i != c.
End(); i++)
297 idBuf[0] = (
id >> 56) & 0xff;
298 idBuf[1] = (
id >> 48) & 0xff;
299 idBuf[2] = (
id >> 40) & 0xff;
300 idBuf[3] = (
id >> 32) & 0xff;
301 idBuf[4] = (
id >> 24) & 0xff;
302 idBuf[5] = (
id >> 16) & 0xff;
303 idBuf[6] = (
id >> 8) & 0xff;
304 idBuf[7] = (
id >> 0) & 0xff;
310 device->GetMac()->SetExtendedAddress(address64);
332 bool explicitFilename)
334 NS_LOG_FUNCTION(
this << prefix << nd << promiscuous << explicitFilename);
348 NS_LOG_INFO(
"LrWpanHelper::EnablePcapInternal(): Device "
349 << device <<
" not of type ns3::lrwpan::LrWpanNetDevice");
355 std::string filename;
356 if (explicitFilename)
370 device->GetMac()->TraceConnectWithoutContext(
"PromiscSniffer",
375 device->GetMac()->TraceConnectWithoutContext(
"Sniffer",
384 bool explicitFilename)
386 uint32_t nodeid = nd->GetNode()->GetId();
387 uint32_t deviceid = nd->GetIfIndex();
388 std::ostringstream oss;
393 NS_LOG_INFO(
"LrWpanHelper::EnableAsciiInternal(): Device "
394 << device <<
" not of type ns3::LrWpanNetDevice");
419 std::string filename;
420 if (explicitFilename)
439 device->GetMac()->TraceConnectWithoutContext(
470 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
471 <<
"/$ns3::lrwpan::LrWpanNetDevice/Mac/MacRx";
472 device->GetMac()->TraceConnect(
478 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
479 <<
"/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTx";
480 device->GetMac()->TraceConnect(
486 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
487 <<
"/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTxEnqueue";
488 device->GetMac()->TraceConnect(
494 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
495 <<
"/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTxDequeue";
496 device->GetMac()->TraceConnect(
502 oss <<
"/NodeList/" << nodeid <<
"/DeviceList/" << deviceid
503 <<
"/$ns3::lrwpan::LrWpanNetDevice/Mac/MacTxDrop";
504 device->GetMac()->TraceConnect(
Manage ASCII trace files for device models.
void HookDefaultDropSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default drop operation trace sink that does not accept nor log a trace con...
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...
static void DefaultDropSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Drop default trace sink.
static void DefaultReceiveSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Receive default trace sink.
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 HookDefaultEnqueueSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default enqueue operation trace sink that does not accept nor log a trace ...
void HookDefaultReceiveSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default receive operation trace sink that does not accept nor log a trace ...
static void DefaultEnqueueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Enqueue default trace sink.
void HookDefaultDequeueSinkWithoutContext(Ptr< T > object, std::string traceName, Ptr< OutputStreamWrapper > stream)
Hook a trace source to the default dequeue operation trace sink that does not accept nor log a trace ...
static void DefaultDequeueSinkWithContext(Ptr< OutputStreamWrapper > file, std::string context, Ptr< const Packet > p)
Basic Dequeue default trace sink.
Ptr< SpectrumChannel > GetChannel()
Get the channel associated to this helper.
Ptr< SpectrumChannel > m_channel
channel to be used for the devices
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel associated to this helper.
void AddMobility(Ptr< lrwpan::LrWpanPhy > phy, Ptr< MobilityModel > m)
Add mobility model to a physical device.
void EnablePcapInternal(std::string prefix, Ptr< NetDevice > nd, bool promiscuous, bool explicitFilename) override
Enable pcap output on the indicated net device.
void CreateAssociatedPan(NetDeviceContainer c, uint16_t panId)
Creates an PAN with associated nodes and assigned addresses(16 and 64) from the nodes in the node con...
std::vector< ObjectFactory > m_propagationLoss
vector of propagation loss models
bool m_useMultiModelSpectrumChannel
indicates whether a MultiModelSpectrumChannel is used
void SetExtendedAddresses(NetDeviceContainer c)
Set the extended 64 bit addresses (EUI-64) for a group of LrWpanNetDevices.
void EnableLogComponents()
Helper to enable all LrWpan log components with one statement.
static std::string LrWpanMacStatePrinter(lrwpan::MacState e)
Transform the LrWpanMacState enumeration into a printable string.
NetDeviceContainer Install(NodeContainer c)
Install a LrWpanNetDevice and the associated structures (e.g., channel) in the nodes.
void EnableAsciiInternal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< NetDevice > nd, bool explicitFilename) override
Enable ascii trace output on the indicated net device.
static std::string LrWpanPhyEnumerationPrinter(lrwpan::PhyEnumeration e)
Transform the LrWpanPhyEnumeration enumeration into a printable string.
LrWpanHelper()
Create a LrWpan helper in an empty state.
ObjectFactory m_propagationDelay
propagation delay model
void SetPropagationDelayModel(std::string name, Ts &&... args)
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void AddPropagationLossModel(std::string name, Ts &&... args)
This class can contain 16 bit addresses.
void CopyFrom(const uint8_t buffer[2])
void CopyFrom(const uint8_t buffer[8])
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
holds a vector of ns3::NetDevice pointers
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
static void EnablePrinting()
Enable printing packets metadata.
Manage pcap files for device models.
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.
Ptr< PcapFileWrapper > CreateFile(std::string filename, std::ios::openmode filemode, DataLinkType dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=0)
Create and initialize a pcap file.
calculate a propagation delay.
Models the propagation loss through a transmission medium.
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Class that implements the LR-WPAN MAC state machine.
Network layer to device interface.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
PhyEnumeration
IEEE802.15.4-2006 PHY Emumerations Table 18 in section 6.2.3.
@ CHANNEL_ACCESS_FAILURE
CHANNEL_ACCESS_FAILURE.
@ CHANNEL_IDLE
CHANNEL_IDLE.
@ SET_PHY_TX_ON
SET_PHY_TX_ON.
@ IEEE_802_15_4_PHY_READ_ONLY
@ IEEE_802_15_4_PHY_BUSY_TX
@ IEEE_802_15_4_PHY_RX_ON
@ IEEE_802_15_4_PHY_TRX_OFF
@ IEEE_802_15_4_PHY_TX_ON
@ IEEE_802_15_4_PHY_INVALID_PARAMETER
@ IEEE_802_15_4_PHY_UNSUPPORTED_ATTRIBUTE
@ IEEE_802_15_4_PHY_SUCCESS
@ IEEE_802_15_4_PHY_FORCE_TRX_OFF
@ IEEE_802_15_4_PHY_BUSY_RX
@ IEEE_802_15_4_PHY_UNSPECIFIED
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
static void AsciiLrWpanMacTransmitSinkWithContext(Ptr< OutputStreamWrapper > stream, std::string context, Ptr< const Packet > p)
Output an ascii line representing the Transmit event (with context)
static void AsciiLrWpanMacTransmitSinkWithoutContext(Ptr< OutputStreamWrapper > stream, Ptr< const Packet > p)
Output an ascii line representing the Transmit event (without context)
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
static void PcapSniffLrWpan(Ptr< PcapFileWrapper > file, Ptr< const Packet > packet)
Write a packet in a PCAP file.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.