A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tid-to-link-mapping-element.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sharan Naribole <sharan.naribole@gmail.com>
18 */
19
20#include <ns3/assert.h>
21#include <ns3/tid-to-link-mapping-element.h>
22
23namespace ns3
24{
25
26uint16_t
28{
29 // IEEE 802.11be D2.0 Figure 9-1002an
31 "Presence bitmap not expected if default mapping is set");
34 {
35 return size;
36 }
38}
39
40void
42{
43 uint8_t val = static_cast<uint8_t>(direction);
44 val |= ((defaultMapping ? 1 : 0) << 2);
45 start.WriteU8(val);
46 NS_ASSERT_MSG(defaultMapping != presenceBitmap.has_value(),
47 "Presence bitmap not expected if default mapping is set");
48 if (presenceBitmap.has_value())
49 {
50 start.WriteU8(presenceBitmap.value());
51 }
52}
53
54uint16_t
56{
57 auto i = start;
58 uint8_t count = 0;
59 auto val = i.ReadU8();
60 count++;
61
62 direction = static_cast<TidLinkMapDir>(val & 0x03);
63 defaultMapping = (((val >> 2) & 0x01) == 1);
64 if (defaultMapping)
65 {
66 return count;
67 }
68 presenceBitmap = i.ReadU8();
69 return ++count;
70}
71
74{
75 return IE_EXTENSION;
76}
77
80{
82}
83
84void
85TidToLinkMapping::SetLinkMappingOfTid(uint8_t tid, std::list<uint8_t> linkIds)
86{
87 NS_ABORT_MSG_IF(tid > 7, "Invalid tid: " << +tid);
89 "Per-TID link mapping not expected if default mapping is set");
90
91 // derive link mapping for the given TID
92 uint16_t linkMapping = 0;
93
94 for (const auto& linkId : linkIds)
95 {
96 linkMapping |= (1 << linkId);
97 }
98
99 m_linkMapping[tid] = linkMapping;
100
101 if (!m_control.presenceBitmap.has_value())
102 {
104 }
105 *m_control.presenceBitmap |= (1 << tid);
106}
107
108std::list<uint8_t>
110{
111 auto it = m_linkMapping.find(tid);
112
113 if (it == m_linkMapping.end())
114 {
115 return {};
116 }
117
118 std::list<uint8_t> linkIds;
119 for (uint8_t linkId = 0; linkId < 15; linkId++)
120 {
121 if (((it->second >> linkId) & 0x0001) == 1)
122 {
123 linkIds.push_back(linkId);
124 }
125 }
126
127 return linkIds;
128}
129
130uint16_t
132{
133 // IEEE 802.11be D2.0 9.4.2.314 TID-To-Link Mapping element
134 uint16_t ret = WIFI_IE_ELEMENT_ID_EXT_SIZE; // Element ID Extension
135 ret += m_control.GetSubfieldSize();
137 "Per-TID link mapping not expected if default mapping is set");
139 return ret;
140}
141
142void
144{
145 // IEEE 802.11be D2.0 9.4.2.314 TID-To-Link Mapping element
146 m_control.Serialize(start);
148 "Per-TID link mapping not expected if default mapping is set");
149
150 for (const auto& [tid, linkMapping] : m_linkMapping)
151 {
152 start.WriteHtolsbU16(linkMapping);
153 }
154}
155
156uint16_t
158{
159 auto i = start;
160 uint16_t count = 0;
161 auto nCtrlOctets = m_control.Deserialize(i);
162 NS_ASSERT_MSG(nCtrlOctets <= length, "Tid-to-Link Mapping deserialize error");
163 i.Next(nCtrlOctets);
164 count += nCtrlOctets;
165 m_linkMapping.clear();
166 if (m_control.presenceBitmap.has_value())
167 {
169 "Default mapping should not be set when presence bitmap is present");
170 const auto presenceBitmap = m_control.presenceBitmap.value();
171 for (uint8_t tid = 0; tid < 8; tid++)
172 {
173 if (((presenceBitmap >> tid) & 0x01) == 1)
174 {
175 m_linkMapping[tid] = i.ReadLsbtohU16();
176 count += 2;
177 }
178 }
179 }
180
181 NS_ABORT_MSG_IF(count != length,
182 "TID-to-Link Mapping Length (" << +length
183 << ") differs "
184 "from actual number of bytes read ("
185 << +count << ")");
186 return count;
187}
188
189} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
#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:86
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
Every class exported by the ns3 library is enclosed in the ns3 namespace.
constexpr uint16_t WIFI_TID_TO_LINK_MAPPING_CONTROL_BASIC_SIZE_B
size in bytes of the TID-To-Link Control field with default link mapping
TidLinkMapDir
TID-to-Link Mapping Control Direction IEEE 802.11be D2.0 Figure 9-1002an.
constexpr uint16_t WIFI_LINK_MAPPING_PER_TID_SIZE_B
size in bytes of the Link Mapping Of TID n field (IEEE 802.11be D2.0 9.4.2.314)
constexpr uint8_t WIFI_IE_ELEMENT_ID_EXT_SIZE
Size in bytes of the Element ID Extension field (IEEE 802.11-2020 9.4.2.1 General)
constexpr uint16_t WIFI_LINK_MAPPING_PRESENCE_IND_SIZE_B
size in bytes of the Link Mapping Presence Indicator field (IEEE 802.11be D2.0 9.4....
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_EXTENSION
#define IE_EXT_TID_TO_LINK_MAPPING_ELEMENT