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 
31 namespace ns3 {
32 namespace olsr {
33 
34 double EmfToSeconds (uint8_t emf);
35 uint8_t SecondsToEmf (double seconds);
36 
75 class PacketHeader : public Header
76 {
77 public:
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  {
114  return m_packetSequenceNumber;
115  }
116 
117 private:
118  uint16_t m_packetLength;
120 
121 public:
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;
131  virtual uint32_t Deserialize (Buffer::Iterator start);
132 };
133 
157 class MessageHeader : public Header
158 {
159 public:
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 
276 private:
278  uint8_t m_vTime;
280  uint8_t m_timeToLive;
281  uint8_t m_hopCount;
283  uint16_t m_messageSize;
284 
285 public:
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;
295  virtual uint32_t Deserialize (Buffer::Iterator start);
296 
313  struct Mid
314  {
315  std::vector<Ipv4Address> interfaceAddresses;
316 
320  void Print (std::ostream &os) const;
325  uint32_t GetSerializedSize (void) const;
333  void Serialize (Buffer::Iterator start) const;
343  uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
344  };
345 
376  struct Hello
377  {
381  struct LinkMessage
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;
437  uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
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;
490  uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
491  };
492 
493 
514  struct Hna
515  {
519  struct Association
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;
554  uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
555  };
556 
557 private:
561  struct
562  {
565  Tc tc;
567  } m_message;
568 
569 public:
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 
608  Tc& GetTc ()
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 
683 static inline std::ostream& operator<< (std::ostream& os, const PacketHeader & packet)
684 {
685  packet.Print (os);
686  return os;
687 }
688 
689 static inline std::ostream& operator<< (std::ostream& os, const MessageHeader & message)
690 {
691  message.Print (os);
692  return os;
693 }
694 
695 typedef std::vector<MessageHeader> MessageList;
696 
697 static 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 
Protocol header serialization and deserialization.
Definition: header.h:42
uint8_t GetHopCount() const
Get the hop count.
Definition: olsr-header.h:254
uint8_t GetTimeToLive() const
Get the time to live.
Definition: olsr-header.h:237
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:295
uint16_t m_messageSequenceNumber
The message sequence number.
Definition: olsr-header.h:282
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
uint16_t m_packetLength
The packet length.
Definition: olsr-header.h:118
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:438
This header can store HELP, TC, MID and HNA messages.
Definition: olsr-header.h:157
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:355
TC Message Format
Definition: olsr-header.h:458
Mid & GetMid()
Set the message type to MID and return the message content.
Definition: olsr-header.h:574
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:426
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
struct ns3::olsr::MessageHeader::@69 m_message
Structure holding the message content.
static std::ostream & operator<<(std::ostream &os, const PacketHeader &packet)
Definition: olsr-header.h:683
void SetPacketSequenceNumber(uint16_t seqnum)
Set the packet sequence number.
Definition: olsr-header.h:103
def start()
Definition: core.py:1844
Mid mid
MID message (optional).
Definition: olsr-header.h:563
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
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:386
virtual void Serialize(Buffer::Iterator start) const
Definition: olsr-header.cc:220
#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
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:289
uint16_t GetPacketLength() const
Get the packet total length.
Definition: olsr-header.h:94
virtual uint32_t GetSerializedSize(void) const
Definition: olsr-header.cc:189
void SetHTime(Time time)
Set the HELLO emission interval.
Definition: olsr-header.h:393
uint8_t m_hopCount
The hop count.
Definition: olsr-header.h:281
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:124
Tc & GetTc()
Set the message type to TC and return the message content.
Definition: olsr-header.h:608
std::vector< LinkMessage > linkMessages
Link messages container.
Definition: olsr-header.h:408
uint8_t hTime
HELLO emission interval (coded)
Definition: olsr-header.h:387
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: olsr-header.cc:150
uint16_t ansn
Advertised Neighbor Sequence Number.
Definition: olsr-header.h:461
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:484
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: olsr-header.cc:183
MessageType m_messageType
The message type.
Definition: olsr-header.h:277
void SetHopCount(uint8_t hopCount)
Set the hop count.
Definition: olsr-header.h:246
Hello hello
HELLO message (optional).
Definition: olsr-header.h:564
void SetMessageType(MessageType messageType)
Set the message type.
Definition: olsr-header.h:178
iterator in a Buffer instance
Definition: buffer.h:98
Tc tc
TC message (optional).
Definition: olsr-header.h:565
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:478
void SetVTime(Time time)
Set the validity time.
Definition: olsr-header.h:195
const Hna & GetHna() const
Get the HNA message.
Definition: olsr-header.h:673
std::vector< Ipv4Address > interfaceAddresses
Interface Address container.
Definition: olsr-header.h:315
std::vector< Ipv4Address > neighborAddresses
Neighbor address container.
Definition: olsr-header.h:460
void SetTimeToLive(uint8_t timeToLive)
Set the time to live.
Definition: olsr-header.h:229
uint16_t m_packetSequenceNumber
The packet sequence number.
Definition: olsr-header.h:119
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: olsr-header.cc:252
virtual void Serialize(Buffer::Iterator start) const
Definition: olsr-header.cc:142
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:313
Association item structure.
Definition: olsr-header.h:519
MessageType
Message type.
Definition: olsr-header.h:163
virtual void Print(std::ostream &os) const
Definition: olsr-header.cc:214
Ipv4Address m_originatorAddress
The originator address.
Definition: olsr-header.h:279
void SetPacketLength(uint16_t length)
Set the packet total length.
Definition: olsr-header.h:85
Hna & GetHna()
Set the message type to HNA and return the message content.
Definition: olsr-header.h:625
virtual uint32_t GetSerializedSize(void) const
Definition: olsr-header.cc:130
uint8_t m_vTime
The validity time.
Definition: olsr-header.h:278
Time GetVTime() const
Get the validity time.
Definition: olsr-header.h:203
MessageType GetMessageType() const
Get the message type.
Definition: olsr-header.h:186
Ipv4Address GetOriginatorAddress() const
Get the originator address.
Definition: olsr-header.h:220
void SetOriginatorAddress(Ipv4Address originatorAddress)
Set the originator address.
Definition: olsr-header.h:212
const Hello & GetHello() const
Get the HELLO message.
Definition: olsr-header.h:653
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
Definition: olsr-header.cc:173
uint8_t willingness
The willingness of a node to carry and forward traffic for other nodes.
Definition: olsr-header.h:407
std::vector< Association > associations
Association container.
Definition: olsr-header.h:525
Time GetHTime() const
Get the HELLO emission interval.
Definition: olsr-header.h:402
uint8_t m_timeToLive
The time to live.
Definition: olsr-header.h:280
uint16_t GetPacketSequenceNumber() const
Get the packet sequence number.
Definition: olsr-header.h:112
std::vector< MessageHeader > MessageList
Definition: olsr-header.h:695
Definition: olsr.py:1
The basic layout of any packet in OLSR is as follows (omitting IP and UDP headers): ...
Definition: olsr-header.h:75
HNA (Host Network Association) Message Format
Definition: olsr-header.h:514
Hna hna
HNA message (optional).
Definition: olsr-header.h:566
uint16_t GetMessageSequenceNumber() const
Get the message sequence number.
Definition: olsr-header.h:271
Hello & GetHello()
Set the message type to HELLO and return the message content.
Definition: olsr-header.h:591
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
HELLO Message Format
Definition: olsr-header.h:376
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:490
uint32_t GetSerializedSize(void) const
Returns the expected size of the header.
Definition: olsr-header.cc:335
const Tc & GetTc() const
Get the TC message.
Definition: olsr-header.h:663
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
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:453
const Mid & GetMid() const
Get the MID message.
Definition: olsr-header.h:643
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:432
MID Message Format
Definition: olsr-header.h:313
uint16_t m_messageSize
The message size.
Definition: olsr-header.h:283
uint8_t SecondsToEmf(double seconds)
Converts a decimal number of seconds to the mantissa/exponent format.
Definition: olsr-header.cc:49
static TypeId GetTypeId(void)
Get the type ID.
Definition: olsr-header.cc:114
void SetMessageSequenceNumber(uint16_t messageSequenceNumber)
Set the message sequence number.
Definition: olsr-header.h:263
double EmfToSeconds(uint8_t olsrFormat)
Converts a number of seconds in the mantissa/exponent format to a decimal number. ...
Definition: olsr-header.cc:91
virtual void Print(std::ostream &os) const
Definition: olsr-header.cc:136
void Print(std::ostream &os) const
This method is used to print the content of a MID message.
Definition: olsr-header.cc:349
a unique identifier for an interface.
Definition: type-id.h:58
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:502
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:301