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;
375
376 uint8_t cmdOption = 0;
378 {
379 cmdOption |= (1 << 4);
380 }
381
383 {
384 cmdOption |= (1 << 5);
385 }
386
387 if (m_cmdOptMcst)
388 {
389 cmdOption |= (1 << 6);
390 }
391 i.WriteU8(cmdOption);
392
397
399 {
401 }
402
404 {
406 }
407}
408
411{
412 Buffer::Iterator i = start;
413
414 uint8_t cmdOption = i.ReadU8();
415 m_cmdOptOrigIeeeAddr = (cmdOption & (1 << 4)) != 0;
416 m_cmdOptRespIeeeAddr = (cmdOption & (1 << 5)) != 0;
417 m_cmdOptMcst = (cmdOption & (1 << 6)) != 0;
418
419 m_routeReqId = (i.ReadU8());
422 m_pathCost = (i.ReadU8());
423
425 {
427 }
428
430 {
432 }
433
434 return i.GetDistanceFrom(start);
435}
436
437void
439{
440 os << "| Command name = ROUTE_REP"
441 << "| Route request identifier = " << static_cast<uint32_t>(m_routeReqId)
442 << "| m_cmdOptOrigIeeeAddr = " << static_cast<uint32_t>(m_cmdOptOrigIeeeAddr)
443 << "| Originator address = " << m_origAddr << "| Responder address = " << m_respAddr
444 << "| Path cost = " << static_cast<uint32_t>(m_pathCost);
446 {
447 os << "| Originator IEEE address = " << m_origIeeeAddr;
448 }
449
451 {
452 os << "| Responder IEEE address = " << m_respIeeeAddr;
453 }
454
455 os << "\n";
456}
457
458void
463
464uint8_t
469
470void
475
481
482void
487
493
494void
496{
497 m_pathCost = cost;
498}
499
500uint8_t
505
506void
512
518
519void
525
531
532/***********************************************************
533 * Beacon Payload
534 ***********************************************************/
535
537{
538 m_protocolId = 0x00;
539 m_stackProfile = 0x00;
540 m_protocolVer = 0x00;
541 m_routerCapacity = false;
542 m_deviceDepth = 0x00;
543 m_endDevCapacity = false;
544 m_extPanId = 0x00;
545 m_txOffset = 0x00;
546 m_nwkUpdateId = 0x00;
547}
548
549TypeId
551{
552 static TypeId tid = TypeId("ns3::zigbee::ZigbeeBeaconPayload")
553 .SetParent<Header>()
554 .SetGroupName("Zigbee")
555 .AddConstructor<ZigbeeBeaconPayload>();
556 return tid;
557}
558
559TypeId
561{
562 return GetTypeId();
563}
564
567{
568 return 16;
569}
570
571void
573{
574 Buffer::Iterator i = start;
575 uint16_t dataBundle1 = 0;
576 uint32_t dataBundle2 = 0;
577
578 dataBundle1 = m_stackProfile & (0x0F); // Bit 0-3
579 dataBundle1 |= (m_protocolVer << 4) & (0x0F << 4); // Bit 4-7
580 dataBundle1 |= (m_routerCapacity << 10) & (0x01 << 10); // Bit 10
581 dataBundle1 |= (m_deviceDepth << 11) & (0x0F << 11); // Bit 11-14
582 dataBundle1 |= (m_endDevCapacity << 15) & (0x01 << 15); // Bit 15
583
584 dataBundle2 = m_txOffset & (0xFFFFFF); // Bit 0-23
585 dataBundle2 |= (m_nwkUpdateId << 24) & (0xFF << 24); // Bit 24-31
586
588 i.WriteHtolsbU16(dataBundle1);
590 i.WriteHtolsbU32(dataBundle2);
591}
592
595{
596 Buffer::Iterator i = start;
597 uint16_t dataBundle1 = 0;
598 uint32_t dataBundle2 = 0;
599
600 m_protocolId = i.ReadU8();
601 dataBundle1 = i.ReadLsbtohU16();
602 m_extPanId = i.ReadU64();
603 dataBundle2 = i.ReadLsbtohU32();
604
605 m_stackProfile = (dataBundle1) & (0x0F); // Bit 0-3
606 m_protocolVer = (dataBundle1 >> 4) & (0x0F); // Bit 4-7
607 m_routerCapacity = (dataBundle1 >> 10) & (0x01); // Bit 10
608 m_deviceDepth = (dataBundle1 >> 11) & (0x0F); // Bit 11-14
609 m_endDevCapacity = (dataBundle1 >> 15) & (0x01); // Bit 15
610
611 m_txOffset = (dataBundle2) & (0xFFFFFF); // Bit 0-23
612 m_nwkUpdateId = (dataBundle2 >> 24) & (0xFF); // Bit 24-31
613
614 return i.GetDistanceFrom(start);
615}
616
617void
618ZigbeeBeaconPayload::Print(std::ostream& os) const
619{
620 os << "\n";
621 os << " | Protocol Id = " << static_cast<uint32_t>(m_protocolId)
622 << " | Stack Profile = " << static_cast<uint32_t>(m_stackProfile)
623 << " | Nwk Protocol Version = " << static_cast<uint32_t>(m_protocolVer)
624 << " | Router Capacity = " << static_cast<uint32_t>(m_routerCapacity)
625 << " | Device Depth = " << static_cast<uint32_t>(m_deviceDepth)
626 << " | End Device Capacity = " << static_cast<uint32_t>(m_endDevCapacity)
627 << " | nwk Pan Id = " << static_cast<uint32_t>(m_extPanId)
628 << " | TxOffset = " << static_cast<uint32_t>(m_txOffset)
629 << " | Nwk Update Id = " << static_cast<uint32_t>(m_nwkUpdateId);
630
631 os << "\n";
632}
633
634void
636{
637 m_stackProfile = stackProfile;
638}
639
640uint8_t
645
646uint8_t
651
652void
654{
655 m_routerCapacity = routerCapacity;
656}
657
658bool
663
664void
666{
667 m_deviceDepth = deviceDepth;
668}
669
670uint8_t
675
676void
678{
679 m_endDevCapacity = endDevCapacity;
680}
681
682bool
687
688void
690{
691 m_extPanId = extPanId;
692}
693
694uint64_t
696{
697 return m_extPanId;
698}
699
700void
702{
703 m_txOffset = txOffset;
704}
705
708{
709 return m_txOffset;
710}
711
712void
714{
715 m_nwkUpdateId = nwkUpdateId;
716}
717
718uint8_t
723
724} // namespace zigbee
725} // 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.