A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
zigbee-nwk-payload-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tokushima University, Tokushima, Japan.
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Ryo Okuda <c611901200@tokushima-u.ac.jp>
7 * Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
8 */
9
11
12#include "ns3/address-utils.h"
13#include "ns3/simulator.h"
14
15namespace ns3
16{
17namespace zigbee
18{
19
20/***********************************************************
21 * NWK Command Identifier
22 ***********************************************************/
23
28
30{
31 m_nwkCmdType = nwkCmdType;
32}
33
36{
37 static TypeId tid = TypeId("ns3::zigbee::ZigbeePayloadType")
39 .SetGroupName("Zigbee")
40 .AddConstructor<ZigbeePayloadType>();
41 return tid;
42}
43
49
50void
52{
53 m_nwkCmdType = nwkCmdType;
54}
55
61
64{
65 return 1;
66}
67
68void
74
77{
78 Buffer::Iterator i = start;
79 m_nwkCmdType = static_cast<NwkCommandType>(i.ReadU8());
80
81 return i.GetDistanceFrom(start);
82}
83
84void
85ZigbeePayloadType::Print(std::ostream& os) const
86{
87 os << "\nPayloadType = ";
88 switch (m_nwkCmdType)
89 {
90 case ROUTE_REQ_CMD:
91 os << "ROUTE_REQ\n";
92 break;
93 case ROUTE_REP_CMD:
94 os << "ROUTE_REP\n";
95 break;
96 case NWK_STATUS_CMD:
97 os << "NWK_STATUS\n";
98 break;
99 case LEAVE_CMD:
100 os << "LEAVE\n";
101 break;
102 case ROUTE_RECORD_CMD:
103 os << "ROUTE_RECORD\n";
104 break;
105 case REJOIN_REQ_CMD:
106 os << "REJOIN_REQ\n";
107 break;
108 case REJOIN_RESP_CMD:
109 os << "REJOIN_RESP\n";
110 break;
111 case LINK_STATUS_CMD:
112 os << "LINK_STATUS\n";
113 break;
114 case NWK_REPORT_CMD:
115 os << "NWK_REPORT \n";
116 break;
117 case NWK_UPDATE_CMD:
118 os << "NWK_UPDATE\n";
119 break;
120 case TIMEOUT_REQ_CMD:
121 os << "TIMEOUT_REQ\n";
122 break;
123 case TIMEOUT_RESP_CMD:
124 os << "TIMEOUT_RESP\n";
125 break;
127 os << "LINK_POWER_DELTA\n";
128 break;
129 default:
130 os << "UNKNOWN\n";
131 }
132}
133
134/***********************************************************
135 * Route Request Command
136 ***********************************************************/
137
146
147TypeId
149{
150 static TypeId tid = TypeId("ns3::zigbee::ZigbeePayloadRouteRequestCommand")
151 .SetParent<Header>()
152 .SetGroupName("Zigbee")
153 .AddConstructor<ZigbeePayloadRouteRequestCommand>();
154 return tid;
155}
156
157TypeId
162
165{
166 uint32_t size = 0;
167 size += 5; // (Command Option + Route request identifier + Destination address + Path cost)
169 {
170 size += 8;
171 }
172
173 return size;
174}
175
176void
189
192{
193 Buffer::Iterator i = start;
194 uint8_t cmdOptField = i.ReadU8();
195 SetCmdOptionField(cmdOptField);
196 m_routeReqId = (i.ReadU8());
197 m_dstAddr = (i.ReadU16());
198 m_pathCost = (i.ReadU8());
199
201 {
203 }
204
205 return i.GetDistanceFrom(start);
206}
207
208void
210{
211 os << "Multicast = " << static_cast<uint32_t>(m_cmdOptMcst)
212 << "| Route request identifier = " << static_cast<uint32_t>(m_routeReqId)
213 << "| Destination address = " << m_dstAddr
214 << "| Path cost = " << static_cast<uint32_t>(m_pathCost) << "| CmdOptFieldManyToOne = ";
215 switch (m_cmdOptManyToOne)
216 {
217 case NO_MANY_TO_ONE:
218 os << "NO_MANY_TO_ONE";
219 break;
220 case ROUTE_RECORD:
221 os << "ROUTE_RECORD";
222 break;
223 case NO_ROUTE_RECORD:
224 os << "NO_ROUTE_RECORD";
225 break;
226 }
227
229 {
230 os << "| Destination IEEE address = " << m_dstIeeeAddr;
231 }
232
233 os << "\n";
234}
235
236void
241
242uint8_t
247
248void
253
254uint8_t
259
260void
265
271
272void
277
278uint8_t
283
284bool
289
290void
296
302
303void
305{
306 m_cmdOptManyToOne = static_cast<ManyToOne>((cmdOptionField >> 3) & (0x03)); // Bit 3-4
307 m_cmdOptDstIeeeAddr = (cmdOptionField >> 5) & (0x01); // Bit 5
308 m_cmdOptMcst = (cmdOptionField >> 6) & (0x01); // Bit 6
309}
310
311uint8_t
313{
314 uint8_t val = 0;
315
316 val |= (m_cmdOptManyToOne << 3) & (0x03 << 3); // Bit 3-4
317 val |= (m_cmdOptDstIeeeAddr << 5) & (0x01 << 5); // Bit 5
318 val |= (m_cmdOptMcst << 6) & (0x01 << 6); // Bit 6
319
320 return val;
321}
322
323/***********************************************************
324 * Route Reply Command
325 ***********************************************************/
326
335
336TypeId
338{
339 static TypeId tid = TypeId("ns3::zigbee::ZigbeePayloadRouteReplyCommand")
340 .SetParent<Header>()
341 .SetGroupName("Zigbee")
342 .AddConstructor<ZigbeePayloadRouteReplyCommand>();
343 return tid;
344}
345
346TypeId
351
354{
355 uint32_t size = 0;
356 size += 7; // (Command Option + Route request identifier + Originator address + Responder
357 // address + Path cost)
359 {
360 size += 8;
361 }
362
364 {
365 size += 8;
366 }
367
368 return size;
369}
370
371void
373{
374 Buffer::Iterator i = start;
380 {
382 }
383
385 {
387 }
388}
389
392{
393 Buffer::Iterator i = start;
394 m_routeReqId = (i.ReadU8());
397 m_pathCost = (i.ReadU8());
399 {
401 }
402
404 {
406 }
407
408 return i.GetDistanceFrom(start);
409}
410
411void
413{
414 os << "| Command name = ROUTE_REP"
415 << "| Route request identifier = " << static_cast<uint32_t>(m_routeReqId)
416 << "| m_cmdOptOrigIeeeAddr = " << static_cast<uint32_t>(m_cmdOptOrigIeeeAddr)
417 << "| Originator address = " << m_origAddr << "| Responder address = " << m_respAddr
418 << "| Path cost = " << static_cast<uint32_t>(m_pathCost);
420 {
421 os << "| Originator IEEE address = " << m_origIeeeAddr;
422 }
423
425 {
426 os << "| Responder IEEE address = " << m_respIeeeAddr;
427 }
428
429 os << "\n";
430}
431
432void
437
438uint8_t
443
444void
449
455
456void
461
467
468void
470{
471 m_pathCost = cost;
472}
473
474uint8_t
479
480void
486
492
493void
499
505
506/***********************************************************
507 * Beacon Payload
508 ***********************************************************/
509
511{
512 m_protocolId = 0x00;
513 m_stackProfile = 0x00;
514 m_protocolVer = 0x00;
515 m_routerCapacity = false;
516 m_deviceDepth = 0x00;
517 m_endDevCapacity = false;
518 m_extPanId = 0x00;
519 m_txOffset = 0x00;
520 m_nwkUpdateId = 0x00;
521}
522
523TypeId
525{
526 static TypeId tid = TypeId("ns3::zigbee::ZigbeeBeaconPayload")
527 .SetParent<Header>()
528 .SetGroupName("Zigbee")
529 .AddConstructor<ZigbeeBeaconPayload>();
530 return tid;
531}
532
533TypeId
535{
536 return GetTypeId();
537}
538
541{
542 return 16;
543}
544
545void
547{
548 Buffer::Iterator i = start;
549 uint16_t dataBundle1 = 0;
550 uint32_t dataBundle2 = 0;
551
552 dataBundle1 = m_stackProfile & (0x0F); // Bit 0-3
553 dataBundle1 |= (m_protocolVer << 4) & (0x0F << 4); // Bit 4-7
554 dataBundle1 |= (m_routerCapacity << 10) & (0x01 << 10); // Bit 10
555 dataBundle1 |= (m_deviceDepth << 11) & (0x0F << 11); // Bit 11-14
556 dataBundle1 |= (m_endDevCapacity << 15) & (0x01 << 15); // Bit 15
557
558 dataBundle2 = m_txOffset & (0xFFFFFF); // Bit 0-23
559 dataBundle2 |= (m_nwkUpdateId << 24) & (0xFF << 24); // Bit 24-31
560
562 i.WriteHtolsbU16(dataBundle1);
564 i.WriteHtolsbU32(dataBundle2);
565}
566
569{
570 Buffer::Iterator i = start;
571 uint16_t dataBundle1 = 0;
572 uint32_t dataBundle2 = 0;
573
574 m_protocolId = i.ReadU8();
575 dataBundle1 = i.ReadLsbtohU16();
576 m_extPanId = i.ReadU64();
577 dataBundle2 = i.ReadLsbtohU32();
578
579 m_stackProfile = (dataBundle1) & (0x0F); // Bit 0-3
580 m_protocolVer = (dataBundle1 >> 4) & (0x0F); // Bit 4-7
581 m_routerCapacity = (dataBundle1 >> 10) & (0x01); // Bit 10
582 m_deviceDepth = (dataBundle1 >> 11) & (0x0F); // Bit 11-14
583 m_endDevCapacity = (dataBundle1 >> 15) & (0x01); // Bit 15
584
585 m_txOffset = (dataBundle2) & (0xFFFFFF); // Bit 0-23
586 m_nwkUpdateId = (dataBundle2 >> 24) & (0xFF); // Bit 24-31
587
588 return i.GetDistanceFrom(start);
589}
590
591void
592ZigbeeBeaconPayload::Print(std::ostream& os) const
593{
594 os << "\n";
595 os << " | Protocol Id = " << static_cast<uint32_t>(m_protocolId)
596 << " | Stack Profile = " << static_cast<uint32_t>(m_stackProfile)
597 << " | Nwk Protocol Version = " << static_cast<uint32_t>(m_protocolVer)
598 << " | Router Capacity = " << static_cast<uint32_t>(m_routerCapacity)
599 << " | Device Depth = " << static_cast<uint32_t>(m_deviceDepth)
600 << " | End Device Capacity = " << static_cast<uint32_t>(m_endDevCapacity)
601 << " | nwk Pan Id = " << static_cast<uint32_t>(m_extPanId)
602 << " | TxOffset = " << static_cast<uint32_t>(m_txOffset)
603 << " | Nwk Update Id = " << static_cast<uint32_t>(m_nwkUpdateId);
604
605 os << "\n";
606}
607
608void
610{
611 m_stackProfile = stackProfile;
612}
613
614uint8_t
619
620uint8_t
625
626void
628{
629 m_routerCapacity = routerCapacity;
630}
631
632bool
637
638void
640{
641 m_deviceDepth = deviceDepth;
642}
643
644uint8_t
649
650void
652{
653 m_endDevCapacity = endDevCapacity;
654}
655
656bool
661
662void
664{
665 m_extPanId = extPanId;
666}
667
668uint64_t
670{
671 return m_extPanId;
672}
673
674void
676{
677 m_txOffset = txOffset;
678}
679
682{
683 return m_txOffset;
684}
685
686void
688{
689 m_nwkUpdateId = nwkUpdateId;
690}
691
692uint8_t
697
698} // namespace zigbee
699} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU64(uint64_t data)
Definition buffer.cc:870
uint64_t ReadU64()
Definition buffer.cc:973
void WriteHtolsbU16(uint16_t data)
Definition buffer.cc:891
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtolsbU32(uint32_t data)
Definition buffer.cc:899
uint16_t ReadLsbtohU16()
Definition buffer.cc:1053
uint32_t GetDistanceFrom(const Iterator &o) const
Definition buffer.cc:769
uint16_t ReadU16()
Definition buffer.h:1024
uint32_t ReadLsbtohU32()
Definition buffer.cc:1065
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Represents the payload portion of a beacon frame.
bool GetRouterCapacity() const
Get the router capacity capability.
uint8_t GetNwkUpdateId() const
Get the value of the nwkUpdateId set to this beacon payload.
uint8_t m_protocolId
Identifies the network layer in use, in this specification this value is always 0.
void SetDeviceDepth(uint8_t deviceDepth)
Set the cevice depth object.
uint8_t GetProtocolId() const
Get the Protocol Id used.
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t m_stackProfile
The zigbee stack profile identifier.
bool m_routerCapacity
True if this device is capable of accepting join requests from router capable devices.
uint8_t GetStackProfile() const
Get the Stack Profile used.
uint8_t m_nwkUpdateId
The value of nwkUpdateId from the NIB.
uint64_t m_extPanId
The globally unique id for the PAN.
static TypeId GetTypeId()
Get the type ID.
void SetRouterCapacity(bool routerCapacity)
Set the Router Capacity capability True = The device is able to accept join.request from router-capab...
void SetNwkUpdateId(uint8_t nwkUpdateId)
Set the value of the nwkUpdateId to this beacon payload.
uint64_t GetExtPanId() const
Get the extended PAN identifier.
uint8_t GetDeviceDepth() const
Get the device depth.
void SetStackProfile(uint8_t stackProfile)
Set the network profile identifier.
void Serialize(Buffer::Iterator start) const override
void SetEndDevCapacity(bool endDevCapacity)
Set the end device Capacity.
void Print(std::ostream &os) const override
bool GetEndDevCapacity() const
Get the end dev capacity.
uint32_t m_txOffset
This indicates the difference in time, measured in symbols, between the beacon transmission time of i...
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetTxOffset(uint32_t txOffset)
Set the Tx Offset time in symbols.
void SetExtPanId(uint64_t extPanId)
Set the extended PAN id.
uint8_t m_deviceDepth
The network depth of this device.
bool m_endDevCapacity
True if the device is capable of accepting join request from end devices seeking to join the network.
uint8_t m_protocolVer
The version of the zigbee protocol.
uint32_t GetTxOffset() const
Get the Tx Offset time in symbols.
Represent a variable portion of the zigbee payload header that includes the route reply command.
uint32_t Deserialize(Buffer::Iterator start) override
bool m_cmdOptRespIeeeAddr
Responder IEEE address flag (Bit 5)
void SetRouteReqId(uint8_t rid)
Set the Route request identifier.
void SetRespIeeeAddr(Mac64Address resp)
Set the Responder IEEE address.
void SetOrigIeeeAddr(Mac64Address orig)
Set the Originator IEEE address.
Mac64Address m_origIeeeAddr
Originator IEEE address (0-8 Octets)
Mac16Address GetRespAddr() const
Get the Responder address.
Mac16Address GetOrigAddr() const
Get the Originator address.
void SetRespAddr(Mac16Address addr)
Set Responder address.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Serialize(Buffer::Iterator start) const override
bool m_cmdOptOrigIeeeAddr
Originator IEEE address flag (Bit 4)
Mac16Address m_origAddr
Originator address (2 Octets)
Mac64Address GetRespIeeeAddr() const
Get the Responder IEEE address.
uint8_t m_routeReqId
Route request identifier (1 Octet)
uint8_t GetRouteReqId() const
Get the Route request identifier.
Mac64Address GetOrigIeeeAddr() const
Get the Originator IEEE address.
void SetOrigAddr(Mac16Address addr)
Set Originator address.
void SetPathCost(uint8_t cost)
Set the path cost.
Mac16Address m_respAddr
Responder address (2 Octets)
Mac64Address m_respIeeeAddr
Responder IEEE address (0-8 Octets)
Represent a variable portion of the zigbee payload header that includes the route request command.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint8_t GetRouteReqId() const
Get the Route request identifier.
void Serialize(Buffer::Iterator start) const override
Mac64Address GetDstIeeeAddr() const
Get the destination IEEE address.
void SetCmdOptManyToOneField(enum ManyToOne manyToOne)
Set the command option field Many To One.
ManyToOne m_cmdOptManyToOne
Many to One Subfield (Bits 3-4)
bool m_cmdOptDstIeeeAddr
Destination IEEE Address Flag (Bit 5)
uint32_t Deserialize(Buffer::Iterator start) override
Mac16Address m_dstAddr
Destination address (2 Octets)
uint8_t GetCmdOptManyToOneField() const
Get the command option field Many To One.
void SetRouteReqId(uint8_t id)
Set the Route request identifier.
void SetDstAddr(Mac16Address addr)
Set Destination address.
Mac16Address GetDstAddr() const
Get the Destination address.
bool IsDstIeeeAddressPresent() const
Describe whether or not the destination IEEE Address field is present in the Route Request.
void SetCmdOptionField(uint8_t cmdOptionField)
Set the complete command option field of the route request command.
Mac64Address m_dstIeeeAddr
Destination IEEE address (0-8 Octets)
void SetDstIeeeAddr(Mac64Address dst)
Set the destination IEEE address.
uint8_t GetCmdOptionField() const
Get the 8bits representing the complete command option field of the route request command.
uint8_t m_routeReqId
Route request identifier (1 Octet)
Represent the static portion of the zigbee payload header that describes the payload command type.
static TypeId GetTypeId()
Get the type ID.
void SetCmdType(enum NwkCommandType nwkCmd)
Set the command frame type.
void Serialize(Buffer::Iterator start) const override
NwkCommandType m_nwkCmdType
The network command Type.
uint32_t Deserialize(Buffer::Iterator start) override
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void Print(std::ostream &os) const override
NwkCommandType GetCmdType() const
Get the command frame type.
uint32_t GetSerializedSize() const override
ManyToOne
Zigbee Specification 3.4.1.3.1 , Table 3-50 Values of the many to one command option field.
NwkCommandType
Zigbee Specification, Payload command types.
@ TIMEOUT_REQ_CMD
Time out request command.
@ TIMEOUT_RESP_CMD
Time out response command.
@ ROUTE_REP_CMD
Route response command.
@ LINK_POWER_DELTA_CMD
Link power delta command.
@ REJOIN_REQ_CMD
Rejoin request command.
@ LINK_STATUS_CMD
Link status command.
@ NWK_UPDATE_CMD
Network update command.
@ NWK_STATUS_CMD
Network status command.
@ REJOIN_RESP_CMD
Rejoin response command.
@ ROUTE_REQ_CMD
Route request command.
@ LEAVE_CMD
Leave network command.
@ ROUTE_RECORD_CMD
Route record command.
@ NWK_REPORT_CMD
Network report command.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.