A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
zigbee-nwk-tables.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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#include "zigbee-nwk-tables.h"
12
13#include "ns3/log.h"
14#include "ns3/pointer.h"
15#include "ns3/simulator.h"
16
17#include <algorithm>
18#include <iomanip>
19
20namespace ns3
21{
22namespace zigbee
23{
24
25NS_LOG_COMPONENT_DEFINE("ZigbeeNwkTables");
26
27/***********************************************************
28 * RREQ Retry Table Entry
29 ***********************************************************/
30
32 EventId rreqRetryEvent,
33 uint8_t rreqRetryCount)
34{
35 m_rreqId = rreqId;
36 m_rreqRetryEventId = rreqRetryEvent;
37 m_rreqRetryCount = rreqRetryCount;
38}
39
40uint8_t
42{
43 return m_rreqId;
44}
45
46void
48{
49 m_rreqRetryCount = rreqRetryCount;
50}
51
52uint8_t
57
58void
63
69
70void
72{
73 std::ostream* os = stream->GetStream();
74 std::ios oldState(nullptr);
75 oldState.copyfmt(*os);
76
77 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
78 *os << std::setw(9) << static_cast<uint32_t>(m_rreqId);
79 *os << std::setw(12) << static_cast<uint32_t>(m_rreqRetryCount);
80 *os << std::setw(9) << (m_rreqRetryEventId.IsPending() ? "TRUE" : "FALSE");
81 *os << std::endl;
82 (*os).copyfmt(oldState);
83}
84
85/***********************************************************
86 * RREQ Retry Table
87 ***********************************************************/
88bool
90{
91 m_rreqRetryTable.emplace_back(entry);
92 return true;
93}
94
95bool
97{
98 NS_LOG_FUNCTION(this << rreqId);
99
100 for (const auto& entry : m_rreqRetryTable)
101 {
102 if (entry->GetRreqId() == rreqId)
103 {
104 entryFound = entry;
105 return true;
106 }
107 }
108 return false;
109}
110
111void
113{
114 std::erase_if(m_rreqRetryTable, [&rreqId](Ptr<RreqRetryTableEntry> entry) {
115 return entry->GetRreqId() == rreqId;
116 });
117}
118
119void
121{
122 for (auto element : m_rreqRetryTable)
123 {
124 element = nullptr;
125 }
126 m_rreqRetryTable.clear();
127}
128
129void
131{
132 std::ostream* os = stream->GetStream();
133 std::ios oldState(nullptr);
134 oldState.copyfmt(*os);
135
136 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
137 *os << "ZigBee RREQ retry table\n";
138 *os << std::setw(9) << "RREQ ID";
139 *os << std::setw(12) << "RREQ Count";
140 *os << std::setw(9) << "Pending" << std::endl;
141
142 for (const auto& entry : m_rreqRetryTable)
143 {
144 entry->Print(stream);
145 }
146 *stream->GetStream() << std::endl;
147}
148
149/***********************************************************
150 * Routing Table Entry
151 ***********************************************************/
152
154 RouteStatus status,
155 bool noRouteCache,
156 bool manyToOne,
157 bool routeRecordReq,
158 bool groupID,
159 Mac16Address nextHopAddr)
160{
161 m_destination = dst;
162 m_nextHopAddr = nextHopAddr;
163 m_status = status;
164 m_noRouteCache = noRouteCache;
165 m_manyToOne = manyToOne;
166 m_routeRecordReq = routeRecordReq;
167 m_groupId = groupID;
168}
169
173
177
178void
183
189
190void
192{
193 m_status = status;
194}
195
198{
199 return m_status;
200}
201
202bool
207
208bool
210{
211 return m_manyToOne;
212}
213
214bool
219
220bool
222{
223 return m_groupId;
224}
225
226void
228{
229 m_nextHopAddr = nextHopAddr;
230}
231
237
238void
243
244Time
249
250void
252{
253 std::ostream* os = stream->GetStream();
254 std::ios oldState(nullptr);
255 oldState.copyfmt(*os);
256
257 std::ostringstream dst;
258 std::ostringstream nextHop;
259
260 dst << m_destination;
261 nextHop << m_nextHopAddr;
262
263 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
264 *os << std::setw(16) << dst.str();
265 *os << std::setw(10) << nextHop.str();
266
267 switch (m_status)
268 {
269 case ROUTE_ACTIVE:
270 *os << std::setw(21) << "ACTIVE";
271 break;
273 *os << std::setw(21) << "DISCOVERY_UNDERWAY";
274 break;
276 *os << std::setw(21) << "DISCOVERY_FAILED";
277 break;
278 case ROUTE_INACTIVE:
279 *os << std::setw(21) << "INACTIVE";
280 break;
282 *os << std::setw(21) << "VALIDATION_UNDERWAY";
283 break;
284 }
285
286 *os << std::setw(16) << (m_noRouteCache ? "TRUE" : "FALSE");
287 *os << std::setw(16) << (m_manyToOne ? "TRUE" : "FALSE");
288 *os << std::setw(16) << (m_routeRecordReq ? "TRUE" : "FALSE");
289 *os << std::setw(16) << (m_groupId ? "TRUE" : "FALSE");
290 *os << std::endl;
291 (*os).copyfmt(oldState);
292}
293
294/***********************************************************
295 * Routing Table
296 ***********************************************************/
297
302
303bool
305{
306 if (m_routingTable.size() < m_maxTableSize)
307 {
308 m_routingTable.emplace_back(rt);
309 return true;
310 }
311 else
312 {
313 return false;
314 }
315}
316
317void
319{
320 std::erase_if(m_routingTable, [](Ptr<RoutingTableEntry> entry) {
321 return Simulator::Now() >= entry->GetLifeTime();
322 });
323}
324
325void
327{
328 for (const auto& entry : m_routingTable)
329 {
330 if (Simulator::Now() >= entry->GetLifeTime())
331 {
332 entry->SetStatus(ROUTE_INACTIVE);
333 }
334 }
335}
336
337void
339{
340 std::erase_if(m_routingTable,
341 [&dst](Ptr<RoutingTableEntry> entry) { return entry->GetDestination() == dst; });
342}
343
344void
346{
347 auto it = std::find_if(
348 m_routingTable.begin(),
349 m_routingTable.end(),
350 [](Ptr<RoutingTableEntry> entry) { return entry->GetStatus() == ROUTE_INACTIVE; });
351
352 if (it != m_routingTable.end())
353 {
354 m_routingTable.erase(it);
355 }
356}
357
358bool
360{
361 NS_LOG_FUNCTION(this << dstAddr);
362
364
365 for (const auto& entry : m_routingTable)
366 {
367 if (entry->GetDestination() == dstAddr)
368 {
369 entryFound = entry;
370 return true;
371 }
372 }
373 return false;
374}
375
376void
378{
379 std::ostream* os = stream->GetStream();
380 std::ios oldState(nullptr);
381 oldState.copyfmt(*os);
382
383 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
384 *os << "ZigBee Routing table\n";
385 *os << std::setw(16) << "Destination";
386 *os << std::setw(10) << "Next hop";
387 *os << std::setw(21) << "Status";
388 *os << std::setw(16) << "No route cache";
389 *os << std::setw(16) << "Many-to-one";
390 *os << std::setw(16) << "Route record";
391 *os << std::setw(16) << "Group Id flag" << std::endl;
392
393 for (const auto& entry : m_routingTable)
394 {
395 entry->Print(stream);
396 }
397 *stream->GetStream() << std::endl;
398}
399
400void
402{
403 for (auto element : m_routingTable)
404 {
405 element = nullptr;
406 }
407 m_routingTable.clear();
408}
409
412{
413 return m_routingTable.size();
414}
415
416void
421
424{
425 return m_maxTableSize;
426}
427
428/***********************************************************
429 * Routing Discovery Table Entry
430 ***********************************************************/
431
433 Mac16Address src,
434 Mac16Address snd,
435 uint8_t forwardCost,
436 uint8_t residualCost,
437 Time expTime)
438{
439 m_routeRequestId = rreqId;
440 m_sourceAddr = src;
441 m_senderAddr = snd;
442 m_forwardCost = forwardCost;
443 m_residualCost = residualCost;
444 m_expirationTime = expTime;
445}
446
450
454
455uint8_t
460
466
472
473uint8_t
478
479uint8_t
484
485void
487{
488 m_forwardCost = pathCost;
489}
490
491void
496
497void
499{
500 m_residualCost = pathcost;
501}
502
503Time
508
509void
514
515void
517{
518 std::ostream* os = stream->GetStream();
519 std::ios oldState(nullptr);
520 oldState.copyfmt(*os);
521
522 std::ostringstream sourceAddr;
523 std::ostringstream senderAddr;
524 std::ostringstream expTime;
525
526 sourceAddr << m_sourceAddr;
527 senderAddr << m_senderAddr;
528 expTime << m_expirationTime.As(Time::S);
529
530 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
531 *os << std::setw(10) << static_cast<uint32_t>(m_routeRequestId);
532 *os << std::setw(16) << sourceAddr.str();
533 *os << std::setw(16) << senderAddr.str();
534 *os << std::setw(16) << static_cast<uint32_t>(m_forwardCost);
535 *os << std::setw(16) << static_cast<uint32_t>(m_residualCost);
536 *os << std::setw(16) << expTime.str();
537 *os << std::endl;
538
539 (*os).copyfmt(oldState);
540}
541
542/***********************************************************
543 * Route Discovery Table
544 ***********************************************************/
545
550
551bool
553{
554 Purge();
555
556 if (m_routeDscTable.size() < m_maxTableSize)
557 {
558 m_routeDscTable.emplace_back(rt);
559 return true;
560 }
561 else
562 {
563 return false;
564 }
565}
566
567bool
569 Mac16Address src,
571{
572 NS_LOG_FUNCTION(this << id);
573 Purge();
574 for (const auto& entry : m_routeDscTable)
575 {
576 if (entry->GetRreqId() == id && entry->GetSourceAddr() == src)
577 {
578 entryFound = entry;
579 return true;
580 }
581 }
582 return false;
583}
584
585void
587{
588 std::erase_if(m_routeDscTable, [](Ptr<RouteDiscoveryTableEntry> entry) {
589 return entry->GetExpTime() < Simulator::Now();
590 });
591}
592
593void
595{
596 std::erase_if(m_routeDscTable, [&id, &src](Ptr<RouteDiscoveryTableEntry> entry) {
597 return (entry->GetRreqId() == id && entry->GetSourceAddr() == src);
598 });
599}
600
601void
603{
604 Purge();
605
606 std::ostream* os = stream->GetStream();
607 std::ios oldState(nullptr);
608 oldState.copyfmt(*os);
609
610 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
611 *os << "ZigBee Route Discovery table\n";
612 *os << std::setw(10) << "RREQ ID";
613 *os << std::setw(16) << "Source Address";
614 *os << std::setw(16) << "Sender Address";
615 *os << std::setw(16) << "Forward Cost";
616 *os << std::setw(16) << "Residual Cost";
617 *os << "Expiration time" << std::endl;
618
619 for (const auto& entry : m_routeDscTable)
620 {
621 entry->Print(stream);
622 }
623 *stream->GetStream() << std::endl;
624}
625
626void
628{
629 for (auto element : m_routeDscTable)
630 {
631 element = nullptr;
632 }
633 m_routeDscTable.clear();
634}
635
636/***********************************************************
637 * Neighbor Table Entry
638 ***********************************************************/
639
641 Mac16Address nwkAddr,
642 NwkDeviceType deviceType,
643 bool rxOnWhenIdle,
644 uint16_t endDevConfig,
645 Time timeoutCounter,
646 Time devTimeout,
647 Relationship relationship,
648 uint8_t txFailure,
649 uint8_t lqi,
650 uint8_t outgoingCost,
651 uint8_t age,
652 bool keepaliveRx,
653 uint8_t macInterfaceIndex)
654{
655 m_extAddr = extAddr;
656 m_nwkAddr = nwkAddr;
657 m_deviceType = deviceType;
658 m_rxOnWhenIdle = rxOnWhenIdle;
659 m_endDevConfig = endDevConfig;
660 m_timeoutCounter = timeoutCounter;
661 m_devTimeout = devTimeout;
662 m_relationship = relationship;
663 m_txFailure = txFailure;
664 m_lqi = lqi;
665 m_outgoingCost = outgoingCost;
666 m_age = age;
667 m_keepaliveRx = keepaliveRx;
668 m_macInterfaceIndex = macInterfaceIndex;
669}
670
674
678
681{
682 return m_extAddr;
683}
684
687{
688 return m_nwkAddr;
689}
690
696
697bool
702
703uint16_t
708
709Time
714
715Time
720
721uint8_t
726
727uint8_t
729{
730 return m_txFailure;
731}
732
733uint8_t
735{
736 return m_lqi;
737}
738
739uint8_t
744
745uint8_t
747{
748 return m_age;
749}
750
751uint64_t
756
757uint64_t
762
763uint8_t
768
774
780
781uint64_t
783{
784 return m_extPanId;
785}
786
787uint8_t
789{
790 return m_logicalCh;
791}
792
793uint8_t
795{
796 return m_depth;
797}
798
799uint8_t
801{
802 return m_bo;
803}
804
805uint8_t
810
811void
813{
814 m_nwkAddr = nwkAddr;
815}
816
817void
822
823void
825{
826 m_rxOnWhenIdle = onWhenIdle;
827}
828
829void
834
835void
840
841void
846
847void
849{
850 m_relationship = relationship;
851}
852
853void
855{
856 m_txFailure = failure;
857}
858
859void
861{
862 m_lqi = lqi;
863}
864
865void
867{
868 m_outgoingCost = cost;
869}
870
871void
873{
874 m_age = age;
875}
876
877void
879{
880 m_incBeaconTimestamp = timestamp;
881}
882
883void
888
889void
894
895void
900
901void
903{
904 m_extPanId = extPanId;
905}
906
907void
909{
910 m_logicalCh = channel;
911}
912
913void
915{
916 m_depth = depth;
917}
918
919void
921{
922 m_bo = bo;
923}
924
925void
927{
928 m_potentialParent = confirm;
929}
930
931void
933{
934 std::ostream* os = stream->GetStream();
935 std::ios oldState(nullptr);
936 oldState.copyfmt(*os);
937
938 std::ostringstream extAddr;
939 std::ostringstream nwkAddr;
940 std::ostringstream devTimeout;
941
942 extAddr << m_extAddr;
943 nwkAddr << m_nwkAddr;
944 devTimeout << m_devTimeout;
945
946 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
947 *os << std::setw(25) << extAddr.str();
948 *os << std::setw(13) << nwkAddr.str();
949 *os << std::setw(16) << devTimeout.str();
950 switch (m_relationship)
951 {
952 case NBR_PARENT:
953 *os << std::setw(16) << "PARENT";
954 break;
955 case NBR_CHILD:
956 *os << std::setw(16) << "CHILD";
957 break;
958 case NBR_SIBLING:
959 *os << std::setw(16) << "SIBLING";
960 break;
961 case NBR_NONE:
962 *os << std::setw(16) << "NONE";
963 break;
964 case NBR_PREV_CHILD:
965 *os << std::setw(16) << "PREVIOUS CHILD";
966 break;
967 case NBR_UNAUTH_CHILD:
968 *os << std::setw(16) << "UNAUTH CHILD";
969 break;
970 }
971
972 switch (m_deviceType)
973 {
975 *os << std::setw(16) << "COORDINATOR";
976 break;
977 case ZIGBEE_ROUTER:
978 *os << std::setw(16) << "ROUTER";
979 break;
980 case ZIGBEE_ENDDEVICE:
981 *os << std::setw(16) << "END DEVICE";
982 break;
983 }
984
985 *os << std::setw(14) << static_cast<uint16_t>(m_txFailure);
986 *os << std::setw(5) << static_cast<uint16_t>(m_lqi);
987 *os << std::setw(16) << static_cast<uint16_t>(m_outgoingCost);
988 *os << std::setw(8) << static_cast<uint16_t>(m_age);
989 *os << std::setw(19) << std::hex << m_extPanId << std::dec;
990 *os << std::setw(11) << (m_potentialParent ? "TRUE" : "FALSE");
991 *os << std::endl;
992 (*os).copyfmt(oldState);
993}
994
995/***********************************************************
996 * Neighbor Table
997 ***********************************************************/
998
1003
1004bool
1006{
1007 if (m_neighborTable.size() < m_maxTableSize)
1008 {
1009 m_neighborTable.emplace_back(entry);
1010 return true;
1011 }
1012 else
1013 {
1014 return false;
1015 }
1016}
1017
1018void
1020{
1021 std::erase_if(m_neighborTable, [](Ptr<NeighborTableEntry> entry) {
1022 return Simulator::Now() >= entry->GetTimeoutCounter();
1023 });
1024}
1025
1026void
1028{
1029 std::erase_if(m_neighborTable, [&extAddr](Ptr<NeighborTableEntry> entry) {
1030 return entry->GetExtAddr() == extAddr;
1031 });
1032}
1033
1034bool
1036{
1037 NS_LOG_FUNCTION(this << nwkAddr);
1038 // Purge();
1039
1040 for (const auto& entry : m_neighborTable)
1041 {
1042 if (entry->GetNwkAddr() == nwkAddr)
1043 {
1044 entryFound = entry;
1045 return true;
1046 }
1047 }
1048
1049 return false;
1050}
1051
1052bool
1054{
1055 NS_LOG_FUNCTION(this << extAddr);
1056 // Purge();
1057
1058 for (const auto& entry : m_neighborTable)
1059 {
1060 if (entry->GetExtAddr() == extAddr)
1061 {
1062 entryFound = entry;
1063 return true;
1064 }
1065 }
1066
1067 return false;
1068}
1069
1070bool
1072{
1073 NS_LOG_FUNCTION(this);
1074
1075 for (const auto& entry : m_neighborTable)
1076 {
1077 if (entry->GetRelationship() == NBR_PARENT)
1078 {
1079 entryFound = entry;
1080 return true;
1081 }
1082 }
1083
1084 return false;
1085}
1086
1087bool
1089{
1090 bool flag = false;
1091 uint8_t currentLinkCost = 7;
1092 uint8_t prevLinkCost = 8;
1093
1094 for (const auto& entry : m_neighborTable)
1095 {
1096 // Note: Permit to join, stack profile , update id and capability are checked when
1097 // the beacon is received (beacon notify indication)
1098 currentLinkCost = GetLinkCost(entry->GetLqi());
1099
1100 if ((epid == entry->GetExtPanId()) &&
1101 (entry->GetDeviceType() == ZIGBEE_COORDINATOR ||
1102 entry->GetDeviceType() == ZIGBEE_ROUTER) &&
1103 (entry->IsPotentialParent()) && (currentLinkCost <= 3))
1104 {
1105 if (currentLinkCost < prevLinkCost)
1106 {
1107 entryFound = entry;
1108 prevLinkCost = currentLinkCost;
1109 }
1110 entryFound = entry;
1111 flag = true;
1112 }
1113 }
1114
1115 return flag;
1116}
1117
1118void
1120{
1121 std::ostream* os = stream->GetStream();
1122 std::ios oldState(nullptr);
1123 oldState.copyfmt(*os);
1124
1125 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
1126 *os << "ZigBee Neighbor Table\n";
1127 *os << std::setw(25) << "IEEE Address";
1128 *os << std::setw(13) << "Nwk Address";
1129 *os << std::setw(16) << "Device Timeout";
1130 *os << std::setw(16) << "Relationship";
1131 *os << std::setw(16) << "Device type";
1132 *os << std::setw(14) << "Tx Failure";
1133 *os << std::setw(5) << "LQI";
1134 *os << std::setw(16) << "Outgoing Cost";
1135 *os << std::setw(8) << "Age";
1136 *os << std::setw(19) << "Ext PAN ID";
1137 *os << std::setw(11) << "Pot. Parent";
1138 *os << std::endl;
1139
1140 for (const auto& entry : m_neighborTable)
1141 {
1142 entry->Print(stream);
1143 }
1144 *stream->GetStream() << std::endl;
1145}
1146
1149{
1150 return m_neighborTable.size();
1151}
1152
1153void
1158
1161{
1162 return m_maxTableSize;
1163}
1164
1165uint8_t
1167{
1168 NS_ASSERT_MSG(lqi <= 255, "LQI does not have a valid range");
1169
1170 uint8_t linkCost;
1171
1172 if (lqi >= 240)
1173 {
1174 linkCost = 1;
1175 }
1176 else if (lqi >= 202)
1177 {
1178 linkCost = 2;
1179 }
1180 else if (lqi >= 154)
1181 {
1182 linkCost = 3;
1183 }
1184 else if (lqi >= 106)
1185 {
1186 linkCost = 4;
1187 }
1188 else if (lqi >= 58)
1189 {
1190 linkCost = 5;
1191 }
1192 else if (lqi >= 11)
1193 {
1194 linkCost = 6;
1195 }
1196 else
1197 {
1198 linkCost = 7;
1199 }
1200
1201 return linkCost;
1202}
1203
1204void
1206{
1207 for (auto element : m_neighborTable)
1208 {
1209 element = nullptr;
1210 }
1211 m_neighborTable.clear();
1212}
1213
1214/***********************************************************
1215 * PAN Id Table
1216 ***********************************************************/
1217
1221
1222void
1223PanIdTable::AddEntry(uint64_t extPanId, uint16_t panId)
1224{
1225 auto i = m_panIdTable.find(extPanId);
1226 if (i == m_panIdTable.end())
1227 {
1228 // New entry
1229 m_panIdTable.emplace(extPanId, panId);
1230
1231 NS_LOG_DEBUG("[New entry, Pan ID Table]"
1232 " | ExtPANId: "
1233 << extPanId << " | PAN Id: " << panId);
1234 }
1235 else
1236 {
1237 // Update entry
1238 if (panId != i->second)
1239 {
1240 m_panIdTable[extPanId] = panId;
1241 }
1242 }
1243}
1244
1245bool
1246PanIdTable::GetEntry(uint64_t extPanId, uint16_t& panId)
1247{
1248 auto i = m_panIdTable.find(extPanId);
1249
1250 if (i == m_panIdTable.end())
1251 {
1252 return false;
1253 }
1254
1255 panId = i->second;
1256 return true;
1257}
1258
1259void
1261{
1262 m_panIdTable.clear();
1263}
1264
1265/***********************************************************
1266 * Broadcast Transaction Table (BTT)
1267 ***********************************************************/
1268
1272
1273bool
1275{
1276 Purge();
1277 m_broadcastTransactionTable.emplace_back(entry);
1278 return true;
1279}
1280
1286
1287void
1292
1298
1299bool
1301{
1302 NS_LOG_FUNCTION(this << seq);
1303 Purge();
1304
1305 for (const auto& entry : m_broadcastTransactionTable)
1306 {
1307 if (entry->GetSeqNum() == seq)
1308 {
1309 entryFound = entry;
1310 return true;
1311 }
1312 }
1313 return false;
1314}
1315
1316void
1318{
1320 return Simulator::Now() >= btr->GetExpirationTime();
1321 });
1322}
1323
1324void
1326{
1327 for (auto element : m_broadcastTransactionTable)
1328 {
1329 element = nullptr;
1330 }
1332}
1333
1334void
1336{
1337 std::ostream* os = stream->GetStream();
1338 std::ios oldState(nullptr);
1339 oldState.copyfmt(*os);
1340
1341 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
1342 *os << "ZigBee Routing table\n";
1343 *os << std::setw(16) << "SrcAddress";
1344 *os << std::setw(16) << "Seq. Num";
1345 *os << std::setw(16) << "Expiration";
1346 *os << std::setw(16) << "Count" << std::endl;
1347
1348 for (const auto& entry : m_broadcastTransactionTable)
1349 {
1350 entry->Print(stream);
1351 }
1352 *stream->GetStream() << std::endl;
1353}
1354
1355/***********************************************************
1356 * Broadcast Transaction Record (BTR)
1357 ***********************************************************/
1358
1360{
1361 m_srcAddr = srcAddr;
1362 m_sequenceNumber = seq;
1363 m_expirationTime = exp;
1365}
1366
1370
1374
1377{
1378 return m_srcAddr;
1379}
1380
1381void
1386
1387uint8_t
1392
1393void
1395{
1396 m_sequenceNumber = seq;
1397}
1398
1399Time
1404
1405void
1410
1411uint8_t
1416
1417void
1422
1423void
1425{
1426 std::ostream* os = stream->GetStream();
1427 std::ios oldState(nullptr);
1428 oldState.copyfmt(*os);
1429
1430 std::ostringstream sourceAddr;
1431 std::ostringstream seq;
1432 std::ostringstream expTime;
1433 std::ostringstream count;
1434
1435 sourceAddr << m_srcAddr;
1436 seq << m_sequenceNumber;
1437 expTime << (m_expirationTime - Simulator::Now()).As(Time::S);
1438 count << m_broadcastRetryCount;
1439
1440 *os << std::resetiosflags(std::ios::adjustfield) << std::setiosflags(std::ios::left);
1441 *os << std::setw(16) << sourceAddr.str();
1442 *os << std::setw(16) << static_cast<uint32_t>(m_sequenceNumber);
1443 *os << std::setw(16) << expTime.str();
1444 *os << std::setw(16) << static_cast<uint32_t>(m_broadcastRetryCount);
1445 *os << std::endl;
1446 (*os).copyfmt(oldState);
1447}
1448
1449} // namespace zigbee
1450} // namespace ns3
An identifier for simulation events.
Definition event-id.h:45
bool IsPending() const
This method is syntactic sugar for !IsExpired().
Definition event-id.cc:65
This class can contain 16 bit addresses.
an EUI-64 address
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ S
second
Definition nstime.h:105
Mac16Address GetSrcAddr() const
Get the source address of the BTR.
void SetSrcAddr(Mac16Address srcAddr)
Set the source address of the BTR.
uint8_t GetBcstRetryCount() const
Get the broadcast retry count value.
void SetSeqNum(uint8_t seq)
Set the sequence number of the BTR.
uint8_t m_sequenceNumber
The RREQ sequence number of the initiator's broadcast.
uint8_t m_broadcastRetryCount
The number of times this BCST has been retried.
uint8_t GetSeqNum() const
Get the sequence number of the BTR.
void SetBcstRetryCount(uint8_t count)
Set the Broadcast retry count object.
Time GetExpirationTime() const
Get the value of the expiration time in the BTR.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the values of the BTR.
Time m_expirationTime
An indicator of when the entry expires.
Mac16Address m_srcAddr
The 16-bit network address of the broadcast initiator.
void SetExpirationTime(Time exp)
Set the expiration time object.
void Dispose()
Dispose of all broadcast transaction records (BTR) in the broadcast transaction table(BTT).
void Print(Ptr< OutputStreamWrapper > stream)
Print the broadcast transaction table (BTT)
uint32_t m_maxTableSize
The maximum size of the Broadcast Transaction table.
void Purge()
Purge expired entries from the broadcast transaction table (BTT).
void SetMaxTableSize(uint32_t size)
Set the maximum size of the broadcast transaction table (BTT)
std::deque< Ptr< BroadcastTransactionRecord > > m_broadcastTransactionTable
The list object representing the broadcast transaction table (BTT)
uint32_t GetMaxTableSize() const
Get the maximum size of the broadcast transaction table (BTT)
uint32_t GetSize()
Get the current Size of the broadcast transaction table (BTT).
bool AddEntry(Ptr< BroadcastTransactionRecord > entry)
Add a broadcast transaction record (BTR) to the broadcast transaction table(BTT).
bool LookUpEntry(uint8_t seq, Ptr< BroadcastTransactionRecord > &entryFound)
Look up for broadcast transaction record in the broadcast transaction table (BTT).
uint8_t GetRelationship() const
Get the relationship object.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the values of the neighbor table entry.
uint64_t m_extPanId
The extendend PAN id (based on the Zigbee coordinator EUI-64 address)
uint8_t GetLogicalCh() const
Get the logical channel used by the the neighbor in this entry.
Time GetTimeoutCounter() const
Get the timeout counter object.
uint32_t GetMacUcstBytesTx() const
Get the number of unicast bytes transmitted to the neighbor registered in this entry.
void SetOutgoingCost(uint8_t cost)
Set the outgoing cost object.
Mac64Address m_extAddr
The IEEE EUI-64 bit address that is unique to every device.
uint8_t GetLqi() const
Get the LQI value from this device to an entry neighbor.
Time GetDevTimeout() const
Get the device timeout object.
uint8_t GetMacInterfaceIndex() const
Get the MAC Interface Index object.
uint32_t GetMacUcstBytesRx() const
Get the number of unicast bytes received to the neighbor registered in this entry.
uint8_t m_outgoingCost
The cost of the outgoing link as measured by the neighbor.
void SetNwkAddr(Mac16Address nwkAddr)
Set the entry registered Network address (MAC short address).
uint64_t GetExtPanId() const
Get the extended PAN identifier.
void SetMacUcstBytesRx(uint32_t rxBytes)
Set the number of unicast bytes received to the neighbor registered in this entry.
uint8_t m_lqi
The estimated link quality for RF transmissions from this device See Zigbee specification r22....
uint64_t m_incBeaconTimestamp
The time in symbols at which the last beacon frame was received from the neighbor.
void SetLqi(uint8_t lqi)
Set the Link quality indicator value from this device to an entry neighbor.
uint8_t m_bo
The beacon order of the device (See IEEE 802.15.4-2011)
uint8_t IsPotentialParent() const
Get the the value of the potential parent field.
uint8_t GetAge() const
Get the number of nwkLinkStatusPeriod intervals since the link status command was received.
void SetIncBeaconTimestamp(uint64_t timestamp)
Set the time in symbols at which the last beacon frame was received from the neighbor.
Mac16Address m_nwkAddr
The 16 bit network address of the neighboring device.
uint32_t m_macUcstBytesRx
The number of bytes received via MAC unicasts from this neighbor (Optional field).
Time m_timeoutCounter
Indicates the current time remaining in seconds, for the end device.
void SetRxOnWhenIdle(bool onWhenIdle)
Set the device is on when idle flag.
uint8_t m_depth
The tree depth of the neighbor device.
uint16_t m_endDevConfig
The end device configuration.
void SetBeaconOrder(uint8_t bo)
Set the value of the beacon order set in this neighbor.
~NeighborTableEntry()
void SetTimeoutCounter(Time counter)
Set the timeout counter object.
uint64_t m_beaconTxTimeOffset
The transmission time difference in symbols, between the neighbor's beacon and its parent beacon (Opt...
NwkDeviceType GetDeviceType() const
Get the device type of this neighbor device.
void SetLogicalCh(uint8_t channel)
Set the logical channel used by the the neighbor in this entry.
uint64_t GetBeaconTxTimeOffset() const
Get the transmission time difference in symbols, between the neighbor's beacon and its parent beacon.
bool m_rxOnWhenIdle
Indicates if the neighbor receiver is enabled during idle periods.
uint8_t m_logicalCh
The logical channel on which the network is operating.
void SetBeaconTxTimeOffset(uint64_t offset)
Set the transmission time difference in symbols, between the neighbor's beacon and its parent beacon.
void SetRelationship(Relationship relationship)
Set the relationship object.
Mac16Address GetNwkAddr() const
Get the entry registered Network address (MAC short address).
void SetPotentialParent(bool confirm)
Set the the value of the potential parent field.
Relationship m_relationship
Relationship between the neighbor and the current device.
Mac64Address GetExtAddr() const
Get the entry registered IEEE address (EUI-64 address).
bool m_keepaliveRx
This value indicates at least one keepalive has been received from the end device since the router ha...
uint8_t m_txFailure
A value indicating if previous transmissions to the device were successful or not.
void SetTxFailure(uint8_t failure)
Set the Tx Failure object.
void SetDeviceType(NwkDeviceType devType)
Set the device type of this neighbor device.
void SetEndDevConfig(uint16_t conf)
Set the end device configuration.
void SetDevTimeout(Time timeout)
Set the device timeout object.
bool IsRxOnWhenIdle() const
Return true is neighboring device is on when idle.
uint16_t GetEndDevConfig() const
Get the end device configuration object.
uint8_t GetDepth() const
The depth of the neighbor device.
uint8_t GetOutgoingCost() const
Get the outgoing cost object.
uint8_t GetTxFailure() const
Get the Tx Failure object.
bool m_potentialParent
An indication of whether the device has been ruled out as a potential parent.
void SetAge(uint8_t age)
Set the number of nwkLinkStatusPeriod intervals since the link status command was received.
uint8_t GetBeaconOrder() const
Get the value of the beacon order set in this neighbor.
uint32_t m_macUcstBytesTx
The number of bytes transmitted via MAC unicast to the neighbor (Optional field).
uint8_t m_macInterfaceIndex
This is an index into the MAC Interface Table indicating what interface the neighbor or child is boun...
Time m_devTimeout
This field indicates the timeout, in seconds, for the end device child.
void SetMacUcstBytesTx(uint32_t txBytes)
Set the number of unicast bytes transmitted to the neighbor registered in this entry.
void SetDepth(uint8_t depth)
Set the depth of the neighbor device.
uint8_t m_age
The number of nwkLinkStatusPeriod intervals since link status command was received.
uint64_t GetIncBeaconTimestamp() const
Get the time in symbols at which the last beacon frame was received from the neighbor.
NwkDeviceType m_deviceType
The type of neighbor device.
void SetExtPanId(uint64_t extPanId)
Set the extended PAN identifier.
NeighborTableEntry()
bool GetParent(Ptr< NeighborTableEntry > &entryFound)
Look for this device Parent neighbor (A.K.A coordinator).
void Dispose()
Dispose of the table and all its elements.
void SetMaxTableSize(uint32_t size)
Set the maximum size of the neighbor table.
bool LookUpForBestParent(uint64_t epid, Ptr< NeighborTableEntry > &entryFound)
Perform a search for the best candidate parent based on some attributes.
NeighborTable()
The neighbor table constructor.
std::deque< Ptr< NeighborTableEntry > > m_neighborTable
The neighbor table object.
uint8_t GetLinkCost(uint8_t lqi) const
Get the link cost based on the link quality indicator (LQI) value.
bool AddEntry(Ptr< NeighborTableEntry > entry)
Add an entry to the neighbor table.
uint32_t m_maxTableSize
The maximum size of the neighbor table.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the neighbor table.
void Purge()
Remove old entries from the neighbor table.
bool LookUpEntry(Mac16Address nwkAddr, Ptr< NeighborTableEntry > &entryFound)
Look and return and entry if exists in the neighbor table.
uint32_t GetSize()
Get the size of the neighbor table.
void Delete(Mac64Address extAddr)
Delete the specified entry from the neighbor table.
uint32_t GetMaxTableSize() const
Get the maximum size of the neighbor table.
std::map< uint64_t, uint16_t > m_panIdTable
The Map object that represents the table of PAN ids.
bool GetEntry(uint64_t extPanId, uint16_t &panId)
Get the 16 bit MAC PAN id based on the reference extended PAN id.
void AddEntry(uint64_t extPanId, uint16_t panId)
Add an entry to the PAN Id table.
PanIdTable()
The constructor of the PanIdTable.
void Dispose()
Dispose of the table and all its elements.
Time m_expirationTime
A time stamp indicating the expiration time.
void SetSenderAddr(Mac16Address sender)
Set the sender address of this entry.
void SetExpTime(Time exp)
Set the expiration time of the route discovery entry.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the values of the route discovery table entry.
Mac16Address m_senderAddr
The 16-bit network address of the device that has sent the most recent lowest cost RREQ command frame...
uint8_t m_routeRequestId
The sequence number for a RREQ command frame that is incremented each time a device initiates a RREQ.
void SetResidualCost(uint8_t pathcost)
Set the resulting pathcost on a reception of a RREP previously requested.
uint8_t GetRreqId() const
Get the route request id (The sequence number used by the RREQ command frame).
Mac16Address m_sourceAddr
The 16-bit network address of the RREQ initiator.
Mac16Address GetSenderAddr() const
Get the sender address of the entry.
uint8_t GetResidualCost() const
Get the value of a residual cost (pathcost) updated by a RREP in this entry.
uint8_t m_residualCost
The accumulated path cost from the current device to the destination device.
~RouteDiscoveryTableEntry()
uint8_t m_forwardCost
The accumulated path cost from the source of the RREQ to the current device.
Mac16Address GetSourceAddr() const
Get the source address of the entry's RREQ initiator.
uint8_t GetForwardCost() const
Get the forward cost of this entry.
Time GetExpTime() const
Get the expiration time of this entry.
RouteDiscoveryTableEntry()
void SetForwardCost(uint8_t pathCost)
Set the forward cost of this entry.
std::deque< Ptr< RouteDiscoveryTableEntry > > m_routeDscTable
The route discovery table object.
RouteDiscoveryTable()
Constructor of route discovery table.
void Purge()
Purge old entries from the route discovery table.
void Dispose()
Dispose of the table and all its elements.
void Delete(uint8_t id, Mac16Address src)
Delete an entry from the route discovery table.
bool AddEntry(Ptr< RouteDiscoveryTableEntry > rt)
Add an entry to the route discovery table, in essence the contents of a RREQ command.
uint32_t m_maxTableSize
The maximum size of the route discovery table.
bool LookUpEntry(uint8_t id, Mac16Address src, Ptr< RouteDiscoveryTableEntry > &entryFound)
Look up for a route discovery table entry, the seareched entry must match the id and the src address ...
void Print(Ptr< OutputStreamWrapper > stream)
Print the contents of the route discovery table.
RoutingTableEntry()
bool IsGroupIdPresent() const
Indicates if the Group Id flag is active.
bool m_noRouteCache
A flag indicating that the destination indicated by this address does not store source routes.
void SetNextHopAddr(Mac16Address nextHopAddr)
Set the value of the next hop address.
Mac16Address m_nextHopAddr
The 16 bit network address of the next hop on the way to the destination.
void SetLifeTime(Time lt)
Set the lifetime of the entry.
RouteStatus m_status
The status of the route.
bool m_manyToOne
A flag indicating that the destination is a concentrator that issued a many-to-one route request.
void SetStatus(RouteStatus status)
Set the status of the routing table entry.
bool m_routeRecordReq
A flag indicating that the route record command frame should be sent to the destination prior to the ...
Mac16Address GetNextHopAddr() const
Get the value of the next hop address.
bool m_groupId
A flag indicating that the destination address is a group id.
~RoutingTableEntry()
bool IsNoRouteCache() const
Indicates if the No Route Cache flag is active.
bool IsRouteRecordReq() const
Indicate if the route record request is active.
Time GetLifeTime() const
Get the value of the entry lifetime.
RouteStatus GetStatus() const
Get the status of the routing table entry.
Mac16Address m_destination
The 16 bit network address or group id of this route.
Mac16Address GetDestination() const
Get the entry destination nwkAddress(MAC 16-bit address)
bool IsManyToOne() const
Indicates if the Many-to-One flag is active.
void SetDestination(Mac16Address dst)
Set the entry destination nwkAddress (MAC 16-bit address)
void Print(Ptr< OutputStreamWrapper > stream) const
Print the values of the routing table entry.
Time m_lifeTime
Indicates the lifetime of the entry.
void DeleteExpiredEntry()
Delete the first occrurance of an expired entry (ROUTE_INACTIVE status)
uint32_t m_maxTableSize
The maximum size of the routing table;.
bool AddEntry(Ptr< RoutingTableEntry > rt)
Adds an entry to the routing table.
void Delete(Mac16Address dst)
Remove an entry from the routing table.
uint32_t GetMaxTableSize() const
Get the maximum size of the routing table.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the Routing table.
uint32_t GetSize()
Get the size of the routing table.
bool LookUpEntry(Mac16Address dstAddr, Ptr< RoutingTableEntry > &entryFound)
Look for an specific entry in the routing table.
void IdentifyExpiredEntries()
Identify and mark entries as ROUTE_INACTIVE status for entries who have exceeded their lifetimes.
void SetMaxTableSize(uint32_t size)
Set the maximum size of the routing table.
RoutingTable()
The constructuctor of a Routing Table object.
void Purge()
Purge old entries from the routing table.
std::deque< Ptr< RoutingTableEntry > > m_routingTable
The object that represents the routing table.
void Dispose()
Dispose of the table and all its elements.
EventId m_rreqRetryEventId
The event id of the next RREQ retry callback.
EventId GetRreqEventId()
Get the RREQ id of the RREQ retry.
uint8_t m_rreqRetryCount
The number of RREQ retries.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the values of the RREQ retry table entry.
uint8_t GetRreqId() const
Get the RREQ Id from the entry.
RreqRetryTableEntry(uint8_t rreqId, EventId rreqRetryEvent, uint8_t rreqRetryCount)
The constructor of the RREQ retry table entry.
void SetRreqEventId(EventId eventId)
Set the event id of the RREQ retry.
uint8_t m_rreqId
The RREQ ID.
void SetRreqRetryCount(uint8_t rreqRetryCount)
Set the RREQ retry count from the entry.
uint8_t GetRreqRetryCount() const
Get the RREQ retry count from the entry.
std::deque< Ptr< RreqRetryTableEntry > > m_rreqRetryTable
The Table containing RREQ Table entries.
void Print(Ptr< OutputStreamWrapper > stream) const
Print the neighbor table.
void Dispose()
Dispose of the table and all its elements.
bool LookUpEntry(uint8_t rreqId, Ptr< RreqRetryTableEntry > &entryFound)
Look up for an entry in the table.
void Delete(uint8_t rreqId)
Delete an entry from the table using the RREQ ID.
bool AddEntry(Ptr< RreqRetryTableEntry > entry)
Adds an entry to the table.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
NwkDeviceType
The network layer device type.
RouteStatus
Route record states.
Relationship
The relationship between the neighbor and the current device.
@ ZIGBEE_COORDINATOR
Zigbee coordinator.
@ ZIGBEE_ENDDEVICE
Zigbee end device.
@ ZIGBEE_ROUTER
Zigbee router.
@ ROUTE_VALIDATION_UNDERWAY
Route discovery validation underway.
@ ROUTE_ACTIVE
Route active.
@ ROUTE_INACTIVE
Route inactive.
@ ROUTE_DISCOVER_FAILED
Route discovery failed.
@ ROUTE_DISCOVERY_UNDERWAY
Route discovery underway.
@ NBR_UNAUTH_CHILD
Neighbor is an unauthenticated child.
@ NBR_PREV_CHILD
Neighbor was a previous child.
@ NBR_CHILD
Neighbor is the child.
@ NBR_SIBLING
Neighbor is the sibling.
@ NBR_PARENT
Neighbor is the parent.
@ NBR_NONE
No relationship.
Definition conf.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Time timeout