A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lr-wpan-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 The Boeing Company
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author:
7 * Tom Henderson <thomas.r.henderson@boeing.com>
8 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
9 * Margherita Filippetti <morag87@gmail.com>
10 */
11#ifndef LR_WPAN_NET_DEVICE_H
12#define LR_WPAN_NET_DEVICE_H
13
14#include "lr-wpan-mac.h"
15
16#include <ns3/net-device.h>
17#include <ns3/traced-callback.h>
18
19namespace ns3
20{
21
22class SpectrumChannel;
23class Node;
24
25namespace lrwpan
26{
27
28class LrWpanPhy;
29class LrWpanCsmaCa;
30
31/**
32 * \ingroup lr-wpan
33 *
34 * \brief Network layer to device interface.
35 *
36 * The ns3::NetDevice includes IP-specific API such as GetMulticast(), Send()
37 * and SendTo() methods, which do not map well the the 802.15.4 MAC MCPS
38 * DataRequest primitive. So, the basic design is to provide, as
39 * much as makes sense, the class ns3::NetDevice API, but rely on the user
40 * accessing the LrWpanMac pointer to make 802.15.4-specific API calls.
41 * As such, this is really just an encapsulating class.
42 */
44{
45 public:
46 /**
47 * Get the type ID.
48 *
49 * \return the object TypeId
50 */
51 static TypeId GetTypeId();
52
54 ~LrWpanNetDevice() override;
55
56 /**
57 * How the pseudo-MAC address is built from
58 * the short address (XXXX) and the PanId (YYYY).
59 *
60 * See \RFC{4944} and \RFC{6282}.
61 */
63 {
64 RFC4944, //!< YYYY:0000:XXXX (with U/L bit set to local)
65 RFC6282 //!< 0200:0000:XXXX
66 };
67
68 /**
69 * Set the MAC to be used by this NetDevice.
70 *
71 * \param mac the MAC to be used
72 */
73 void SetMac(Ptr<LrWpanMac> mac);
74
75 /**
76 * Set the PHY to be used by the MAC and this NetDevice.
77 *
78 * \param phy the PHY to be used
79 */
80 void SetPhy(Ptr<LrWpanPhy> phy);
81
82 /**
83 * Set the CSMA/CA implementation to be used by the MAC and this NetDevice.
84 *
85 * \param csmaca the CSMA/CA implementation to be used
86 */
87 void SetCsmaCa(Ptr<LrWpanCsmaCa> csmaca);
88
89 /**
90 * Set the channel to which the NetDevice, and therefore the PHY, should be
91 * attached to.
92 *
93 * \param channel the channel to be used
94 */
95 void SetChannel(Ptr<SpectrumChannel> channel);
96
97 /**
98 * Get the MAC used by this NetDevice.
99 *
100 * \return the MAC object
101 */
102 Ptr<LrWpanMac> GetMac() const;
103
104 /**
105 * Get the PHY used by this NetDevice.
106 *
107 * \return the PHY object
108 */
109 Ptr<LrWpanPhy> GetPhy() const;
110
111 /**
112 * Get the CSMA/CA implementation used by this NetDevice.
113 *
114 * \return the CSMA/CA implementation object
115 */
117
118 // From class NetDevice
119 void SetIfIndex(const uint32_t index) override;
120 uint32_t GetIfIndex() const override;
121 Ptr<Channel> GetChannel() const override;
122 /**
123 * This method indirects to LrWpanMac::SetShortAddress ()
124 * \param address The short address.
125 */
126 void SetAddress(Address address) override;
127 /**
128 * This method indirects to LrWpanMac::SetShortAddress ()
129 * \returns The short address.
130 */
131 Address GetAddress() const override;
132
133 /**
134 * This method is use to manually configure the coordinator through
135 * which the device or coordinator is associated. When assigning a short address
136 * the extended address must also be present.
137 *
138 * \param panId The id of the PAN used by the coordinator device.
139 *
140 * \param coordExtAddr The coordinator extended address (EUI-64) through which this
141 * device or coordinator is associated.
142 *
143 * \param coordShortAddr The coordinator assigned short address through which this
144 * device or coordinator is associated.
145 * [FF:FF] address indicates that the value is unknown.
146 * [FF:FE] indicates that the associated coordinator is using only
147 * its extended address.
148 *
149 *
150 * \param assignedShortAddr The assigned short address for this device.
151 * [FF:FF] address indicates that the device have no short address
152 * and is not associated.
153 * [FF:FE] address indicates that the devices has associated but
154 * has not been allocated a short address.
155 *
156 */
157 void SetPanAssociation(uint16_t panId,
158 Mac64Address coordExtAddr,
159 Mac16Address coordShortAddr,
160 Mac16Address assignedShortAddr);
161
162 bool SetMtu(const uint16_t mtu) override;
163 uint16_t GetMtu() const override;
164 bool IsLinkUp() const override;
165 void AddLinkChangeCallback(Callback<void> callback) override;
166 bool IsBroadcast() const override;
167 Address GetBroadcast() const override;
168 bool IsMulticast() const override;
169 Address GetMulticast(Ipv4Address multicastGroup) const override;
170 Address GetMulticast(Ipv6Address addr) const override;
171 bool IsBridge() const override;
172 bool IsPointToPoint() const override;
173 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
174 bool SendFrom(Ptr<Packet> packet,
175 const Address& source,
176 const Address& dest,
177 uint16_t protocolNumber) override;
178 Ptr<Node> GetNode() const override;
179 void SetNode(Ptr<Node> node) override;
180 bool NeedsArp() const override;
181
183 void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override;
184 bool SupportsSendFrom() const override;
185
186 /**
187 * The callback used by the MAC to hand over incoming packets to the
188 * NetDevice. This callback will in turn use the ReceiveCallback set by
189 * SetReceiveCallback() to notify upper layers.
190 *
191 * \param params 802.15.4 specific parameters, including source and destination addresses
192 * \param pkt the packet do be delivered
193 */
195
196 /**
197 * Assign a fixed random variable stream number to the random variables
198 * used by this model. Return the number of streams that have been assigned.
199 *
200 * \param stream first stream index to use
201 * \return the number of stream indices assigned by this model
202 */
203 int64_t AssignStreams(int64_t stream);
204
205 private:
206 // Inherited from NetDevice/Object
207 void DoDispose() override;
208 void DoInitialize() override;
209
210 /**
211 * Mark NetDevice link as up.
212 */
213 void LinkUp();
214
215 /**
216 * Mark NetDevice link as down.
217 */
218 void LinkDown();
219
220 /**
221 * Attribute accessor method for the "Channel" attribute.
222 *
223 * \return the channel to which this NetDevice is attached
224 */
226
227 /**
228 * Configure PHY, MAC and CSMA/CA.
229 */
230 void CompleteConfig();
231
232 /**
233 * Builds a "pseudo 48-bit address" from the PanId and Short Address
234 * The form is PanId : 0x0 : 0x0 : ShortAddress
235 *
236 * The address follows RFC 4944, section 6, and it is used to build an
237 * Interface ID.
238 *
239 * The Interface ID should have its U/L bit is set to zero, to indicate that
240 * this interface ID is not globally unique.
241 * However, the U/L bit flipping is performed when the IPv6 address is created.
242 *
243 * As a consequence, here we set it to 1.
244 *
245 * \param panId The PanID
246 * \param shortAddr The Short MAC address
247 * \return a Pseudo-Mac48Address
248 */
249 Mac48Address BuildPseudoMacAddress(uint16_t panId, Mac16Address shortAddr) const;
250
251 /**
252 * The MAC for this NetDevice.
253 */
255
256 /**
257 * The PHY for this NetDevice.
258 */
260
261 /**
262 * The CSMA/CA implementation for this NetDevice.
263 */
265
266 /**
267 * The node associated with this NetDevice.
268 */
270
271 /**
272 * True if MAC, PHY and CSMA/CA where successfully configured and the
273 * NetDevice is ready for being used.
274 */
276
277 /**
278 * Configure the NetDevice to request MAC layer acknowledgments when sending
279 * packets using the Send() API.
280 */
282
283 /**
284 * Is the link/device currently up and running?
285 */
287
288 /**
289 * The interface index of this NetDevice.
290 */
292
293 /**
294 * Trace source for link up/down changes.
295 */
297
298 /**
299 * Upper layer callback used for notification of new data packet arrivals.
300 */
302
303 /**
304 * How the pseudo MAC address is created.
305 *
306 * According to \RFC{4944} the pseudo-MAC is YYYY:0000:XXXX (with U/L bit set to local)
307 * According to \RFC{6282} the pseudo-MAC is 0200:0000:XXXX
308 */
310};
311
312} // namespace lrwpan
313} // namespace ns3
314
315#endif /* LR_WPAN_NET_DEVICE_H */
a polymophic address class
Definition address.h:90
Callback template class.
Definition callback.h:422
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
This class can contain 16 bit addresses.
an EUI-48 address
an EUI-64 address
Network layer to device interface.
Definition net-device.h:87
Smart pointer class similar to boost::intrusive_ptr.
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
Network layer to device interface.
bool SupportsSendFrom() const override
void LinkDown()
Mark NetDevice link as down.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Ptr< LrWpanPhy > m_phy
The PHY for this NetDevice.
uint32_t m_ifIndex
The interface index of this NetDevice.
void LinkUp()
Mark NetDevice link as up.
PseudoMacAddressMode_e m_pseudoMacMode
How the pseudo MAC address is created.
Ptr< LrWpanMac > m_mac
The MAC for this NetDevice.
Ptr< LrWpanMac > GetMac() const
Get the MAC used by this NetDevice.
uint16_t GetMtu() const override
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void SetIfIndex(const uint32_t index) override
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetAddress(Address address) override
This method indirects to LrWpanMac::SetShortAddress ()
ReceiveCallback m_receiveCallback
Upper layer callback used for notification of new data packet arrivals.
bool m_configComplete
True if MAC, PHY and CSMA/CA where successfully configured and the NetDevice is ready for being used.
bool SetMtu(const uint16_t mtu) override
Ptr< SpectrumChannel > DoGetChannel() const
Attribute accessor method for the "Channel" attribute.
bool m_useAcks
Configure the NetDevice to request MAC layer acknowledgments when sending packets using the Send() AP...
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...
Address GetAddress() const override
This method indirects to LrWpanMac::SetShortAddress ()
void AddLinkChangeCallback(Callback< void > callback) override
uint32_t GetIfIndex() const override
PseudoMacAddressMode_e
How the pseudo-MAC address is built from the short address (XXXX) and the PanId (YYYY).
@ RFC4944
YYYY:0000:XXXX (with U/L bit set to local)
void SetCsmaCa(Ptr< LrWpanCsmaCa > csmaca)
Set the CSMA/CA implementation to be used by the MAC and this NetDevice.
bool IsBroadcast() const override
void CompleteConfig()
Configure PHY, MAC and CSMA/CA.
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
Ptr< LrWpanCsmaCa > m_csmaca
The CSMA/CA implementation for this NetDevice.
TracedCallback m_linkChanges
Trace source for link up/down changes.
Address GetBroadcast() const override
Ptr< Channel > GetChannel() const 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...
Ptr< LrWpanCsmaCa > GetCsmaCa() const
Get the CSMA/CA implementation used by this NetDevice.
void SetPhy(Ptr< LrWpanPhy > phy)
Set the PHY to be used by the MAC and this NetDevice.
void DoDispose() override
Destructor implementation.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
void SetChannel(Ptr< SpectrumChannel > channel)
Set the channel to which the NetDevice, and therefore the PHY, should be attached to.
Ptr< LrWpanPhy > GetPhy() const
Get the PHY used by this NetDevice.
bool m_linkUp
Is the link/device currently up and running?
bool IsBridge() const override
Return true if the net device is acting as a bridge.
void SetNode(Ptr< Node > node) override
bool IsMulticast() const override
static TypeId GetTypeId()
Get the type ID.
void McpsDataIndication(McpsDataIndicationParams params, Ptr< Packet > pkt)
The callback used by the MAC to hand over incoming packets to the NetDevice.
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
void DoInitialize() override
Initialize() implementation.
void SetMac(Ptr< LrWpanMac > mac)
Set the MAC to be used by this NetDevice.
Ptr< Node > m_node
The node associated with this NetDevice.
Ptr< Node > GetNode() const override
Every class exported by the ns3 library is enclosed in the ns3 namespace.