00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef OLSR_HEADER_H
00022 #define OLSR_HEADER_H
00023
00024 #include <stdint.h>
00025 #include <vector>
00026 #include "ns3/header.h"
00027 #include "ns3/ipv4-address.h"
00028 #include "ns3/nstime.h"
00029
00030
00031 namespace ns3 {
00032 namespace olsr {
00033
00034 double EmfToSeconds (uint8_t emf);
00035 uint8_t SecondsToEmf (double seconds);
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 class PacketHeader : public Header
00070 {
00071 public:
00072 PacketHeader ();
00073 virtual ~PacketHeader ();
00074
00075 void SetPacketLength (uint16_t length)
00076 {
00077 m_packetLength = length;
00078 }
00079 uint16_t GetPacketLength () const
00080 {
00081 return m_packetLength;
00082 }
00083
00084 void SetPacketSequenceNumber (uint16_t seqnum)
00085 {
00086 m_packetSequenceNumber = seqnum;
00087 }
00088 uint16_t GetPacketSequenceNumber () const
00089 {
00090 return m_packetSequenceNumber;
00091 }
00092
00093 private:
00094 uint16_t m_packetLength;
00095 uint16_t m_packetSequenceNumber;
00096
00097 public:
00098 static TypeId GetTypeId (void);
00099 virtual TypeId GetInstanceTypeId (void) const;
00100 virtual void Print (std::ostream &os) const;
00101 virtual uint32_t GetSerializedSize (void) const;
00102 virtual void Serialize (Buffer::Iterator start) const;
00103 virtual uint32_t Deserialize (Buffer::Iterator start);
00104 };
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 class MessageHeader : public Header
00117 {
00118 public:
00119
00120 enum MessageType {
00121 HELLO_MESSAGE = 1,
00122 TC_MESSAGE = 2,
00123 MID_MESSAGE = 3,
00124 HNA_MESSAGE = 4,
00125 };
00126
00127 MessageHeader ();
00128 virtual ~MessageHeader ();
00129
00130 void SetMessageType (MessageType messageType)
00131 {
00132 m_messageType = messageType;
00133 }
00134 MessageType GetMessageType () const
00135 {
00136 return m_messageType;
00137 }
00138
00139 void SetVTime (Time time)
00140 {
00141 m_vTime = SecondsToEmf (time.GetSeconds ());
00142 }
00143 Time GetVTime () const
00144 {
00145 return Seconds (EmfToSeconds (m_vTime));
00146 }
00147
00148 void SetOriginatorAddress (Ipv4Address originatorAddress)
00149 {
00150 m_originatorAddress = originatorAddress;
00151 }
00152 Ipv4Address GetOriginatorAddress () const
00153 {
00154 return m_originatorAddress;
00155 }
00156
00157 void SetTimeToLive (uint8_t timeToLive)
00158 {
00159 m_timeToLive = timeToLive;
00160 }
00161 uint8_t GetTimeToLive () const
00162 {
00163 return m_timeToLive;
00164 }
00165
00166 void SetHopCount (uint8_t hopCount)
00167 {
00168 m_hopCount = hopCount;
00169 }
00170 uint8_t GetHopCount () const
00171 {
00172 return m_hopCount;
00173 }
00174
00175 void SetMessageSequenceNumber (uint16_t messageSequenceNumber)
00176 {
00177 m_messageSequenceNumber = messageSequenceNumber;
00178 }
00179 uint16_t GetMessageSequenceNumber () const
00180 {
00181 return m_messageSequenceNumber;
00182 }
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 private:
00194 MessageType m_messageType;
00195 uint8_t m_vTime;
00196 Ipv4Address m_originatorAddress;
00197 uint8_t m_timeToLive;
00198 uint8_t m_hopCount;
00199 uint16_t m_messageSequenceNumber;
00200 uint16_t m_messageSize;
00201
00202 public:
00203 static TypeId GetTypeId (void);
00204 virtual TypeId GetInstanceTypeId (void) const;
00205 virtual void Print (std::ostream &os) const;
00206 virtual uint32_t GetSerializedSize (void) const;
00207 virtual void Serialize (Buffer::Iterator start) const;
00208 virtual uint32_t Deserialize (Buffer::Iterator start);
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 struct Mid
00224 {
00225 std::vector<Ipv4Address> interfaceAddresses;
00226 void Print (std::ostream &os) const;
00227 uint32_t GetSerializedSize (void) const;
00228 void Serialize (Buffer::Iterator start) const;
00229 uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
00230 };
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 struct Hello
00259 {
00260 struct LinkMessage {
00261 uint8_t linkCode;
00262 std::vector<Ipv4Address> neighborInterfaceAddresses;
00263 };
00264
00265 uint8_t hTime;
00266 void SetHTime (Time time)
00267 {
00268 this->hTime = SecondsToEmf (time.GetSeconds ());
00269 }
00270 Time GetHTime () const
00271 {
00272 return Seconds (EmfToSeconds (this->hTime));
00273 }
00274
00275 uint8_t willingness;
00276 std::vector<LinkMessage> linkMessages;
00277
00278 void Print (std::ostream &os) const;
00279 uint32_t GetSerializedSize (void) const;
00280 void Serialize (Buffer::Iterator start) const;
00281 uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
00282 };
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 struct Tc
00301 {
00302 std::vector<Ipv4Address> neighborAddresses;
00303 uint16_t ansn;
00304
00305 void Print (std::ostream &os) const;
00306 uint32_t GetSerializedSize (void) const;
00307 void Serialize (Buffer::Iterator start) const;
00308 uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
00309 };
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 struct Hna
00332 {
00333 struct Association
00334 {
00335 Ipv4Address address;
00336 Ipv4Mask mask;
00337 };
00338 std::vector<Association> associations;
00339
00340 void Print (std::ostream &os) const;
00341 uint32_t GetSerializedSize (void) const;
00342 void Serialize (Buffer::Iterator start) const;
00343 uint32_t Deserialize (Buffer::Iterator start, uint32_t messageSize);
00344 };
00345
00346 private:
00347 struct
00348 {
00349 Mid mid;
00350 Hello hello;
00351 Tc tc;
00352 Hna hna;
00353 } m_message;
00354
00355 public:
00356
00357 Mid& GetMid ()
00358 {
00359 if (m_messageType == 0)
00360 {
00361 m_messageType = MID_MESSAGE;
00362 }
00363 else
00364 {
00365 NS_ASSERT (m_messageType == MID_MESSAGE);
00366 }
00367 return m_message.mid;
00368 }
00369
00370 Hello& GetHello ()
00371 {
00372 if (m_messageType == 0)
00373 {
00374 m_messageType = HELLO_MESSAGE;
00375 }
00376 else
00377 {
00378 NS_ASSERT (m_messageType == HELLO_MESSAGE);
00379 }
00380 return m_message.hello;
00381 }
00382
00383 Tc& GetTc ()
00384 {
00385 if (m_messageType == 0)
00386 {
00387 m_messageType = TC_MESSAGE;
00388 }
00389 else
00390 {
00391 NS_ASSERT (m_messageType == TC_MESSAGE);
00392 }
00393 return m_message.tc;
00394 }
00395
00396 Hna& GetHna ()
00397 {
00398 if (m_messageType == 0)
00399 {
00400 m_messageType = HNA_MESSAGE;
00401 }
00402 else
00403 {
00404 NS_ASSERT (m_messageType == HNA_MESSAGE);
00405 }
00406 return m_message.hna;
00407 }
00408
00409
00410 const Mid& GetMid () const
00411 {
00412 NS_ASSERT (m_messageType == MID_MESSAGE);
00413 return m_message.mid;
00414 }
00415
00416 const Hello& GetHello () const
00417 {
00418 NS_ASSERT (m_messageType == HELLO_MESSAGE);
00419 return m_message.hello;
00420 }
00421
00422 const Tc& GetTc () const
00423 {
00424 NS_ASSERT (m_messageType == TC_MESSAGE);
00425 return m_message.tc;
00426 }
00427
00428 const Hna& GetHna () const
00429 {
00430 NS_ASSERT (m_messageType == HNA_MESSAGE);
00431 return m_message.hna;
00432 }
00433
00434
00435 };
00436
00437
00438 static inline std::ostream& operator<< (std::ostream& os, const PacketHeader & packet)
00439 {
00440 packet.Print (os);
00441 return os;
00442 }
00443
00444 static inline std::ostream& operator<< (std::ostream& os, const MessageHeader & message)
00445 {
00446 message.Print (os);
00447 return os;
00448 }
00449
00450 typedef std::vector<MessageHeader> MessageList;
00451
00452 static inline std::ostream& operator<< (std::ostream& os, const MessageList & messages)
00453 {
00454 os << "[";
00455 for (std::vector<MessageHeader>::const_iterator messageIter = messages.begin ();
00456 messageIter != messages.end (); messageIter++)
00457 {
00458 messageIter->Print (os);
00459 if (messageIter+1 != messages.end ())
00460 os << ", ";
00461 }
00462 os << "]";
00463 return os;
00464 }
00465
00466
00467 }}
00468
00469 #endif
00470