Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
fetherframe.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #ifndef FETHERFRAME_H
6 #define FETHERFRAME_H 1
7 
8 #include <endian.h>
9 #ifndef htobe16
10  #include "../endian_conversion.h"
11 #endif
12 
13 #include "../fframe.h"
14 #include "../caddress.h"
15 
16 namespace rofl
17 {
18 
19 class eEtherFrameInvalidSyntax : public eFrameInvalidSyntax {}; // invalid syntax
20 
25 class fetherframe : public fframe {
26  static const unsigned int ETH_ADDR_LEN = 6;
27 
28 public: // static
29 
30 #define DEFAULT_ETHER_FRAME_SIZE 1518
31 
32  /* Ethernet constants and definitions */
33 
34  // Ethernet II header
35  struct eth_hdr_t {
36  uint8_t dl_dst[ETH_ADDR_LEN];
37  uint8_t dl_src[ETH_ADDR_LEN];
38  uint16_t dl_type;
39  uint8_t data[0];
40  } __attribute__((packed));
41 
42  //Ethernet LLC header
43  struct eth_llc_hdr_t {
44  uint8_t dl_dst[ETH_ADDR_LEN];
45  uint8_t dl_src[ETH_ADDR_LEN];
46  uint16_t dl_len;
47  uint8_t dl_dsap;
48  uint8_t dl_ssap;
49  uint8_t dl_control;
50  uint8_t dl_vendor_code[3];
51  uint16_t dl_type;
52  uint8_t data[0];
53  }__attribute__((packed));
54 
55 public: // methods
56 
57 
62  uint8_t* data,
63  size_t datalen);
64 
65 
70  size_t len = DEFAULT_ETHER_FRAME_SIZE);
71 
72 
76  virtual
77  ~fetherframe();
78 
79 
83  virtual void
84  reset(
85  uint8_t *data, size_t datalen);
86 
87 
91  void
92  set_dl_src(cmacaddr const& dl_src) throw (eFrameInval);
93 
97  cmacaddr
98  get_dl_src() const;
99 
103  void
104  set_dl_dst(cmacaddr const& dl_dst) throw (eFrameInval);
105 
109  cmacaddr
110  get_dl_dst() const;
111 
115  void
116  set_dl_type(uint16_t dl_type) throw (eFrameInval);
117 
121  uint16_t
122  get_dl_type() const;
123 
124  bool
125  is_llc_frame() const;
126 
127 public: // overloaded from fframe
128 
131  virtual bool
132  complete() const;
133 
136  virtual size_t
137  need_bytes() const;
138 
142  virtual void
143  validate(uint16_t total_len = 0) const;
144 
148  virtual void
149  initialize();
150 
151 
155  virtual void
157  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
158 
159 
163  virtual uint8_t*
164  payload() const throw (eFrameNoPayload);
165 
166 
170  virtual size_t
171  payloadlen() const throw (eFrameNoPayload);
172 
173 
174 
175 public: // data structures
176 
177  // pointer to ethernet header
178  struct eth_hdr_t *eth_hdr;
179  struct eth_llc_hdr_t *eth_llc_hdr;
180 
181 public:
182 
183  friend std::ostream&
184  operator<< (std::ostream& os, fetherframe const& frame) {
185  os << dynamic_cast<fframe const&>( frame );
186  os << rofl::indent(2) << "<fetherframe " << std::endl;
187  os << rofl::indent(4) << "<dl-dst >" << std::endl;
188  { rofl::indent i(6); os << frame.get_dl_dst(); }
189  os << rofl::indent(4) << "<dl-src >" << std::endl;
190  { rofl::indent i(6); os << frame.get_dl_src(); }
191  os << rofl::indent(4) << "<dl-type:0x" << std::hex << (int)frame.get_dl_type() << std::dec << " >" << std::endl;
192  return os;
193  };
194 };
195 
196 }; // end of namespace
197 
198 #endif
fetherframe(uint8_t *data, size_t datalen)
Definition: fetherframe.cc:9
cmacaddr get_dl_src() const
Definition: fetherframe.cc:182
virtual void validate(uint16_t total_len=0) const
Definition: fetherframe.cc:146
Definition: fetherframe.h:19
void set_dl_src(cmacaddr const &dl_src)
Definition: fetherframe.cc:163
Definition: caddress.h:152
virtual ~fetherframe()
Definition: fetherframe.cc:30
Definition: fframe.h:23
virtual size_t payloadlen() const
Definition: fetherframe.cc:126
Definition: fframe.h:21
void set_dl_type(uint16_t dl_type)
Definition: fetherframe.cc:217
virtual void initialize()
Definition: fetherframe.cc:46
virtual bool complete() const
Definition: fetherframe.cc:59
virtual uint8_t * payload() const
Definition: fetherframe.cc:107
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: fetherframe.cc:86
Definition: fetherframe.h:43
virtual size_t need_bytes() const
Definition: fetherframe.cc:73
virtual void reset(uint8_t *data, size_t datalen)
Definition: fetherframe.cc:37
Definition: fframe.h:20
void set_dl_dst(cmacaddr const &dl_dst)
Definition: fetherframe.cc:190
Definition: fetherframe.h:35
Definition: fetherframe.h:25
Definition: fframe.h:22
Definition: logging.h:76
Definition: fframe.h:31
cmacaddr get_dl_dst() const
Definition: fetherframe.cc:209
uint16_t get_dl_type() const
Definition: fetherframe.cc:235