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 * Author: Pavel Boyko <boyko@iitp.ru> |
|
19 */ |
|
20 |
|
21 #include "ie-vector.h" |
|
22 #include "ns3/test.h" |
|
23 #include "ns3/packet.h" |
|
24 // All information elements: |
|
25 #include "dot11s/ie-dot11s-beacon-timing.h" |
|
26 #include "dot11s/ie-dot11s-configuration.h" |
|
27 #include "dot11s/ie-dot11s-id.h" |
|
28 #include "dot11s/ie-dot11s-metric-report.h" |
|
29 #include "dot11s/ie-dot11s-peer-management.h" |
|
30 #include "dot11s/ie-dot11s-peering-protocol.h" |
|
31 #include "dot11s/ie-dot11s-perr.h" |
|
32 #include "dot11s/ie-dot11s-prep.h" |
|
33 #include "dot11s/ie-dot11s-preq.h" |
|
34 #include "dot11s/ie-dot11s-rann.h" |
|
35 |
|
36 namespace ns3 { |
|
37 WifiInformationElementVector::WifiInformationElementVector () : |
|
38 m_maxSize (1500) |
|
39 { |
|
40 } |
|
41 WifiInformationElementVector::~WifiInformationElementVector () |
|
42 { |
|
43 } |
|
44 void |
|
45 WifiInformationElementVector::SetMaxSize (uint16_t size) |
|
46 { |
|
47 m_maxSize = size; |
|
48 } |
|
49 WifiInformationElementVector::Iterator |
|
50 WifiInformationElementVector::Begin () |
|
51 { |
|
52 return m_elements.begin (); |
|
53 } |
|
54 WifiInformationElementVector::Iterator |
|
55 WifiInformationElementVector::End () |
|
56 { |
|
57 return m_elements.end (); |
|
58 } |
|
59 bool |
|
60 WifiInformationElementVector::AddInformationElement (Ptr<WifiInformationElement> element) |
|
61 { |
|
62 if (element->GetSerializedSize () + GetSize () > m_maxSize) |
|
63 { |
|
64 return false; |
|
65 } |
|
66 m_elements.push_back (element); |
|
67 return true; |
|
68 } |
|
69 Ptr<WifiInformationElement> |
|
70 WifiInformationElementVector::FindFirst (enum WifiElementId id) const |
|
71 { |
|
72 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++) |
|
73 { |
|
74 if ((*i)->ElementId () == id) |
|
75 { |
|
76 return (*i); |
|
77 } |
|
78 } |
|
79 return 0; |
|
80 } |
|
81 WifiInformationElementVector |
|
82 WifiInformationElementVector::DeserializePacket (Ptr<Packet> packet) |
|
83 { |
|
84 WifiInformationElementVector retval; |
|
85 EmptyIe ie; |
|
86 while (packet->PeekHeader (ie)) |
|
87 { |
|
88 Ptr<WifiInformationElement> newElement; |
|
89 switch (ie.GetElementId ()) |
|
90 { |
|
91 case IE11S_MESH_CONFIGURATION: |
|
92 newElement = Create<dot11s::IeConfiguration> (); |
|
93 break; |
|
94 case IE11S_MESH_ID: |
|
95 newElement = Create<dot11s::IeMeshId> (); |
|
96 break; |
|
97 case IE11S_LINK_METRIC_REPORT: |
|
98 newElement = Create<dot11s::IeLinkMetricReport> (); |
|
99 break; |
|
100 case IE11S_PEERING_MANAGEMENT: |
|
101 newElement = Create<dot11s::IePeerManagement> (); |
|
102 break; |
|
103 case IE11S_BEACON_TIMING: |
|
104 newElement = Create<dot11s::IeBeaconTiming> (); |
|
105 break; |
|
106 case IE11S_RANN: |
|
107 newElement = Create<dot11s::IeRann> (); |
|
108 break; |
|
109 case IE11S_PREQ: |
|
110 newElement = Create<dot11s::IePreq> (); |
|
111 break; |
|
112 case IE11S_PREP: |
|
113 newElement = Create<dot11s::IePrep> (); |
|
114 break; |
|
115 case IE11S_PERR: |
|
116 newElement = Create<dot11s::IePerr> (); |
|
117 break; |
|
118 case IE11S_MESH_PEERING_PROTOCOL_VERSION: |
|
119 newElement = Create<dot11s::IePeeringProtocol> (); |
|
120 break; |
|
121 default: |
|
122 NS_FATAL_ERROR ("Information element " << (uint16_t) ie.GetElementId () << " is not implemented"); |
|
123 } |
|
124 packet->RemoveHeader (*newElement); |
|
125 if (!retval.AddInformationElement (newElement)) |
|
126 { |
|
127 NS_FATAL_ERROR ("Check max size for information element!"); |
|
128 } |
|
129 if (packet->GetSize () == 0) |
|
130 { |
|
131 return retval; |
|
132 } |
|
133 } |
|
134 return retval; |
|
135 } |
|
136 Ptr<Packet> |
|
137 WifiInformationElementVector::MakePacket (bool sortByElementId) |
|
138 { |
|
139 if (sortByElementId) |
|
140 { |
|
141 //TODO: sort |
|
142 } |
|
143 Ptr<Packet> packet = Create<Packet> (); |
|
144 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++) |
|
145 { |
|
146 packet->AddHeader (**i); |
|
147 } |
|
148 return packet; |
|
149 } |
|
150 uint32_t |
|
151 WifiInformationElementVector::GetSize () const |
|
152 { |
|
153 uint32_t size = 0; |
|
154 for (IE_VECTOR::const_iterator i = m_elements.begin (); i != m_elements.end (); i++) |
|
155 { |
|
156 size += (*i)->GetSerializedSize (); |
|
157 } |
|
158 return size; |
|
159 } |
|
160 WifiInformationElementVector::EmptyIe::~EmptyIe () |
|
161 { |
|
162 } |
|
163 WifiInformationElementVector::EmptyIe::EmptyIe () : |
|
164 m_elementId (0), m_length (0) |
|
165 { |
|
166 } |
|
167 TypeId |
|
168 WifiInformationElementVector::EmptyIe::GetTypeId () |
|
169 { |
|
170 static TypeId tid = TypeId ("ns3::WifiInformationElementVector::EmptyIe") |
|
171 .SetParent<Header> (); |
|
172 return tid; |
|
173 } |
|
174 TypeId |
|
175 WifiInformationElementVector::EmptyIe::GetInstanceTypeId () const |
|
176 { |
|
177 return GetTypeId (); |
|
178 } |
|
179 uint8_t |
|
180 WifiInformationElementVector::EmptyIe::GetLength () |
|
181 { |
|
182 return m_length; |
|
183 } |
|
184 uint8_t |
|
185 WifiInformationElementVector::EmptyIe::GetElementId () |
|
186 { |
|
187 return m_elementId; |
|
188 } |
|
189 uint32_t |
|
190 WifiInformationElementVector::EmptyIe::GetSerializedSize () const |
|
191 { |
|
192 return 2; |
|
193 } |
|
194 void |
|
195 WifiInformationElementVector::EmptyIe::Serialize (Buffer::Iterator start) const |
|
196 { |
|
197 start.WriteU8 (m_elementId); |
|
198 start.WriteU8 (m_length); |
|
199 } |
|
200 uint32_t |
|
201 WifiInformationElementVector::EmptyIe::Deserialize (Buffer::Iterator start) |
|
202 { |
|
203 Buffer::Iterator i = start; |
|
204 m_elementId = i.ReadU8 (); |
|
205 m_length = i.ReadU8 (); |
|
206 return i.GetDistanceFrom (start); |
|
207 } |
|
208 void |
|
209 WifiInformationElementVector::EmptyIe::Print (std::ostream &os) const |
|
210 { |
|
211 } |
|
212 } |
|