A Discrete-Event Network Simulator
API
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
31namespace ns3 {
32namespace olsr {
33
34double EmfToSeconds (uint8_t emf);
35uint8_t SecondsToEmf (double seconds);
36
75class PacketHeader : public Header
76{
77public:
78 PacketHeader ();
79 virtual ~PacketHeader ();
80
85 void SetPacketLength (uint16_t length)
86 {
87 m_packetLength = length;
88 }
89
94 uint16_t GetPacketLength () const
95 {
96 return m_packetLength;
97 }
98
103 void SetPacketSequenceNumber (uint16_t seqnum)
104 {
105 m_packetSequenceNumber = seqnum;
106 }
107
112 uint16_t GetPacketSequenceNumber () const
113 {
115 }
116
117private:
118 uint16_t m_packetLength;
120
121public:
126 static TypeId GetTypeId (void);
127 virtual TypeId GetInstanceTypeId (void) const;
128 virtual void Print (std::ostream &os) const;
129 virtual uint32_t GetSerializedSize (void) const;
130 virtual void Serialize (Buffer::Iterator start) const;
132};
133
157class MessageHeader : public Header
158{
159public:
164 {
169 };
170
171 MessageHeader ();
172 virtual ~MessageHeader ();
173
178 void SetMessageType (MessageType messageType)
179 {
180 m_messageType = messageType;
181 }
187 {
188 return m_messageType;
189 }
190
195 void SetVTime (Time time)
196 {
197 m_vTime = SecondsToEmf (time.GetSeconds ());
198 }
203 Time GetVTime () const
204 {
205 return Seconds (EmfToSeconds (m_vTime));
206 }
207
212 void SetOriginatorAddress (Ipv4Address originatorAddress)
213 {
214 m_originatorAddress = originatorAddress;
215 }
221 {
222 return m_originatorAddress;
223 }
224
229 void SetTimeToLive (uint8_t timeToLive)
230 {
231 m_timeToLive = timeToLive;
232 }
237 uint8_t GetTimeToLive () const
238 {
239 return m_timeToLive;
240 }
241
246 void SetHopCount (uint8_t hopCount)
247 {
248 m_hopCount = hopCount;
249 }
254 uint8_t GetHopCount () const
255 {
256 return m_hopCount;
257 }
258
263 void SetMessageSequenceNumber (uint16_t messageSequenceNumber)
264 {
265 m_messageSequenceNumber = messageSequenceNumber;
266 }
271 uint16_t GetMessageSequenceNumber () const
272 {
274 }
275
276private:
278 uint8_t m_vTime;
280 uint8_t m_timeToLive;
281 uint8_t m_hopCount;
283 uint16_t m_messageSize;
284
285public:
290 static TypeId GetTypeId (void);
291 virtual TypeId GetInstanceTypeId (void) const;
292 virtual void Print (std::ostream &os) const;
293 virtual uint32_t GetSerializedSize (void) const;
294 virtual void Serialize (Buffer::Iterator start) const;
296
313 struct Mid
314 {
315 std::vector<Ipv4Address> interfaceAddresses;
320 void Print (std::ostream &os) const;
325 uint32_t GetSerializedSize (void) const;
333 void Serialize (Buffer::Iterator start) const;
344 };
345
376 struct Hello
377 {
382 {
383 uint8_t linkCode;
384 std::vector<Ipv4Address> neighborInterfaceAddresses;
385 };
386
387 uint8_t hTime;
388
393 void SetHTime (Time time)
394 {
395 this->hTime = SecondsToEmf (time.GetSeconds ());
396 }
397
402 Time GetHTime () const
403 {
404 return Seconds (EmfToSeconds (this->hTime));
405 }
406
407 uint8_t willingness;
408 std::vector<LinkMessage> linkMessages;
409
414 void Print (std::ostream &os) const;
419 uint32_t GetSerializedSize (void) const;
427 void Serialize (Buffer::Iterator start) const;
438 };
439
458 struct Tc
459 {
460 std::vector<Ipv4Address> neighborAddresses;
461 uint16_t ansn;
462
467 void Print (std::ostream &os) const;
472 uint32_t GetSerializedSize (void) const;
480 void Serialize (Buffer::Iterator start) const;
491 };
492
493
514 struct Hna
515 {
520 {
523 };
524
525 std::vector<Association> associations;
526
531 void Print (std::ostream &os) const;
536 uint32_t GetSerializedSize (void) const;
544 void Serialize (Buffer::Iterator start) const;
555 };
556
557private:
561 struct
562 {
568
569public:
575 {
576 if (m_messageType == 0)
577 {
579 }
580 else
581 {
583 }
584 return m_message.mid;
585 }
586
592 {
593 if (m_messageType == 0)
594 {
596 }
597 else
598 {
600 }
601 return m_message.hello;
602 }
603
609 {
610 if (m_messageType == 0)
611 {
613 }
614 else
615 {
617 }
618 return m_message.tc;
619 }
620
626 {
627 if (m_messageType == 0)
628 {
630 }
631 else
632 {
634 }
635 return m_message.hna;
636 }
637
638
643 const Mid& GetMid () const
644 {
646 return m_message.mid;
647 }
648
653 const Hello& GetHello () const
654 {
656 return m_message.hello;
657 }
658
663 const Tc& GetTc () const
664 {
666 return m_message.tc;
667 }
668
673 const Hna& GetHna () const
674 {
676 return m_message.hna;
677 }
678
679
680};
681
682
683static inline std::ostream& operator<< (std::ostream& os, const PacketHeader & packet)
684{
685 packet.Print (os);
686 return os;
687}
688
689static inline std::ostream& operator<< (std::ostream& os, const MessageHeader & message)
690{
691 message.Print (os);
692 return os;
693}
694
695typedef std::vector<MessageHeader> MessageList;
696
697static inline std::ostream& operator<< (std::ostream& os, const MessageList & messages)
698{
699 os << "[";
700 for (std::vector<MessageHeader>::const_iterator messageIter = messages.begin ();
701 messageIter != messages.end (); messageIter++)
702 {
703 messageIter->Print (os);
704 if (messageIter + 1 != messages.end ())
705 {
706 os << ", ";
707 }
708 }
709 os << "]";
710 return os;
711}
712
713
714}
715} // namespace olsr, ns3
716
717#endif /* OLSR_HEADER_H */
718
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
a unique identifier for an interface.
Definition: type-id.h:59
This header can store HELP, TC, MID and HNA messages.
Definition: olsr-header.h:158
Mid mid
MID message (optional).
Definition: olsr-header.h:563
const Hello & GetHello() const
Get the HELLO message.
Definition: olsr-header.h:653
void SetOriginatorAddress(Ipv4Address originatorAddress)
Set the originator address.
Definition: olsr-header.h:212
Ipv4Address GetOriginatorAddress() const
Get the originator address.
Definition: olsr-header.h:220
void SetHopCount(uint8_t hopCount)
Set the hop count.
Definition: olsr-header.h:246
const Hna & GetHna() const
Get the HNA message.
Definition: olsr-header.h:673
MessageType m_messageType
The message type.
Definition: olsr-header.h:277
Mid & GetMid()
Set the message type to MID and return the message content.
Definition: olsr-header.h:574
virtual uint32_t GetSerializedSize(void) const
Definition: olsr-header.cc:189
Tc & GetTc()
Set the message type to TC and return the message content.
Definition: olsr-header.h:608
static TypeId GetTypeId(void)
Get the type ID.
Definition: olsr-header.cc:173
Hello & GetHello()
Set the message type to HELLO and return the message content.
Definition: olsr-header.h:591
virtual void Print(std::ostream &os) const
Definition: olsr-header.cc:214
uint8_t GetTimeToLive() const
Get the time to live.
Definition: olsr-header.h:237
const Mid & GetMid() const
Get the MID message.
Definition: olsr-header.h:643
uint8_t m_hopCount
The hop count.
Definition: olsr-header.h:281
Hello hello
HELLO message (optional).
Definition: olsr-header.h:564
Ipv4Address m_originatorAddress
The originator address.
Definition: olsr-header.h:279
const Tc & GetTc() const
Get the TC message.
Definition: olsr-header.h:663
Hna hna
HNA message (optional).
Definition: olsr-header.h:566
uint8_t m_vTime
The validity time.
Definition: olsr-header.h:278
void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
Set the message sequence number.
Definition: olsr-header.h:263
uint8_t m_timeToLive
The time to live.
Definition: olsr-header.h:280
Tc tc
TC message (optional).
Definition: olsr-header.h:565
void SetMessageType(MessageType messageType)
Set the message type.
Definition: olsr-header.h:178
uint8_t GetHopCount() const
Get the hop count.
Definition: olsr-header.h:254
MessageType GetMessageType() const
Get the message type.
Definition: olsr-header.h:186
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:183
Hna & GetHna()
Set the message type to HNA and return the message content.
Definition: olsr-header.h:625
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: olsr-header.cc:291
struct ns3::olsr::MessageHeader::@69 m_message
Structure holding the message content.
Time GetVTime() const
Get the validity time.
Definition: olsr-header.h:203
virtual void Serialize(Buffer::Iterator start) const
Definition: olsr-header.cc:259
void SetTimeToLive(uint8_t timeToLive)
Set the time to live.
Definition: olsr-header.h:229
uint16_t m_messageSize
The message size.
Definition: olsr-header.h:283
uint16_t GetMessageSequenceNumber() const
Get the message sequence number.
Definition: olsr-header.h:271
void SetVTime(Time time)
Set the validity time.
Definition: olsr-header.h:195
uint16_t m_messageSequenceNumber
The message sequence number.
Definition: olsr-header.h:282
MessageType
Message type.
Definition: olsr-header.h:164
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers):
Definition: olsr-header.h:76
void SetPacketSequenceNumber(uint16_t seqnum)
Set the packet sequence number.
Definition: olsr-header.h:103
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:124
virtual void Serialize(Buffer::Iterator start) const
Definition: olsr-header.cc:142
static TypeId GetTypeId(void)
Get the type ID.
Definition: olsr-header.cc:114
void SetPacketLength(uint16_t length)
Set the packet total length.
Definition: olsr-header.h:85
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: olsr-header.cc:150
uint16_t m_packetLength
The packet length.
Definition: olsr-header.h:118
uint16_t GetPacketLength() const
Get the packet total length.
Definition: olsr-header.h:94
virtual void Print(std::ostream &os) const
Definition: olsr-header.cc:136
uint16_t m_packetSequenceNumber
The packet sequence number.
Definition: olsr-header.h:119
uint16_t GetPacketSequenceNumber() const
Get the packet sequence number.
Definition: olsr-header.h:112
virtual uint32_t GetSerializedSize(void) const
Definition: olsr-header.cc:130
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
static std::ostream & operator<<(std::ostream &os, const PacketHeader &packet)
Definition: olsr-header.h:683
double EmfToSeconds(uint8_t olsrFormat)
Converts a number of seconds in the mantissa/exponent format to a decimal number.
Definition: olsr-header.cc:91
uint8_t SecondsToEmf(double seconds)
Converts a decimal number of seconds to the mantissa/exponent format.
Definition: olsr-header.cc:49
std::vector< MessageHeader > MessageList
Definition: olsr-header.h:695
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
def start()
Definition: core.py:1853
HELLO Message Format.
Definition: olsr-header.h:377
void SetHTime(Time time)
Set the HELLO emission interval.
Definition: olsr-header.h:393
uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize)
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet.
Definition: olsr-header.cc:462
uint8_t willingness
The willingness of a node to carry and forward traffic for other nodes.
Definition: olsr-header.h:407
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:388
void Print(std::ostream &os) const
This method is used to print the content of a Hello message.
Definition: olsr-header.cc:402
std::vector< LinkMessage > linkMessages
Link messages container.
Definition: olsr-header.h:408
uint8_t hTime
HELLO emission interval (coded)
Definition: olsr-header.h:387
Time GetHTime() const
Get the HELLO emission interval.
Definition: olsr-header.h:402
void Serialize(Buffer::Iterator start) const
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet.
Definition: olsr-header.cc:431
HNA (Host Network Association) Message Format.
Definition: olsr-header.h:515
void Serialize(Buffer::Iterator start) const
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet.
Definition: olsr-header.cc:595
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:569
uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize)
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet.
Definition: olsr-header.cc:607
std::vector< Association > associations
Association container.
Definition: olsr-header.h:525
void Print(std::ostream &os) const
This method is used to print the content of a Hna message.
Definition: olsr-header.cc:575
MID Message Format.
Definition: olsr-header.h:314
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:328
std::vector< Ipv4Address > interfaceAddresses
Interface Address container.
Definition: olsr-header.h:315
void Serialize(Buffer::Iterator start) const
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet.
Definition: olsr-header.cc:354
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:334
uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize)
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet.
Definition: olsr-header.cc:366
TC Message Format.
Definition: olsr-header.h:459
uint16_t ansn
Advertised Neighbor Sequence Number.
Definition: olsr-header.h:461
std::vector< Ipv4Address > neighborAddresses
Neighbor address container.
Definition: olsr-header.h:460
void Serialize(Buffer::Iterator start) const
This method is used by Packet::AddHeader to store a header into the byte buffer of a packet.
Definition: olsr-header.cc:529
void Print(std::ostream &os) const
This method is used to print the content of a Tc message.
Definition: olsr-header.cc:508
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:502
uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize)
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet.
Definition: olsr-header.cc:544