A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
olsr-header.h
Go to the documentation of this file.
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
#ifndef OLSR_HEADER_H
22
#define OLSR_HEADER_H
23
24
#include <stdint.h>
25
#include <vector>
26
#include "ns3/header.h"
27
#include "ns3/ipv4-address.h"
28
#include "ns3/nstime.h"
29
30
31
namespace
ns3 {
32
namespace
olsr {
33
34
double
EmfToSeconds
(uint8_t emf);
35
uint8_t
SecondsToEmf
(
double
seconds);
36
37
// 3.3. Packet Format
38
//
39
// The basic layout of any packet in OLSR is as follows (omitting IP and
40
// UDP headers):
41
//
42
// 0 1 2 3
43
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
44
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45
// | Packet Length | Packet Sequence Number |
46
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
47
// | Message Type | Vtime | Message Size |
48
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49
// | Originator Address |
50
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
51
// | Time To Live | Hop Count | Message Sequence Number |
52
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53
// | |
54
// : MESSAGE :
55
// | |
56
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57
// | Message Type | Vtime | Message Size |
58
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
59
// | Originator Address |
60
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61
// | Time To Live | Hop Count | Message Sequence Number |
62
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63
// | |
64
// : MESSAGE :
65
// | |
66
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67
// : :
68
// (etc.)
69
class
PacketHeader
:
public
Header
70
{
71
public
:
72
PacketHeader
();
73
virtual
~PacketHeader
();
74
75
void
SetPacketLength
(uint16_t length)
76
{
77
m_packetLength
= length;
78
}
79
uint16_t
GetPacketLength
()
const
80
{
81
return
m_packetLength
;
82
}
83
84
void
SetPacketSequenceNumber
(uint16_t seqnum)
85
{
86
m_packetSequenceNumber
= seqnum;
87
}
88
uint16_t
GetPacketSequenceNumber
()
const
89
{
90
return
m_packetSequenceNumber
;
91
}
92
93
private
:
94
uint16_t
m_packetLength
;
95
uint16_t
m_packetSequenceNumber
;
96
97
public
:
98
static
TypeId
GetTypeId
(
void
);
99
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
100
virtual
void
Print
(std::ostream &os)
const
;
101
virtual
uint32_t
GetSerializedSize
(
void
)
const
;
102
virtual
void
Serialize
(
Buffer::Iterator
start
)
const
;
103
virtual
uint32_t
Deserialize
(
Buffer::Iterator
start
);
104
};
105
106
107
// 0 1 2 3
108
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
109
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110
// | Message Type | Vtime | Message Size |
111
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112
// | Originator Address |
113
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114
// | Time To Live | Hop Count | Message Sequence Number |
115
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116
class
MessageHeader
:
public
Header
117
{
118
public
:
119
120
enum
MessageType
{
121
HELLO_MESSAGE
= 1,
122
TC_MESSAGE
= 2,
123
MID_MESSAGE
= 3,
124
HNA_MESSAGE
= 4,
125
};
126
127
MessageHeader
();
128
virtual
~MessageHeader
();
129
130
void
SetMessageType
(
MessageType
messageType)
131
{
132
m_messageType
= messageType;
133
}
134
MessageType
GetMessageType
()
const
135
{
136
return
m_messageType
;
137
}
138
139
void
SetVTime
(
Time
time)
140
{
141
m_vTime
=
SecondsToEmf
(time.
GetSeconds
());
142
}
143
Time
GetVTime
()
const
144
{
145
return
Seconds
(
EmfToSeconds
(
m_vTime
));
146
}
147
148
void
SetOriginatorAddress
(
Ipv4Address
originatorAddress)
149
{
150
m_originatorAddress
= originatorAddress;
151
}
152
Ipv4Address
GetOriginatorAddress
()
const
153
{
154
return
m_originatorAddress
;
155
}
156
157
void
SetTimeToLive
(uint8_t timeToLive)
158
{
159
m_timeToLive
= timeToLive;
160
}
161
uint8_t
GetTimeToLive
()
const
162
{
163
return
m_timeToLive
;
164
}
165
166
void
SetHopCount
(uint8_t hopCount)
167
{
168
m_hopCount
= hopCount;
169
}
170
uint8_t
GetHopCount
()
const
171
{
172
return
m_hopCount
;
173
}
174
175
void
SetMessageSequenceNumber
(uint16_t messageSequenceNumber)
176
{
177
m_messageSequenceNumber
= messageSequenceNumber;
178
}
179
uint16_t
GetMessageSequenceNumber
()
const
180
{
181
return
m_messageSequenceNumber
;
182
}
183
184
// void SetMessageSize (uint16_t messageSize)
185
// {
186
// m_messageSize = messageSize;
187
// }
188
// uint16_t GetMessageSize () const
189
// {
190
// return m_messageSize;
191
// }
192
193
private
:
194
MessageType
m_messageType
;
195
uint8_t
m_vTime
;
196
Ipv4Address
m_originatorAddress
;
197
uint8_t
m_timeToLive
;
198
uint8_t
m_hopCount
;
199
uint16_t
m_messageSequenceNumber
;
200
uint16_t
m_messageSize
;
201
202
public
:
203
static
TypeId
GetTypeId
(
void
);
204
virtual
TypeId
GetInstanceTypeId
(
void
)
const
;
205
virtual
void
Print
(std::ostream &os)
const
;
206
virtual
uint32_t
GetSerializedSize
(
void
)
const
;
207
virtual
void
Serialize
(
Buffer::Iterator
start
)
const
;
208
virtual
uint32_t
Deserialize
(
Buffer::Iterator
start
);
209
210
// 5.1. MID Message Format
211
//
212
// The proposed format of a MID message is as follows:
213
//
214
// 0 1 2 3
215
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
216
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217
// | OLSR Interface Address |
218
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219
// | OLSR Interface Address |
220
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221
// | ... |
222
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223
struct
Mid
224
{
225
std::vector<Ipv4Address>
interfaceAddresses
;
226
void
Print
(std::ostream &os)
const
;
227
uint32_t
GetSerializedSize
(
void
)
const
;
228
void
Serialize
(
Buffer::Iterator
start
)
const
;
229
uint32_t
Deserialize
(
Buffer::Iterator
start
, uint32_t messageSize);
230
};
231
232
// 6.1. HELLO Message Format
233
//
234
// 0 1 2 3
235
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
236
//
237
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
238
// | Reserved | Htime | Willingness |
239
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
240
// | Link Code | Reserved | Link Message Size |
241
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
242
// | Neighbor Interface Address |
243
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244
// | Neighbor Interface Address |
245
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
246
// : . . . :
247
// : :
248
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
249
// | Link Code | Reserved | Link Message Size |
250
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
251
// | Neighbor Interface Address |
252
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253
// | Neighbor Interface Address |
254
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
255
// : :
256
// : :
257
// (etc.)
258
struct
Hello
259
{
260
struct
LinkMessage
{
261
uint8_t
linkCode
;
262
std::vector<Ipv4Address>
neighborInterfaceAddresses
;
263
};
264
265
uint8_t
hTime
;
266
void
SetHTime
(
Time
time)
267
{
268
this->
hTime
=
SecondsToEmf
(time.
GetSeconds
());
269
}
270
Time
GetHTime
()
const
271
{
272
return
Seconds
(
EmfToSeconds
(this->
hTime
));
273
}
274
275
uint8_t
willingness
;
276
std::vector<LinkMessage>
linkMessages
;
277
278
void
Print
(std::ostream &os)
const
;
279
uint32_t
GetSerializedSize
(
void
)
const
;
280
void
Serialize
(
Buffer::Iterator
start
)
const
;
281
uint32_t
Deserialize
(
Buffer::Iterator
start
, uint32_t messageSize);
282
};
283
284
// 9.1. TC Message Format
285
//
286
// The proposed format of a TC message is as follows:
287
//
288
// 0 1 2 3
289
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
290
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
291
// | ANSN | Reserved |
292
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
293
// | Advertised Neighbor Main Address |
294
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
295
// | Advertised Neighbor Main Address |
296
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
297
// | ... |
298
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
299
300
struct
Tc
301
{
302
std::vector<Ipv4Address>
neighborAddresses
;
303
uint16_t
ansn
;
304
305
void
Print
(std::ostream &os)
const
;
306
uint32_t
GetSerializedSize
(
void
)
const
;
307
void
Serialize
(
Buffer::Iterator
start
)
const
;
308
uint32_t
Deserialize
(
Buffer::Iterator
start
, uint32_t messageSize);
309
};
310
311
312
// 12.1. HNA Message Format
313
//
314
// The proposed format of an HNA-message is:
315
//
316
// 0 1 2 3
317
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
318
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
319
// | Network Address |
320
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
321
// | Netmask |
322
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
323
// | Network Address |
324
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
325
// | Netmask |
326
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
327
// | ... |
328
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
329
330
// Note: HNA stands for Host Network Association
331
struct
Hna
332
{
333
struct
Association
334
{
335
Ipv4Address
address
;
336
Ipv4Mask
mask
;
337
};
338
std::vector<Association>
associations
;
339
340
void
Print
(std::ostream &os)
const
;
341
uint32_t
GetSerializedSize
(
void
)
const
;
342
void
Serialize
(
Buffer::Iterator
start
)
const
;
343
uint32_t
Deserialize
(
Buffer::Iterator
start
, uint32_t messageSize);
344
};
345
346
private
:
347
struct
348
{
349
Mid
mid
;
350
Hello
hello
;
351
Tc
tc
;
352
Hna
hna
;
353
}
m_message
;
// union not allowed
354
355
public
:
356
357
Mid
&
GetMid
()
358
{
359
if
(
m_messageType
== 0)
360
{
361
m_messageType
=
MID_MESSAGE
;
362
}
363
else
364
{
365
NS_ASSERT
(
m_messageType
==
MID_MESSAGE
);
366
}
367
return
m_message
.mid;
368
}
369
370
Hello
&
GetHello
()
371
{
372
if
(
m_messageType
== 0)
373
{
374
m_messageType
=
HELLO_MESSAGE
;
375
}
376
else
377
{
378
NS_ASSERT
(
m_messageType
==
HELLO_MESSAGE
);
379
}
380
return
m_message
.hello;
381
}
382
383
Tc
&
GetTc
()
384
{
385
if
(
m_messageType
== 0)
386
{
387
m_messageType
=
TC_MESSAGE
;
388
}
389
else
390
{
391
NS_ASSERT
(
m_messageType
==
TC_MESSAGE
);
392
}
393
return
m_message
.tc;
394
}
395
396
Hna
&
GetHna
()
397
{
398
if
(
m_messageType
== 0)
399
{
400
m_messageType
=
HNA_MESSAGE
;
401
}
402
else
403
{
404
NS_ASSERT
(
m_messageType
==
HNA_MESSAGE
);
405
}
406
return
m_message
.hna;
407
}
408
409
410
const
Mid
&
GetMid
()
const
411
{
412
NS_ASSERT
(
m_messageType
==
MID_MESSAGE
);
413
return
m_message
.mid;
414
}
415
416
const
Hello
&
GetHello
()
const
417
{
418
NS_ASSERT
(
m_messageType
==
HELLO_MESSAGE
);
419
return
m_message
.hello;
420
}
421
422
const
Tc
&
GetTc
()
const
423
{
424
NS_ASSERT
(
m_messageType
==
TC_MESSAGE
);
425
return
m_message
.tc;
426
}
427
428
const
Hna
&
GetHna
()
const
429
{
430
NS_ASSERT
(
m_messageType
==
HNA_MESSAGE
);
431
return
m_message
.hna;
432
}
433
434
435
};
436
437
438
static
inline
std::ostream&
operator<<
(std::ostream& os,
const
PacketHeader
& packet)
439
{
440
packet.
Print
(os);
441
return
os;
442
}
443
444
static
inline
std::ostream&
operator<<
(std::ostream& os,
const
MessageHeader
& message)
445
{
446
message.
Print
(os);
447
return
os;
448
}
449
450
typedef
std::vector<MessageHeader>
MessageList
;
451
452
static
inline
std::ostream&
operator<<
(std::ostream& os,
const
MessageList
& messages)
453
{
454
os <<
"["
;
455
for
(std::vector<MessageHeader>::const_iterator messageIter = messages.begin ();
456
messageIter != messages.end (); messageIter++)
457
{
458
messageIter->Print (os);
459
if
(messageIter+1 != messages.end ())
460
os <<
", "
;
461
}
462
os <<
"]"
;
463
return
os;
464
}
465
466
467
}
468
}
// namespace olsr, ns3
469
470
#endif
/* OLSR_HEADER_H */
471
src
olsr
model
olsr-header.h
Generated on Tue May 14 2013 11:08:31 for ns-3 by
1.8.1.2