A Discrete-Event Network Simulator
API
non-inheritance.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
18  */
19 
20 #include "non-inheritance.h"
21 
22 #include <algorithm>
23 #include <iterator>
24 
25 namespace ns3
26 {
27 
30 {
31  return IE_EXTENSION;
32 }
33 
36 {
38 }
39 
40 void
41 NonInheritance::Print(std::ostream& os) const
42 {
43  os << "NonInheritance=[";
44  std::copy(m_elemIdList.cbegin(), m_elemIdList.cend(), std::ostream_iterator<uint16_t>(os, " "));
45  os << "][";
46  std::copy(m_elemIdExtList.cbegin(),
47  m_elemIdExtList.cend(),
48  std::ostream_iterator<uint16_t>(os, " "));
49  os << "]";
50 }
51 
52 uint16_t
54 {
55  uint16_t size = 1; // Element ID Extension
56  size += 1 /* Length */ + m_elemIdList.size();
57  size += 1 /* Length */ + m_elemIdExtList.size();
58  return size;
59 }
60 
61 void
63 {
64  start.WriteU8(m_elemIdList.size());
65  for (const auto id : m_elemIdList)
66  {
67  start.WriteU8(id);
68  }
69  start.WriteU8(m_elemIdExtList.size());
70  for (const auto id : m_elemIdExtList)
71  {
72  start.WriteU8(id);
73  }
74 }
75 
76 uint16_t
78 {
79  auto i = start;
80  auto count = i.ReadU8();
81  for (uint8_t j = 0; j < count; j++)
82  {
83  m_elemIdList.emplace(i.ReadU8());
84  }
85  count = i.ReadU8();
86  for (uint8_t j = 0; j < count; j++)
87  {
88  m_elemIdExtList.emplace(i.ReadU8());
89  }
90  return i.GetDistanceFrom(start);
91 }
92 
93 void
94 NonInheritance::Add(uint8_t elemId, uint8_t elemIdExt)
95 {
96  elemId != IE_EXTENSION ? m_elemIdList.insert(elemId) : m_elemIdExtList.insert(elemIdExt);
97 }
98 
99 bool
100 NonInheritance::IsPresent(uint8_t elemId, uint8_t elemIdExt) const
101 {
102  return elemId != IE_EXTENSION ? m_elemIdList.count(elemId) == 1
103  : m_elemIdExtList.count(elemIdExt) == 1;
104 }
105 
106 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint16_t DeserializeInformationField(Buffer::Iterator start, uint16_t length) override
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets)
std::set< uint8_t > m_elemIdList
list of unique Element ID values (in increasing order)
bool IsPresent(uint8_t elemId, uint8_t elemIdExt=0) const
void Add(uint8_t elemId, uint8_t elemIdExt=0)
Add the Information Element specified by the given Element ID and Element ID Extension.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
uint16_t GetInformationFieldSize() const override
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
void SerializeInformationField(Buffer::Iterator start) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
WifiInformationElementId ElementIdExt() const override
Get the wifi information element ID extension.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
std::set< uint8_t > m_elemIdExtList
list of unique Element ID Extension values
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
#define IE_EXTENSION
#define IE_EXT_NON_INHERITANCE