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 /**
38  * \ingroup olsr
39  *
40  * The basic layout of any packet in OLSR is as follows (omitting IP and
41  * UDP headers):
42   \verbatim
43     0                   1                   2                   3
44     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
45    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46    |         Packet Length         |    Packet Sequence Number     |
47    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48    |  Message Type |     Vtime     |         Message Size          |
49    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50    |                      Originator Address                       |
51    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52    |  Time To Live |   Hop Count   |    Message Sequence Number    |
53    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54    |                                                               |
55    :                            MESSAGE                            :
56    |                                                               |
57    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58    |  Message Type |     Vtime     |         Message Size          |
59    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60    |                      Originator Address                       |
61    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62    |  Time To Live |   Hop Count   |    Message Sequence Number    |
63    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64    |                                                               |
65    :                            MESSAGE                            :
66    |                                                               |
67    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68    :                                                               :
69             (etc.)
70   \endverbatim
71   *
72   * This header only holds the common part of a message group, i.e.,
73   * the first 4 bytes.
74   */
75 class PacketHeader : public Header
76 {
77 public:
78   PacketHeader ();
79   virtual ~PacketHeader ();
80 
81   /**
82    * Set the packet total length.
83    * \param length The packet length.
84    */
SetPacketLength(uint16_t length)85   void SetPacketLength (uint16_t length)
86   {
87     m_packetLength = length;
88   }
89 
90   /**
91    * Get the packet total length.
92    * \return The packet length.
93    */
GetPacketLength()94   uint16_t GetPacketLength () const
95   {
96     return m_packetLength;
97   }
98 
99   /**
100    * Set the packet sequence number.
101    * \param seqnum The packet sequence number.
102    */
SetPacketSequenceNumber(uint16_t seqnum)103   void SetPacketSequenceNumber (uint16_t seqnum)
104   {
105     m_packetSequenceNumber = seqnum;
106   }
107 
108   /**
109    * Get the packet sequence number.
110    * \returns The packet sequence number.
111    */
GetPacketSequenceNumber()112   uint16_t GetPacketSequenceNumber () const
113   {
114     return m_packetSequenceNumber;
115   }
116 
117 private:
118   uint16_t m_packetLength;          //!< The packet length.
119   uint16_t m_packetSequenceNumber;  //!< The packet sequence number.
120 
121 public:
122   /**
123    * \brief Get the type ID.
124    * \return The object TypeId.
125    */
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 
134 /**
135  * \ingroup olsr
136  *
137  * This header can store HELP, TC, MID and HNA messages.
138  * The header size is variable, and depends on the
139  * actual message type.
140  *
141   \verbatim
142     0                   1                   2                   3
143     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
144    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
145    |  Message Type |     Vtime     |         Message Size          |
146    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
147    |                      Originator Address                       |
148    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
149    |  Time To Live |   Hop Count   |    Message Sequence Number    |
150    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
151    |                                                               |
152    :                            MESSAGE                            :
153    |                                                               |
154    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155   \endverbatim
156  */
157 class MessageHeader : public Header
158 {
159 public:
160   /**
161    * Message type
162    */
163   enum MessageType
164   {
165     HELLO_MESSAGE = 1,
166     TC_MESSAGE    = 2,
167     MID_MESSAGE   = 3,
168     HNA_MESSAGE   = 4,
169   };
170 
171   MessageHeader ();
172   virtual ~MessageHeader ();
173 
174   /**
175    * Set the message type.
176    * \param messageType The message type.
177    */
SetMessageType(MessageType messageType)178   void SetMessageType (MessageType messageType)
179   {
180     m_messageType = messageType;
181   }
182   /**
183    * Get the message type.
184    * \return The message type.
185    */
GetMessageType()186   MessageType GetMessageType () const
187   {
188     return m_messageType;
189   }
190 
191   /**
192    * Set the validity time.
193    * \param time The validity time.
194    */
SetVTime(Time time)195   void SetVTime (Time time)
196   {
197     m_vTime = SecondsToEmf (time.GetSeconds ());
198   }
199   /**
200    * Get the validity time.
201    * \return The validity time.
202    */
GetVTime()203   Time GetVTime () const
204   {
205     return Seconds (EmfToSeconds (m_vTime));
206   }
207 
208   /**
209    * Set the originator address.
210    * \param originatorAddress The originator address.
211    */
SetOriginatorAddress(Ipv4Address originatorAddress)212   void SetOriginatorAddress (Ipv4Address originatorAddress)
213   {
214     m_originatorAddress = originatorAddress;
215   }
216   /**
217    * Get the originator address.
218    * \return The originator address.
219    */
GetOriginatorAddress()220   Ipv4Address GetOriginatorAddress () const
221   {
222     return m_originatorAddress;
223   }
224 
225   /**
226    * Set the time to live.
227    * \param timeToLive The time to live.
228    */
SetTimeToLive(uint8_t timeToLive)229   void SetTimeToLive (uint8_t timeToLive)
230   {
231     m_timeToLive = timeToLive;
232   }
233   /**
234    * Get the time to live.
235    * \return The time to live.
236    */
GetTimeToLive()237   uint8_t GetTimeToLive () const
238   {
239     return m_timeToLive;
240   }
241 
242   /**
243    * Set the hop count.
244    * \param hopCount The hop count.
245    */
SetHopCount(uint8_t hopCount)246   void SetHopCount (uint8_t hopCount)
247   {
248     m_hopCount = hopCount;
249   }
250   /**
251    * Get the hop count.
252    * \return The hop count.
253    */
GetHopCount()254   uint8_t GetHopCount () const
255   {
256     return m_hopCount;
257   }
258 
259   /**
260    * Set the message sequence number.
261    * \param messageSequenceNumber The message sequence number.
262    */
SetMessageSequenceNumber(uint16_t messageSequenceNumber)263   void SetMessageSequenceNumber (uint16_t messageSequenceNumber)
264   {
265     m_messageSequenceNumber = messageSequenceNumber;
266   }
267   /**
268    * Get the message sequence number.
269    * \return The message sequence number.
270    */
GetMessageSequenceNumber()271   uint16_t GetMessageSequenceNumber () const
272   {
273     return m_messageSequenceNumber;
274   }
275 
276 private:
277   MessageType m_messageType;        //!< The message type
278   uint8_t m_vTime;                  //!< The validity time.
279   Ipv4Address m_originatorAddress;  //!< The originator address.
280   uint8_t m_timeToLive;             //!< The time to live.
281   uint8_t m_hopCount;               //!< The hop count.
282   uint16_t m_messageSequenceNumber; //!< The message sequence number.
283   uint16_t m_messageSize;           //!< The message size.
284 
285 public:
286   /**
287    * \brief Get the type ID.
288    * \return The object TypeId.
289    */
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 
297   /**
298    * \ingroup olsr
299    * MID Message Format
300    *
301   \verbatim
302     0                   1                   2                   3
303     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
304    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
305    |                    OLSR Interface Address                     |
306    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
307    |                    OLSR Interface Address                     |
308    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
309    |                              ...                              |
310    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
311   \endverbatim
312   */
313   struct Mid
314   {
315     std::vector<Ipv4Address> interfaceAddresses;  //!< Interface Address container.
316     /**
317      * This method is used to print the content of a MID message.
318      * \param os output stream
319      */
320     void Print (std::ostream &os) const;
321     /**
322      * Returns the expected size of the header.
323      * \returns the expected size of the header.
324      */
325     uint32_t GetSerializedSize (void) const;
326     /**
327      * This method is used by Packet::AddHeader to
328      * store a header into the byte buffer of a packet.
329      *
330      * \param start an iterator which points to where the header should
331      *        be written.
332      */
333     void Serialize (Buffer::Iterator start) const;
334     /**
335      * This method is used by Packet::RemoveHeader to
336      * re-create a header from the byte buffer of a packet.
337      *
338      * \param start an iterator which points to where the header should
339      *        read from.
340      * \param messageSize the message size.
341      * \returns the number of bytes read.
342      */
343     uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
344   };
345 
346   /**
347    * \ingroup olsr
348    * HELLO Message Format
349    *
350   \verbatim
351     0                   1                   2                   3
352     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
353 
354    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
355    |          Reserved             |     Htime     |  Willingness  |
356    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
357    |   Link Code   |   Reserved    |       Link Message Size       |
358    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
359    |                  Neighbor Interface Address                   |
360    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
361    |                  Neighbor Interface Address                   |
362    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
363    :                             .  .  .                           :
364    :                                                               :
365    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
366    |   Link Code   |   Reserved    |       Link Message Size       |
367    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
368    |                  Neighbor Interface Address                   |
369    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
370    |                  Neighbor Interface Address                   |
371    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372    :                                                               :
373      (etc.)
374   \endverbatim
375   */
376   struct Hello
377   {
378     /**
379      * Link message item
380      */
381     struct LinkMessage
382     {
383       uint8_t linkCode;       //!< Link code
384       std::vector<Ipv4Address> neighborInterfaceAddresses;  //!< Neighbor interface address container.
385     };
386 
387     uint8_t hTime;  //!< HELLO emission interval (coded)
388 
389     /**
390      * Set the HELLO emission interval.
391      * \param time The HELLO emission interval.
392      */
SetHTimeHello393     void SetHTime (Time time)
394     {
395       this->hTime = SecondsToEmf (time.GetSeconds ());
396     }
397 
398     /**
399      * Get the HELLO emission interval.
400      * \return The HELLO emission interval.
401      */
GetHTimeHello402     Time GetHTime () const
403     {
404       return Seconds (EmfToSeconds (this->hTime));
405     }
406 
407     uint8_t willingness; //!< The willingness of a node to carry and forward traffic for other nodes.
408     std::vector<LinkMessage> linkMessages; //!< Link messages container.
409 
410     /**
411      * This method is used to print the content of a Hello message.
412      * \param os output stream
413      */
414     void Print (std::ostream &os) const;
415     /**
416      * Returns the expected size of the header.
417      * \returns the expected size of the header.
418      */
419     uint32_t GetSerializedSize (void) const;
420     /**
421      * This method is used by Packet::AddHeader to
422      * store a header into the byte buffer of a packet.
423      *
424      * \param start an iterator which points to where the header should
425      *        be written.
426      */
427     void Serialize (Buffer::Iterator start) const;
428     /**
429      * This method is used by Packet::RemoveHeader to
430      * re-create a header from the byte buffer of a packet.
431      *
432      * \param start an iterator which points to where the header should
433      *        read from.
434      * \param messageSize the message size.
435      * \returns the number of bytes read.
436      */
437     uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
438   };
439 
440   /**
441    * \ingroup olsr
442    * TC Message Format
443    *
444    \verbatim
445      0                   1                   2                   3
446      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
447     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
448     |              ANSN             |           Reserved            |
449     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
450     |               Advertised Neighbor Main Address                |
451     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
452     |               Advertised Neighbor Main Address                |
453     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
454     |                              ...                              |
455     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
456    \endverbatim
457    */
458   struct Tc
459   {
460     std::vector<Ipv4Address> neighborAddresses; //!< Neighbor address container.
461     uint16_t ansn;  //!< Advertised Neighbor Sequence Number.
462 
463     /**
464      * This method is used to print the content of a Tc message.
465      * \param os output stream
466      */
467     void Print (std::ostream &os) const;
468     /**
469      * Returns the expected size of the header.
470      * \returns the expected size of the header.
471      */
472     uint32_t GetSerializedSize (void) const;
473     /**
474      * This method is used by Packet::AddHeader to
475      * store a header into the byte buffer of a packet.
476      *
477      * \param start an iterator which points to where the header should
478      *        be written.
479      */
480     void Serialize (Buffer::Iterator start) const;
481     /**
482      * This method is used by Packet::RemoveHeader to
483      * re-create a header from the byte buffer of a packet.
484      *
485      * \param start an iterator which points to where the header should
486      *        read from.
487      * \param messageSize the message size.
488      * \returns the number of bytes read.
489      */
490     uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
491   };
492 
493 
494   /**
495    * \ingroup olsr
496    * HNA (Host Network Association) Message Format
497    *
498    \verbatim
499      0                   1                   2                   3
500      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
501     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
502     |                         Network Address                       |
503     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
504     |                             Netmask                           |
505     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
506     |                         Network Address                       |
507     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
508     |                             Netmask                           |
509     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
510     |                              ...                              |
511     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512    \endverbatim
513    */
514   struct Hna
515   {
516     /**
517      * Association item structure.
518      */
519     struct Association
520     {
521       Ipv4Address address; //!< IPv4 Address.
522       Ipv4Mask mask;       //!< IPv4 netmask.
523     };
524 
525     std::vector<Association> associations; //!< Association container.
526 
527     /**
528      * This method is used to print the content of a Hna message.
529      * \param os output stream
530      */
531     void Print (std::ostream &os) const;
532     /**
533      * Returns the expected size of the header.
534      * \returns the expected size of the header.
535      */
536     uint32_t GetSerializedSize (void) const;
537     /**
538      * This method is used by Packet::AddHeader to
539      * store a header into the byte buffer of a packet.
540      *
541      * \param start an iterator which points to where the header should
542      *        be written.
543      */
544     void Serialize (Buffer::Iterator start) const;
545     /**
546      * This method is used by Packet::RemoveHeader to
547      * re-create a header from the byte buffer of a packet.
548      *
549      * \param start an iterator which points to where the header should
550      *        read from.
551      * \param messageSize the message size.
552      * \returns the number of bytes read.
553      */
554     uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
555   };
556 
557 private:
558   /**
559    * Structure holding the message content.
560    */
561   struct
562   {
563     Mid mid;      //!< MID message (optional).
564     Hello hello;  //!< HELLO message (optional).
565     Tc tc;        //!< TC message (optional).
566     Hna hna;      //!< HNA message (optional).
567   } m_message; //!< The actual message being carried.
568 
569 public:
570   /**
571    * Set the message type to MID and return the message content.
572    * \returns The MID message.
573    */
GetMid()574   Mid& GetMid ()
575   {
576     if (m_messageType == 0)
577       {
578         m_messageType = MID_MESSAGE;
579       }
580     else
581       {
582         NS_ASSERT (m_messageType == MID_MESSAGE);
583       }
584     return m_message.mid;
585   }
586 
587   /**
588    * Set the message type to HELLO and return the message content.
589    * \returns The HELLO message.
590    */
GetHello()591   Hello& GetHello ()
592   {
593     if (m_messageType == 0)
594       {
595         m_messageType = HELLO_MESSAGE;
596       }
597     else
598       {
599         NS_ASSERT (m_messageType == HELLO_MESSAGE);
600       }
601     return m_message.hello;
602   }
603 
604   /**
605    * Set the message type to TC and return the message content.
606    * \returns The TC message.
607    */
GetTc()608   Tc& GetTc ()
609   {
610     if (m_messageType == 0)
611       {
612         m_messageType = TC_MESSAGE;
613       }
614     else
615       {
616         NS_ASSERT (m_messageType == TC_MESSAGE);
617       }
618     return m_message.tc;
619   }
620 
621   /**
622    * Set the message type to HNA and return the message content.
623    * \returns The HNA message.
624    */
GetHna()625   Hna& GetHna ()
626   {
627     if (m_messageType == 0)
628       {
629         m_messageType = HNA_MESSAGE;
630       }
631     else
632       {
633         NS_ASSERT (m_messageType == HNA_MESSAGE);
634       }
635     return m_message.hna;
636   }
637 
638 
639   /**
640    * Get the MID message.
641    * \returns The MID message.
642    */
GetMid()643   const Mid& GetMid () const
644   {
645     NS_ASSERT (m_messageType == MID_MESSAGE);
646     return m_message.mid;
647   }
648 
649   /**
650    * Get the HELLO message.
651    * \returns The HELLO message.
652    */
GetHello()653   const Hello& GetHello () const
654   {
655     NS_ASSERT (m_messageType == HELLO_MESSAGE);
656     return m_message.hello;
657   }
658 
659   /**
660    * Get the TC message.
661    * \returns The TC message.
662    */
GetTc()663   const Tc& GetTc () const
664   {
665     NS_ASSERT (m_messageType == TC_MESSAGE);
666     return m_message.tc;
667   }
668 
669   /**
670    * Get the HNA message.
671    * \returns The HNA message.
672    */
GetHna()673   const Hna& GetHna () const
674   {
675     NS_ASSERT (m_messageType == HNA_MESSAGE);
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 
719