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