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 "ns3/abort.h"
12#include "ns3/log.h"
13#include "ns3/node.h"
14#include "ns3/pointer.h"
15
16namespace ns3
17{
18namespace lorawan
19{
20
21NS_LOG_COMPONENT_DEFINE("LoraNetDevice");
22
23NS_OBJECT_ENSURE_REGISTERED(LoraNetDevice);
24
25TypeId
27{
28 static TypeId tid =
29 TypeId("ns3::LoraNetDevice")
31 .AddConstructor<LoraNetDevice>()
32 .SetGroupName("lorawan")
33 .AddAttribute("Channel",
34 "The channel attached to this device",
38 .AddAttribute("Phy",
39 "The PHY layer attached to this device.",
43 .AddAttribute("Mac",
44 "The MAC layer attached to this device.",
48 return tid;
49}
50
52 : m_node(nullptr),
53 m_phy(nullptr),
54 m_mac(nullptr),
55 m_configComplete(false)
56{
58}
59
64
65void
70
73{
74 return m_mac;
75}
76
77void
82
85{
86 return m_phy;
87}
88
89void
91{
93
94 // Verify we have all the necessary pieces
95 if (!m_mac || !m_phy || !m_node || m_configComplete)
96 {
97 return;
98 }
99
100 m_mac->SetPhy(m_phy);
101 m_configComplete = true;
102}
103
104void
106{
107 NS_LOG_FUNCTION(this << packet);
108
109 // Send the packet to the MAC layer, if it exists
111 m_mac->Send(packet);
112}
113
114void
116{
117 NS_LOG_FUNCTION(this << packet);
118
119 // Fill protocol and address with empty stuff
120 NS_LOG_DEBUG("Calling receiveCallback");
121 m_receiveCallback(this, packet, 0, Address());
122}
123
124/******************************************
125 * Methods inherited from NetDevice *
126 ******************************************/
127
130{
131 NS_LOG_FUNCTION(this);
132 return m_phy->GetChannel();
133}
134
137{
138 NS_LOG_FUNCTION(this);
139 return m_phy->GetChannel();
140}
141
142void
144{
145 NS_LOG_FUNCTION(this << index);
146}
147
150{
151 NS_LOG_FUNCTION(this);
152
153 return 0;
154}
155
156void
161
164{
165 NS_LOG_FUNCTION(this);
166
167 return Address();
168}
169
170bool
171LoraNetDevice::SetMtu(const uint16_t mtu)
172{
173 NS_ABORT_MSG("Unsupported");
174
175 return false;
176}
177
178uint16_t
180{
181 NS_LOG_FUNCTION(this);
182
183 return 0;
184}
185
186bool
188{
189 NS_LOG_FUNCTION(this);
190
191 return m_phy != nullptr;
192}
193
194void
199
200bool
202{
203 NS_LOG_FUNCTION(this);
204
205 return true;
206}
207
210{
211 NS_LOG_FUNCTION(this);
212
213 return Address();
214}
215
216bool
218{
219 NS_LOG_FUNCTION(this);
220
221 return true;
222}
223
226{
227 NS_ABORT_MSG("Unsupported");
228
229 return Address();
230}
231
234{
235 NS_LOG_FUNCTION(this);
236
237 return Address();
238}
239
240bool
242{
243 NS_LOG_FUNCTION(this);
244
245 return false;
246}
247
248bool
250{
251 NS_LOG_FUNCTION(this);
252
253 return false;
254}
255
256bool
257LoraNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
258
259{
260 NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
261
262 // Fallback to the vanilla Send method
263 Send(packet);
264
265 return true;
266}
267
268bool
270 const Address& source,
271 const Address& dest,
272 uint16_t protocolNumber)
273
274{
275 NS_ABORT_MSG("Unsupported");
276
277 return false;
278}
279
282{
283 NS_LOG_FUNCTION(this);
284
285 return m_node;
286}
287
288void
290{
291 NS_LOG_FUNCTION(this);
292
293 m_node = node;
295}
296
297bool
299{
300 NS_LOG_FUNCTION(this);
301
302 return true;
303}
304
305void
311
312void
317
318bool
320{
322
323 return false;
324}
325
326} // namespace lorawan
327} // namespace ns3
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.
Network layer to device interface.
Definition net-device.h:87
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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.