A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
zigbee-group-table.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 Tokushima University, Japan
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author:
7
* Alberto Gallegos Ramonet <alramonet@is.tokushima-u.ac.jp>
8
*/
9
10
#include "
zigbee-group-table.h
"
11
12
#include "ns3/log.h"
13
14
namespace
ns3
15
{
16
namespace
zigbee
17
{
18
19
NS_LOG_COMPONENT_DEFINE
(
"ZigbeeGroupTable"
);
20
21
ZigbeeGroupTable::ZigbeeGroupTable
() =
default
;
22
23
ZigbeeGroupTable::~ZigbeeGroupTable
() =
default
;
24
25
bool
26
ZigbeeGroupTable::AddEntry
(uint16_t groupId, uint8_t endPoint)
27
{
28
NS_LOG_FUNCTION
(
this
<< groupId <<
static_cast<
uint16_t
>
(endPoint));
29
30
if
(
m_groupTable
.size() ==
MAX_GROUP_ID_ENTRIES
)
31
{
32
NS_LOG_WARN
(
"Group table is full, cannot add group ID "
<< groupId);
33
return
false
;
// too many groups
34
}
35
36
// Check the group entry existence, if it does not exist, create it.
37
auto
& group =
m_groupTable
[groupId];
38
if
(group[endPoint])
39
{
40
NS_LOG_INFO
(
"Endpoint "
<<
static_cast<
uint16_t
>
(endPoint) <<
" already exists in group "
41
<< groupId);
42
return
false
;
// endPoint already in group
43
}
44
45
NS_LOG_INFO
(
"Adding endpoint "
<<
static_cast<
uint16_t
>
(endPoint) <<
" to group "
<< groupId);
46
group.set(endPoint);
47
return
true
;
48
}
49
50
bool
51
ZigbeeGroupTable::RemoveEntry
(uint16_t groupId, uint8_t endPoint)
52
{
53
NS_LOG_FUNCTION
(
this
<< groupId <<
static_cast<
uint16_t
>
(endPoint));
54
55
auto
group =
m_groupTable
.find(groupId);
56
auto
endPoints = group->second;
57
58
if
(group ==
m_groupTable
.end())
59
{
60
NS_LOG_WARN
(
"Group ID "
<< groupId <<
" does not exist, cannot remove endpoint "
61
<<
static_cast<
uint16_t
>
(endPoint));
62
return
false
;
// group doesn't exist
63
}
64
65
if
(!endPoints[endPoint])
66
{
67
NS_LOG_WARN
(
"Endpoint "
<<
static_cast<
uint16_t
>
(endPoint) <<
" not found in group "
68
<< groupId);
69
return
false
;
// endpoint not in this group
70
}
71
else
72
{
73
endPoints.reset(endPoint);
// Turn bit in bitset off (0)
74
NS_LOG_INFO
(
"Removed endpoint "
<<
static_cast<
uint16_t
>
(endPoint) <<
" from group "
75
<< groupId);
76
77
if
(endPoints.none())
78
{
79
m_groupTable
.erase(group);
// remove group if no endpoints left
80
}
81
return
true
;
// endpoint removed successfully
82
}
83
}
84
85
bool
86
ZigbeeGroupTable::RemoveMembership
(uint8_t endPoint)
87
{
88
NS_LOG_FUNCTION
(
this
<<
static_cast<
uint16_t
>
(endPoint));
89
90
bool
removed =
false
;
91
for
(
auto
group =
m_groupTable
.begin(); group !=
m_groupTable
.end(); ++group)
92
{
93
if
(group->second[endPoint])
94
{
95
group->second.reset(endPoint);
// Turn bit in bitset off (0)
96
NS_LOG_INFO
(
"Removed endpoint "
<<
static_cast<
uint16_t
>
(endPoint) <<
" from group "
97
<< group->first);
98
99
if
(group->second.none())
100
{
101
m_groupTable
.erase(group);
// remove group if no endpoints left
102
}
103
removed =
true
;
// endpoint removed successfully
104
}
105
}
106
return
removed;
107
}
108
109
bool
110
ZigbeeGroupTable::IsGroupMember
(uint16_t groupId)
const
111
{
112
return
m_groupTable
.find(groupId) !=
m_groupTable
.end();
113
}
114
115
bool
116
ZigbeeGroupTable::LookUpEndPoints
(uint16_t groupId, std::vector<uint8_t>& endPoints)
const
117
{
118
bool
hasEndPoints =
false
;
119
auto
group =
m_groupTable
.find(groupId);
120
121
if
(group ==
m_groupTable
.end())
122
{
123
NS_LOG_WARN
(
"Group ID "
<< groupId <<
" does not exist, cannot look up endpoints"
);
124
return
false
;
// group doesn't exist
125
}
126
127
for
(
auto
endpoint = 0; endpoint <
MAX_ENDPOINT_ENTRIES
; ++endpoint)
128
{
129
if
(group->second[endpoint])
130
{
131
endPoints.push_back(endpoint);
132
hasEndPoints =
true
;
133
}
134
}
135
return
hasEndPoints;
136
}
137
138
}
// namespace zigbee
139
}
// namespace ns3
ns3::zigbee::ZigbeeGroupTable::RemoveEntry
bool RemoveEntry(uint16_t groupId, uint8_t endPoint)
Remove endpoint from a group.
Definition
zigbee-group-table.cc:51
ns3::zigbee::ZigbeeGroupTable::IsGroupMember
bool IsGroupMember(uint16_t groupId) const
Indicates whether the group ID exists in the group table.
Definition
zigbee-group-table.cc:110
ns3::zigbee::ZigbeeGroupTable::m_groupTable
std::unordered_map< uint16_t, std::bitset< MAX_ENDPOINT_ENTRIES > > m_groupTable
The group table object.
Definition
zigbee-group-table.h:104
ns3::zigbee::ZigbeeGroupTable::MAX_ENDPOINT_ENTRIES
static constexpr int MAX_ENDPOINT_ENTRIES
The maximum amount of endpoints allowed per group id entry.
Definition
zigbee-group-table.h:101
ns3::zigbee::ZigbeeGroupTable::LookUpEndPoints
bool LookUpEndPoints(uint16_t groupId, std::vector< uint8_t > &endPoints) const
Look up the endpoints associated with a given group ID.
Definition
zigbee-group-table.cc:116
ns3::zigbee::ZigbeeGroupTable::ZigbeeGroupTable
ZigbeeGroupTable()
Constructor for Zigbee group table.
ns3::zigbee::ZigbeeGroupTable::RemoveMembership
bool RemoveMembership(uint8_t endPoint)
Remove the endPoint from all groups.
Definition
zigbee-group-table.cc:86
ns3::zigbee::ZigbeeGroupTable::~ZigbeeGroupTable
~ZigbeeGroupTable()
Destructor for Zigbee group table.
ns3::zigbee::ZigbeeGroupTable::MAX_GROUP_ID_ENTRIES
static constexpr int MAX_GROUP_ID_ENTRIES
The maximum amount of group ID entries allowed in the table.
Definition
zigbee-group-table.h:99
ns3::zigbee::ZigbeeGroupTable::AddEntry
bool AddEntry(uint16_t groupId, uint8_t endPoint)
Add a group ID and its related endpoint.
Definition
zigbee-group-table.cc:26
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition
log.h:250
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition
log.h:264
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
zigbee-group-table.h
src
zigbee
model
zigbee-group-table.cc
Generated on Tue Jul 15 2025 18:41:07 for ns-3 by
1.11.0