A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ie-dot11s-perr.cc
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 {
26 IePerr::IePerr ()
27 {
28 }
29 IePerr::~IePerr ()
30 {
31 }
34 {
35  return IE11S_PERR;
36 }
37 void
38 IePerr::Print (std::ostream &os) const
39 {
40  os << std::endl << "<information_element id=" << ElementId () << ">" << std::endl;
41  os << "Number of failed destinations: = " << m_addressUnits.size ();
42  for (unsigned int j = 0; j < m_addressUnits.size (); j++)
43  {
44  os << "Failed destination address: = " << m_addressUnits[j].destination << ", sequence number = "
45  << m_addressUnits[j].seqnum;
46  }
47  os << std::endl << "</information_element>" << std::endl;
48 }
49 uint8_t
50 IePerr::GetNumOfDest () const
51 {
52  return m_addressUnits.size ();
53 }
54 void
56 {
57  i.WriteU8 (0);
58  i.WriteU8 (m_addressUnits.size ());
59  for (unsigned int j = 0; j < m_addressUnits.size (); j++)
60  {
61  WriteTo (i, m_addressUnits[j].destination);
62  i.WriteHtolsbU32 (m_addressUnits[j].seqnum);
63  }
64 }
65 uint8_t
67 {
68  Buffer::Iterator i = start;
69  i.Next (1); //Mode flags is not used now
70  uint8_t numOfDest = i.ReadU8 ();
71  NS_ASSERT ((2 + 10 * numOfDest ) == length);
72  length = 0; //to avoid compiler warning in optimized builds
73  for (unsigned int j = 0; j < numOfDest; j++)
74  {
76  ReadFrom (i, unit.destination);
77  unit.seqnum = i.ReadLsbtohU32 ();
78  m_addressUnits.push_back (unit);
79  }
80  return i.GetDistanceFrom (start);
81 }
82 
83 uint8_t
85 {
86  uint8_t retval = 1 //ModeFlags
87  + 1 //NumOfDests
88  + (6 + 4) * m_addressUnits.size ();
89  return retval;
90 }
91 
92 void
93 IePerr::AddAddressUnit (HwmpProtocol::FailedDestination unit)
94 {
95  for (unsigned int i = 0; i < m_addressUnits.size (); i++)
96  {
97  if (m_addressUnits[i].destination == unit.destination)
98  {
99  return;
100  }
101  }
102  if ((m_addressUnits.size () + 1) * 10 + 2 > 255)
103  {
104  return;
105  }
106  m_addressUnits.push_back (unit);
107 }
108 bool
109 IePerr::IsFull () const
110 {
111  return (GetInformationFieldSize () + 2 /* ID + LENGTH*/+ 10 /* Size of Mac48Address + uint32_t (one unit)*/> 255);
112 }
113 std::vector<HwmpProtocol::FailedDestination>
114 IePerr::GetAddressUnitVector () const
115 {
116  return m_addressUnits;
117 }
118 void
119 IePerr::DeleteAddressUnit (Mac48Address address)
120 {
121  for (std::vector<HwmpProtocol::FailedDestination>::iterator i = m_addressUnits.begin (); i
122  != m_addressUnits.end (); i++)
123  {
124  if (i->destination == address)
125  {
126  m_addressUnits.erase (i);
127  break;
128  }
129  }
130 }
131 void
132 IePerr::ResetPerr ()
133 {
134  m_addressUnits.clear ();
135 }
136 bool
137 operator== (const IePerr & a, const IePerr & b)
138 {
139  if (a.m_addressUnits.size () != b.m_addressUnits.size ())
140  {
141  return false;
142  }
143  for (unsigned int i = 0; i < a.m_addressUnits.size (); i++)
144  {
145  if (a.m_addressUnits[i].destination != b.m_addressUnits[i].destination)
146  {
147  return false;
148  }
149  if (a.m_addressUnits[i].seqnum != b.m_addressUnits[i].seqnum)
150  {
151  return false;
152  }
153  }
154  return true;
155 }
156 std::ostream &
157 operator << (std::ostream & os, const IePerr & a)
158 {
159  a.Print (os);
160  return os;
161 }
162 } // namespace dot11s
163 } // namespace ns3
164 
165 
virtual void SerializeInformationField(Buffer::Iterator i) const
structure of unreachable destination - address and sequence number
Definition: hwmp-protocol.h:57
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
virtual uint8_t GetInformationFieldSize() const
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
iterator in a Buffer instance
Definition: buffer.h:98
virtual void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
void Next(void)
Definition: buffer.h:666
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
void WriteU8(uint8_t data)
Definition: buffer.h:690
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
uint8_t ReadU8(void)
Definition: buffer.h:819
uint8_t WifiInformationElementId
uint32_t ReadLsbtohU32(void)
Definition: buffer.cc:1101
void WriteHtolsbU32(uint32_t data)
Definition: buffer.cc:942