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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Davide Magrin <magrinda@dei.unipd.it>
7 */
8
9#include "lora-net-device.h"
10
11#include "lora-channel.h"
12#include "lora-phy.h"
13#include "lorawan-mac.h"
14
15#include "ns3/node.h"
16#include "ns3/pointer.h"
17
18namespace ns3
19{
20namespace lorawan
21{
22
23NS_LOG_COMPONENT_DEFINE("LoraNetDevice");
24
26
27TypeId
29{
30 static TypeId tid =
31 TypeId("ns3::LoraNetDevice")
33 .AddConstructor<LoraNetDevice>()
34 .SetGroupName("lorawan")
35 .AddAttribute("Channel",
36 "The channel attached to this device",
40 .AddAttribute("Phy",
41 "The PHY layer attached to this device.",
45 .AddAttribute("Mac",
46 "The MAC layer attached to this device.",
50 return tid;
51}
52
54 : m_node(nullptr),
55 m_phy(nullptr),
56 m_mac(nullptr),
57 m_configComplete(false)
58{
60}
61
66
67void
72
75{
76 return m_mac;
77}
78
79void
84
87{
88 return m_phy;
89}
90
91void
93{
95
96 // Verify we have all the necessary pieces
97 if (!m_mac || !m_phy || !m_node || m_configComplete)
98 {
99 return;
100 }
101
102 m_mac->SetPhy(m_phy);
103 m_mac->SetReceiveCallback(MakeCallback(&LoraNetDevice::Receive, this));
104 m_configComplete = true;
105}
106
107void
109{
110 NS_LOG_FUNCTION(this << packet);
111
112 // Send the packet to the MAC layer, if it exists
114 m_mac->Send(packet);
115}
116
117void
119{
120 NS_LOG_FUNCTION(this << packet);
121
122 // Fill protocol and address with empty stuff
123 NS_LOG_DEBUG("Calling receiveCallback");
124 m_receiveCallback(this, packet, 0, Address());
125}
126
127/******************************************
128 * Methods inherited from NetDevice *
129 ******************************************/
130
133{
134 NS_LOG_FUNCTION(this);
135 return m_phy->GetChannel();
136}
137
140{
141 NS_LOG_FUNCTION(this);
142 return m_phy->GetChannel();
143}
144
145void
147{
148 NS_LOG_FUNCTION(this << index);
149}
150
153{
154 NS_LOG_FUNCTION(this);
155
156 return 0;
157}
158
159void
164
167{
168 NS_LOG_FUNCTION(this);
169
170 return Address();
171}
172
173bool
174LoraNetDevice::SetMtu(const uint16_t mtu)
175{
176 NS_ABORT_MSG("Unsupported");
177
178 return false;
179}
180
181uint16_t
183{
184 NS_LOG_FUNCTION(this);
185
186 return 0;
187}
188
189bool
191{
192 NS_LOG_FUNCTION(this);
193
194 return (bool)(m_phy);
195}
196
197void
202
203bool
205{
206 NS_LOG_FUNCTION(this);
207
208 return true;
209}
210
213{
214 NS_LOG_FUNCTION(this);
215
216 return Address();
217}
218
219bool
221{
222 NS_LOG_FUNCTION(this);
223
224 return true;
225}
226
229{
230 NS_ABORT_MSG("Unsupported");
231
232 return Address();
233}
234
237{
238 NS_LOG_FUNCTION(this);
239
240 return Address();
241}
242
243bool
245{
246 NS_LOG_FUNCTION(this);
247
248 return false;
249}
250
251bool
253{
254 NS_LOG_FUNCTION(this);
255
256 return false;
257}
258
259bool
260LoraNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
261
262{
263 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
264
265 // Fallback to the vanilla Send method
266 Send(packet);
267
268 return true;
269}
270
271bool
273 const Address& source,
274 const Address& dest,
275 uint16_t protocolNumber)
276
277{
278 NS_ABORT_MSG("Unsupported");
279
280 return false;
281}
282
285{
286 NS_LOG_FUNCTION(this);
287
288 return m_node;
289}
290
291void
293{
294 NS_LOG_FUNCTION(this);
295
296 m_node = node;
298}
299
300bool
302{
303 NS_LOG_FUNCTION(this);
304
305 return true;
306}
307
308void
314
315void
320
321bool
323{
325
326 return false;
327}
328
329} // namespace lorawan
330} // namespace ns3
a polymophic address class
Definition address.h:114
Callback template class.
Definition callback.h:428
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
Network layer to device interface.
Definition net-device.h:87
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, PacketType > PromiscReceiveCallback
Definition net-device.h:352
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition net-device.h:322
AttributeValue implementation for Pointer.
Definition pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Hold together all LoRa related objects.
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:55
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:250
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:273
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...
Definition callback.h:690
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#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:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.