28 #include <ns3/abort.h>
29 #include <ns3/boolean.h>
32 #include <ns3/packet.h>
33 #include <ns3/pointer.h>
34 #include <ns3/spectrum-channel.h>
47 TypeId(
"ns3::LrWpanNetDevice")
49 .SetGroupName(
"LrWpan")
51 .AddAttribute(
"Channel",
52 "The channel attached to this device",
55 MakePointerChecker<SpectrumChannel>())
57 "The PHY layer attached to this device.",
60 MakePointerChecker<LrWpanPhy>())
62 "The MAC layer attached to this device.",
65 MakePointerChecker<LrWpanMac>())
66 .AddAttribute(
"UseAcks",
67 "Request acknowledgments for data frames.",
72 "PseudoMacAddressMode",
73 "Build the pseudo-MAC Address according to RFC 4944 or RFC 6282 "
74 "(default: RFC 6282).",
78 "RFC 6282 (don't use PanId)",
80 "RFC 4944 (use PanId)"));
85 : m_configComplete(false)
88 m_mac = CreateObject<LrWpanMac>();
89 m_phy = CreateObject<LrWpanPhy>();
90 m_csmaca = CreateObject<LrWpanCsmaCa>();
137 m_phy->SetErrorModel(model);
138 m_phy->SetDevice(
this);
143 m_phy->SetPlmeGetAttributeConfirmCallback(
145 m_phy->SetPlmeSetTRXStateConfirmCallback(
147 m_phy->SetPlmeSetAttributeConfirmCallback(
227 return m_phy->GetChannel();
250 return m_phy->GetChannel();
272 m_mac->SetShortAddress(addr16);
277 m_mac->SetPanId(panId);
281 NS_ABORT_MSG(
"LrWpanNetDevice::SetAddress - address is not of a compatible type");
292 return m_mac->GetExtendedAddress();
297 return pseudoAddress;
307 m_mac->SetPanId(panId);
308 m_mac->SetAssociatedCoor(coordExtAddr);
309 m_mac->SetAssociatedCoor(coordShortAddr);
310 m_mac->SetShortAddress(assignedShortAddr);
360 return pseudoAddress;
385 return pseudoAddress;
414 NS_LOG_ERROR(
"Fragmentation is needed for this packet, drop the packet ");
431 m_mcpsDataRequestParams.
m_dstAddr = dst16;
442 m_mac->McpsDataRequest(m_mcpsDataRequestParams, packet);
450 uint16_t protocolNumber)
495 NS_LOG_WARN(
"Unsupported; use LrWpan MAC APIs instead");
533 buf[1] = panId & 0xff;
543 shortAddr.
CopyTo(buf + 4);
548 return pseudoAddress;
555 int64_t streamIndex = stream;
556 streamIndex +=
m_csmaca->AssignStreams(stream);
557 streamIndex +=
m_phy->AssignStreams(stream);
558 NS_LOG_DEBUG(
"Number of assigned RV streams: " << (streamIndex - stream));
559 return (streamIndex - stream);
a polymophic address class
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
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 PlmeGetAttributeConfirm(LrWpanPhyEnumeration status, LrWpanPibAttributeIdentifier id, Ptr< 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 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 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.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
static TypeId GetTypeId()
Get the type ID.
PseudoMacAddressMode_e m_pseudoMacMode
How the pseudo MAC address is created.
@ RFC4944
YYYY:0000:XXXX (with U/L bit set to local)
Ptr< LrWpanMac > m_mac
The MAC for this NetDevice.
Address GetAddress() const override
This method indirects to LrWpanMac::SetShortAddress ()
Ptr< Node > GetNode() const override
bool m_useAcks
Configure the NetDevice to request MAC layer acknowledgments when sending packets using the Send() AP...
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaca)
Set the CSMA/CA implementation to be used by the MAC and this NetDevice.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
Ptr< SpectrumChannel > DoGetChannel() const
Attribute accessor method for the "Channel" attribute.
Ptr< LrWpanMac > GetMac() const
Get the MAC used by this NetDevice.
bool SupportsSendFrom() const override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
void AddLinkChangeCallback(Callback< void > callback) override
void SetNode(Ptr< Node > node) override
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.
bool IsBroadcast() const override
bool SetMtu(const uint16_t mtu) override
uint16_t GetMtu() const override
bool IsMulticast() const override
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.
bool m_linkUp
Is the link/device currently up and running?
Ptr< LrWpanPhy > GetPhy() const
Get the PHY used by this NetDevice.
uint32_t GetIfIndex() const override
bool IsLinkUp() const override
Ptr< LrWpanPhy > m_phy
The PHY for this NetDevice.
void SetAddress(Address address) override
This method indirects to LrWpanMac::SetShortAddress ()
void SetPanAssociation(uint16_t panId, Mac64Address coordExtAddr, Mac16Address coordShortAddr, Mac16Address assignedShortAddr)
This method is use to manually configure the coordinator through which the device or coordinator is a...
Ptr< LrWpanCsmaCa > GetCsmaCa() const
Get the CSMA/CA implementation used by this NetDevice.
Address GetBroadcast() const override
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to be used by this NetDevice.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
void SetIfIndex(const uint32_t index) override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool m_configComplete
True if MAC, PHY and CSMA/CA where successfully configured and the NetDevice is ready for being used.
bool NeedsArp() const override
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
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...
~LrWpanNetDevice() override
Ptr< LrWpanCsmaCa > m_csmaca
The CSMA/CA implementation for this NetDevice.
TracedCallback m_linkChanges
Trace source for link up/down changes.
void CompleteConfig()
Configure PHY, MAC and CSMA/CA.
void DoDispose() override
Destructor implementation.
void LinkUp()
Mark NetDevice link as up.
Ptr< Channel > GetChannel() const override
void DoInitialize() override
Initialize() implementation.
void LinkDown()
Mark NetDevice link as down.
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()
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
static bool IsMatchingType(const Address &address)
static Mac64Address ConvertFrom(const Address &address)
Network layer to device interface.
virtual void DoInitialize()
Initialize() implementation.
virtual void DoDispose()
Destructor implementation.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Hold objects of type Ptr<T>.
Smart pointer class similar to boost::intrusive_ptr.
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.
#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 > MakeBooleanChecker()
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
MCPS-DATA.indication params.
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)