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_configComplete = true;
104}
105
106void
108{
109 NS_LOG_FUNCTION(this << packet);
110
111 // Send the packet to the MAC layer, if it exists
113 m_mac->Send(packet);
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << packet);
120
121 // Fill protocol and address with empty stuff
122 NS_LOG_DEBUG("Calling receiveCallback");
123 m_receiveCallback(this, packet, 0, Address());
124}
125
126/******************************************
127 * Methods inherited from NetDevice *
128 ******************************************/
129
132{
133 NS_LOG_FUNCTION(this);
134 return m_phy->GetChannel();
135}
136
139{
140 NS_LOG_FUNCTION(this);
141 return m_phy->GetChannel();
142}
143
144void
146{
147 NS_LOG_FUNCTION(this << index);
148}
149
152{
153 NS_LOG_FUNCTION(this);
154
155 return 0;
156}
157
158void
163
166{
167 NS_LOG_FUNCTION(this);
168
169 return Address();
170}
171
172bool
173LoraNetDevice::SetMtu(const uint16_t mtu)
174{
175 NS_ABORT_MSG("Unsupported");
176
177 return false;
178}
179
180uint16_t
182{
183 NS_LOG_FUNCTION(this);
184
185 return 0;
186}
187
188bool
190{
191 NS_LOG_FUNCTION(this);
192
193 return (bool)(m_phy);
194}
195
196void
201
202bool
204{
205 NS_LOG_FUNCTION(this);
206
207 return true;
208}
209
212{
213 NS_LOG_FUNCTION(this);
214
215 return Address();
216}
217
218bool
220{
221 NS_LOG_FUNCTION(this);
222
223 return true;
224}
225
228{
229 NS_ABORT_MSG("Unsupported");
230
231 return Address();
232}
233
236{
237 NS_LOG_FUNCTION(this);
238
239 return Address();
240}
241
242bool
244{
245 NS_LOG_FUNCTION(this);
246
247 return false;
248}
249
250bool
252{
253 NS_LOG_FUNCTION(this);
254
255 return false;
256}
257
258bool
259LoraNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
260
261{
262 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
263
264 // Fallback to the vanilla Send method
265 Send(packet);
266
267 return true;
268}
269
270bool
272 const Address& source,
273 const Address& dest,
274 uint16_t protocolNumber)
275
276{
277 NS_ABORT_MSG("Unsupported");
278
279 return false;
280}
281
284{
285 NS_LOG_FUNCTION(this);
286
287 return m_node;
288}
289
290void
292{
293 NS_LOG_FUNCTION(this);
294
295 m_node = node;
297}
298
299bool
301{
302 NS_LOG_FUNCTION(this);
303
304 return true;
305}
306
307void
313
314void
319
320bool
322{
324
325 return false;
326}
327
328} // namespace lorawan
329} // 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:341
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition net-device.h:311
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
#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.