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