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