Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
fmplsframe.h
1 
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef FMPLSFRAME_H
7 #define FMPLSFRAME_H 1
8 
9 #include <endian.h>
10 #ifndef htobe16
11  #include "../endian_conversion.h"
12 #endif
13 
14 #include "../fframe.h"
15 #include "../cmemory.h"
16 
17 namespace rofl
18 {
19 
20 class eMplsFrameBase : public eFrameBase {};
21 class eMplsFrameInvalidSyntax : public eMplsFrameBase, public eFrameInvalidSyntax {}; // invalid syntax
23 
28 class fmplsframe : public fframe {
29 public: // static
30 
31  /* Ethernet constants and definitions */
32 
33  // VLAN ethernet types
34  enum mpls_ether_t {
35  MPLS_ETHER = 0x8847,
36  MPLS_ETHER_UPSTREAM = 0x8848,
37  };
38 
39  // MPLS header
40  struct mpls_hdr_t {
41  uint8_t label[3];
42  uint8_t ttl;
43  } __attribute__((packed));
44 
45 public: // methods
46 
47 
51  virtual void
52  reset(
53  uint8_t *data, size_t datalen);
54 
55 
59  fmplsframe(
60  uint8_t* data,
61  size_t datalen);
62 
63 
67  virtual
68  ~fmplsframe();
69 
70 
71 public: // overloaded from fframe
72 
75  virtual bool
76  complete() const;
77 
80  virtual size_t
81  need_bytes() const;
82 
86  virtual void
87  validate(uint16_t total_len = 0) const;
88 
92  virtual void
93  initialize();
94 
98  virtual void
100  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
101 
105  virtual uint8_t*
106  payload() const throw (eFrameNoPayload);
107 
111  virtual size_t
112  payloadlen() const throw (eFrameNoPayload);
113 
114 
115 public:
116 
119  void
120  set_mpls_label(uint32_t label);
121 
124  uint32_t
125  get_mpls_label() const;
126 
129  void
130  set_mpls_tc(uint8_t tc);
131 
134  uint8_t
135  get_mpls_tc() const;
136 
139  void
140  dec_mpls_ttl();
141 
144  void
145  set_mpls_ttl(uint8_t ttl);
146 
149  uint8_t
150  get_mpls_ttl() const;
151 
154  void
155  set_mpls_bos(bool flag = true);
156 
159  bool
160  get_mpls_bos() const;
161 
162 
163 public: // data structures
164 
165  // pointer to ethernet header
166  struct mpls_hdr_t *mpls_hdr;
167 
168 public:
169 
170  friend std::ostream&
171  operator<< (std::ostream& os, fmplsframe const& frame) {
172  os << dynamic_cast<fframe const&>( frame ) << std::endl;
173  os << indent(2) << "<fmlpsframe ";
174  os << "label:" << (int)frame.get_mpls_label() << " ";
175  os << "tc:" << (int)frame.get_mpls_tc() << " ";
176  os << "bos:" << (int)frame.get_mpls_bos() << " ";
177  os << "ttl:" << (int)frame.get_mpls_ttl() << " ";
178  os << ">" << std::endl;
179  return os;
180  };
181 };
182 
183 
184 }; // end of namespace
185 
186 #endif
virtual ~fmplsframe()
Definition: fmplsframe.cc:20
virtual size_t need_bytes() const
Definition: fmplsframe.cc:58
virtual void reset(uint8_t *data, size_t datalen)
Definition: fmplsframe.cc:28
virtual bool complete() const
Definition: fmplsframe.cc:46
Definition: fframe.h:21
Definition: fmplsframe.h:22
Definition: fmplsframe.h:28
virtual size_t payloadlen() const
Definition: fmplsframe.cc:97
Definition: fframe.h:19
Definition: fmplsframe.h:21
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: fmplsframe.cc:72
Definition: fmplsframe.h:20
fmplsframe(uint8_t *data, size_t datalen)
Definition: fmplsframe.cc:9
Definition: fframe.h:20
virtual void validate(uint16_t total_len=0) const
Definition: fmplsframe.cc:107
Definition: fmplsframe.h:40
Definition: fframe.h:22
Definition: logging.h:76
Definition: fframe.h:31
void set_mpls_bos(bool flag=true)
Definition: fmplsframe.cc:176
virtual uint8_t * payload() const
Definition: fmplsframe.cc:85
virtual void initialize()
Definition: fmplsframe.cc:38