A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lora-device-address.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_DEVICE_ADDRESS_H
21#define LORA_DEVICE_ADDRESS_H
22
23#include "ns3/address.h"
24
25#include <string>
26
27namespace ns3
28{
29namespace lorawan
30{
31
32/**
33 * \ingroup lorawan
34 *
35 * Class representing the NetworkId component of a LoraDeviceAddress (7 bits).
36 */
37class NwkID
38{
39 public:
40 /**
41 * Construct a new NwkID object.
42 *
43 * \param nwkId The network id value [0:127].
44 *
45 * \todo Add warning as in Set().
46 */
47 NwkID(uint8_t nwkId = 0);
48
49 /**
50 * Set the NwkID, starting from a 8-bit representation of a 7-bit integer.
51 *
52 * This method will ignore the most significant bit of the argument. This
53 * means that all arguments such that nwkId > 127 will actually be
54 * considered as nwkId mod 127.
55 *
56 * \param nwkId The Network Id value to set.
57 */
58 void Set(uint8_t nwkId);
59
60 /**
61 * Get an uint8_t representation of the 7-bit network ID.
62 *
63 * \return The Network Id.
64 */
65 uint8_t Get() const;
66
67 private:
68 uint8_t m_nwkId; //!< 8-bit integer representation of the network id
69};
70
71/**
72 * \ingroup lorawan
73 *
74 * Class representing the Network Address component of a LoraDeviceAddress (25
75 * bits)
76 */
78{
79 public:
80 /**
81 * Construct a new NwkAddr object.
82 *
83 * \param nwkId Network addr value [0:2^25-1].
84 *
85 * \todo Add warning as in Set().
86 */
87 NwkAddr(uint32_t nwkId = 0);
88
89 /**
90 * Set the NwkAddr, starting from a 32-bit representation of a 25-bit integer.
91 *
92 * This method will ignore the most significant bits of the argument. This
93 * means that all arguments such that nwkAddr > 2^25-1 will actually be
94 * considered as nwkAddr mod 2^25-1.
95 *
96 * \param nwkAddr The Network Address to set.
97 */
98 void Set(uint32_t nwkAddr);
99
100 /**
101 * Get an uint32_t representation of the 25-bit network address.
102 *
103 * \return The Network Address.
104 */
105 uint32_t Get() const;
106
107 private:
108 uint32_t m_nwkAddr; //!< 8-bit integer representation of the network id
109};
110
111/**
112 * \ingroup lorawan
113 *
114 * This class represents the device address of a LoraWAN end device.
115 */
117{
118 public:
119 LoraDeviceAddress(); //!< Default constructor
120
121 /**
122 * Build a new address from a 32-bit integer.
123 *
124 * \param address Full numeric value of the address.
125 */
127
128 /**
129 * Build a new address from a network id and network address.
130 *
131 * \param nwkId Network id numeric value.
132 * \param nwkAddr Network address numeric value.
133 */
134 LoraDeviceAddress(uint8_t nwkId, uint32_t nwkAddr);
135
136 /**
137 * Build a new address from a network id and network address.
138 *
139 * \param nwkId Network id object.
140 * \param nwkAddr Network address object.
141 */
142 LoraDeviceAddress(NwkID nwkId, NwkAddr nwkAddr);
143
144 /**
145 * Convert this address to a buffer.
146 *
147 * \param buf [out] buffer to fill with serialized address.
148 */
149 void Serialize(uint8_t buf[4]) const;
150
151 /**
152 * Convert the input buffer into a new address.
153 *
154 * \param buf [in] buffer containing serialized address.
155 * \return The LoraDeviceAddress object.
156 */
157 static LoraDeviceAddress Deserialize(const uint8_t buf[4]);
158
159 /**
160 * Convert from an ordinary address to a LoraDeviceAddress instance.
161 *
162 * \param address Reference to ordinary Address object.
163 * \return The LoraDeviceAddress object.
164 */
165 static LoraDeviceAddress ConvertFrom(const Address& address);
166
167 /**
168 * Set the address as a 32 bit integer.
169 *
170 * \param address Full numeric value of the address.
171 */
172 void Set(uint32_t address);
173
174 /**
175 * Set the address, combining a network id and a network address.
176 *
177 * Note that nwkId is 7 bits long, and this function expects the 7 least
178 * significant bits to contain the nwkId. Similarly for the nwkAddr, the 25
179 * least significant bits of the uint32 are those that are expected to
180 * contain the nwkAddr.
181 *
182 * \param nwkId Network id numeric value.
183 * \param nwkAddr Network address numeric value.
184 *
185 * \todo Not implemented, this is a placeholder for future implementation.
186 */
187 void Set(uint8_t nwkId, uint32_t nwkAddr);
188
189 /**
190 * Get the address in 32-bit integer form.
191 *
192 * \return Full numeric value of the address.
193 */
194 uint32_t Get() const;
195
196 /**
197 * Get the NwkID of this device.
198 *
199 * \remark The NwkID bit-by-bit representation will be contained in the 7
200 * least significant bits of the returned uint8_t.
201 *
202 * \return An 8-bit representation of the Network Id of this Device Address.
203 */
204 uint8_t GetNwkID();
205
206 /**
207 * Set the NwkID of this device.
208 *
209 * \remark The NwkID is expected to be contained on the 7 least significant
210 * bits of the uint8_t.
211 *
212 * \param nwkId The network id to set.
213 */
214 void SetNwkID(uint8_t nwkId);
215
216 /**
217 * Get the NwkAddr of this device.
218 *
219 * \remark The NwkAddr will be contained on the 25 least significant bits of
220 * the uint32_t.
221 *
222 * \return A 32-bit representation of the Network Address of this Device Address.
223 */
225
226 /**
227 * Set the NwkAddr of this device.
228 *
229 * \remark The NwkAddr is expected to be contained on the least significant
230 * bits of the uint32_t.
231 *
232 * \param nwkAddr The network address to set.
233 */
234 void SetNwkAddr(uint32_t nwkAddr);
235
236 /**
237 * Print the address bit-by-bit to a human-readable string.
238 *
239 * \return The string containing the network address.
240 */
241 std::string Print() const;
242
243 /**
244 * Equality comparison operator
245 * \param other Address to compare.
246 * \return True if the addresses are equal.
247 */
248 bool operator==(const LoraDeviceAddress& other) const;
249 /**
250 * Inequality comparison operator
251 * \param other Address to compare.
252 * \return True if the addresses are different.
253 */
254 bool operator!=(const LoraDeviceAddress& other) const;
255 /**
256 * Less-then comparison operator
257 * \param other Address to compare.
258 * \return True if the first address is less than the second.
259 */
260 bool operator<(const LoraDeviceAddress& other) const;
261 /**
262 * Greater-then comparison operator
263 * \param other Address to compare.
264 * \return True if the first address is greater than the second.
265 */
266 bool operator>(const LoraDeviceAddress& other) const;
267
268 private:
269 /**
270 * Convert this instance of LoraDeviceAddress to an Address.
271 *
272 * \return The Address object.
273 */
274 Address ConvertTo() const;
275
276 /**
277 * Get a new address type id.
278 * \return The new address type id.
279 */
280 static uint8_t GetType();
281
282 NwkID m_nwkId; //!< The network Id of this address
283 NwkAddr m_nwkAddr; //!< The network address of this address
284};
285
286/**
287 * Operator overload to correctly handle logging when an address is passed as
288 * an argument.
289 */
290std::ostream& operator<<(std::ostream& os, const LoraDeviceAddress& address);
291
292} // namespace lorawan
293} // namespace ns3
294#endif
a polymophic address class
Definition: address.h:101
This class represents the device address of a LoraWAN end device.
void SetNwkID(uint8_t nwkId)
Set the NwkID of this device.
LoraDeviceAddress()
Default constructor.
NwkAddr m_nwkAddr
The network address of this address.
static LoraDeviceAddress Deserialize(const uint8_t buf[4])
Convert the input buffer into a new address.
static LoraDeviceAddress ConvertFrom(const Address &address)
Convert from an ordinary address to a LoraDeviceAddress instance.
NwkID m_nwkId
The network Id of this address.
uint32_t GetNwkAddr()
Get the NwkAddr of this device.
uint32_t Get() const
Get the address in 32-bit integer form.
void Set(uint32_t address)
Set the address as a 32 bit integer.
void SetNwkAddr(uint32_t nwkAddr)
Set the NwkAddr of this device.
static uint8_t GetType()
Get a new address type id.
std::string Print() const
Print the address bit-by-bit to a human-readable string.
void Serialize(uint8_t buf[4]) const
Convert this address to a buffer.
bool operator>(const LoraDeviceAddress &other) const
Greater-then comparison operator.
bool operator<(const LoraDeviceAddress &other) const
Less-then comparison operator.
uint8_t GetNwkID()
Get the NwkID of this device.
bool operator!=(const LoraDeviceAddress &other) const
Inequality comparison operator.
Address ConvertTo() const
Convert this instance of LoraDeviceAddress to an Address.
bool operator==(const LoraDeviceAddress &other) const
Equality comparison operator.
void Set(uint8_t nwkId, uint32_t nwkAddr)
Set the address, combining a network id and a network address.
Class representing the Network Address component of a LoraDeviceAddress (25 bits)
uint32_t m_nwkAddr
8-bit integer representation of the network id
void Set(uint32_t nwkAddr)
Set the NwkAddr, starting from a 32-bit representation of a 25-bit integer.
uint32_t Get() const
Get an uint32_t representation of the 25-bit network address.
Class representing the NetworkId component of a LoraDeviceAddress (7 bits).
uint8_t m_nwkId
8-bit integer representation of the network id
uint8_t Get() const
Get an uint8_t representation of the 7-bit network ID.
void Set(uint8_t nwkId)
Set the NwkID, starting from a 8-bit representation of a 7-bit integer.
std::ostream & operator<<(std::ostream &os, const EndDeviceStatus &status)
Every class exported by the ns3 library is enclosed in the ns3 namespace.