A Discrete-Event Network Simulator
API
wimax-tlv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 INRIA, UDcast
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  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18  *
19  */
20 
21 #ifndef WIMAX_TLV_H
22 #define WIMAX_TLV_H
23 
24 #define WIMAX_TLV_EXTENDED_LENGTH_MASK 0x80
25 
26 #include "ns3/assert.h"
27 #include "ns3/header.h"
28 #include "ns3/ipv4-address.h"
29 #include "ns3/log.h"
30 #include "ns3/uinteger.h"
31 
32 #include <cstdlib>
33 #include <vector>
34 
35 namespace ns3
36 {
37 
44 class TlvValue
45 {
46  public:
47  virtual ~TlvValue()
48  {
49  }
50 
55  virtual uint32_t GetSerializedSize() const = 0;
60  virtual void Serialize(Buffer::Iterator start) const = 0;
67  virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) = 0;
72  virtual TlvValue* Copy() const = 0;
73 
74  private:
75 };
76 
77 // =============================================================================
86 class Tlv : public Header
87 {
88  public:
91  {
92  HMAC_TUPLE = 149,
99  };
100 
108  Tlv(uint8_t type, uint64_t length, const TlvValue& value);
109  Tlv();
110  ~Tlv() override;
115  static TypeId GetTypeId();
116  TypeId GetInstanceTypeId() const override;
117  void Print(std::ostream& os) const override;
118  uint32_t GetSerializedSize() const override;
119  void Serialize(Buffer::Iterator start) const override;
120  uint32_t Deserialize(Buffer::Iterator start) override;
125  uint8_t GetSizeOfLen() const;
130  uint8_t GetType() const;
135  uint64_t GetLength() const;
140  TlvValue* PeekValue();
145  Tlv* Copy() const;
150  TlvValue* CopyValue() const;
156  Tlv& operator=(const Tlv& o);
161  Tlv(const Tlv& tlv);
162 
163  private:
164  uint8_t m_type;
165  uint64_t m_length;
167 };
168 
169 // ==============================================================================
174 class U8TlvValue : public TlvValue
175 {
176  public:
182  U8TlvValue(uint8_t value);
183  U8TlvValue();
184  ~U8TlvValue() override;
185  uint32_t GetSerializedSize() const override;
186  void Serialize(Buffer::Iterator start) const override;
187  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override;
198  uint8_t GetValue() const;
203  U8TlvValue* Copy() const override;
204 
205  private:
206  uint8_t m_value;
207 };
208 
209 // ==============================================================================
214 class U16TlvValue : public TlvValue
215 {
216  public:
222  U16TlvValue(uint16_t value);
223  U16TlvValue();
224  ~U16TlvValue() override;
225  uint32_t GetSerializedSize() const override;
226  void Serialize(Buffer::Iterator start) const override;
227  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override;
238  uint16_t GetValue() const;
243  U16TlvValue* Copy() const override;
244 
245  private:
246  uint16_t m_value;
247 };
248 
249 // ==============================================================================
254 class U32TlvValue : public TlvValue
255 {
256  public:
262  U32TlvValue(uint32_t value);
263  U32TlvValue();
264  ~U32TlvValue() override;
265 
266  uint32_t GetSerializedSize() const override;
267  void Serialize(Buffer::Iterator start) const override;
268  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override;
279  uint32_t GetValue() const;
284  U32TlvValue* Copy() const override;
285 
286  private:
287  uint32_t m_value;
288 };
289 
290 // ==============================================================================
291 
296 class VectorTlvValue : public TlvValue
297 {
298  public:
300  typedef std::vector<Tlv*>::const_iterator Iterator;
301  VectorTlvValue();
302  ~VectorTlvValue() override;
303  uint32_t GetSerializedSize() const override;
304  void Serialize(Buffer::Iterator start) const override;
305  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override = 0;
310  Iterator Begin() const;
315  Iterator End() const;
320  void Add(const Tlv& val);
325  VectorTlvValue* Copy() const override = 0;
326 
327  private:
328  std::vector<Tlv*>* m_tlvList;
329 };
330 
331 // ==============================================================================
337 {
338  public:
340  enum Type
341  {
342  SFID = 1,
343  CID = 2,
357  SDU_Size = 16,
368  reserved2 = 27,
370  IPV4_CS_Parameters = 100
371  };
372 
374  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
375  SfVectorTlvValue* Copy() const override;
376 };
377 
378 // ==============================================================================
379 
385 {
386  public:
388  enum Type
389  {
392  };
393 
395  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
396  CsParamVectorTlvValue* Copy() const override;
397 
398  private:
399 };
400 
401 // ==============================================================================
402 
408 {
409  public:
412  {
413  Priority = 1,
414  ToS = 2,
415  Protocol = 3,
416  IP_src = 4,
417  IP_dst = 5,
418  Port_src = 6,
419  Port_dst = 7,
420  Index = 14,
421  };
422 
424  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
425  ClassificationRuleVectorTlvValue* Copy() const override;
426 
427  private:
428 };
429 
430 // ==============================================================================
435 class TosTlvValue : public TlvValue
436 {
437  public:
438  TosTlvValue();
446  TosTlvValue(uint8_t low, uint8_t high, uint8_t mask);
447  ~TosTlvValue() override;
448  uint32_t GetSerializedSize() const override;
449  void Serialize(Buffer::Iterator start) const override;
450  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
455  uint8_t GetLow() const;
460  uint8_t GetHigh() const;
465  uint8_t GetMask() const;
470  TosTlvValue* Copy() const override;
471 
472  private:
473  uint8_t m_low;
474  uint8_t m_high;
475  uint8_t m_mask;
476 };
477 
478 // ==============================================================================
484 {
485  public:
487  struct PortRange
488  {
489  uint16_t PortLow;
490  uint16_t PortHigh;
491  };
492 
494  typedef std::vector<PortRange>::const_iterator Iterator;
496  ~PortRangeTlvValue() override;
497  uint32_t GetSerializedSize() const override;
498  void Serialize(Buffer::Iterator start) const override;
499  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
505  void Add(uint16_t portLow, uint16_t portHigh);
510  Iterator Begin() const;
515  Iterator End() const;
520  PortRangeTlvValue* Copy() const override;
521 
522  private:
523  std::vector<PortRange>* m_portRange;
524 };
525 
526 // ==============================================================================
532 {
533  public:
535  ~ProtocolTlvValue() override;
537  typedef std::vector<uint8_t>::const_iterator Iterator;
538  uint32_t GetSerializedSize() const override;
539  void Serialize(Buffer::Iterator start) const override;
540  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
545  void Add(uint8_t protocol);
550  Iterator Begin() const;
555  Iterator End() const;
560  ProtocolTlvValue* Copy() const override;
561 
562  private:
563  std::vector<uint8_t>* m_protocol;
564 };
565 
566 // ==============================================================================
567 
573 {
574  public:
576  struct Ipv4Addr
577  {
580  };
581 
583  typedef std::vector<Ipv4Addr>::const_iterator Iterator;
585  ~Ipv4AddressTlvValue() override;
586  uint32_t GetSerializedSize() const override;
587  void Serialize(Buffer::Iterator start) const override;
588  uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override;
594  void Add(Ipv4Address address, Ipv4Mask mask);
599  Iterator Begin() const;
604  Iterator End() const;
605  Ipv4AddressTlvValue* Copy() const override;
606 
607  private:
608  std::vector<Ipv4Addr>* m_ipv4Addr;
609 };
610 
611 } // namespace ns3
612 
613 #endif /* WIMAX_TLV_H */
iterator in a Buffer instance
Definition: buffer.h:100
this class implements the classifier descriptor as a tlv vector
Definition: wimax-tlv.h:408
ClassificationRuleVectorTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:708
ClassificationRuleTlvType
ClassificationRuleTlvType enumeration.
Definition: wimax-tlv.h:412
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:719
this class implements the convergence sub-layer descriptor as a tlv vector
Definition: wimax-tlv.h:385
CsParamVectorTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:691
Type
Type enumeration.
Definition: wimax-tlv.h:389
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:640
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Ipv4AddressTlvValue class.
Definition: wimax-tlv.h:573
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:1074
std::vector< Ipv4Addr >::const_iterator Iterator
IPv4 address vector iterator typedef.
Definition: wimax-tlv.h:583
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:1038
void Add(Ipv4Address address, Ipv4Mask mask)
Add IPv4 address and mask.
Definition: wimax-tlv.cc:1062
std::vector< Ipv4Addr > * m_ipv4Addr
ipv4 addr
Definition: wimax-tlv.h:608
Ipv4AddressTlvValue * Copy() const override
Copy function.
Definition: wimax-tlv.cc:1080
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:1032
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:1068
~Ipv4AddressTlvValue() override
Definition: wimax-tlv.cc:1021
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:1048
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
PortRangeTlvValue class.
Definition: wimax-tlv.h:484
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:880
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:896
std::vector< PortRange > * m_portRange
port range
Definition: wimax-tlv.h:523
std::vector< PortRange >::const_iterator Iterator
PortRange vector iterator typedef.
Definition: wimax-tlv.h:494
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:925
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:886
~PortRangeTlvValue() override
Definition: wimax-tlv.cc:873
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:919
void Add(uint16_t portLow, uint16_t portHigh)
Add a range.
Definition: wimax-tlv.cc:910
PortRangeTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:931
ProtocolTlvValue class.
Definition: wimax-tlv.h:532
~ProtocolTlvValue() override
Definition: wimax-tlv.cc:948
std::vector< uint8_t > * m_protocol
protocol
Definition: wimax-tlv.h:563
void Add(uint8_t protocol)
Add protocol number.
Definition: wimax-tlv.cc:986
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:992
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:959
ProtocolTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:1004
std::vector< uint8_t >::const_iterator Iterator
Iterator typedef.
Definition: wimax-tlv.h:537
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:998
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:974
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:965
SfVectorTlvValue class.
Definition: wimax-tlv.h:337
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:306
Type
Type enumeration.
Definition: wimax-tlv.h:341
@ Fixed_length_versus_Variable_length_SDU_Indicator
Definition: wimax-tlv.h:356
@ ARQ_RETRY_TIMEOUT_Transmitter_Delay
Definition: wimax-tlv.h:361
SfVectorTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:295
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:87
uint8_t m_type
type
Definition: wimax-tlv.h:164
TlvValue * CopyValue() const
Copy TlvValue.
Definition: wimax-tlv.cc:75
~Tlv() override
Definition: wimax-tlv.cc:65
uint64_t m_length
length
Definition: wimax-tlv.h:165
Tlv * Copy() const
Copy TLV.
Definition: wimax-tlv.cc:229
uint8_t GetType() const
Get type value.
Definition: wimax-tlv.cc:211
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: wimax-tlv.cc:40
Tlv & operator=(const Tlv &o)
assignment operator
Definition: wimax-tlv.cc:88
TlvValue * PeekValue()
Peek value.
Definition: wimax-tlv.cc:223
static TypeId GetTypeId()
Register this type.
Definition: wimax-tlv.cc:32
uint64_t GetLength() const
Get length value.
Definition: wimax-tlv.cc:217
CommonTypes
CommonTypes enumeration.
Definition: wimax-tlv.h:91
@ UPLINK_SERVICE_FLOW
Definition: wimax-tlv.h:96
@ VENDOR_ID_EMCODING
Definition: wimax-tlv.h:97
@ DOWNLINK_SERVICE_FLOW
Definition: wimax-tlv.h:95
@ CURRENT_TRANSMIT_POWER
Definition: wimax-tlv.h:94
@ HMAC_TUPLE
Definition: wimax-tlv.h:92
@ MAC_VERSION_ENCODING
Definition: wimax-tlv.h:93
@ VENDOR_SPECIFIC_INFORMATION
Definition: wimax-tlv.h:98
uint8_t GetSizeOfLen() const
Get size of length field.
Definition: wimax-tlv.cc:108
void Print(std::ostream &os) const override
Definition: wimax-tlv.cc:46
TlvValue * m_value
value
Definition: wimax-tlv.h:166
uint32_t GetSerializedSize() const override
Definition: wimax-tlv.cc:102
void Serialize(Buffer::Iterator start) const override
Definition: wimax-tlv.cc:126
The value field of a tlv can take different values (uint8_t, uint16, vector, ...).
Definition: wimax-tlv.h:45
virtual ~TlvValue()
Definition: wimax-tlv.h:47
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen)=0
Deserialize from a buffer.
virtual uint32_t GetSerializedSize() const =0
Get serialized size in bytes.
virtual TlvValue * Copy() const =0
Copy function.
virtual void Serialize(Buffer::Iterator start) const =0
Serialize to a buffer.
TosTlvValue class.
Definition: wimax-tlv.h:436
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:827
uint8_t m_high
high
Definition: wimax-tlv.h:474
uint8_t GetHigh() const
Get high part.
Definition: wimax-tlv.cc:850
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:821
~TosTlvValue() override
Definition: wimax-tlv.cc:816
uint8_t GetLow() const
Get low part.
Definition: wimax-tlv.cc:844
uint8_t GetMask() const
Get the mask.
Definition: wimax-tlv.cc:856
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:835
TosTlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:862
uint8_t m_mask
mask
Definition: wimax-tlv.h:475
uint8_t m_low
low
Definition: wimax-tlv.h:473
a unique identifier for an interface.
Definition: type-id.h:59
U16TlvValue class.
Definition: wimax-tlv.h:215
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:554
U16TlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:579
uint16_t m_value
value
Definition: wimax-tlv.h:246
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:548
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:560
uint16_t GetValue() const
Get value.
Definition: wimax-tlv.cc:573
~U16TlvValue() override
Definition: wimax-tlv.cc:543
U32TlvValue class.
Definition: wimax-tlv.h:255
uint32_t GetValue() const
Get value.
Definition: wimax-tlv.cc:626
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:601
~U32TlvValue() override
Definition: wimax-tlv.cc:596
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:607
U32TlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:632
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:613
uint32_t m_value
value
Definition: wimax-tlv.h:287
U8TlvValue class.
Definition: wimax-tlv.h:175
~U8TlvValue() override
Definition: wimax-tlv.cc:490
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen) override
Deserialize from a buffer.
Definition: wimax-tlv.cc:507
uint8_t GetValue() const
Get value.
Definition: wimax-tlv.cc:520
uint8_t m_value
value
Definition: wimax-tlv.h:206
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:495
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:501
U8TlvValue * Copy() const override
Copy.
Definition: wimax-tlv.cc:526
this class is used to implement a vector of values in one tlv value field
Definition: wimax-tlv.h:297
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:251
VectorTlvValue * Copy() const override=0
Copy.
~VectorTlvValue() override
Definition: wimax-tlv.cc:240
std::vector< Tlv * >::const_iterator Iterator
TLV vector iterator typedef.
Definition: wimax-tlv.h:300
void Serialize(Buffer::Iterator start) const override
Serialize to a buffer.
Definition: wimax-tlv.cc:262
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:278
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:272
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:284
std::vector< Tlv * > * m_tlvList
tlv list
Definition: wimax-tlv.h:328
uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength) override=0
Deserialize from a buffer.
address
Definition: first.py:47
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PortRange structure.
Definition: wimax-tlv.h:488