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
308
309bool
314
315void
317{
318 m_cmdOptManyToOne = static_cast<ManyToOne>((cmdOptionField >> 3) & (0x03)); // Bit 3-4
319 m_cmdOptDstIeeeAddr = (cmdOptionField >> 5) & (0x01); // Bit 5
320 m_cmdOptMcst = (cmdOptionField >> 6) & (0x01); // Bit 6
321}
322
323uint8_t
325{
326 uint8_t val = 0;
327
328 val |= (m_cmdOptManyToOne << 3) & (0x03 << 3); // Bit 3-4
329 val |= (m_cmdOptDstIeeeAddr << 5) & (0x01 << 5); // Bit 5
330 val |= (m_cmdOptMcst << 6) & (0x01 << 6); // Bit 6
331
332 return val;
333}
334
335/***********************************************************
336 * Route Reply Command
337 ***********************************************************/
338
347
348TypeId
350{
351 static TypeId tid = TypeId("ns3::zigbee::ZigbeePayloadRouteReplyCommand")
352 .SetParent<Header>()
353 .SetGroupName("Zigbee")
354 .AddConstructor<ZigbeePayloadRouteReplyCommand>();
355 return tid;
356}
357
358TypeId
363
366{
367 uint32_t size = 0;
368 size += 7; // (Command Option + Route request identifier + Originator address + Responder
369 // address + Path cost)
371 {
372 size += 8;
373 }
374
376 {
377 size += 8;
378 }
379
380 return size;
381}
382
383void
385{
386 Buffer::Iterator i = start;
387
388 uint8_t cmdOption = 0;
390 {
391 cmdOption |= (1 << 4);
392 }
393
395 {
396 cmdOption |= (1 << 5);
397 }
398
399 if (m_cmdOptMcst)
400 {
401 cmdOption |= (1 << 6);
402 }
403 i.WriteU8(cmdOption);
404
409
411 {
413 }
414
416 {
418 }
419}
420
423{
424 Buffer::Iterator i = start;
425
426 uint8_t cmdOption = i.ReadU8();
427 m_cmdOptOrigIeeeAddr = (cmdOption & (1 << 4)) != 0;
428 m_cmdOptRespIeeeAddr = (cmdOption & (1 << 5)) != 0;
429 m_cmdOptMcst = (cmdOption & (1 << 6)) != 0;
430
431 m_routeReqId = (i.ReadU8());
434 m_pathCost = (i.ReadU8());
435
437 {
439 }
440
442 {
444 }
445
446 return i.GetDistanceFrom(start);
447}
448
449void
451{
452 os << "| Command name = ROUTE_REP"
453 << "| Route request identifier = " << static_cast<uint32_t>(m_routeReqId)
454 << "| m_cmdOptOrigIeeeAddr = " << static_cast<uint32_t>(m_cmdOptOrigIeeeAddr)
455 << "| Originator address = " << m_origAddr << "| Responder address = " << m_respAddr
456 << "| Path cost = " << static_cast<uint32_t>(m_pathCost);
458 {
459 os << "| Originator IEEE address = " << m_origIeeeAddr;
460 }
461
463 {
464 os << "| Responder IEEE address = " << m_respIeeeAddr;
465 }
466
467 os << "\n";
468}
469
470void
475
476uint8_t
481
482void
487
493
494void
499
505
506void
508{
509 m_pathCost = cost;
510}
511
512uint8_t
517
518void
524
530
531void
537
543
544/***********************************************************
545 * Beacon Payload
546 ***********************************************************/
547
549{
550 m_protocolId = 0x00;
551 m_stackProfile = 0x00;
552 m_protocolVer = 0x00;
553 m_routerCapacity = false;
554 m_deviceDepth = 0x00;
555 m_endDevCapacity = false;
556 m_extPanId = 0x00;
557 m_txOffset = 0x00;
558 m_nwkUpdateId = 0x00;
559}
560
561TypeId
563{
564 static TypeId tid = TypeId("ns3::zigbee::ZigbeeBeaconPayload")
565 .SetParent<Header>()
566 .SetGroupName("Zigbee")
567 .AddConstructor<ZigbeeBeaconPayload>();
568 return tid;
569}
570
571TypeId
573{
574 return GetTypeId();
575}
576
579{
580 return 16;
581}
582
583void
585{
586 Buffer::Iterator i = start;
587 uint16_t dataBundle1 = 0;
588 uint32_t dataBundle2 = 0;
589
590 dataBundle1 = m_stackProfile & (0x0F); // Bit 0-3
591 dataBundle1 |= (m_protocolVer << 4) & (0x0F << 4); // Bit 4-7
592 dataBundle1 |= (m_routerCapacity << 10) & (0x01 << 10); // Bit 10
593 dataBundle1 |= (m_deviceDepth << 11) & (0x0F << 11); // Bit 11-14
594 dataBundle1 |= (m_endDevCapacity << 15) & (0x01 << 15); // Bit 15
595
596 dataBundle2 = m_txOffset & (0xFFFFFF); // Bit 0-23
597 dataBundle2 |= (m_nwkUpdateId << 24) & (0xFF << 24); // Bit 24-31
598
600 i.WriteHtolsbU16(dataBundle1);
602 i.WriteHtolsbU32(dataBundle2);
603}
604
607{
608 Buffer::Iterator i = start;
609 uint16_t dataBundle1 = 0;
610 uint32_t dataBundle2 = 0;
611
612 m_protocolId = i.ReadU8();
613 dataBundle1 = i.ReadLsbtohU16();
614 m_extPanId = i.ReadU64();
615 dataBundle2 = i.ReadLsbtohU32();
616
617 m_stackProfile = (dataBundle1) & (0x0F); // Bit 0-3
618 m_protocolVer = (dataBundle1 >> 4) & (0x0F); // Bit 4-7
619 m_routerCapacity = (dataBundle1 >> 10) & (0x01); // Bit 10
620 m_deviceDepth = (dataBundle1 >> 11) & (0x0F); // Bit 11-14
621 m_endDevCapacity = (dataBundle1 >> 15) & (0x01); // Bit 15
622
623 m_txOffset = (dataBundle2) & (0xFFFFFF); // Bit 0-23
624 m_nwkUpdateId = (dataBundle2 >> 24) & (0xFF); // Bit 24-31
625
626 return i.GetDistanceFrom(start);
627}
628
629void
630ZigbeeBeaconPayload::Print(std::ostream& os) const
631{
632 os << "\n";
633 os << " | Protocol Id = " << static_cast<uint32_t>(m_protocolId)
634 << " | Stack Profile = " << static_cast<uint32_t>(m_stackProfile)
635 << " | Nwk Protocol Version = " << static_cast<uint32_t>(m_protocolVer)
636 << " | Router Capacity = " << static_cast<uint32_t>(m_routerCapacity)
637 << " | Device Depth = " << static_cast<uint32_t>(m_deviceDepth)
638 << " | End Device Capacity = " << static_cast<uint32_t>(m_endDevCapacity)
639 << " | nwk Pan Id = " << static_cast<uint32_t>(m_extPanId)
640 << " | TxOffset = " << static_cast<uint32_t>(m_txOffset)
641 << " | Nwk Update Id = " << static_cast<uint32_t>(m_nwkUpdateId);
642
643 os << "\n";
644}
645
646void
648{
649 m_stackProfile = stackProfile;
650}
651
652uint8_t
657
658uint8_t
663
664void
666{
667 m_routerCapacity = routerCapacity;
668}
669
670bool
675
676void
678{
679 m_deviceDepth = deviceDepth;
680}
681
682uint8_t
687
688void
690{
691 m_endDevCapacity = endDevCapacity;
692}
693
694bool
699
700void
702{
703 m_extPanId = extPanId;
704}
705
706uint64_t
708{
709 return m_extPanId;
710}
711
712void
714{
715 m_txOffset = txOffset;
716}
717
720{
721 return m_txOffset;
722}
723
724void
726{
727 m_nwkUpdateId = nwkUpdateId;
728}
729
730uint8_t
735
736} // namespace zigbee
737} // 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 (64-bit) contained in the route request command.
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 SetMulticastField(bool mcst)
Set the command option multicast field.
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.
bool GetMulticastField() const
Get the command option multicast field.
Mac64Address m_dstIeeeAddr
Destination IEEE address (0-8 Octets)
void SetDstIeeeAddr(Mac64Address dst)
Set the destination IEEE address, also automatically sets the command option DstIeeeAddr field.
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.