A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 "olsr-repositories.h"
24
25#include "ns3/header.h"
26#include "ns3/ipv4-address.h"
27#include "ns3/nstime.h"
28
29#include <stdint.h>
30#include <vector>
31
32namespace ns3
33{
34namespace olsr
35{
36
37double EmfToSeconds(uint8_t emf);
38uint8_t SecondsToEmf(double seconds);
39
78class PacketHeader : public Header
79{
80 public:
82 ~PacketHeader() override;
83
88 void SetPacketLength(uint16_t length)
89 {
90 m_packetLength = length;
91 }
92
97 uint16_t GetPacketLength() const
98 {
99 return m_packetLength;
100 }
101
106 void SetPacketSequenceNumber(uint16_t seqnum)
107 {
108 m_packetSequenceNumber = seqnum;
109 }
110
115 uint16_t GetPacketSequenceNumber() const
116 {
118 }
119
120 private:
121 uint16_t m_packetLength;
123
124 public:
129 static TypeId GetTypeId();
130 TypeId GetInstanceTypeId() const override;
131 void Print(std::ostream& os) const override;
132 uint32_t GetSerializedSize() const override;
133 void Serialize(Buffer::Iterator start) const override;
134 uint32_t Deserialize(Buffer::Iterator start) override;
135};
136
160class MessageHeader : public Header
161{
162 public:
167 {
172 };
173
175 ~MessageHeader() override;
176
181 void SetMessageType(MessageType messageType)
182 {
183 m_messageType = messageType;
184 }
185
191 {
192 return m_messageType;
193 }
194
199 void SetVTime(Time time)
200 {
202 }
203
209 {
211 }
212
217 void SetOriginatorAddress(Ipv4Address originatorAddress)
218 {
219 m_originatorAddress = originatorAddress;
220 }
221
227 {
228 return m_originatorAddress;
229 }
230
235 void SetTimeToLive(uint8_t timeToLive)
236 {
237 m_timeToLive = timeToLive;
238 }
239
244 uint8_t GetTimeToLive() const
245 {
246 return m_timeToLive;
247 }
248
253 void SetHopCount(uint8_t hopCount)
254 {
255 m_hopCount = hopCount;
256 }
257
262 uint8_t GetHopCount() const
263 {
264 return m_hopCount;
265 }
266
271 void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
272 {
273 m_messageSequenceNumber = messageSequenceNumber;
274 }
275
281 {
283 }
284
285 private:
287 uint8_t m_vTime;
289 uint8_t m_timeToLive;
290 uint8_t m_hopCount;
292 uint16_t m_messageSize;
293
294 public:
299 static TypeId GetTypeId();
300 TypeId GetInstanceTypeId() const override;
301 void Print(std::ostream& os) const override;
302 uint32_t GetSerializedSize() const override;
303 void Serialize(Buffer::Iterator start) const override;
304 uint32_t Deserialize(Buffer::Iterator start) override;
305
322 struct Mid
323 {
324 std::vector<Ipv4Address> interfaceAddresses;
329 void Print(std::ostream& os) const;
342 void Serialize(Buffer::Iterator start) const;
352 uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize);
353 };
354
385 struct Hello
386 {
391 {
392 uint8_t linkCode;
393 std::vector<Ipv4Address>
395 };
396
397 uint8_t hTime;
398
403 void SetHTime(Time time)
404 {
405 this->hTime = SecondsToEmf(time.GetSeconds());
406 }
407
413 {
414 return Seconds(EmfToSeconds(this->hTime));
415 }
416
419 std::vector<LinkMessage> linkMessages;
420
425 void Print(std::ostream& os) const;
438 void Serialize(Buffer::Iterator start) const;
448 uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize);
449 };
450
469 struct Tc
470 {
471 std::vector<Ipv4Address> neighborAddresses;
472 uint16_t ansn;
473
478 void Print(std::ostream& os) const;
491 void Serialize(Buffer::Iterator start) const;
501 uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize);
502 };
503
524 struct Hna
525 {
530 {
533 };
534
535 std::vector<Association> associations;
536
541 void Print(std::ostream& os) const;
554 void Serialize(Buffer::Iterator start) const;
564 uint32_t Deserialize(Buffer::Iterator start, uint32_t messageSize);
565 };
566
567 private:
571 struct
572 {
578
579 public:
585 {
586 if (m_messageType == 0)
587 {
589 }
590 else
591 {
593 }
594 return m_message.mid;
595 }
596
602 {
603 if (m_messageType == 0)
604 {
606 }
607 else
608 {
610 }
611 return m_message.hello;
612 }
613
619 {
620 if (m_messageType == 0)
621 {
623 }
624 else
625 {
627 }
628 return m_message.tc;
629 }
630
636 {
637 if (m_messageType == 0)
638 {
640 }
641 else
642 {
644 }
645 return m_message.hna;
646 }
647
652 const Mid& GetMid() const
653 {
655 return m_message.mid;
656 }
657
662 const Hello& GetHello() const
663 {
665 return m_message.hello;
666 }
667
672 const Tc& GetTc() const
673 {
675 return m_message.tc;
676 }
677
682 const Hna& GetHna() const
683 {
685 return m_message.hna;
686 }
687};
688
689inline std::ostream&
690operator<<(std::ostream& os, const PacketHeader& packet)
691{
692 packet.Print(os);
693 return os;
694}
695
696inline std::ostream&
697operator<<(std::ostream& os, const MessageHeader& message)
698{
699 message.Print(os);
700 return os;
701}
702
703typedef std::vector<MessageHeader> MessageList;
704
705inline std::ostream&
706operator<<(std::ostream& os, const MessageList& messages)
707{
708 os << "[";
709 for (std::vector<MessageHeader>::const_iterator messageIter = messages.begin();
710 messageIter != messages.end();
711 messageIter++)
712 {
713 messageIter->Print(os);
714 if (messageIter + 1 != messages.end())
715 {
716 os << ", ";
717 }
718 }
719 os << "]";
720 return os;
721}
722
723} // namespace olsr
724} // namespace ns3
725
726#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:161
Mid mid
MID message (optional).
Definition: olsr-header.h:573
const Hello & GetHello() const
Get the HELLO message.
Definition: olsr-header.h:662
void SetOriginatorAddress(Ipv4Address originatorAddress)
Set the originator address.
Definition: olsr-header.h:217
Ipv4Address GetOriginatorAddress() const
Get the originator address.
Definition: olsr-header.h:226
void SetHopCount(uint8_t hopCount)
Set the hop count.
Definition: olsr-header.h:253
void Print(std::ostream &os) const override
Definition: olsr-header.cc:213
const Hna & GetHna() const
Get the HNA message.
Definition: olsr-header.h:682
MessageType m_messageType
The message type.
Definition: olsr-header.h:286
struct ns3::olsr::MessageHeader::@66 m_message
Structure holding the message content.
Mid & GetMid()
Set the message type to MID and return the message content.
Definition: olsr-header.h:584
Tc & GetTc()
Set the message type to TC and return the message content.
Definition: olsr-header.h:618
Hello & GetHello()
Set the message type to HELLO and return the message content.
Definition: olsr-header.h:601
uint8_t GetTimeToLive() const
Get the time to live.
Definition: olsr-header.h:244
const Mid & GetMid() const
Get the MID message.
Definition: olsr-header.h:652
uint8_t m_hopCount
The hop count.
Definition: olsr-header.h:290
Hello hello
HELLO message (optional).
Definition: olsr-header.h:574
Ipv4Address m_originatorAddress
The originator address.
Definition: olsr-header.h:288
const Tc & GetTc() const
Get the TC message.
Definition: olsr-header.h:672
Hna hna
HNA message (optional).
Definition: olsr-header.h:576
uint8_t m_vTime
The validity time.
Definition: olsr-header.h:287
void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
Set the message sequence number.
Definition: olsr-header.h:271
uint8_t m_timeToLive
The time to live.
Definition: olsr-header.h:289
Tc tc
TC message (optional).
Definition: olsr-header.h:575
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:181
uint8_t GetHopCount() const
Get the hop count.
Definition: olsr-header.h:262
MessageType GetMessageType() const
Get the message type.
Definition: olsr-header.h:190
Hna & GetHna()
Set the message type to HNA and return the message content.
Definition: olsr-header.h:635
Time GetVTime() const
Get the validity time.
Definition: olsr-header.h:208
void SetTimeToLive(uint8_t timeToLive)
Set the time to live.
Definition: olsr-header.h:235
uint16_t m_messageSize
The message size.
Definition: olsr-header.h:292
uint32_t GetSerializedSize() const override
Definition: olsr-header.cc:187
uint16_t GetMessageSequenceNumber() const
Get the message sequence number.
Definition: olsr-header.h:280
void SetVTime(Time time)
Set the validity time.
Definition: olsr-header.h:199
uint16_t m_messageSequenceNumber
The message sequence number.
Definition: olsr-header.h:291
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:167
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers):
Definition: olsr-header.h:79
void SetPacketSequenceNumber(uint16_t seqnum)
Set the packet sequence number.
Definition: olsr-header.h:106
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:88
uint32_t GetSerializedSize() const override
Definition: olsr-header.cc:129
uint16_t m_packetLength
The packet length.
Definition: olsr-header.h:121
uint16_t GetPacketLength() const
Get the packet total length.
Definition: olsr-header.h:97
void Print(std::ostream &os) const override
Definition: olsr-header.cc:135
uint16_t m_packetSequenceNumber
The packet sequence number.
Definition: olsr-header.h:122
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:115
#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
Willingness
Willingness for forwarding packets from other nodes.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
std::ostream & operator<<(std::ostream &os, const PacketHeader &packet)
Definition: olsr-header.h:690
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:703
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: olsr.py:1
HELLO Message Format.
Definition: olsr-header.h:386
void SetHTime(Time time)
Set the HELLO emission interval.
Definition: olsr-header.h:403
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
Willingness willingness
The willingness of a node to carry and forward traffic for other nodes.
Definition: olsr-header.h:417
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:419
uint8_t hTime
HELLO emission interval (coded)
Definition: olsr-header.h:397
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:412
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:525
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:535
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:323
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:324
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:470
uint16_t ansn
Advertised Neighbor Sequence Number.
Definition: olsr-header.h:472
std::vector< Ipv4Address > neighborAddresses
Neighbor address container.
Definition: olsr-header.h:471
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