A Discrete-Event Network Simulator
API
sixlowpan-header.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Universita' di Firenze, Italy
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: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  * Michele Muccio <michelemuccio@virgilio.it>
20  */
21 
22 #ifndef SIXLOWPANHEADER_H_
23 #define SIXLOWPANHEADER_H_
24 
25 #include "ns3/header.h"
26 #include "ns3/ipv6-address.h"
27 #include "ns3/packet.h"
28 #include "ns3/ipv6-header.h"
29 
30 namespace ns3 {
31 
48 {
49 public:
79  {
80  LOWPAN_NALP = 0x0,
81  LOWPAN_NALP_N = 0x3F,
82  LOWPAN_IPv6 = 0x41,
83  LOWPAN_HC1 = 0x42,
84  LOWPAN_BC0 = 0x50,
85  LOWPAN_IPHC = 0x60,
86  LOWPAN_IPHC_N = 0x7F,
87  LOWPAN_MESH = 0x80,
88  LOWPAN_MESH_N = 0xBF,
89  LOWPAN_FRAG1 = 0xC0,
91  LOWPAN_FRAGN = 0xE0,
94  };
95 
103  {
104  LOWPAN_NHC = 0xE0,
105  LOWPAN_NHC_N = 0xEF,
109  };
110 
111  SixLowPanDispatch (void);
112 
118  static Dispatch_e GetDispatchType (uint8_t dispatch);
119 
125  static NhcDispatch_e GetNhcDispatchType (uint8_t dispatch);
126 
127 };
128 
133 class SixLowPanHc1 : public Header
134 {
135 public:
144  {
145  HC1_PIII = 0x00,
146  HC1_PIIC = 0x01,
147  HC1_PCII = 0x02,
148  HC1_PCIC = 0x03
149  };
150 
158  {
159  HC1_NC = 0x00,
160  HC1_UDP = 0x01,
161  HC1_ICMP = 0x02,
162  HC1_TCP = 0x03
163  };
164 
165  SixLowPanHc1 (void);
166 
171  static TypeId GetTypeId (void);
172 
178  virtual TypeId GetInstanceTypeId (void) const;
179 
180  virtual void Print (std::ostream& os) const;
181 
186  virtual uint32_t GetSerializedSize (void) const;
187 
192  virtual void Serialize (Buffer::Iterator start) const;
193 
199  virtual uint32_t Deserialize (Buffer::Iterator start);
200 
205  void SetHopLimit (uint8_t limit);
206 
211  uint8_t GetHopLimit (void) const;
212 
217  LowPanHc1Addr_e GetDstCompression () const;
218 
223  const uint8_t* GetDstInterface () const;
224 
229  const uint8_t* GetDstPrefix () const;
230 
235  uint32_t GetFlowLabel () const;
236 
241  uint8_t GetNextHeader () const;
242 
247  LowPanHc1Addr_e GetSrcCompression () const;
248 
253  const uint8_t* GetSrcInterface () const;
254 
259  const uint8_t* GetSrcPrefix () const;
260 
265  uint8_t GetTrafficClass () const;
266 
271  bool IsTcflCompression () const;
272 
277  bool IsHc2HeaderPresent () const;
278 
283  void SetDstCompression (LowPanHc1Addr_e dstCompression);
284 
289  void SetDstInterface (const uint8_t* dstInterface);
290 
295  void SetDstPrefix (const uint8_t* dstPrefix);
296 
301  void SetFlowLabel (uint32_t flowLabel);
302 
307  void SetNextHeader (uint8_t nextHeader);
308 
313  void SetSrcCompression (LowPanHc1Addr_e srcCompression);
314 
319  void SetSrcInterface (const uint8_t* srcInterface);
320 
325  void SetSrcPrefix (const uint8_t* srcPrefix);
326 
331  void SetTcflCompression (bool tcflCompression);
332 
337  void SetHc2HeaderPresent (bool hc2HeaderPresent);
338 
343  void SetTrafficClass (uint8_t trafficClass);
344 
345 private:
346  uint8_t m_hopLimit;
347  uint8_t m_srcPrefix[8];
348  uint8_t m_srcInterface[8];
349  uint8_t m_dstPrefix[8];
350  uint8_t m_dstInterface[8];
351  uint8_t m_trafficClass;
352  uint32_t m_flowLabel;
353  uint8_t m_nextHeader;
359 };
360 
368 std::ostream & operator<< (std::ostream & os, SixLowPanHc1 const &header);
369 
374 class SixLowPanFrag1 : public Header
375 {
376 public:
377  SixLowPanFrag1 (void);
378 
383  static TypeId GetTypeId (void);
384 
389  virtual TypeId GetInstanceTypeId (void) const;
390 
391  virtual void Print (std::ostream& os) const;
392 
397  virtual uint32_t GetSerializedSize (void) const;
398 
403  virtual void Serialize (Buffer::Iterator start) const;
404 
410  virtual uint32_t Deserialize (Buffer::Iterator start);
411 
416  void SetDatagramSize (uint16_t datagramSize);
417 
422  uint16_t GetDatagramSize (void) const;
423 
428  void SetDatagramTag (uint16_t datagramTag);
429 
434  uint16_t GetDatagramTag (void) const;
435 
436 private:
437  uint16_t m_datagramSize;
438  uint16_t m_datagramTag;
439 
440 };
441 
449 std::ostream & operator<< (std::ostream & os, SixLowPanFrag1 const & header);
450 
455 class SixLowPanFragN : public Header
456 {
457 public:
458  SixLowPanFragN (void);
459 
464  static TypeId GetTypeId (void);
465 
470  virtual TypeId GetInstanceTypeId (void) const;
471 
472  virtual void Print (std::ostream& os) const;
473 
478  virtual uint32_t GetSerializedSize (void) const;
479 
484  virtual void Serialize (Buffer::Iterator start) const;
485 
491  virtual uint32_t Deserialize (Buffer::Iterator start);
492 
497  void SetDatagramSize (uint16_t datagramSize);
498 
503  uint16_t GetDatagramSize (void) const;
504 
509  void SetDatagramTag (uint16_t datagramTag);
510 
515  uint16_t GetDatagramTag (void) const;
516 
521  void SetDatagramOffset (uint8_t datagramOffset);
522 
527  uint8_t GetDatagramOffset (void) const;
528 
529 private:
530  uint16_t m_datagramSize;
531  uint16_t m_datagramTag;
533 
534 };
535 
543 std::ostream & operator<< (std::ostream & os, SixLowPanFragN const &header);
544 
549 class SixLowPanIpv6 : public Header
550 {
551 public:
552  SixLowPanIpv6 (void);
553 
558  static TypeId GetTypeId (void);
559 
564  virtual TypeId GetInstanceTypeId (void) const;
565 
566  virtual void Print (std::ostream& os) const;
567 
572  virtual uint32_t GetSerializedSize (void) const;
573 
578  virtual void Serialize (Buffer::Iterator start) const;
579 
585  virtual uint32_t Deserialize (Buffer::Iterator start);
586 
587 };
588 
596 std::ostream & operator<< (std::ostream & os, SixLowPanIpv6 const & header);
597 
609 class SixLowPanIphc : public Header
610 {
611 public:
622  {
623  TF_FULL = 0,
626  TF_ELIDED
627  };
628 
637  enum Hlim_e
638  {
639  HLIM_INLINE = 0,
642  HLIM_COMPR_255
643  };
644 
654  {
655  HC_INLINE = 0,
658  HC_COMPR_0
659  };
660 
661  SixLowPanIphc (void);
666  SixLowPanIphc (uint8_t dispatch);
667 
672  static TypeId GetTypeId (void);
673 
678  virtual TypeId GetInstanceTypeId (void) const;
679 
680  virtual void Print (std::ostream& os) const;
681 
686  virtual uint32_t GetSerializedSize (void) const;
687 
692  virtual void Serialize (Buffer::Iterator start) const;
693 
699  virtual uint32_t Deserialize (Buffer::Iterator start);
700 
705  void SetTf (TrafficClassFlowLabel_e tfField);
706 
711  TrafficClassFlowLabel_e GetTf (void) const;
712 
717  void SetNh (bool nhField);
718 
723  bool GetNh (void) const;
724 
729  void SetHlim (Hlim_e hlimField);
730 
735  Hlim_e GetHlim (void) const;
736 
741  void SetCid (bool cidField);
742 
747  bool GetCid (void) const;
748 
753  void SetSac (bool sacField);
754 
759  bool GetSac (void) const;
760 
765  void SetSam (HeaderCompression_e samField);
766 
771  HeaderCompression_e GetSam (void) const;
772 
777  void SetM (bool mField);
778 
783  bool GetM (void) const;
784 
789  void SetDac (bool dacField);
790 
795  bool GetDac (void) const;
796 
801  void SetDam (HeaderCompression_e damField);
802 
807  HeaderCompression_e GetDam (void) const;
808 
813  void SetSrcContextId (uint8_t srcContextId);
814 
819  uint8_t GetSrcContextId (void) const;
820 
825  void SetDstContextId (uint8_t dstContextId);
826 
831  uint8_t GetDstContextId (void) const;
832 
837  void SetEcn (uint8_t ecn);
838 
843  uint8_t GetEcn (void) const;
844 
849  void SetDscp (uint8_t dscp);
850 
855  uint8_t GetDscp (void) const;
856 
861  void SetFlowLabel (uint32_t flowLabel);
862 
867  uint32_t GetFlowLabel (void) const;
868 
873  void SetNextHeader (uint8_t nextHeader);
874 
879  uint8_t GetNextHeader (void) const;
880 
885  void SetHopLimit (uint8_t hopLimit);
886 
891  uint8_t GetHopLimit (void) const;
892 
897  void SetSrcAddress (Ipv6Address srcAddress);
898 
903  Ipv6Address GetSrcAddress () const;
904 
909  void SetDstAddress (Ipv6Address dstAddress);
910 
915  Ipv6Address GetDstAddress () const;
916 
917 private:
918  uint16_t m_baseFormat;
920  uint8_t m_ecn : 2;
921  uint8_t m_dscp : 6;
922  uint32_t m_flowLabel : 20;
923  uint8_t m_nextHeader;
924  uint8_t m_hopLimit;
927 
932  void PostProcessSac ();
937  void PostProcessDac ();
938 
939 };
940 
948 std::ostream & operator<< (std::ostream & os, SixLowPanIphc const &header);
949 
961 {
962 public:
976  enum Eid_e
977  {
978  EID_HOPBYHOP_OPTIONS_H = 0,
983  EID_IPv6_H = 7
984  };
985 
986  SixLowPanNhcExtension (void);
987 
992  static TypeId GetTypeId (void);
993 
998  virtual TypeId GetInstanceTypeId (void) const;
999 
1000  virtual void Print (std::ostream& os) const;
1001 
1006  virtual uint32_t GetSerializedSize (void) const;
1007 
1012  virtual void Serialize (Buffer::Iterator start) const;
1013 
1019  virtual uint32_t Deserialize (Buffer::Iterator start);
1020 
1026 
1031  void SetEid (Eid_e extensionHeaderType);
1032 
1037  Eid_e GetEid (void) const;
1038 
1043  void SetNextHeader (uint8_t nextHeader);
1044 
1049  uint8_t GetNextHeader (void) const;
1050 
1055  void SetNh (bool nhField);
1056 
1061  bool GetNh (void) const;
1062 
1068  void SetBlob (const uint8_t* blob, uint32_t size);
1069 
1076  uint32_t CopyBlob (uint8_t* blob, uint32_t size) const;
1077 
1078 private:
1082  uint8_t m_nhcBlob[256];
1083 };
1084 
1092 std::ostream & operator<< (std::ostream & os, SixLowPanNhcExtension const &header);
1093 
1094 
1106 {
1107 public:
1116  enum Ports_e
1117  {
1118  PORTS_INLINE = 0,
1121  PORTS_LAST_SRC_LAST_DST
1122  };
1123 
1124  SixLowPanUdpNhcExtension (void);
1125 
1130  static TypeId GetTypeId (void);
1131 
1136  virtual TypeId GetInstanceTypeId (void) const;
1137 
1138  virtual void Print (std::ostream& os) const;
1139 
1144  virtual uint32_t GetSerializedSize (void) const;
1145 
1150  virtual void Serialize (Buffer::Iterator start) const;
1151 
1157  virtual uint32_t Deserialize (Buffer::Iterator start);
1158 
1164 
1169  void SetPorts (Ports_e port);
1170 
1175  Ports_e GetPorts (void) const;
1176 
1181  void SetSrcPort (uint16_t port);
1182 
1187  uint16_t GetSrcPort () const;
1188 
1193  void SetDstPort (uint16_t port);
1194 
1199  uint16_t GetDstPort () const;
1200 
1205  void SetC (bool cField);
1206 
1211  bool GetC (void) const;
1212 
1217  void SetChecksum (uint16_t checksum);
1218 
1223  uint16_t GetChecksum (void) const;
1224 
1225 private:
1226  uint8_t m_baseFormat;
1227  uint16_t m_checksum;
1228  uint16_t m_srcPort;
1229  uint16_t m_dstPort;
1230 };
1231 
1239 std::ostream & operator<< (std::ostream & os, SixLowPanUdpNhcExtension const &header);
1240 
1241 }
1242 
1243 #endif /* SIXLOWPANHEADER_H_ */
Protocol header serialization and deserialization.
Definition: header.h:42
NhcDispatch_e
Dispatch values for Next Header compression.
Ipv6Address m_dstAddress
Dst address.
TrafficClassFlowLabel_e
TF: Traffic Class, Flow Label.
uint16_t m_dstPort
Destination port.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
static Dispatch_e GetDispatchType(uint8_t dispatch)
Get the Dispatch type.
LOWPAN_IPHC base Encoding - see RFC 6282.
def start()
Definition: core.py:1806
LowPanHc1Addr_e m_srcCompression
Source compression type.
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
Hlim_e
HLIM: Hop Limit.
6LoWPAN FRAGN header - see RFC 4944.
uint16_t port
Definition: dsdv-manet.cc:45
iterator in a Buffer instance
Definition: buffer.h:98
uint16_t m_srcPort
Source port.
uint16_t m_datagramTag
Datagram tag.
uint8_t m_hopLimit
Hop Limit.
LowPanHc1Addr_e m_dstCompression
Destination compression type.
Dispatch header helper.
uint16_t m_datagramSize
Datagram size.
uint32_t m_flowLabel
Flow Label.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
uint16_t m_datagramTag
Datagram tag.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t m_trafficClass
Traffic Class.
LowPanHc1NextHeader_e m_nextHeaderCompression
Next header compression.
6LoWPAN HC1 header - see RFC 4944.
uint8_t m_hopLimit
Hop Limit.
uint8_t m_nhcExtensionHeader
NHC extension header type.
Describes an IPv6 address.
Definition: ipv6-address.h:49
Ipv6Address m_srcAddress
Src address.
uint8_t m_datagramOffset
Datagram offset.
bool m_tcflCompression
Is TC and FL compressed.
uint16_t m_datagramSize
Datagram size.
void Print(ComponentCarrier cc)
uint8_t m_baseFormat
Dispatch + encoding fields.
uint8_t m_nhcBlobLength
Length of the NHC compressed header.
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
uint16_t m_baseFormat
Dispatch + encoding fields.
Eid_e
EID: IPv6 Extension Header ID.
bool m_hc2HeaderPresent
Is next header HC2 compressed.
uint8_t m_nhcNextHeader
Next header.
Dispatch_e
Dispatch values, as defined in RFC 4944 and RFC 6282
LowPanHc1NextHeader_e
Next header information.
HeaderCompression_e
Source or Destination Address Mode.
uint8_t m_nextHeader
Next header.
6LoWPAN FRAG1 header - see RFC 4944.
a unique identifier for an interface.
Definition: type-id.h:58
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
uint8_t m_nextHeader
Next header.
uint8_t m_srcdstContextId
Src and Dst Context ID.
LowPanHc1Addr_e
Kind of address compression.