A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-net-device.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 University of Padova
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: Davide Magrin <magrinda@dei.unipd.it>
18 */
19
20#include "lora-net-device.h"
21
22#include "ns3/abort.h"
23#include "ns3/log.h"
24#include "ns3/node.h"
25#include "ns3/pointer.h"
26
27namespace ns3
28{
29namespace lorawan
30{
31
32NS_LOG_COMPONENT_DEFINE("LoraNetDevice");
33
34NS_OBJECT_ENSURE_REGISTERED(LoraNetDevice);
35
36TypeId
38{
39 static TypeId tid =
40 TypeId("ns3::LoraNetDevice")
42 .AddConstructor<LoraNetDevice>()
43 .SetGroupName("lorawan")
44 .AddAttribute("Channel",
45 "The channel attached to this device",
48 MakePointerChecker<LoraChannel>())
49 .AddAttribute("Phy",
50 "The PHY layer attached to this device.",
53 MakePointerChecker<LoraPhy>())
54 .AddAttribute("Mac",
55 "The MAC layer attached to this device.",
58 MakePointerChecker<LorawanMac>());
59 return tid;
60}
61
63 : m_node(nullptr),
64 m_phy(nullptr),
65 m_mac(nullptr),
66 m_configComplete(false)
67{
69}
70
72{
74}
75
76void
78{
79 m_mac = mac;
80}
81
84{
85 return m_mac;
86}
87
88void
90{
91 m_phy = phy;
92}
93
96{
97 return m_phy;
98}
99
100void
102{
104
105 // Verify we have all the necessary pieces
106 if (!m_mac || !m_phy || !m_node || m_configComplete)
107 {
108 return;
109 }
110
111 m_mac->SetPhy(m_phy);
112 m_configComplete = true;
113}
114
115void
117{
118 NS_LOG_FUNCTION(this << packet);
119
120 // Send the packet to the MAC layer, if it exists
122 m_mac->Send(packet);
123}
124
125void
127{
128 NS_LOG_FUNCTION(this << packet);
129
130 // Fill protocol and address with empty stuff
131 NS_LOG_DEBUG("Calling receiveCallback");
132 m_receiveCallback(this, packet, 0, Address());
133}
134
135/******************************************
136 * Methods inherited from NetDevice *
137 ******************************************/
138
141{
142 NS_LOG_FUNCTION(this);
143 return m_phy->GetChannel();
144}
145
148{
149 NS_LOG_FUNCTION(this);
150 return m_phy->GetChannel();
151}
152
153void
155{
156 NS_LOG_FUNCTION(this << index);
157}
158
161{
162 NS_LOG_FUNCTION(this);
163
164 return 0;
165}
166
167void
169{
170 NS_LOG_FUNCTION(this);
171}
172
175{
176 NS_LOG_FUNCTION(this);
177
178 return Address();
179}
180
181bool
182LoraNetDevice::SetMtu(const uint16_t mtu)
183{
184 NS_ABORT_MSG("Unsupported");
185
186 return false;
187}
188
189uint16_t
191{
192 NS_LOG_FUNCTION(this);
193
194 return 0;
195}
196
197bool
199{
200 NS_LOG_FUNCTION(this);
201
202 return m_phy != nullptr;
203}
204
205void
207{
208 NS_LOG_FUNCTION(this);
209}
210
211bool
213{
214 NS_LOG_FUNCTION(this);
215
216 return true;
217}
218
221{
222 NS_LOG_FUNCTION(this);
223
224 return Address();
225}
226
227bool
229{
230 NS_LOG_FUNCTION(this);
231
232 return true;
233}
234
237{
238 NS_ABORT_MSG("Unsupported");
239
240 return Address();
241}
242
245{
246 NS_LOG_FUNCTION(this);
247
248 return Address();
249}
250
251bool
253{
254 NS_LOG_FUNCTION(this);
255
256 return false;
257}
258
259bool
261{
262 NS_LOG_FUNCTION(this);
263
264 return false;
265}
266
267bool
268LoraNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
269
270{
271 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
272
273 // Fallback to the vanilla Send method
274 Send(packet);
275
276 return true;
277}
278
279bool
281 const Address& source,
282 const Address& dest,
283 uint16_t protocolNumber)
284
285{
286 NS_ABORT_MSG("Unsupported");
287
288 return false;
289}
290
293{
294 NS_LOG_FUNCTION(this);
295
296 return m_node;
297}
298
299void
301{
302 NS_LOG_FUNCTION(this);
303
304 m_node = node;
306}
307
308bool
310{
311 NS_LOG_FUNCTION(this);
312
313 return true;
314}
315
316void
318{
321}
322
323void
325{
327}
328
329bool
331{
333
334 return false;
335}
336
337} // namespace lorawan
338} // namespace ns3
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
Network layer to device interface.
Definition: net-device.h:98
AttributeValue implementation for Pointer.
Definition: pointer.h:48
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
uint16_t GetMtu() const override
void SetMac(Ptr< LorawanMac > mac)
Set which LorawanMac instance is linked to this device.
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
bool NeedsArp() const override
Ptr< Node > GetNode() const override
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool IsMulticast() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
bool IsBridge() const override
Return true if the net device is acting as a bridge.
Ptr< LoraPhy > GetPhy() const
Get the LoraPhy instance that is linked to this NetDevice.
~LoraNetDevice() override
Destructor.
Ptr< LoraChannel > DoGetChannel() const
Return the LoraChannel this device is connected to.
Ptr< LorawanMac > m_mac
The LorawanMac this NetDevice is connected to.
bool SupportsSendFrom() const override
LoraNetDevice()
Default constructor.
bool IsLinkUp() const override
Ptr< Channel > GetChannel() const override
void SetPromiscReceiveCallback(PromiscReceiveCallback cb) override
void AddLinkChangeCallback(Callback< void > callback) override
void SetAddress(Address address) override
Set the address of this interface.
static TypeId GetTypeId()
Register this type.
Address GetBroadcast() const override
Ptr< LorawanMac > GetMac() const
Get the LorawanMac instance that is linked to this NetDevice.
Ptr< LoraPhy > m_phy
The LoraPhy this NetDevice is connected to.
Ptr< Node > m_node
The Node this NetDevice is connected to.
bool IsBroadcast() const override
void SetIfIndex(const uint32_t index) override
Address GetAddress() const override
bool SetMtu(const uint16_t mtu) override
void Receive(Ptr< Packet > packet)
Callback the Mac layer calls whenever a packet arrives and needs to be forwarded up the stack.
void SetNode(Ptr< Node > node) override
NetDevice::ReceiveCallback m_receiveCallback
Upper layer callback used for notification of new data packet arrivals.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
bool m_configComplete
Whether the configuration was already completed.
void CompleteConfig()
Complete the configuration of this LoRa device by connecting all lower components (PHY,...
void SetPhy(Ptr< LoraPhy > phy)
Set which LoraPhy instance is linked to this device.
uint32_t GetIfIndex() const override
void Send(Ptr< Packet > packet)
Send a packet through the LoRaWAN stack.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:259
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.