Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
farpv4frame.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 FARPV4FRAME_H
6 #define FARPV4FRAME_H 1
7 
8 #include <inttypes.h>
9 #include <endian.h>
10 #ifndef be32toh
11  #include "../endian_conversion.h"
12 #endif
13 
14 #include "../fframe.h"
15 #include "../caddress.h"
16 
17 namespace rofl
18 {
19 
20 class eARPv4FrameBase : public eFrameInval {};
22 
23 
24 class farpv4frame : public fframe {
25  static const unsigned int ETH_ADDR_LEN = 6;
26 
27 public: // static
28 
29  /* ARPv4 constants and definitions */
30  enum arpv4_ether_t {
31  ARPV4_ETHER = 0x0806,
32  };
33 
34  enum arpv4_opcodes_t {
35  ARPV4_OPCODE_REQUEST = 0x01,
36  ARPV4_OPCODE_REPLY = 0x02,
37  };
38 
39  struct arpv4_hdr_t {
40  uint16_t ar_hrd; // hardware address format
41  uint16_t ar_pro; // protocol address format
42  uint8_t ar_hln; // hardware address length
43  uint8_t ar_pln; // protocol address length
44  uint16_t ar_op; // ARP opcode
45  uint8_t dl_src[ETH_ADDR_LEN]; // source MAC address
46  uint32_t ip_src; // source IP address
47  uint8_t dl_dst[ETH_ADDR_LEN]; // destination MAC address
48  uint32_t ip_dst; // destination IP address
49  } __attribute__((packed));
50  /* ARPv4 definitions */
51 
52 #define DEFAULT_ARPV4_FRAME_SIZE sizeof(struct arpv4_hdr_t)
53 
54 public:
55 
56 
61  uint8_t *_data,
62  size_t _datalen);
63 
64 
69  size_t len = DEFAULT_ARPV4_FRAME_SIZE);
70 
71 
75  virtual
76  ~farpv4frame();
77 
81  void
82  set_hw_addr_type(
83  uint16_t hwaddrtype);
84 
88  uint16_t
89  get_hw_addr_type() const;
90 
94  void
95  set_prot_addr_type(
96  uint16_t prothwaddrtype);
97 
101  uint16_t
102  get_prot_addr_type() const;
103 
107  void
108  set_hw_addr_size(
109  uint8_t size);
110 
114  uint8_t
115  get_hw_addr_size() const;
116 
120  void
121  set_prot_hw_addr_size(
122  uint8_t size);
123 
127  uint8_t
128  get_prot_hw_addr_size() const;
129 
133  void
134  set_opcode(
135  uint16_t operation);
136 
140  uint16_t
141  get_opcode() const;
142 
146  void
147  set_dl_src(
148  cmacaddr const& dl_src);
149 
153  cmacaddr
154  get_dl_src() const;
155 
159  void
160  set_dl_dst(
161  cmacaddr const& dl_dst);
162 
166  cmacaddr
167  get_dl_dst() const;
168 
172  void
173  set_nw_src(
174  uint32_t src);
175 
179  void
180  set_nw_src(
181  caddress_in4 const& addr);
182 
187  get_nw_src() const;
188 
192  void
193  set_nw_dst(
194  uint32_t dst);
195 
199  void
200  set_nw_dst(
201  caddress_in4 const& addr);
202 
207  get_nw_dst() const;
208 
209 
210 public: // overloaded from fframe
211 
214  virtual bool
215  complete() const;
216 
219  virtual size_t
220  need_bytes() const;
221 
225  virtual void
226  validate(uint16_t total_len = 0) const;
227 
231  virtual void
232  initialize();
233 
237  virtual void
239  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
240 
244  virtual uint8_t*
245  payload() const throw (eFrameNoPayload);
246 
250  virtual size_t
251  payloadlen() const throw (eFrameNoPayload);
252 
253 
254 
255 public: // data structures
256 
257  // pointer to pppoe header
258  struct arpv4_hdr_t *arp_hdr;
259 
260 public:
261 
262  friend std::ostream&
263  operator<< (std::ostream& os, farpv4frame const& frame) {
264  os << dynamic_cast<fframe const&>( frame );
265  os << indent(2) << "<farpv4frame ";
266  os << "opcode:" << (int)frame.get_opcode() << " ";
267  os << "hw-addr-type:" << (int)frame.get_hw_addr_type() << " ";
268  os << "hw-addr-size:" << (int)frame.get_hw_addr_size() << " ";
269  os << "prot-addr-type:" << (int)frame.get_prot_addr_type() << " ";
270  os << "prot-addr-size:" << (int)frame.get_prot_hw_addr_size() << " ";
271  os << "dl-dst:" << frame.get_dl_dst() << " ";
272  os << "dl-src:" << frame.get_dl_src() << " ";
273  os << "nw-dst:" << frame.get_nw_dst() << " ";
274  os << "nw-src:" << frame.get_nw_src() << " ";
275  os << ">" << std::endl;
276  return os;
277  };
278 };
279 
280 }; // end of namespace
281 
282 #endif
Definition: caddress.h:152
Definition: fframe.h:23
void set_nw_dst(uint32_t dst)
Definition: farpv4frame.cc:237
farpv4frame(uint8_t *_data, size_t _datalen)
Definition: farpv4frame.cc:9
Definition: fframe.h:21
virtual size_t need_bytes() const
Definition: farpv4frame.cc:57
virtual bool complete() const
Definition: farpv4frame.cc:46
Definition: farpv4frame.h:21
virtual ~farpv4frame()
Definition: farpv4frame.cc:30
void set_nw_src(uint32_t src)
Definition: farpv4frame.cc:213
Definition: farpv4frame.h:39
Definition: caddress.h:415
Definition: fframe.h:20
virtual size_t payloadlen() const
Definition: farpv4frame.cc:88
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: farpv4frame.cc:71
Definition: farpv4frame.h:20
Definition: fframe.h:22
virtual void initialize()
Definition: farpv4frame.cc:38
Definition: logging.h:76
Definition: fframe.h:31
virtual uint8_t * payload() const
Definition: farpv4frame.cc:80
Definition: farpv4frame.h:24
virtual void validate(uint16_t total_len=0) const
Definition: farpv4frame.cc:96