A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
zigbee-nwk-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tokushima University, Japan
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors:
7 * Ryo Okuda <c611901200@tokushima-u.ac.jp>
8 * Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
9 */
10
11#ifndef ZIGBEE_NWK_HEADER_H
12#define ZIGBEE_NWK_HEADER_H
13
14#include "ns3/header.h"
15#include "ns3/mac16-address.h"
16#include "ns3/mac64-address.h"
17
18namespace ns3
19{
20
21namespace zigbee
22{
23
24/**
25 * Zigbee Specification r22.1.0, Values of the frame Type Sub-field (Table 3-46)
26 */
28{
29 DATA = 0, //!< Data frame type
30 NWK_COMMAND = 1, //!< Network command frame type
31 INTER_PAN = 3 //!< Inter-Pan frame type
32};
33
34/**
35 * Zigbee Specification r22.1.0, Values of the discover route sub-field (Table 3-47)
36 */
38{
39 SUPPRESS_ROUTE_DISCOVERY = 0x00, //!< Suppress route discovery
40 ENABLE_ROUTE_DISCOVERY = 0x01 //!< Enable route discovery
41};
42
43/**
44 * Zigbee Specification r22.1.0, Multicast Mode Sub-Field (Table 3-7)
45 */
47{
48 NONMEMBER = 0, //!< Non member multicast mode
49 MEMBER = 1, //!< Member multicast mode
50};
51
52/**
53 * @ingroup zigbee
54 * Represent the NWK Header with the Frame Control and Routing fields
55 * Zigbee Specification r22.1.0, General NPDU Frame Format (Section 3.3.1)
56 */
57class ZigbeeNwkHeader : public Header
58{
59 public:
61
62 ~ZigbeeNwkHeader() override;
63
64 /**
65 * Set the Frame type used (Data or Command)
66 * @param nwkType The frame type
67 */
68 void SetFrameType(enum NwkType nwkType);
69
70 /**
71 * Set the Frame Control field "Frame Type" bits
72 * @return The frame type
73 */
74 NwkType GetFrameType() const;
75
76 /**
77 * Set the Protocol version
78 * @param ver The protocol version
79 */
80 void SetProtocolVer(uint8_t ver);
81
82 /**
83 * Get Frame protocol version
84 * @return The protocol version used by the frame
85 */
86 uint8_t GetProtocolVer() const;
87
88 /**
89 * Suppress or enable route discovery for this frame
90 * @param discoverRoute Suppress or enable route discovery
91 */
92 void SetDiscoverRoute(enum DiscoverRouteType discoverRoute);
93
94 /**
95 * Get the status of frame discovery route (suppress or enabled)
96 * @return The discovery route status
97 */
99
100 /**
101 * Set to true the value of the multicast flag in the frame control field.
102 */
103 void SetMulticast();
104
105 /**
106 * Inform whether or not the current frame is used in multicast.
107 * @return True = MCST false = UCST or BCST
108 */
109 bool IsMulticast() const;
110
111 /**
112 * Inform whether or not security is enabled.
113 * @return True security enabled.
114 */
115 bool IsSecurityEnabled() const;
116
117 /**
118 * This flag is used by the NWK to indicate if the the initiator device of the
119 * message is an end device and the nwkParentInformation field of the NIB has other value than
120 * 0.
121 */
123
124 /**
125 * Get whether or not the source of this message was an end device.
126 * @return True of the source of the message was an end device.
127 */
128 bool GetEndDeviceInitiator() const;
129
130 /**
131 * Set Destination address
132 * @param addr The destination address (16 bit)
133 */
134 void SetDstAddr(Mac16Address addr);
135
136 /**
137 * Get the Destination address
138 * @return the Destination address (16bits)
139 */
140 Mac16Address GetDstAddr() const;
141
142 /**
143 * Set Source address
144 * @param addr The source address (16 bit)
145 */
146 void SetSrcAddr(Mac16Address addr);
147
148 /**
149 * Get the Source address
150 * @return the Source address (16bits)
151 */
152 Mac16Address GetSrcAddr() const;
153
154 /**
155 * Set the Radius
156 * @param radius radius
157 */
158 void SetRadius(uint8_t radius);
159
160 /**
161 * Get the Radius
162 * @return the Radius
163 */
164 uint8_t GetRadius() const;
165
166 /**
167 * Set the Sequence number
168 * @param seqNum sequence number
169 */
170 void SetSeqNum(uint8_t seqNum);
171
172 /**
173 * Get the frame Sequence number
174 * @return the sequence number
175 */
176 uint8_t GetSeqNum() const;
177
178 /**
179 * Set the destination IEEE address
180 * @param dst The destination IEEE address (64 bits)
181 */
183
184 /**
185 * Get the destination IEEE address
186 * @return The destination IEEE address (64bits)
187 */
189
190 /**
191 * Set the source IEEE address
192 * @param src The source IEEE address
193 */
195
196 /**
197 * Get the source IEEE address
198 * @return The source IEEE address (64bits)
199 */
201
202 /**
203 * Set the multicast mode
204 *
205 * @param mode The multicast mode (member or non-member)
206 */
208
209 /**
210 * Get the multicast mode
211 *
212 * @return The multicast mode (member or non-member)
213 */
215
216 /**
217 * Set the non-member radius
218 *
219 * @param radius The non-member radius (0-7)
220 */
221 void SetNonMemberRadius(uint8_t radius);
222
223 /**
224 * Get the non-member radius
225 *
226 * @return The non-member radius (0-7)
227 */
228 uint8_t GetNonMemberRadius() const;
229
230 /**
231 * Set the maximum non-member radius
232 *
233 * @param radius The maximum non-member radius (0-7)
234 */
235 void SetMaxNonMemberRadius(uint8_t radius);
236
237 /**
238 * Get the maximum non-member radius
239 *
240 * @return The maximum non-member radius (0-7)
241 */
242 uint8_t GetMaxNonMemberRadius() const;
243
244 void Serialize(Buffer::Iterator start) const override;
245 uint32_t Deserialize(Buffer::Iterator start) override;
246 uint32_t GetSerializedSize() const override;
247 /**
248 * Get the type ID.
249 *
250 * @return the object TypeId
251 */
252 static TypeId GetTypeId();
253 TypeId GetInstanceTypeId() const override;
254 void Print(std::ostream& os) const override;
255
256 private:
257 /**
258 * Set the Frame control field
259 * @param frameControl 16 bits representing the frame control
260 */
261 void SetFrameControl(uint16_t frameControl);
262 /**
263 * Get the Frame control field
264 * @return The 16 bits of the Frame control field
265 */
266 uint16_t GetFrameControl() const;
267 /**
268 * Set the Multicast control field (mcstMode, nonMemberRadius, maxNonMemberRadius)
269 * @param multicastControl 8 bits representing the multicast control field
270 */
271 void SetMulticastControl(uint8_t multicastControl);
272 /**
273 * Get The Multicast control field
274 * @return The 8 bits representing the multicast control field
275 */
276 uint8_t GetMulticastControl() const;
277
278 /* Frame Control (2 Octets) */
279
280 NwkType m_fctrlFrmType; //!< Frame type (Bit 0-1)
281 uint8_t m_fctrlPrtVer; //!< Protocol version (Bit 2-5)
282 DiscoverRouteType m_fctrlDscvRoute; //!< Discover route (Bit 6-7)
283 bool m_fctrlMcst; //!< Multicast flag (Bit 8)
284 bool m_fctrlSecurity; //!< Security flag (Bit 9)
285 bool m_fctrlSrcRoute; //!< Source route flag (Bit 10)
286 bool m_fctrlDstIEEEAddr; //!< Destination IEEE address flag (Bit 11)
287 bool m_fctrlSrcIEEEAddr; //!< Source IEEE address flag (Bit 12)
288 bool m_fctrlEndDevIni; //!< End device initiator flag (Bit 13)
289 // Reserved (Bits 14-15)
290
291 /* Routing Fields (variable) */
292
293 Mac16Address m_dstAddr; //!< Destination address (2 Octets)
294 Mac16Address m_srcAddr; //!< Source address (2 Octets)
295 uint8_t m_radius; //!< Radius (1 Octet)
296 uint8_t m_seqNum; //!< Sequence number (1 Octet)
297 Mac64Address m_dstIeeeAddr; //!< Destination IEEE address (0 or 8 Octets)
298 Mac64Address m_srcIeeeAddr; //!< Source IEEE address (0 or 8 Octets)
299 // Multicast Control (1 Octet)
300 MulticastMode m_mcstMode{NONMEMBER}; //!< Multicast mode sub-field (Bits 0-1)
301 uint8_t m_nonMemberRadius; //!< Non member radius sub-field (Bits 2-4)
302 uint8_t m_maxNonMemberRadius; //!< Max non member radius sub-field (Bit 5-7)
303
304 // TODO: Add source route subframe
305 // uint8_t m_relayCount; //!< Relay Count Sub-Field
306 // uint8_t m_relayIndex; //!< Relay Index
307 // TODO: Add Relay List when supported
308};
309} // namespace zigbee
310} // namespace ns3
311
312#endif /* ZIGBEE_NWK_HEADER_H */
iterator in a Buffer instance
Definition buffer.h:89
Protocol header serialization and deserialization.
Definition header.h:33
This class can contain 16 bit addresses.
an EUI-64 address
a unique identifier for an interface.
Definition type-id.h:49
Represent the NWK Header with the Frame Control and Routing fields Zigbee Specification r22....
uint8_t GetMulticastControl() const
Get The Multicast control field.
void SetMulticast()
Set to true the value of the multicast flag in the frame control field.
void SetDstIeeeAddr(Mac64Address dst)
Set the destination IEEE address.
bool GetEndDeviceInitiator() const
Get whether or not the source of this message was an end device.
void SetDiscoverRoute(enum DiscoverRouteType discoverRoute)
Suppress or enable route discovery for this frame.
void SetSrcAddr(Mac16Address addr)
Set Source address.
void SetFrameControl(uint16_t frameControl)
Set the Frame control field.
uint8_t m_radius
Radius (1 Octet)
void SetEndDeviceInitiator()
This flag is used by the NWK to indicate if the the initiator device of the message is an end device ...
bool m_fctrlDstIEEEAddr
Destination IEEE address flag (Bit 11)
bool m_fctrlSecurity
Security flag (Bit 9)
Mac64Address m_srcIeeeAddr
Source IEEE address (0 or 8 Octets)
uint8_t m_fctrlPrtVer
Protocol version (Bit 2-5)
uint8_t m_maxNonMemberRadius
Max non member radius sub-field (Bit 5-7)
bool m_fctrlSrcRoute
Source route flag (Bit 10)
uint32_t GetSerializedSize() const override
uint32_t Deserialize(Buffer::Iterator start) override
DiscoverRouteType m_fctrlDscvRoute
Discover route (Bit 6-7)
uint16_t GetFrameControl() const
Get the Frame control field.
void SetProtocolVer(uint8_t ver)
Set the Protocol version.
static TypeId GetTypeId()
Get the type ID.
MulticastMode GetMulticastMode() const
Get the multicast mode.
bool m_fctrlEndDevIni
End device initiator flag (Bit 13)
bool IsMulticast() const
Inform whether or not the current frame is used in multicast.
void SetSeqNum(uint8_t seqNum)
Set the Sequence number.
void SetNonMemberRadius(uint8_t radius)
Set the non-member radius.
uint8_t m_nonMemberRadius
Non member radius sub-field (Bits 2-4)
uint8_t GetNonMemberRadius() const
Get the non-member radius.
uint8_t GetRadius() const
Get the Radius.
Mac64Address GetDstIeeeAddr() const
Get the destination IEEE address.
bool IsSecurityEnabled() const
Inform whether or not security is enabled.
uint8_t GetSeqNum() const
Get the frame Sequence number.
bool m_fctrlMcst
Multicast flag (Bit 8)
Mac64Address GetSrcIeeeAddr() const
Get the source IEEE address.
uint8_t m_seqNum
Sequence number (1 Octet)
Mac16Address m_dstAddr
Destination address (2 Octets)
void SetSrcIeeeAddr(Mac64Address src)
Set the source IEEE address.
NwkType GetFrameType() const
Set the Frame Control field "Frame Type" bits.
void Serialize(Buffer::Iterator start) const override
void SetRadius(uint8_t radius)
Set the Radius.
void SetMulticastMode(MulticastMode mode)
Set the multicast mode.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetFrameType(enum NwkType nwkType)
Set the Frame type used (Data or Command)
uint8_t GetMaxNonMemberRadius() const
Get the maximum non-member radius.
Mac64Address m_dstIeeeAddr
Destination IEEE address (0 or 8 Octets)
void SetMaxNonMemberRadius(uint8_t radius)
Set the maximum non-member radius.
NwkType m_fctrlFrmType
Frame type (Bit 0-1)
Mac16Address GetDstAddr() const
Get the Destination address.
void SetDstAddr(Mac16Address addr)
Set Destination address.
uint8_t GetProtocolVer() const
Get Frame protocol version.
DiscoverRouteType GetDiscoverRoute() const
Get the status of frame discovery route (suppress or enabled)
Mac16Address m_srcAddr
Source address (2 Octets)
Mac16Address GetSrcAddr() const
Get the Source address.
void Print(std::ostream &os) const override
MulticastMode m_mcstMode
Multicast mode sub-field (Bits 0-1)
void SetMulticastControl(uint8_t multicastControl)
Set the Multicast control field (mcstMode, nonMemberRadius, maxNonMemberRadius)
bool m_fctrlSrcIEEEAddr
Source IEEE address flag (Bit 12)
DiscoverRouteType
Zigbee Specification r22.1.0, Values of the discover route sub-field (Table 3-47)
@ SUPPRESS_ROUTE_DISCOVERY
Suppress route discovery.
@ ENABLE_ROUTE_DISCOVERY
Enable route discovery.
NwkType
Zigbee Specification r22.1.0, Values of the frame Type Sub-field (Table 3-46)
@ NWK_COMMAND
Network command frame type.
@ DATA
Data frame type.
@ INTER_PAN
Inter-Pan frame type.
MulticastMode
Zigbee Specification r22.1.0, Multicast Mode Sub-Field (Table 3-7)
@ MEMBER
Member multicast mode.
@ NONMEMBER
Non member multicast mode.
Every class exported by the ns3 library is enclosed in the ns3 namespace.