27 #include <ns3/abort.h>
30 #include <ns3/spectrum-channel.h>
31 #include <ns3/pointer.h>
32 #include <ns3/boolean.h>
33 #include <ns3/mobility-model.h>
34 #include <ns3/packet.h>
48 .SetGroupName (
"LrWpan")
50 .AddAttribute (
"Channel",
"The channel attached to this device",
53 MakePointerChecker<SpectrumChannel> ())
54 .AddAttribute (
"Phy",
"The PHY layer attached to this device.",
58 MakePointerChecker<LrWpanPhy> ())
59 .AddAttribute (
"Mac",
"The MAC layer attached to this device.",
63 MakePointerChecker<LrWpanMac> ())
64 .AddAttribute (
"UseAcks",
"Request acknowledgments for data frames.",
68 .AddAttribute (
"PseudoMacAddressMode",
"Build the pseudo-MAC Address according to RFC 4944 or RFC 6282 (default: RFC 6282).",
78 : m_configComplete (false)
81 m_mac = CreateObject<LrWpanMac> ();
82 m_phy = CreateObject<LrWpanPhy> ();
83 m_csmaca = CreateObject<LrWpanCsmaCa> ();
113 m_phy->Initialize ();
114 m_mac->Initialize ();
139 NS_LOG_WARN (
"LrWpanNetDevice: no Mobility found on the node, probably it's not a good idea.");
143 m_phy->SetErrorModel (model);
144 m_phy->SetDevice (
this);
229 return m_phy->GetChannel ();
252 return m_phy->GetChannel ();
270 m_mac->SetShortAddress (addr16);
275 m_mac->SetPanId (panId);
279 NS_ABORT_MSG (
"LrWpanNetDevice::SetAddress - address is not of a compatible type");
290 return m_mac->GetExtendedAddress ();
295 return pseudoAddress;
344 return pseudoAddress;
368 return pseudoAddress;
397 NS_LOG_ERROR (
"Fragmentation is needed for this packet, drop the packet ");
414 m_mcpsDataRequestParams.
m_dstAddr = dst16;
425 m_mac->McpsDataRequest (m_mcpsDataRequestParams, packet);
474 NS_LOG_WARN (
"Unsupported; use LrWpan MAC APIs instead");
512 buf[1] = panId & 0xff;
527 return pseudoAddress;
534 int64_t streamIndex = stream;
535 streamIndex +=
m_csmaca->AssignStreams (stream);
536 streamIndex +=
m_phy->AssignStreams (stream);
537 NS_LOG_DEBUG (
"Number of assigned RV streams: " << (streamIndex - stream));
538 return (streamIndex - stream);
a polymophic address class
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
AttributeValue implementation for Boolean.
Hold variables of type enum.
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
void PlmeCcaConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.2 PLME-CCA.confirm status.
void PlmeSetTRXStateConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.2.8 PLME-SET-TRX-STATE.confirm Set PHY state.
void PlmeEdConfirm(LrWpanPhyEnumeration status, uint8_t energyLevel)
IEEE 802.15.4-2006 section 6.2.2.4 PLME-ED.confirm status and energy level.
void SetLrWpanMacState(LrWpanMacState macState)
CSMA-CA algorithm calls back the MAC after executing channel assessment.
void PdDataIndication(uint32_t psduLength, Ptr< Packet > p, uint8_t lqi)
IEEE 802.15.4-2006 section 6.2.1.3 PD-DATA.indication Indicates the transfer of an MPDU from PHY to M...
void PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, LrWpanPhyPibAttributes *attribute)
IEEE 802.15.4-2006 section 6.2.2.6 PLME-GET.confirm Get attributes per definition from Table 23 in se...
void PlmeSetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id)
IEEE 802.15.4-2006 section 6.2.2.10 PLME-SET.confirm Set attributes per definition from Table 23 in s...
void PdDataConfirm(LrWpanPhyEnumeration status)
IEEE 802.15.4-2006 section 6.2.1.2 Confirm the end of transmission of an MPDU to MAC.
Network layer to device interface.
virtual void SetIfIndex(const uint32_t index)
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual void DoInitialize(void)
Initialize() implementation.
virtual bool IsBroadcast(void) const
virtual bool SetMtu(const uint16_t mtu)
virtual ~LrWpanNetDevice(void)
virtual bool NeedsArp(void) const
PseudoMacAddressMode_e m_pseudoMacMode
How the pseudo MAC address is created.
virtual bool IsLinkUp(void) const
virtual void DoDispose(void)
Destructor implementation.
@ RFC4944
YYYY:0000:XXXX (with U/L bit set to local)
virtual void SetNode(Ptr< Node > node)
Ptr< LrWpanMac > m_mac
The MAC for this NetDevice.
virtual Ptr< Channel > GetChannel(void) const
void CompleteConfig(void)
Configure PHY, MAC and CSMA/CA.
virtual void SetAddress(Address address)
This method indirects to LrWpanMac::SetShortAddress ()
bool m_useAcks
Configure the NetDevice to request MAC layer acknowledgments when sending packets using the Send() AP...
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual Ptr< Node > GetNode(void) const
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaca)
Set the CSMA/CA implementation to be used by the MAC and this NetDevice.
void LinkUp(void)
Mark NetDevice link as up.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
virtual void SetPromiscReceiveCallback(PromiscReceiveCallback cb)
Ptr< Node > m_node
The node associated with this NetDevice.
void SetPhy(Ptr< LrWpanPhy > phy)
Set the PHY to be used by the MAC and this NetDevice.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
void McpsDataIndication(McpsDataIndicationParams params, Ptr< Packet > pkt)
The callback used by the MAC to hand over incoming packets to the NetDevice.
ReceiveCallback m_receiveCallback
Upper layer callback used for notification of new data packet arrivals.
virtual bool IsMulticast(void) const
bool m_linkUp
Is the link/device currently up and running?
Ptr< LrWpanPhy > GetPhy(void) const
Get the PHY used by this NetDevice.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
Ptr< LrWpanPhy > m_phy
The PHY for this NetDevice.
Ptr< LrWpanMac > GetMac(void) const
Get the MAC used by this NetDevice.
virtual Address GetBroadcast(void) const
virtual uint32_t GetIfIndex(void) const
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to be used by this NetDevice.
virtual Address GetAddress(void) const
This method indirects to LrWpanMac::SetShortAddress ()
void LinkDown(void)
Mark NetDevice link as down.
virtual bool SupportsSendFrom(void) const
bool m_configComplete
True if MAC, PHY and CSMA/CA where successfully configured and the NetDevice is ready for being used.
Mac48Address BuildPseudoMacAddress(uint16_t panId, Mac16Address shortAddr) const
Builds a "pseudo 48-bit address" from the PanId and Short Address The form is PanId : 0x0 : 0x0 : Sho...
static TypeId GetTypeId(void)
Get the type ID.
Ptr< LrWpanCsmaCa > GetCsmaCa(void) const
Get the CSMA/CA implementation used by this NetDevice.
Ptr< SpectrumChannel > DoGetChannel(void) const
Attribute accessor method for the "Channel" attribute.
Ptr< LrWpanCsmaCa > m_csmaca
The CSMA/CA implementation for this NetDevice.
TracedCallback m_linkChanges
Trace source for link up/down changes.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual uint16_t GetMtu(void) const
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
uint32_t m_ifIndex
The interface index of this NetDevice.
This class can contain 16 bit addresses.
static Mac16Address GetMulticast(Ipv6Address address)
Returns the multicast address associated with an IPv6 address according to RFC 4944 Section 9.
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[2]) const
void CopyFrom(const uint8_t buffer[2])
static Mac16Address GetBroadcast(void)
static bool IsMatchingType(const Address &address)
void CopyFrom(const uint8_t buffer[6])
static Mac48Address ConvertFrom(const Address &address)
void CopyTo(uint8_t buffer[6]) const
Keep track of the current position and velocity of an object.
Network layer to device interface.
virtual void DoDispose(void)
Destructor implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
virtual void DoInitialize(void)
Initialize() implementation.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Hold objects of type Ptr<T>.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
@ TX_OPTION_ACK
TX_OPTION_ACK.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
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...
MCPS-DATA.indication params.
uint8_t m_dstAddrMode
Destination address mode.
uint16_t m_srcPanId
Source PAN identifier.
Mac64Address m_srcExtAddr
Source extended address.
Mac16Address m_srcAddr
Source address.
MCPS-DATA.request params.
LrWpanAddressMode m_srcAddrMode
Source address mode.
LrWpanAddressMode m_dstAddrMode
Destination address mode.
uint16_t m_dstPanId
Destination PAN identifier.
Mac16Address m_dstAddr
Destination address.
uint8_t m_msduHandle
MSDU handle.
uint8_t m_txOptions
Tx Options (bitfield)