A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
peer-link-frame.cc
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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  * Authors: Kirill Andreev <andreev@iitp.ru>
19  */
20 
21 #include "peer-link-frame.h"
22 #include "ie-dot11s-peer-management.h"
23 #include "ns3/mesh-wifi-interface-mac.h"
24 #include "ns3/test.h"
25 #include "ns3/packet.h"
26 
27 namespace ns3 {
28 namespace dot11s {
29 NS_OBJECT_ENSURE_REGISTERED (PeerLinkFrameStart);
30 
31 PeerLinkFrameStart::PeerLinkFrameStart () :
32  m_subtype (255), m_capability (0), m_aid (0), m_rates (SupportedRates ()), m_meshId (),
33  m_config (IeConfiguration ()), m_reasonCode ((uint16_t)REASON11S_RESERVED)
34 {
35 }
36 void
38 {
39  m_subtype = subtype;
40 }
41 void
42 PeerLinkFrameStart::SetPlinkFrameStart (PeerLinkFrameStart::PlinkFrameStartFields fields)
43 {
44  m_subtype = fields.subtype;
45  m_protocol = fields.protocol;
46  if (m_subtype != (uint8_t)(WifiActionHeader::PEER_LINK_CLOSE))
47  {
48  m_capability = fields.capability;
49  }
50  if (m_subtype == (uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM))
51  {
52  m_aid = fields.aid;
53  }
54  if (m_subtype != (uint8_t)(WifiActionHeader::PEER_LINK_CLOSE))
55  {
56  m_rates = fields.rates;
57  }
58  if (m_subtype != (uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM))
59  {
60  m_meshId = fields.meshId;
61  }
62  if (m_subtype != (uint8_t)(WifiActionHeader::PEER_LINK_CLOSE))
63  {
64  m_config = fields.config;
65  }
66  else
67  {
68  m_reasonCode = fields.reasonCode;
69  }
70 }
71 PeerLinkFrameStart::PlinkFrameStartFields
72 PeerLinkFrameStart::GetFields () const
73 {
74  PlinkFrameStartFields retval;
75  //TODO: protocol version:
76  retval.subtype = m_subtype;
77  retval.capability = m_capability;
78  retval.aid = m_aid;
79  retval.rates = m_rates;
80  retval.meshId = m_meshId;
81  retval.config = m_config;
82  retval.reasonCode = m_reasonCode;
83  return retval;
84 }
85 TypeId
86 PeerLinkFrameStart::GetTypeId ()
87 {
88  static TypeId tid = TypeId ("ns3::dot11s::PeerLinkFrameStart").SetParent<Header> ().AddConstructor<
89  PeerLinkFrameStart> ();
90  return tid;
91 }
92 TypeId
94 {
95  return GetTypeId ();
96 }
97 void
98 PeerLinkFrameStart::Print (std::ostream &os) const
99 {
100  os << "subtype = " << (uint16_t) m_subtype << std::endl << "capability = " << m_capability << std::endl << "laid = "
101  << (uint16_t) m_aid << std::endl << "rates = " << m_rates << std::endl << "meshId = ";
102  m_meshId.Print (os);
103  os << std::endl << "configuration = ";
104  m_config.Print (os);
105  os << std::endl << "reason code = " << m_reasonCode;
106 }
107 uint32_t
109 {
110  uint32_t size = 3; //Peering protocol
111  NS_ASSERT (m_subtype < 3);
112  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
113  {
114  size += 2; //capability
115  }
116  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
117  {
118  size += 2; //AID of remote peer
119  }
120  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
121  {
122  size += m_rates.GetSerializedSize ();
123  size += m_rates.extended.GetSerializedSize ();
124  }
125  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
126  {
127  size += m_meshId.GetInformationFieldSize () + 2;
128  }
129  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
130  {
131  size += m_config.GetInformationFieldSize () + 2;
132  }
133  else
134  {
135  size += 2; //reasonCode
136  }
137  return size;
138 }
139 void
141 {
142  Buffer::Iterator i = start;
143  NS_ASSERT (m_subtype < 3);
144  i = m_protocol.Serialize (i);
145  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
146  {
147  i.WriteHtolsbU16 (m_capability);
148  }
149  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
150  {
151  i.WriteHtolsbU16 (m_aid);
152  }
153  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
154  {
155  i = m_rates.Serialize (i);
156  i = m_rates.extended.Serialize (i);
157  }
158  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
159  {
160  i = m_meshId.Serialize (i);
161  }
162  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
163  {
164  i = m_config.Serialize (i);
165  }
166  else
167  {
168  i.WriteHtolsbU16 (m_reasonCode);
169  }
170 }
171 uint32_t
173 {
174  Buffer::Iterator i = start;
175  NS_ASSERT (m_subtype < 3);
176  {
177  uint8_t id = i.ReadU8 ();
178  uint8_t length = i.ReadU8 ();
179  m_protocol.DeserializeInformationField (i, length);
180  if ((m_protocol.ElementId () != (WifiInformationElementId) id) || (m_protocol.GetInformationFieldSize () != length))
181  {
182  NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
183  }
184  i.Next (m_protocol.GetInformationFieldSize ());
185  }
186  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
187  {
188  m_capability = i.ReadLsbtohU16 ();
189  }
190  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) == m_subtype)
191  {
192  m_aid = i.ReadLsbtohU16 ();
193  }
194  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
195  {
196  i = m_rates.Deserialize (i);
197  i = m_rates.extended.DeserializeIfPresent (i);
198  }
199  if ((uint8_t)(WifiActionHeader::PEER_LINK_CONFIRM) != m_subtype)
200  {
201  uint8_t id = i.ReadU8 ();
202  uint8_t length = i.ReadU8 ();
203  m_meshId.DeserializeInformationField (i, length);
204  if ((m_meshId.ElementId () != (WifiInformationElementId) id) || (m_meshId.GetInformationFieldSize () != length))
205  {
206  NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
207  }
208  i.Next (m_meshId.GetInformationFieldSize ());
209  }
210  if ((uint8_t)(WifiActionHeader::PEER_LINK_CLOSE) != m_subtype)
211  {
212  uint8_t id = i.ReadU8 ();
213  uint8_t length = i.ReadU8 ();
214  m_config.DeserializeInformationField (i, length);
215  if ((m_config.ElementId () != (WifiInformationElementId) id) || (m_config.GetInformationFieldSize () != length))
216  {
217  NS_FATAL_ERROR ("Broken frame: Element ID does not match IE itself!");
218  }
219  i.Next (m_config.GetInformationFieldSize ());
220  }
221  else
222  {
223  m_reasonCode = i.ReadLsbtohU16 ();
224  }
225  return i.GetDistanceFrom (start);
226 }
227 bool
228 operator== (const PeerLinkFrameStart & a, const PeerLinkFrameStart & b)
229 {
230  return ((a.m_subtype == b.m_subtype) && (a.m_capability == b.m_capability) && (a.m_aid == b.m_aid)
231  && (a.m_meshId.IsEqual (b.m_meshId)) && (a.m_config == b.m_config)
232  && (a.m_reasonCode == b.m_reasonCode));
233 }
234 } // namespace dot11s
235 } // namespace ns3
236 
virtual uint8_t DeserializeInformationField(Buffer::Iterator i, uint8_t length)
#define NS_ASSERT(condition)
Definition: assert.h:64
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
Buffer::Iterator Deserialize(Buffer::Iterator i)
uint32_t GetDistanceFrom(Iterator const &o) const
Definition: buffer.cc:807
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
iterator in a Buffer instance
Definition: buffer.h:98
virtual uint8_t DeserializeInformationField(Buffer::Iterator i, uint8_t length)
virtual void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
Buffer::Iterator DeserializeIfPresent(Buffer::Iterator i)
void Next(void)
Definition: buffer.h:666
virtual void Print(std::ostream &os) const
In addition, a subclass may optionally override the following...
virtual uint8_t DeserializeInformationField(Buffer::Iterator start, uint8_t length)
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
Definition: ie-dot11s-id.cc:53
virtual uint8_t GetInformationFieldSize() const
Definition: ie-dot11s-id.cc:86
virtual WifiInformationElementId ElementId() const
Own unique Element ID.
void WriteHtolsbU16(uint16_t data)
Definition: buffer.cc:935
uint8_t ReadU8(void)
Definition: buffer.h:819
uint16_t ReadLsbtohU16(void)
Definition: buffer.cc:1090
uint8_t WifiInformationElementId
virtual uint8_t GetInformationFieldSize() const
Buffer::Iterator Serialize(Buffer::Iterator i) const
Serialize entire IE including Element ID and length fields.
virtual uint8_t GetInformationFieldSize() const