File: | /tmp/asd-nat/home/nat/Work/ns-3-dev-git/build/../src/olsr/model/olsr-header.cc |
Location: | line 59, column 3 |
Description: | The result of the '<<' expression is undefined |
1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |||||
2 | /* | |||||
3 | * Copyright (c) 2007 INESC Porto | |||||
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: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> | |||||
19 | */ | |||||
20 | ||||||
21 | #include <cmath> | |||||
22 | ||||||
23 | #include "ns3/assert.h" | |||||
24 | #include "ns3/log.h" | |||||
25 | ||||||
26 | #include "olsr-header.h" | |||||
27 | ||||||
28 | #define IPV4_ADDRESS_SIZE4 4 | |||||
29 | #define OLSR_MSG_HEADER_SIZE12 12 | |||||
30 | #define OLSR_PKT_HEADER_SIZE4 4 | |||||
31 | ||||||
32 | namespace ns3 { | |||||
33 | ||||||
34 | NS_LOG_COMPONENT_DEFINE ("OlsrHeader")static ns3::LogComponent g_log = ns3::LogComponent ("OlsrHeader" , "../src/olsr/model/olsr-header.cc"); | |||||
35 | ||||||
36 | namespace olsr { | |||||
37 | ||||||
38 | ||||||
39 | /// Scaling factor used in RFC 3626. | |||||
40 | #define OLSR_C0.0625 0.0625 | |||||
41 | ||||||
42 | /// | |||||
43 | /// \brief Converts a decimal number of seconds to the mantissa/exponent format. | |||||
44 | /// | |||||
45 | /// \param seconds decimal number of seconds we want to convert. | |||||
46 | /// \return the number of seconds in mantissa/exponent format. | |||||
47 | /// | |||||
48 | uint8_t | |||||
49 | SecondsToEmf (double seconds) | |||||
50 | { | |||||
51 | int a, b = 0; | |||||
52 | ||||||
53 | // find the largest integer 'b' such that: T/C >= 2^b | |||||
54 | for (b = 0; (seconds / OLSR_C0.0625) >= (1 << b); ++b) | |||||
| ||||||
55 | { | |||||
56 | } | |||||
57 | NS_ASSERT ((seconds / OLSR_C) < (1 << b))do { if (!((seconds / 0.0625) < (1 << b))) { std::cerr << "assert failed. cond=\"" << "(seconds / OLSR_C) < (1 << b)" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 57 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
58 | b--; | |||||
59 | NS_ASSERT ((seconds / OLSR_C) >= (1 << b))do { if (!((seconds / 0.0625) >= (1 << b))) { std::cerr << "assert failed. cond=\"" << "(seconds / OLSR_C) >= (1 << b)" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 59 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
| ||||||
60 | ||||||
61 | // compute the expression 16*(T/(C*(2^b))-1), which may not be a integer | |||||
62 | double tmp = 16 * (seconds / (OLSR_C0.0625 * (1 << b)) - 1); | |||||
63 | ||||||
64 | // round it up. This results in the value for 'a' | |||||
65 | a = (int) std::ceil (tmp - 0.5); | |||||
66 | ||||||
67 | // if 'a' is equal to 16: increment 'b' by one, and set 'a' to 0 | |||||
68 | if (a == 16) | |||||
69 | { | |||||
70 | b += 1; | |||||
71 | a = 0; | |||||
72 | } | |||||
73 | ||||||
74 | // now, 'a' and 'b' should be integers between 0 and 15, | |||||
75 | NS_ASSERT (a >= 0 && a < 16)do { if (!(a >= 0 && a < 16)) { std::cerr << "assert failed. cond=\"" << "a >= 0 && a < 16" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 75 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
76 | NS_ASSERT (b >= 0 && b < 16)do { if (!(b >= 0 && b < 16)) { std::cerr << "assert failed. cond=\"" << "b >= 0 && b < 16" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 76 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
77 | ||||||
78 | // the field will be a byte holding the value a*16+b | |||||
79 | return (uint8_t)((a << 4) | b); | |||||
80 | } | |||||
81 | ||||||
82 | /// | |||||
83 | /// \brief Converts a number of seconds in the mantissa/exponent format to a decimal number. | |||||
84 | /// | |||||
85 | /// \param olsr_format number of seconds in mantissa/exponent format. | |||||
86 | /// \return the decimal number of seconds. | |||||
87 | /// | |||||
88 | double | |||||
89 | EmfToSeconds (uint8_t olsrFormat) | |||||
90 | { | |||||
91 | int a = (olsrFormat >> 4); | |||||
92 | int b = (olsrFormat & 0xf); | |||||
93 | // value = C*(1+a/16)*2^b [in seconds] | |||||
94 | return OLSR_C0.0625 * (1 + a / 16.0) * (1 << b); | |||||
95 | } | |||||
96 | ||||||
97 | ||||||
98 | ||||||
99 | // ---------------- OLSR Packet ------------------------------- | |||||
100 | ||||||
101 | NS_OBJECT_ENSURE_REGISTERED (PacketHeader)static struct ObjectPacketHeaderRegistrationClass { ObjectPacketHeaderRegistrationClass () { ns3::TypeId tid = PacketHeader::GetTypeId (); tid.SetSize (sizeof (PacketHeader)); tid.GetParent (); } } ObjectPacketHeaderRegistrationVariable; | |||||
102 | ||||||
103 | PacketHeader::PacketHeader () | |||||
104 | { | |||||
105 | } | |||||
106 | ||||||
107 | PacketHeader::~PacketHeader () | |||||
108 | { | |||||
109 | } | |||||
110 | ||||||
111 | TypeId | |||||
112 | PacketHeader::GetTypeId (void) | |||||
113 | { | |||||
114 | static TypeId tid = TypeId ("ns3::olsr::PacketHeader") | |||||
115 | .SetParent<Header> () | |||||
116 | .SetGroupName ("Olsr") | |||||
117 | .AddConstructor<PacketHeader> () | |||||
118 | ; | |||||
119 | return tid; | |||||
120 | } | |||||
121 | TypeId | |||||
122 | PacketHeader::GetInstanceTypeId (void) const | |||||
123 | { | |||||
124 | return GetTypeId (); | |||||
125 | } | |||||
126 | ||||||
127 | uint32_t | |||||
128 | PacketHeader::GetSerializedSize (void) const | |||||
129 | { | |||||
130 | return OLSR_PKT_HEADER_SIZE4; | |||||
131 | } | |||||
132 | ||||||
133 | void | |||||
134 | PacketHeader::Print (std::ostream &os) const | |||||
135 | { | |||||
136 | /// \todo | |||||
137 | } | |||||
138 | ||||||
139 | void | |||||
140 | PacketHeader::Serialize (Buffer::Iterator start) const | |||||
141 | { | |||||
142 | Buffer::Iterator i = start; | |||||
143 | i.WriteHtonU16 (m_packetLength); | |||||
144 | i.WriteHtonU16 (m_packetSequenceNumber); | |||||
145 | } | |||||
146 | ||||||
147 | uint32_t | |||||
148 | PacketHeader::Deserialize (Buffer::Iterator start) | |||||
149 | { | |||||
150 | Buffer::Iterator i = start; | |||||
151 | m_packetLength = i.ReadNtohU16 (); | |||||
152 | m_packetSequenceNumber = i.ReadNtohU16 (); | |||||
153 | return GetSerializedSize (); | |||||
154 | } | |||||
155 | ||||||
156 | ||||||
157 | // ---------------- OLSR Message ------------------------------- | |||||
158 | ||||||
159 | NS_OBJECT_ENSURE_REGISTERED (MessageHeader)static struct ObjectMessageHeaderRegistrationClass { ObjectMessageHeaderRegistrationClass () { ns3::TypeId tid = MessageHeader::GetTypeId (); tid.SetSize (sizeof (MessageHeader)); tid.GetParent (); } } ObjectMessageHeaderRegistrationVariable; | |||||
160 | ||||||
161 | MessageHeader::MessageHeader () | |||||
162 | : m_messageType (MessageHeader::MessageType (0)) | |||||
163 | { | |||||
164 | } | |||||
165 | ||||||
166 | MessageHeader::~MessageHeader () | |||||
167 | { | |||||
168 | } | |||||
169 | ||||||
170 | TypeId | |||||
171 | MessageHeader::GetTypeId (void) | |||||
172 | { | |||||
173 | static TypeId tid = TypeId ("ns3::olsr::MessageHeader") | |||||
174 | .SetParent<Header> () | |||||
175 | .SetGroupName ("Olsr") | |||||
176 | .AddConstructor<MessageHeader> () | |||||
177 | ; | |||||
178 | return tid; | |||||
179 | } | |||||
180 | TypeId | |||||
181 | MessageHeader::GetInstanceTypeId (void) const | |||||
182 | { | |||||
183 | return GetTypeId (); | |||||
184 | } | |||||
185 | ||||||
186 | uint32_t | |||||
187 | MessageHeader::GetSerializedSize (void) const | |||||
188 | { | |||||
189 | uint32_t size = OLSR_MSG_HEADER_SIZE12; | |||||
190 | switch (m_messageType) | |||||
191 | { | |||||
192 | case MID_MESSAGE: | |||||
193 | size += m_message.mid.GetSerializedSize (); | |||||
194 | break; | |||||
195 | case HELLO_MESSAGE: | |||||
196 | NS_LOG_DEBUG ("Hello Message Size: " << size << " + " << m_message.hello.GetSerializedSize ())do { if (g_log.IsEnabled (ns3::LOG_DEBUG)) { if (g_log.IsEnabled (ns3::LOG_PREFIX_TIME)) { ns3::LogTimePrinter printer = ns3:: LogGetTimePrinter (); if (printer != 0) { (*printer)(std::clog ); std::clog << " "; } }; if (g_log.IsEnabled (ns3::LOG_PREFIX_NODE )) { ns3::LogNodePrinter printer = ns3::LogGetNodePrinter (); if (printer != 0) { (*printer)(std::clog); std::clog << " "; } }; ; if (g_log.IsEnabled (ns3::LOG_PREFIX_FUNC)) { std ::clog << g_log.Name () << ":" << __FUNCTION__ << "(): "; }; if (g_log.IsEnabled (ns3::LOG_PREFIX_LEVEL )) { std::clog << "[" << g_log.GetLevelLabel (ns3 ::LOG_DEBUG) << "] "; }; std::clog << "Hello Message Size: " << size << " + " << m_message.hello.GetSerializedSize () << std::endl; } } while (false); | |||||
197 | size += m_message.hello.GetSerializedSize (); | |||||
198 | break; | |||||
199 | case TC_MESSAGE: | |||||
200 | size += m_message.tc.GetSerializedSize (); | |||||
201 | break; | |||||
202 | case HNA_MESSAGE: | |||||
203 | size += m_message.hna.GetSerializedSize (); | |||||
204 | break; | |||||
205 | default: | |||||
206 | NS_ASSERT (false)do { if (!(false)) { std::cerr << "assert failed. cond=\"" << "false" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 206 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } } while ( false); | |||||
207 | } | |||||
208 | return size; | |||||
209 | } | |||||
210 | ||||||
211 | void | |||||
212 | MessageHeader::Print (std::ostream &os) const | |||||
213 | { | |||||
214 | /// \todo | |||||
215 | } | |||||
216 | ||||||
217 | void | |||||
218 | MessageHeader::Serialize (Buffer::Iterator start) const | |||||
219 | { | |||||
220 | Buffer::Iterator i = start; | |||||
221 | i.WriteU8 (m_messageType); | |||||
222 | i.WriteU8 (m_vTime); | |||||
223 | i.WriteHtonU16 (GetSerializedSize ()); | |||||
224 | i.WriteHtonU32 (m_originatorAddress.Get ()); | |||||
225 | i.WriteU8 (m_timeToLive); | |||||
226 | i.WriteU8 (m_hopCount); | |||||
227 | i.WriteHtonU16 (m_messageSequenceNumber); | |||||
228 | ||||||
229 | switch (m_messageType) | |||||
230 | { | |||||
231 | case MID_MESSAGE: | |||||
232 | m_message.mid.Serialize (i); | |||||
233 | break; | |||||
234 | case HELLO_MESSAGE: | |||||
235 | m_message.hello.Serialize (i); | |||||
236 | break; | |||||
237 | case TC_MESSAGE: | |||||
238 | m_message.tc.Serialize (i); | |||||
239 | break; | |||||
240 | case HNA_MESSAGE: | |||||
241 | m_message.hna.Serialize (i); | |||||
242 | break; | |||||
243 | default: | |||||
244 | NS_ASSERT (false)do { if (!(false)) { std::cerr << "assert failed. cond=\"" << "false" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 244 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } } while ( false); | |||||
245 | } | |||||
246 | ||||||
247 | } | |||||
248 | ||||||
249 | uint32_t | |||||
250 | MessageHeader::Deserialize (Buffer::Iterator start) | |||||
251 | { | |||||
252 | uint32_t size; | |||||
253 | Buffer::Iterator i = start; | |||||
254 | m_messageType = (MessageType) i.ReadU8 (); | |||||
255 | NS_ASSERT (m_messageType >= HELLO_MESSAGE && m_messageType <= HNA_MESSAGE)do { if (!(m_messageType >= HELLO_MESSAGE && m_messageType <= HNA_MESSAGE)) { std::cerr << "assert failed. cond=\"" << "m_messageType >= HELLO_MESSAGE && m_messageType <= HNA_MESSAGE" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 255 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
256 | m_vTime = i.ReadU8 (); | |||||
257 | m_messageSize = i.ReadNtohU16 (); | |||||
258 | m_originatorAddress = Ipv4Address (i.ReadNtohU32 ()); | |||||
259 | m_timeToLive = i.ReadU8 (); | |||||
260 | m_hopCount = i.ReadU8 (); | |||||
261 | m_messageSequenceNumber = i.ReadNtohU16 (); | |||||
262 | size = OLSR_MSG_HEADER_SIZE12; | |||||
263 | switch (m_messageType) | |||||
264 | { | |||||
265 | case MID_MESSAGE: | |||||
266 | size += m_message.mid.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE12); | |||||
267 | break; | |||||
268 | case HELLO_MESSAGE: | |||||
269 | size += m_message.hello.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE12); | |||||
270 | break; | |||||
271 | case TC_MESSAGE: | |||||
272 | size += m_message.tc.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE12); | |||||
273 | break; | |||||
274 | case HNA_MESSAGE: | |||||
275 | size += m_message.hna.Deserialize (i, m_messageSize - OLSR_MSG_HEADER_SIZE12); | |||||
276 | break; | |||||
277 | default: | |||||
278 | NS_ASSERT (false)do { if (!(false)) { std::cerr << "assert failed. cond=\"" << "false" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 278 << std::endl; ::ns3::FatalImpl::FlushStreams (); if (true) std::terminate (); } while (false); } } while ( false); | |||||
279 | } | |||||
280 | return size; | |||||
281 | } | |||||
282 | ||||||
283 | ||||||
284 | // ---------------- OLSR MID Message ------------------------------- | |||||
285 | ||||||
286 | uint32_t | |||||
287 | MessageHeader::Mid::GetSerializedSize (void) const | |||||
288 | { | |||||
289 | return this->interfaceAddresses.size () * IPV4_ADDRESS_SIZE4; | |||||
290 | } | |||||
291 | ||||||
292 | void | |||||
293 | MessageHeader::Mid::Print (std::ostream &os) const | |||||
294 | { | |||||
295 | /// \todo | |||||
296 | } | |||||
297 | ||||||
298 | void | |||||
299 | MessageHeader::Mid::Serialize (Buffer::Iterator start) const | |||||
300 | { | |||||
301 | Buffer::Iterator i = start; | |||||
302 | ||||||
303 | for (std::vector<Ipv4Address>::const_iterator iter = this->interfaceAddresses.begin (); | |||||
304 | iter != this->interfaceAddresses.end (); iter++) | |||||
305 | { | |||||
306 | i.WriteHtonU32 (iter->Get ()); | |||||
307 | } | |||||
308 | } | |||||
309 | ||||||
310 | uint32_t | |||||
311 | MessageHeader::Mid::Deserialize (Buffer::Iterator start, uint32_t messageSize) | |||||
312 | { | |||||
313 | Buffer::Iterator i = start; | |||||
314 | ||||||
315 | this->interfaceAddresses.clear (); | |||||
316 | NS_ASSERT (messageSize % IPV4_ADDRESS_SIZE == 0)do { if (!(messageSize % 4 == 0)) { std::cerr << "assert failed. cond=\"" << "messageSize % IPV4_ADDRESS_SIZE == 0" << "\", " ; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 316 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
317 | ||||||
318 | int numAddresses = messageSize / IPV4_ADDRESS_SIZE4; | |||||
319 | this->interfaceAddresses.erase (this->interfaceAddresses.begin (), | |||||
320 | this->interfaceAddresses.end ()); | |||||
321 | for (int n = 0; n < numAddresses; ++n) | |||||
322 | { | |||||
323 | this->interfaceAddresses.push_back (Ipv4Address (i.ReadNtohU32 ())); | |||||
324 | } | |||||
325 | return GetSerializedSize (); | |||||
326 | } | |||||
327 | ||||||
328 | ||||||
329 | ||||||
330 | // ---------------- OLSR HELLO Message ------------------------------- | |||||
331 | ||||||
332 | uint32_t | |||||
333 | MessageHeader::Hello::GetSerializedSize (void) const | |||||
334 | { | |||||
335 | uint32_t size = 4; | |||||
336 | for (std::vector<LinkMessage>::const_iterator iter = this->linkMessages.begin (); | |||||
337 | iter != this->linkMessages.end (); iter++) | |||||
338 | { | |||||
339 | const LinkMessage &lm = *iter; | |||||
340 | size += 4; | |||||
341 | size += IPV4_ADDRESS_SIZE4 * lm.neighborInterfaceAddresses.size (); | |||||
342 | } | |||||
343 | return size; | |||||
344 | } | |||||
345 | ||||||
346 | void | |||||
347 | MessageHeader::Hello::Print (std::ostream &os) const | |||||
348 | { | |||||
349 | /// \todo | |||||
350 | } | |||||
351 | ||||||
352 | void | |||||
353 | MessageHeader::Hello::Serialize (Buffer::Iterator start) const | |||||
354 | { | |||||
355 | Buffer::Iterator i = start; | |||||
356 | ||||||
357 | i.WriteU16 (0); // Reserved | |||||
358 | i.WriteU8 (this->hTime); | |||||
359 | i.WriteU8 (this->willingness); | |||||
360 | ||||||
361 | for (std::vector<LinkMessage>::const_iterator iter = this->linkMessages.begin (); | |||||
362 | iter != this->linkMessages.end (); iter++) | |||||
363 | { | |||||
364 | const LinkMessage &lm = *iter; | |||||
365 | ||||||
366 | i.WriteU8 (lm.linkCode); | |||||
367 | i.WriteU8 (0); // Reserved | |||||
368 | ||||||
369 | // The size of the link message, counted in bytes and measured | |||||
370 | // from the beginning of the "Link Code" field and until the | |||||
371 | // next "Link Code" field (or - if there are no more link types | |||||
372 | // - the end of the message). | |||||
373 | i.WriteHtonU16 (4 + lm.neighborInterfaceAddresses.size () * IPV4_ADDRESS_SIZE4); | |||||
374 | ||||||
375 | for (std::vector<Ipv4Address>::const_iterator neigh_iter = lm.neighborInterfaceAddresses.begin (); | |||||
376 | neigh_iter != lm.neighborInterfaceAddresses.end (); neigh_iter++) | |||||
377 | { | |||||
378 | i.WriteHtonU32 (neigh_iter->Get ()); | |||||
379 | } | |||||
380 | } | |||||
381 | } | |||||
382 | ||||||
383 | uint32_t | |||||
384 | MessageHeader::Hello::Deserialize (Buffer::Iterator start, uint32_t messageSize) | |||||
385 | { | |||||
386 | Buffer::Iterator i = start; | |||||
387 | ||||||
388 | NS_ASSERT (messageSize >= 4)do { if (!(messageSize >= 4)) { std::cerr << "assert failed. cond=\"" << "messageSize >= 4" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 388 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
389 | ||||||
390 | this->linkMessages.clear (); | |||||
391 | ||||||
392 | uint16_t helloSizeLeft = messageSize; | |||||
393 | ||||||
394 | i.ReadNtohU16 (); // Reserved | |||||
395 | this->hTime = i.ReadU8 (); | |||||
396 | this->willingness = i.ReadU8 (); | |||||
397 | ||||||
398 | helloSizeLeft -= 4; | |||||
399 | ||||||
400 | while (helloSizeLeft) | |||||
401 | { | |||||
402 | LinkMessage lm; | |||||
403 | NS_ASSERT (helloSizeLeft >= 4)do { if (!(helloSizeLeft >= 4)) { std::cerr << "assert failed. cond=\"" << "helloSizeLeft >= 4" << "\", "; do { std:: cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 403 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
404 | lm.linkCode = i.ReadU8 (); | |||||
405 | i.ReadU8 (); // Reserved | |||||
406 | uint16_t lmSize = i.ReadNtohU16 (); | |||||
407 | NS_ASSERT ((lmSize - 4) % IPV4_ADDRESS_SIZE == 0)do { if (!((lmSize - 4) % 4 == 0)) { std::cerr << "assert failed. cond=\"" << "(lmSize - 4) % IPV4_ADDRESS_SIZE == 0" << "\", " ; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 407 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
408 | for (int n = (lmSize - 4) / IPV4_ADDRESS_SIZE4; n; --n) | |||||
409 | { | |||||
410 | lm.neighborInterfaceAddresses.push_back (Ipv4Address (i.ReadNtohU32 ())); | |||||
411 | } | |||||
412 | helloSizeLeft -= lmSize; | |||||
413 | this->linkMessages.push_back (lm); | |||||
414 | } | |||||
415 | ||||||
416 | return messageSize; | |||||
417 | } | |||||
418 | ||||||
419 | ||||||
420 | ||||||
421 | // ---------------- OLSR TC Message ------------------------------- | |||||
422 | ||||||
423 | uint32_t | |||||
424 | MessageHeader::Tc::GetSerializedSize (void) const | |||||
425 | { | |||||
426 | return 4 + this->neighborAddresses.size () * IPV4_ADDRESS_SIZE4; | |||||
427 | } | |||||
428 | ||||||
429 | void | |||||
430 | MessageHeader::Tc::Print (std::ostream &os) const | |||||
431 | { | |||||
432 | /// \todo | |||||
433 | } | |||||
434 | ||||||
435 | void | |||||
436 | MessageHeader::Tc::Serialize (Buffer::Iterator start) const | |||||
437 | { | |||||
438 | Buffer::Iterator i = start; | |||||
439 | ||||||
440 | i.WriteHtonU16 (this->ansn); | |||||
441 | i.WriteHtonU16 (0); // Reserved | |||||
442 | ||||||
443 | for (std::vector<Ipv4Address>::const_iterator iter = this->neighborAddresses.begin (); | |||||
444 | iter != this->neighborAddresses.end (); iter++) | |||||
445 | { | |||||
446 | i.WriteHtonU32 (iter->Get ()); | |||||
447 | } | |||||
448 | } | |||||
449 | ||||||
450 | uint32_t | |||||
451 | MessageHeader::Tc::Deserialize (Buffer::Iterator start, uint32_t messageSize) | |||||
452 | { | |||||
453 | Buffer::Iterator i = start; | |||||
454 | ||||||
455 | this->neighborAddresses.clear (); | |||||
456 | NS_ASSERT (messageSize >= 4)do { if (!(messageSize >= 4)) { std::cerr << "assert failed. cond=\"" << "messageSize >= 4" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 456 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
457 | ||||||
458 | this->ansn = i.ReadNtohU16 (); | |||||
459 | i.ReadNtohU16 (); // Reserved | |||||
460 | ||||||
461 | NS_ASSERT ((messageSize - 4) % IPV4_ADDRESS_SIZE == 0)do { if (!((messageSize - 4) % 4 == 0)) { std::cerr << "assert failed. cond=\"" << "(messageSize - 4) % IPV4_ADDRESS_SIZE == 0" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 461 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
462 | int numAddresses = (messageSize - 4) / IPV4_ADDRESS_SIZE4; | |||||
463 | this->neighborAddresses.clear (); | |||||
464 | for (int n = 0; n < numAddresses; ++n) | |||||
465 | { | |||||
466 | this->neighborAddresses.push_back (Ipv4Address (i.ReadNtohU32 ())); | |||||
467 | } | |||||
468 | ||||||
469 | return messageSize; | |||||
470 | } | |||||
471 | ||||||
472 | ||||||
473 | // ---------------- OLSR HNA Message ------------------------------- | |||||
474 | ||||||
475 | uint32_t | |||||
476 | MessageHeader::Hna::GetSerializedSize (void) const | |||||
477 | { | |||||
478 | return 2 * this->associations.size () * IPV4_ADDRESS_SIZE4; | |||||
479 | } | |||||
480 | ||||||
481 | void | |||||
482 | MessageHeader::Hna::Print (std::ostream &os) const | |||||
483 | { | |||||
484 | /// \todo | |||||
485 | } | |||||
486 | ||||||
487 | void | |||||
488 | MessageHeader::Hna::Serialize (Buffer::Iterator start) const | |||||
489 | { | |||||
490 | Buffer::Iterator i = start; | |||||
491 | ||||||
492 | for (size_t n = 0; n < this->associations.size (); ++n) | |||||
493 | { | |||||
494 | i.WriteHtonU32 (this->associations[n].address.Get ()); | |||||
495 | i.WriteHtonU32 (this->associations[n].mask.Get ()); | |||||
496 | } | |||||
497 | } | |||||
498 | ||||||
499 | uint32_t | |||||
500 | MessageHeader::Hna::Deserialize (Buffer::Iterator start, uint32_t messageSize) | |||||
501 | { | |||||
502 | Buffer::Iterator i = start; | |||||
503 | ||||||
504 | NS_ASSERT (messageSize % (IPV4_ADDRESS_SIZE * 2) == 0)do { if (!(messageSize % (4 * 2) == 0)) { std::cerr << "assert failed. cond=\"" << "messageSize % (IPV4_ADDRESS_SIZE * 2) == 0" << "\", "; do { std::cerr << "file=" << "../src/olsr/model/olsr-header.cc" << ", line=" << 504 << std::endl; ::ns3::FatalImpl ::FlushStreams (); if (true) std::terminate (); } while (false ); } } while (false); | |||||
505 | int numAddresses = messageSize / IPV4_ADDRESS_SIZE4 / 2; | |||||
506 | this->associations.clear (); | |||||
507 | for (int n = 0; n < numAddresses; ++n) | |||||
508 | { | |||||
509 | Ipv4Address address (i.ReadNtohU32 ()); | |||||
510 | Ipv4Mask mask (i.ReadNtohU32 ()); | |||||
511 | this->associations.push_back ((Association) { address, mask}); | |||||
512 | } | |||||
513 | return messageSize; | |||||
514 | } | |||||
515 | ||||||
516 | } | |||||
517 | } // namespace olsr, ns3 | |||||
518 |