A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-net-device.h
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#ifndef LORA_NET_DEVICE_H
21#define LORA_NET_DEVICE_H
22
23#include "lora-channel.h"
24#include "lora-phy.h"
25#include "lorawan-mac.h"
26
27#include "ns3/net-device.h"
28
29namespace ns3
30{
31namespace lorawan
32{
33
34class LoraChannel;
35class LoraPhy;
36class LorawanMac;
37
38/**
39 * \defgroup lorawan LoRaWAN Models
40 *
41 * This section documents the API of the ns-3 lorawan module. For a generic functional description,
42 * please refer to the ns-3 manual.
43 */
44
45/**
46 * \ingroup lorawan
47 *
48 * Hold together all LoRa related objects.
49 *
50 * This class holds together pointers to LoraChannel, LoraPhy and LorawanMac,
51 * exposing methods through which Application instances can send packets. The
52 * Application only needs to craft its packets, the NetDevice will take care of
53 * calling the LorawanMac's Send method with the appropriate parameters.
54 */
56{
57 public:
58 /**
59 * Register this type.
60 * \return The object TypeId.
61 */
62 static TypeId GetTypeId();
63
64 LoraNetDevice(); //!< Default constructor
65 ~LoraNetDevice() override; //!< Destructor
66
67 /**
68 * Set which LorawanMac instance is linked to this device.
69 *
70 * \param mac The MAC layer to use.
71 */
72 void SetMac(Ptr<LorawanMac> mac);
73
74 /**
75 * Set which LoraPhy instance is linked to this device.
76 *
77 * \param phy The PHY layer to use.
78 */
79 void SetPhy(Ptr<LoraPhy> phy);
80
81 /**
82 * Get the LorawanMac instance that is linked to this NetDevice.
83 *
84 * \return The MAC we are currently using.
85 */
86 Ptr<LorawanMac> GetMac() const;
87
88 /**
89 * Get the LoraPhy instance that is linked to this NetDevice.
90 *
91 * \return The PHY we are currently using.
92 */
93 Ptr<LoraPhy> GetPhy() const;
94
95 /**
96 * Send a packet through the LoRaWAN stack.
97 *
98 * \param packet The packet to send.
99 */
100 void Send(Ptr<Packet> packet);
101
102 /**
103 * \copydoc ns3::NetDevice::Send
104
105 * \note This function is implemented to achieve compliance with the NetDevice
106 * interface. Note that the dest and protocolNumber args are ignored.
107 */
108 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
109
110 /**
111 * Callback the Mac layer calls whenever a packet arrives and needs to be
112 * forwarded up the stack.
113 *
114 * \param packet The packet that was received.
115 */
116 void Receive(Ptr<Packet> packet);
117
118 // From class NetDevice. Some of these have little meaning for a LoRaWAN
119 // network device (since, for instance, IP is not used in the standard)
121 Ptr<Channel> GetChannel() const override;
122 void SetNode(Ptr<Node> node) override;
123 Ptr<Node> GetNode() const override;
124
125 void SetIfIndex(const uint32_t index) override;
126 uint32_t GetIfIndex() const override;
127 void SetAddress(Address address) override;
128 Address GetAddress() const override;
129 bool SetMtu(const uint16_t mtu) override;
130 uint16_t GetMtu() const override;
131 bool IsLinkUp() const override;
132 void AddLinkChangeCallback(Callback<void> callback) override;
133 bool IsBroadcast() const override;
134 Address GetBroadcast() const override;
135 bool IsMulticast() const override;
136 Address GetMulticast(Ipv4Address multicastGroup) const override;
137 Address GetMulticast(Ipv6Address addr) const override;
138 bool IsBridge() const override;
139 bool IsPointToPoint() const override;
140 bool SendFrom(Ptr<Packet> packet,
141 const Address& source,
142 const Address& dest,
143 uint16_t protocolNumber) override;
144 bool NeedsArp() const override;
146 bool SupportsSendFrom() const override;
147
148 protected:
149 /**
150 * Receive a packet from the lower layer and pass the
151 * packet up the stack.
152 *
153 * \param packet The packet we need to forward.
154 * \param from The from address.
155 * \param to The to address.
156 *
157 * \todo Not implemented, this is a placeholder for future implementation.
158 */
160
161 private:
162 /**
163 * Return the LoraChannel this device is connected to.
164 *
165 * \return A pointer to the LoraChannel object.
166 */
168
169 /**
170 * Complete the configuration of this LoRa device by connecting all lower
171 * components (PHY, MAC, Channel) together.
172 */
173 void CompleteConfig();
174
175 // Member variables
176 Ptr<Node> m_node; //!< The Node this NetDevice is connected to.
177 Ptr<LoraPhy> m_phy; //!< The LoraPhy this NetDevice is connected to.
178 Ptr<LorawanMac> m_mac; //!< The LorawanMac this NetDevice is connected to.
179 bool m_configComplete; //!< Whether the configuration was already completed.
180
181 /**
182 * Upper layer callback used for notification of new data packet arrivals.
183 */
185};
186
187} // namespace lorawan
188
189} // namespace ns3
190#endif /* LORA_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
an EUI-48 address
Definition: mac48-address.h:46
Network layer to device interface.
Definition: net-device.h:98
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
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.
void ForwardUp(Ptr< Packet > packet, Mac48Address from, Mac48Address to)
Receive a packet from the lower layer and pass the packet up the stack.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.