A Discrete-Event Network Simulator
API
ie-dot11s-perr.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008,2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Kirill Andreev <andreev@iitp.ru>
19  */
20 
21 #include "ie-dot11s-perr.h"
22 #include "ns3/address-utils.h"
23 #include "ns3/packet.h"
24 namespace ns3 {
25 namespace dot11s {
27 {
28 }
30 {
31 }
34 {
35  return IE_PERR;
36 }
37 void
38 IePerr::Print (std::ostream &os) const
39 {
40  os << "PERR=(Number of failed destinations=" << m_addressUnits.size ();
41  for (unsigned int j = 0; j < m_addressUnits.size (); j++)
42  {
43  os << "(Failed destination address=" << m_addressUnits[j].destination << ", sequence number = "
44  << m_addressUnits[j].seqnum << ")";
45  }
46  os << ")";
47 }
48 uint8_t
50 {
51  return m_addressUnits.size ();
52 }
53 void
55 {
56  i.WriteU8 (0);// TTL
57  i.WriteU8 (m_addressUnits.size ()); // number of Destinations
58  for (unsigned int j = 0; j < m_addressUnits.size (); j++)
59  {
60  i.WriteU8 (0); // not used // Bit 6: AE (Address Extension) subfield (1 = destination external address is present, 0 = otherwise).
61  WriteTo (i, m_addressUnits[j].destination);
62  i.WriteHtolsbU32 (m_addressUnits[j].seqnum);
63  i.WriteU8 (0);
64  i.WriteU8 (0);
65  }
66 }
67 uint8_t
69 {
71  i.Next (1); //TTL //Mode flags is not used now
72  uint8_t numOfDest = i.ReadU8 ();
73  NS_ABORT_UNLESS ((2 + 13 * numOfDest ) == length);
74 
75  for (unsigned int j = 0; j < numOfDest; j++)
76  {
77  i.Next (1); // flags is not used now
79  ReadFrom (i, unit.destination);
80  unit.seqnum = i.ReadLsbtohU32 ();
81  m_addressUnits.push_back (unit);
82  i.Next (2); // Reason
83  }
84  return i.GetDistanceFrom (start);
85 }
86 
87 uint8_t
89 {
90  uint8_t retval = 1 //TTL //ModeFlags
91  + 1 //NumOfDests
92  + 1 * m_addressUnits.size () //ModeFlags
93  + (6 + 4) * m_addressUnits.size ()
94  + 2* m_addressUnits.size (); // Reason Code
95  return retval;
96 }
97 
98 void
100 {
101  for (unsigned int i = 0; i < m_addressUnits.size (); i++)
102  {
103  if (m_addressUnits[i].destination == unit.destination)
104  {
105  return;
106  }
107  }
108  if ((m_addressUnits.size () + 1) * 13 + 2 > 255)
109  {
110  return;
111  }
112  m_addressUnits.push_back (unit);
113 }
114 bool
116 {
117  // -fstrict-overflow sensitive, see bug 1868
118  return (GetInformationFieldSize ()
119  > 255
120  - 2 /* ID + LENGTH*/
121  - 13// 10 /* Size of Mac48Address + uint32_t (one unit)*/
122  );
123 }
124 std::vector<HwmpProtocol::FailedDestination>
126 {
127  return m_addressUnits;
128 }
129 void
131 {
132  for (std::vector<HwmpProtocol::FailedDestination>::iterator i = m_addressUnits.begin (); i
133  != m_addressUnits.end (); i++)
134  {
135  if (i->destination == address)
136  {
137  m_addressUnits.erase (i);
138  break;
139  }
140  }
141 }
142 void
144 {
145  m_addressUnits.clear ();
146 }
147 bool
148 operator== (const IePerr & a, const IePerr & b)
149 {
150  if (a.m_addressUnits.size () != b.m_addressUnits.size ())
151  {
152  return false;
153  }
154  for (unsigned int i = 0; i < a.m_addressUnits.size (); i++)
155  {
156  if (a.m_addressUnits[i].destination != b.m_addressUnits[i].destination)
157  {
158  return false;
159  }
160  if (a.m_addressUnits[i].seqnum != b.m_addressUnits[i].seqnum)
161  {
162  return false;
163  }
164  }
165  return true;
166 }
167 std::ostream &
168 operator << (std::ostream & os, const IePerr & a)
169 {
170  a.Print (os);
171  return os;
172 }
173 } // namespace dot11s
174 } // namespace ns3
175 
176 
std::vector< HwmpProtocol::FailedDestination > m_addressUnits
address units
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:76
void ReadFrom(Buffer::Iterator &i, Ipv4Address &ad)
Read an Ipv4Address from a Buffer.
def start()
Definition: core.py:1844
void AddAddressUnit(HwmpProtocol::FailedDestination unit)
Add address unit function.
void WriteTo(Buffer::Iterator &i, Ipv4Address ad)
Write an Ipv4Address to a Buffer.
virtual uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
Deserialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
See 7.3.2.98 of 802.11s draft 2.07.
bool operator==(const MeshHeader &a, const MeshHeader &b)
iterator in a Buffer instance
Definition: buffer.h:98
#define NS_ABORT_UNLESS(cond)
Abnormal program termination if a condition is false.
Definition: abort.h:128
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:783
virtual WifiInformationElementId ElementId() const
void Next(void)
go forward by one byte
Definition: buffer.h:845
std::vector< HwmpProtocol::FailedDestination > GetAddressUnitVector() const
Get address unit vector function.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:37
virtual void SerializeInformationField(Buffer::Iterator i) const
Serialize information (i.e., the body of the IE, not including the Element ID and length octets) ...
an EUI-48 address
Definition: mac48-address.h:43
Mac48Address destination
destination address
Definition: hwmp-protocol.h:78
bool IsFull() const
Is full function.
uint8_t GetNumOfDest() const
Get number of destination function.
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
uint8_t WifiInformationElementId
This type is used to represent an Information Element ID.
void DeleteAddressUnit(Mac48Address address)
Delete address unit function.
void ResetPerr()
Reset PERR.
virtual void Print(std::ostream &os) const
Generate human-readable form of IE.
std::ostream & operator<<(std::ostream &os, const IeBeaconTiming &a)
virtual uint8_t GetInformationFieldSize() const
Length of serialized information (i.e., the length of the body of the IE, not including the Element I...
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1076
#define IE_PERR
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:917