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