A Discrete-Event Network Simulator
API
ie-dot11s-perr.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008,2009 IITP RAS
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: Kirill Andreev <andreev@iitp.ru>
18  */
19 
20 #include "ie-dot11s-perr.h"
21 
22 #include "ns3/address-utils.h"
23 #include "ns3/packet.h"
24 
25 namespace ns3
26 {
27 namespace dot11s
28 {
30 {
31 }
32 
34 {
35 }
36 
39 {
40  return IE_PERR;
41 }
42 
43 void
44 IePerr::Print(std::ostream& os) const
45 {
46  os << "PERR=(Number of failed destinations=" << m_addressUnits.size();
47  for (unsigned int j = 0; j < m_addressUnits.size(); j++)
48  {
49  os << "(Failed destination address=" << m_addressUnits[j].destination
50  << ", sequence number = " << m_addressUnits[j].seqnum << ")";
51  }
52  os << ")";
53 }
54 
55 uint8_t
57 {
58  return m_addressUnits.size();
59 }
60 
61 void
63 {
64  i.WriteU8(0); // TTL
65  i.WriteU8(m_addressUnits.size()); // number of Destinations
66  for (unsigned int j = 0; j < m_addressUnits.size(); j++)
67  {
68  i.WriteU8(0); // not used // Bit 6: AE (Address Extension) subfield (1 = destination
69  // external address is present, 0 = otherwise).
70  WriteTo(i, m_addressUnits[j].destination);
71  i.WriteHtolsbU32(m_addressUnits[j].seqnum);
72  i.WriteU8(0);
73  i.WriteU8(0);
74  }
75 }
76 
77 uint16_t
79 {
81  i.Next(1); // TTL //Mode flags is not used now
82  uint8_t numOfDest = i.ReadU8();
83  NS_ABORT_UNLESS((2 + 13 * numOfDest) == length);
84 
85  for (unsigned int j = 0; j < numOfDest; j++)
86  {
87  i.Next(1); // flags is not used now
89  ReadFrom(i, unit.destination);
90  unit.seqnum = i.ReadLsbtohU32();
91  m_addressUnits.push_back(unit);
92  i.Next(2); // Reason
93  }
94  return i.GetDistanceFrom(start);
95 }
96 
97 uint16_t
99 {
100  uint16_t retval = 1 // TTL //ModeFlags
101  + 1 // NumOfDests
102  + 1 * m_addressUnits.size() // ModeFlags
103  + (6 + 4) * m_addressUnits.size() + 2 * m_addressUnits.size(); // Reason Code
104  return retval;
105 }
106 
107 void
109 {
110  for (unsigned int i = 0; i < m_addressUnits.size(); i++)
111  {
112  if (m_addressUnits[i].destination == unit.destination)
113  {
114  return;
115  }
116  }
117  if ((m_addressUnits.size() + 1) * 13 + 2 > 255)
118  {
119  return;
120  }
121  m_addressUnits.push_back(unit);
122 }
123 
124 bool
126 {
127  // -fstrict-overflow sensitive, see bug 1868
128  return (GetInformationFieldSize() > 255 - 2 /* ID + LENGTH*/
129  -
130  13 // 10 /* Size of Mac48Address + uint32_t (one unit)*/
131  );
132 }
133 
134 std::vector<HwmpProtocol::FailedDestination>
136 {
137  return m_addressUnits;
138 }
139 
140 void
142 {
143  for (auto i = m_addressUnits.begin(); i != m_addressUnits.end(); i++)
144  {
145  if (i->destination == address)
146  {
147  m_addressUnits.erase(i);
148  break;
149  }
150  }
151 }
152 
153 void
155 {
156  m_addressUnits.clear();
157 }
158 
159 bool
160 operator==(const IePerr& a, const IePerr& b)
161 {
162  if (a.m_addressUnits.size() != b.m_addressUnits.size())
163  {
164  return false;
165  }
166  for (unsigned int i = 0; i < a.m_addressUnits.size(); i++)
167  {
168  if (a.m_addressUnits[i].destination != b.m_addressUnits[i].destination)
169  {
170  return false;
171  }
172  if (a.m_addressUnits[i].seqnum != b.m_addressUnits[i].seqnum)
173  {
174  return false;
175  }
176  }
177  return true;
178 }
179 
180 std::ostream&
181 operator<<(std::ostream& os, const IePerr& a)
182 {
183  a.Print(os);
184  return os;
185 }
186 } // namespace dot11s
187 } // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:100
uint8_t ReadU8()
Definition: buffer.h:1027
void WriteU8(uint8_t data)
Definition: buffer.h:881
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:910
uint32_t GetDistanceFrom(const Iterator &o) const
Definition: buffer.cc:780
uint32_t ReadLsbtohU32()
Definition: buffer.cc:1076
void Next()
go forward by one byte
Definition: buffer.h:853
an EUI-48 address
Definition: mac48-address.h:46
See 7.3.2.98 of 802.11s draft 2.07.
void Print(std::ostream &os) const override
Generate human-readable form of IE.
void SerializeInformationField(Buffer::Iterator i) const override
Serialize information (i.e., the body of the IE, not including the Element ID and length octets)
void DeleteAddressUnit(Mac48Address address)
Delete address unit function.
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)
bool IsFull() const
Is full function.
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 ResetPerr()
Reset PERR.
void AddAddressUnit(HwmpProtocol::FailedDestination unit)
Add address unit function.
WifiInformationElementId ElementId() const override
Get the wifi information element ID.
uint8_t GetNumOfDest() const
Get number of destination function.
std::vector< HwmpProtocol::FailedDestination > GetAddressUnitVector() const
Get address unit vector function.
std::vector< HwmpProtocol::FailedDestination > m_addressUnits
address units
#define NS_ABORT_UNLESS(cond)
Abnormal program termination if a condition is false.
Definition: abort.h:129
address
Definition: first.py:47
bool operator==(const MeshHeader &a, const MeshHeader &b)
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
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.
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:89
Mac48Address destination
destination address
Definition: hwmp-protocol.h:90
#define IE_PERR