A Discrete-Event Network Simulator
API
olsr-header.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INESC Porto
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
18 */
19
20#ifndef OLSR_HEADER_H
21#define OLSR_HEADER_H
22
23#include "ns3/header.h"
24#include "ns3/ipv4-address.h"
25#include "ns3/nstime.h"
26
27#include <stdint.h>
28#include <vector>
29
30namespace ns3
31{
32namespace olsr
33{
34
35double EmfToSeconds(uint8_t emf);
36uint8_t SecondsToEmf(double seconds);
37
76class PacketHeader : public Header
77{
78 public:
80 ~PacketHeader() override;
81
86 void SetPacketLength(uint16_t length)
87 {
88 m_packetLength = length;
89 }
90
95 uint16_t GetPacketLength() const
96 {
97 return m_packetLength;
98 }
99
104 void SetPacketSequenceNumber(uint16_t seqnum)
105 {
106 m_packetSequenceNumber = seqnum;
107 }
108
113 uint16_t GetPacketSequenceNumber() const
114 {
116 }
117
118 private:
119 uint16_t m_packetLength;
121
122 public:
127 static TypeId GetTypeId();
128 TypeId GetInstanceTypeId() const override;
129 void Print(std::ostream& os) const override;
130 uint32_t GetSerializedSize() const override;
131 void Serialize(Buffer::Iterator start) const override;
133};
134
158class MessageHeader : public Header
159{
160 public:
165 {
170 };
171
173 ~MessageHeader() override;
174
179 void SetMessageType(MessageType messageType)
180 {
181 m_messageType = messageType;
182 }
183
189 {
190 return m_messageType;
191 }
192
197 void SetVTime(Time time)
198 {
200 }
201
207 {
209 }
210
215 void SetOriginatorAddress(Ipv4Address originatorAddress)
216 {
217 m_originatorAddress = originatorAddress;
218 }
219
225 {
226 return m_originatorAddress;
227 }
228
233 void SetTimeToLive(uint8_t timeToLive)
234 {
235 m_timeToLive = timeToLive;
236 }
237
242 uint8_t GetTimeToLive() const
243 {
244 return m_timeToLive;
245 }
246
251 void SetHopCount(uint8_t hopCount)
252 {
253 m_hopCount = hopCount;
254 }
255
260 uint8_t GetHopCount() const
261 {
262 return m_hopCount;
263 }
264
269 void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
270 {
271 m_messageSequenceNumber = messageSequenceNumber;
272 }
273
279 {
281 }
282
283 private:
285 uint8_t m_vTime;
287 uint8_t m_timeToLive;
288 uint8_t m_hopCount;
290 uint16_t m_messageSize;
291
292 public:
297 static TypeId GetTypeId();
298 TypeId GetInstanceTypeId() const override;
299 void Print(std::ostream& os) const override;
300 uint32_t GetSerializedSize() const override;
301 void Serialize(Buffer::Iterator start) const override;
303
320 struct Mid
321 {
322 std::vector<Ipv4Address> interfaceAddresses;
327 void Print(std::ostream& os) const;
340 void Serialize(Buffer::Iterator start) const;
351 };
352
383 struct Hello
384 {
389 {
390 uint8_t linkCode;
391 std::vector<Ipv4Address>
393 };
394
395 uint8_t hTime;
396
401 void SetHTime(Time time)
402 {
403 this->hTime = SecondsToEmf(time.GetSeconds());
404 }
405
411 {
412 return Seconds(EmfToSeconds(this->hTime));
413 }
414
415 uint8_t willingness;
417 std::vector<LinkMessage> linkMessages;
418
423 void Print(std::ostream& os) const;
436 void Serialize(Buffer::Iterator start) const;
447 };
448
467 struct Tc
468 {
469 std::vector<Ipv4Address> neighborAddresses;
470 uint16_t ansn;
471
476 void Print(std::ostream& os) const;
489 void Serialize(Buffer::Iterator start) const;
500 };
501
522 struct Hna
523 {
528 {
531 };
532
533 std::vector<Association> associations;
534
539 void Print(std::ostream& os) const;
552 void Serialize(Buffer::Iterator start) const;
563 };
564
565 private:
569 struct
570 {
576
577 public:
583 {
584 if (m_messageType == 0)
585 {
587 }
588 else
589 {
591 }
592 return m_message.mid;
593 }
594
600 {
601 if (m_messageType == 0)
602 {
604 }
605 else
606 {
608 }
609 return m_message.hello;
610 }
611
617 {
618 if (m_messageType == 0)
619 {
621 }
622 else
623 {
625 }
626 return m_message.tc;
627 }
628
634 {
635 if (m_messageType == 0)
636 {
638 }
639 else
640 {
642 }
643 return m_message.hna;
644 }
645
650 const Mid& GetMid() const
651 {
653 return m_message.mid;
654 }
655
660 const Hello& GetHello() const
661 {
663 return m_message.hello;
664 }
665
670 const Tc& GetTc() const
671 {
673 return m_message.tc;
674 }
675
680 const Hna& GetHna() const
681 {
683 return m_message.hna;
684 }
685};
686
687static inline std::ostream&
688operator<<(std::ostream& os, const PacketHeader& packet)
689{
690 packet.Print(os);
691 return os;
692}
693
694static inline std::ostream&
695operator<<(std::ostream& os, const MessageHeader& message)
696{
697 message.Print(os);
698 return os;
699}
700
701typedef std::vector<MessageHeader> MessageList;
702
703static inline std::ostream&
704operator<<(std::ostream& os, const MessageList& messages)
705{
706 os << "[";
707 for (std::vector<MessageHeader>::const_iterator messageIter = messages.begin();
708 messageIter != messages.end();
709 messageIter++)
710 {
711 messageIter->Print(os);
712 if (messageIter + 1 != messages.end())
713 {
714 os << ", ";
715 }
716 }
717 os << "]";
718 return os;
719}
720
721} // namespace olsr
722} // namespace ns3
723
724#endif /* OLSR_HEADER_H */
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
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:159
Mid mid
MID message (optional).
Definition: olsr-header.h:571
const Hello & GetHello() const
Get the HELLO message.
Definition: olsr-header.h:660
void SetOriginatorAddress(Ipv4Address originatorAddress)
Set the originator address.
Definition: olsr-header.h:215
Ipv4Address GetOriginatorAddress() const
Get the originator address.
Definition: olsr-header.h:224
void SetHopCount(uint8_t hopCount)
Set the hop count.
Definition: olsr-header.h:251
void Print(std::ostream &os) const override
Definition: olsr-header.cc:213
const Hna & GetHna() const
Get the HNA message.
Definition: olsr-header.h:680
MessageType m_messageType
The message type.
Definition: olsr-header.h:284
Mid & GetMid()
Set the message type to MID and return the message content.
Definition: olsr-header.h:582
Tc & GetTc()
Set the message type to TC and return the message content.
Definition: olsr-header.h:616
Hello & GetHello()
Set the message type to HELLO and return the message content.
Definition: olsr-header.h:599
uint8_t GetTimeToLive() const
Get the time to live.
Definition: olsr-header.h:242
const Mid & GetMid() const
Get the MID message.
Definition: olsr-header.h:650
uint8_t m_hopCount
The hop count.
Definition: olsr-header.h:288
Hello hello
HELLO message (optional).
Definition: olsr-header.h:572
Ipv4Address m_originatorAddress
The originator address.
Definition: olsr-header.h:286
const Tc & GetTc() const
Get the TC message.
Definition: olsr-header.h:670
Hna hna
HNA message (optional).
Definition: olsr-header.h:574
uint8_t m_vTime
The validity time.
Definition: olsr-header.h:285
void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
Set the message sequence number.
Definition: olsr-header.h:269
uint8_t m_timeToLive
The time to live.
Definition: olsr-header.h:287
Tc tc
TC message (optional).
Definition: olsr-header.h:573
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:181
void SetMessageType(MessageType messageType)
Set the message type.
Definition: olsr-header.h:179
uint8_t GetHopCount() const
Get the hop count.
Definition: olsr-header.h:260
MessageType GetMessageType() const
Get the message type.
Definition: olsr-header.h:188
Hna & GetHna()
Set the message type to HNA and return the message content.
Definition: olsr-header.h:633
struct ns3::olsr::MessageHeader::@69 m_message
Structure holding the message content.
Time GetVTime() const
Get the validity time.
Definition: olsr-header.h:206
void SetTimeToLive(uint8_t timeToLive)
Set the time to live.
Definition: olsr-header.h:233
uint16_t m_messageSize
The message size.
Definition: olsr-header.h:290
uint32_t GetSerializedSize() const override
Definition: olsr-header.cc:187
uint16_t GetMessageSequenceNumber() const
Get the message sequence number.
Definition: olsr-header.h:278
void SetVTime(Time time)
Set the validity time.
Definition: olsr-header.h:197
uint16_t m_messageSequenceNumber
The message sequence number.
Definition: olsr-header.h:289
uint32_t Deserialize(Buffer::Iterator start) override
Definition: olsr-header.cc:289
void Serialize(Buffer::Iterator start) const override
Definition: olsr-header.cc:258
static TypeId GetTypeId()
Get the type ID.
Definition: olsr-header.cc:171
MessageType
Message type.
Definition: olsr-header.h:165
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers):
Definition: olsr-header.h:77
void SetPacketSequenceNumber(uint16_t seqnum)
Set the packet sequence number.
Definition: olsr-header.h:104
static TypeId GetTypeId()
Get the type ID.
Definition: olsr-header.cc:113
uint32_t Deserialize(Buffer::Iterator start) override
Definition: olsr-header.cc:149
void SetPacketLength(uint16_t length)
Set the packet total length.
Definition: olsr-header.h:86
uint32_t GetSerializedSize() const override
Definition: olsr-header.cc:129
uint16_t m_packetLength
The packet length.
Definition: olsr-header.h:119
uint16_t GetPacketLength() const
Get the packet total length.
Definition: olsr-header.h:95
void Print(std::ostream &os) const override
Definition: olsr-header.cc:135
uint16_t m_packetSequenceNumber
The packet sequence number.
Definition: olsr-header.h:120
void Serialize(Buffer::Iterator start) const override
Definition: olsr-header.cc:141
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:123
uint16_t GetPacketSequenceNumber() const
Get the packet sequence number.
Definition: olsr-header.h:113
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
static std::ostream & operator<<(std::ostream &os, const PacketHeader &packet)
Definition: olsr-header.h:688
double EmfToSeconds(uint8_t olsrFormat)
Converts a number of seconds in the mantissa/exponent format to a decimal number.
Definition: olsr-header.cc:92
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:701
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
HELLO Message Format.
Definition: olsr-header.h:384
void SetHTime(Time time)
Set the HELLO emission interval.
Definition: olsr-header.h:401
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:461
uint8_t willingness
The willingness of a node to carry and forward traffic for other nodes.
Definition: olsr-header.h:415
void Print(std::ostream &os) const
This method is used to print the content of a Hello message.
Definition: olsr-header.cc:399
std::vector< LinkMessage > linkMessages
Link messages container.
Definition: olsr-header.h:417
uint8_t hTime
HELLO emission interval (coded)
Definition: olsr-header.h:395
uint32_t GetSerializedSize() const
Returns the expected size of the header.
Definition: olsr-header.cc:384
Time GetHTime() const
Get the HELLO emission interval.
Definition: olsr-header.h:410
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:427
HNA (Host Network Association) Message Format.
Definition: olsr-header.h:523
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:592
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:604
std::vector< Association > associations
Association container.
Definition: olsr-header.h:533
void Print(std::ostream &os) const
This method is used to print the content of a Hna message.
Definition: olsr-header.cc:572
uint32_t GetSerializedSize() const
Returns the expected size of the header.
Definition: olsr-header.cc:566
MID Message Format.
Definition: olsr-header.h:321
uint32_t GetSerializedSize() const
Returns the expected size of the header.
Definition: olsr-header.cc:325
std::vector< Ipv4Address > interfaceAddresses
Interface Address container.
Definition: olsr-header.h:322
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:351
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:331
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:364
TC Message Format.
Definition: olsr-header.h:468
uint16_t ansn
Advertised Neighbor Sequence Number.
Definition: olsr-header.h:470
std::vector< Ipv4Address > neighborAddresses
Neighbor address container.
Definition: olsr-header.h:469
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:526
uint32_t GetSerializedSize() const
Returns the expected size of the header.
Definition: olsr-header.cc:499
void Print(std::ostream &os) const
This method is used to print the content of a Tc message.
Definition: olsr-header.cc:505
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:542