A Discrete-Event Network Simulator
API
wimax-tlv.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA, UDcast
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  * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  *
20  */
21 
22 #ifndef WIMAX_TLV_H
23 #define WIMAX_TLV_H
24 
25 #define WIMAX_TLV_EXTENDED_LENGTH_MASK 0x80
26 
27 #include "ns3/ipv4-address.h"
28 #include <cstdlib>
29 #include "ns3/log.h"
30 #include "ns3/assert.h"
31 #include "ns3/uinteger.h"
32 #include "ns3/header.h"
33 #include <vector>
34 
35 namespace ns3 {
36 
43 class TlvValue
44 {
45 public:
46  virtual ~TlvValue ()
47  {
48  }
53  virtual uint32_t GetSerializedSize (void) const = 0;
58  virtual void Serialize (Buffer::Iterator start) const = 0;
65  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLen ) = 0;
70  virtual TlvValue * Copy (void) const = 0;
71 private:
72 };
73 
74 
75 // =============================================================================
83 class Tlv : public Header
84 {
85 public:
88  {
89  HMAC_TUPLE = 149,
96  };
104  Tlv (uint8_t type, uint64_t length, const TlvValue & value);
105  Tlv (void);
106  ~Tlv (void);
111  static TypeId GetTypeId (void);
112  virtual TypeId GetInstanceTypeId (void) const;
113  virtual void Print (std::ostream &os) const;
114  virtual uint32_t GetSerializedSize (void) const;
115  virtual void Serialize (Buffer::Iterator start) const;
116  virtual uint32_t Deserialize (Buffer::Iterator start);
121  uint8_t GetSizeOfLen (void) const;
126  uint8_t GetType (void) const;
131  uint64_t GetLength (void) const;
136  TlvValue* PeekValue (void);
141  Tlv * Copy (void) const;
146  TlvValue * CopyValue (void) const;
152  Tlv &operator = (Tlv const& o);
157  Tlv (const Tlv & tlv);
158 
159 private:
160  uint8_t m_type;
161  uint64_t m_length;
163 };
164 
165 // ==============================================================================
170 class U8TlvValue : public TlvValue
171 {
172 public:
178  U8TlvValue (uint8_t value);
179  U8TlvValue ();
180  ~U8TlvValue (void);
181  virtual uint32_t GetSerializedSize (void) const;
182  virtual void Serialize (Buffer::Iterator start) const;
183  virtual uint32_t Deserialize (Buffer::Iterator start,uint64_t valueLen);
194  uint8_t GetValue (void) const;
199  U8TlvValue * Copy (void) const;
200 private:
201  uint8_t m_value;
202 };
203 
204 // ==============================================================================
209 class U16TlvValue : public TlvValue
210 {
211 public:
217  U16TlvValue (uint16_t value);
218  U16TlvValue ();
219  ~U16TlvValue (void);
220  virtual uint32_t GetSerializedSize (void) const;
221  virtual void Serialize (Buffer::Iterator start) const;
222  virtual uint32_t Deserialize (Buffer::Iterator start,uint64_t valueLen);
233  uint16_t GetValue (void) const;
238  virtual U16TlvValue * Copy (void) const;
239 private:
240  uint16_t m_value;
241 };
242 
243 // ==============================================================================
248 class U32TlvValue : public TlvValue
249 {
250 public:
256  U32TlvValue (uint32_t value);
257  U32TlvValue ();
258  ~U32TlvValue (void);
259 
260  virtual uint32_t GetSerializedSize (void) const;
261  virtual void Serialize (Buffer::Iterator start) const;
262  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLen);
273  uint32_t GetValue (void) const;
278  virtual U32TlvValue * Copy (void) const;
279 private:
280  uint32_t m_value;
281 };
282 
283 // ==============================================================================
284 
289 class VectorTlvValue : public TlvValue
290 {
291 public:
293  typedef std::vector<Tlv*>::const_iterator Iterator;
294  VectorTlvValue (void);
295  ~VectorTlvValue (void);
296  virtual uint32_t GetSerializedSize (void) const;
297  virtual void Serialize (Buffer::Iterator start) const;
298  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength) = 0;
303  Iterator Begin () const;
308  Iterator End () const;
313  void Add (const Tlv & val);
318  virtual VectorTlvValue * Copy (void) const = 0;
319 private:
320  std::vector<Tlv*> * m_tlvList;
321 };
322 
323 // ==============================================================================
329 {
330 
331 public:
333  enum Type
334  {
335  SFID = 1,
336  CID = 2,
350  SDU_Size = 16,
361  reserved2 = 27,
364  };
365  SfVectorTlvValue ();
366  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
367  virtual SfVectorTlvValue * Copy (void) const;
368 
369 };
370 // ==============================================================================
371 
377 {
378 public:
380  enum Type
381  {
384  };
386  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
387  virtual CsParamVectorTlvValue * Copy (void) const;
388 private:
389 };
390 
391 // ==============================================================================
392 
398 {
399 public:
402  {
403  Priority = 1,
404  ToS = 2,
405  Protocol = 3,
406  IP_src = 4,
407  IP_dst = 5,
408  Port_src = 6,
409  Port_dst = 7,
410  Index = 14,
411  };
413  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
414  virtual ClassificationRuleVectorTlvValue * Copy (void) const;
415 private:
416 };
417 
418 // ==============================================================================
423 class TosTlvValue : public TlvValue
424 {
425 public:
426  TosTlvValue ();
434  TosTlvValue (uint8_t low, uint8_t high, uint8_t mask);
435  ~TosTlvValue ();
436  virtual uint32_t GetSerializedSize (void) const;
437  virtual void Serialize (Buffer::Iterator start) const;
438  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
443  uint8_t GetLow (void) const;
448  uint8_t GetHigh (void) const;
453  uint8_t GetMask (void) const;
458  virtual TosTlvValue * Copy () const;
459 private:
460  uint8_t m_low;
461  uint8_t m_high;
462  uint8_t m_mask;
463 };
464 
465 // ==============================================================================
471 {
472 public:
474  struct PortRange
475  {
476  uint16_t PortLow;
477  uint16_t PortHigh;
478  };
480  typedef std::vector<struct PortRange>::const_iterator Iterator;
483  virtual uint32_t GetSerializedSize (void) const;
484  virtual void Serialize (Buffer::Iterator start) const;
485  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
491  void Add (uint16_t portLow, uint16_t portHigh);
496  Iterator Begin () const;
501  Iterator End () const;
506  virtual PortRangeTlvValue * Copy (void) const;
507 private:
508  std::vector<struct PortRange> * m_portRange;
509 };
510 
511 // ==============================================================================
517 {
518 public:
519  ProtocolTlvValue ();
522  typedef std::vector<uint8_t>::const_iterator Iterator;
523  virtual uint32_t GetSerializedSize (void) const;
524  virtual void Serialize (Buffer::Iterator start) const;
525  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
530  void Add (uint8_t protocol);
535  Iterator Begin () const;
540  Iterator End () const;
545  virtual ProtocolTlvValue * Copy (void) const;
546 private:
547  std::vector<uint8_t> * m_protocol;
548 };
549 
550 // ==============================================================================
551 
557 {
558 public:
560  struct ipv4Addr
561  {
564  };
566  typedef std::vector<struct ipv4Addr>::const_iterator Iterator;
569  virtual uint32_t GetSerializedSize (void) const;
570  virtual void Serialize (Buffer::Iterator start) const;
571  virtual uint32_t Deserialize (Buffer::Iterator start, uint64_t valueLength);
577  void Add (Ipv4Address address, Ipv4Mask Mask);
582  Iterator Begin () const;
587  Iterator End () const;
588  virtual Ipv4AddressTlvValue * Copy () const;
589 private:
590  std::vector<struct ipv4Addr> * m_ipv4Addr;
591 };
592 
593 }
594 
595 #endif /* WIMAX_TLV_H */
Protocol header serialization and deserialization.
Definition: header.h:42
uint8_t GetLow(void) const
Get low part.
Definition: wimax-tlv.cc:858
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:307
uint64_t GetLength(void) const
Get length value.
Definition: wimax-tlv.cc:219
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:1054
U16TlvValue class.
Definition: wimax-tlv.h:209
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:1038
virtual uint32_t GetSerializedSize(void) const
Definition: wimax-tlv.cc:103
std::vector< struct ipv4Addr >::const_iterator Iterator
IPv4 address vector iterator typedef.
Definition: wimax-tlv.h:566
std::vector< uint8_t >::const_iterator Iterator
Iterator typedef.
Definition: wimax-tlv.h:522
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:896
PortRange structure.
Definition: wimax-tlv.h:474
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:926
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: wimax-tlv.cc:42
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:263
ProtocolTlvValue class.
Definition: wimax-tlv.h:516
virtual uint32_t GetSerializedSize(void) const =0
Get serialized size in bytes.
Type
Type enumeration.
Definition: wimax-tlv.h:333
def start()
Definition: core.py:1855
SfVectorTlvValue class.
Definition: wimax-tlv.h:328
uint64_t m_length
length
Definition: wimax-tlv.h:161
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)=0
Deserialize from a buffer.
virtual uint32_t Deserialize(Buffer::Iterator start)
Definition: wimax-tlv.cc:147
void Add(uint16_t portLow, uint16_t portHigh)
Add a range.
Definition: wimax-tlv.cc:918
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:932
virtual ~TlvValue()
Definition: wimax-tlv.h:46
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:278
TosTlvValue class.
Definition: wimax-tlv.h:423
this class implements the convergence sub-layer descriptor as a tlv vector
Definition: wimax-tlv.h:376
uint16_t m_value
value
Definition: wimax-tlv.h:240
virtual PortRangeTlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:938
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:850
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:251
Ipv4AddressTlvValue class.
Definition: wimax-tlv.h:556
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:618
virtual void Print(std::ostream &os) const
Definition: wimax-tlv.cc:47
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:83
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:905
iterator in a Buffer instance
Definition: buffer.h:98
The value field of a tlv can take different values (uint8_t, uint16, vector, ...).
Definition: wimax-tlv.h:43
Tlv * Copy(void) const
Copy TLV.
Definition: wimax-tlv.cc:230
std::vector< struct ipv4Addr > * m_ipv4Addr
ipv4 addr
Definition: wimax-tlv.h:590
TlvValue * m_value
value
Definition: wimax-tlv.h:162
uint8_t GetSizeOfLen(void) const
Get size of length field.
Definition: wimax-tlv.cc:109
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:284
virtual U32TlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:641
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:514
std::vector< struct PortRange >::const_iterator Iterator
PortRange vector iterator typedef.
Definition: wimax-tlv.h:480
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:971
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:648
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:965
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:998
uint8_t m_value
value
Definition: wimax-tlv.h:201
virtual VectorTlvValue * Copy(void) const =0
Copy.
virtual CsParamVectorTlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:702
Type
Type enumeration.
Definition: wimax-tlv.h:380
std::vector< Tlv * > * m_tlvList
tlv list
Definition: wimax-tlv.h:320
uint8_t GetMask(void) const
Get the mask.
Definition: wimax-tlv.cc:868
virtual TosTlvValue * Copy() const
Copy.
Definition: wimax-tlv.cc:874
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:272
uint32_t GetValue(void) const
Get value.
Definition: wimax-tlv.cc:635
static TypeId GetTypeId(void)
Register this type.
Definition: wimax-tlv.cc:32
Tlv(void)
Definition: wimax-tlv.cc:59
ClassificationRuleTlvType
ClassificationRuleTlvType enumeration.
Definition: wimax-tlv.h:401
uint8_t GetHigh(void) const
Get high part.
Definition: wimax-tlv.cc:863
U8TlvValue class.
Definition: wimax-tlv.h:170
virtual TlvValue * Copy(void) const =0
Copy function.
uint8_t GetType(void) const
Get type value.
Definition: wimax-tlv.cc:214
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:891
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:1004
std::vector< uint8_t > * m_protocol
protocol
Definition: wimax-tlv.h:547
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:1077
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:564
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:613
void Add(uint8_t protocol)
Add protocol number.
Definition: wimax-tlv.cc:992
uint8_t m_low
low
Definition: wimax-tlv.h:460
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:519
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen)=0
Deserialize from a buffer.
uint8_t GetValue(void) const
Get value.
Definition: wimax-tlv.cc:537
Ipv4Address Address
address
Definition: wimax-tlv.h:562
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
std::vector< struct PortRange > * m_portRange
port range
Definition: wimax-tlv.h:508
U8TlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:543
TlvValue * PeekValue(void)
Peek value.
Definition: wimax-tlv.cc:224
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:843
~Tlv(void)
Definition: wimax-tlv.cc:66
this class implements the classifier descriptor as a tlv vector
Definition: wimax-tlv.h:397
uint16_t GetValue(void) const
Get value.
Definition: wimax-tlv.cc:587
virtual Ipv4AddressTlvValue * Copy() const
Copy function.
Definition: wimax-tlv.cc:1089
uint8_t m_type
type
Definition: wimax-tlv.h:160
PortRangeTlvValue class.
Definition: wimax-tlv.h:470
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:1083
this class is used to implement a vector of values in one tlv value field
Definition: wimax-tlv.h:289
virtual uint32_t GetSerializedSize(void) const
Get serialized size in bytes.
Definition: wimax-tlv.cc:838
virtual SfVectorTlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:296
Tlv & operator=(Tlv const &o)
assignment operator
Definition: wimax-tlv.cc:89
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen)
Deserialize from a buffer.
Definition: wimax-tlv.cc:524
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen)
Deserialize from a buffer.
Definition: wimax-tlv.cc:623
virtual ProtocolTlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:1010
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:569
virtual ClassificationRuleVectorTlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:719
virtual U16TlvValue * Copy(void) const
Copy.
Definition: wimax-tlv.cc:593
virtual void Serialize(Buffer::Iterator start) const =0
Serialize to a buffer.
U32TlvValue class.
Definition: wimax-tlv.h:248
virtual void Serialize(Buffer::Iterator start) const
Definition: wimax-tlv.cc:127
uint8_t m_high
high
Definition: wimax-tlv.h:461
void Add(Ipv4Address address, Ipv4Mask Mask)
Add IPv4 address and mask.
Definition: wimax-tlv.cc:1068
uint8_t m_mask
mask
Definition: wimax-tlv.h:462
TlvValue * CopyValue(void) const
Copy TlvValue.
Definition: wimax-tlv.cc:76
uint32_t m_value
value
Definition: wimax-tlv.h:280
std::vector< Tlv * >::const_iterator Iterator
TLV vector iterator typedef.
Definition: wimax-tlv.h:293
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:262
CommonTypes
CommonTypes enumeration.
Definition: wimax-tlv.h:87
a unique identifier for an interface.
Definition: type-id.h:58
virtual void Serialize(Buffer::Iterator start) const
Serialize to a buffer.
Definition: wimax-tlv.cc:1044
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:980
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLength)
Deserialize from a buffer.
Definition: wimax-tlv.cc:730
virtual uint32_t Deserialize(Buffer::Iterator start, uint64_t valueLen)
Deserialize from a buffer.
Definition: wimax-tlv.cc:574