Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
ficmpv4frame.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 FICMPV4FRAME_H
6 #define FICMPV4FRAME_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 eICMPv4FrameBase : public eFrameBase {};
22 
23 
24 
25 class ficmpv4frame : public fframe {
26 public:
27 
28  /* ICMPv4 constants and definitions */
29  struct icmpv4_hdr_t {
30  uint8_t type;
31  uint8_t code;
32  uint16_t checksum;
33  uint8_t data[0];
34  } __attribute__((packed));
35 
36  /* for UDP checksum calculation */
37  struct ip_pseudo_hdr_t {
38  uint32_t src;
39  uint32_t dst;
40  uint8_t reserved;
41  uint8_t proto;
42  uint16_t len;
43  } __attribute__((packed));
44 
45  enum tcp_ip_proto_t {
46  ICMPV4_IP_PROTO = 1,
47  };
48 
49  enum icmpv4_type_t {
50  ICMP_TYPE_DESTINATION_UNREACHABLE = 3,
51  ICMP_TYPE_ECHO_REPLY = 0,
52  ICMP_TYPE_ECHO_REQUEST = 8,
53  };
54 
55  enum icmpv4_code_t {
56  ICMP_CODE_HOST_UNREACHABLE = 1,
57  ICMP_CODE_NO_CODE = 0,
58  ICMP_CODE_DATAGRAM_TOO_BIG = 4,
59  };
60 
61 #define DEFAULT_ICMPV4_FRAME_SIZE sizeof(struct icmpv4_hdr_t)
62 
63 public:
64 
65 
70  uint8_t *data,
71  size_t datalen);
72 
73 
78  size_t len = DEFAULT_ICMPV4_FRAME_SIZE);
79 
80 
84  virtual
85  ~ficmpv4frame();
86 
87 
91  void
92  icmpv4_calc_checksum(uint16_t length);
93 
94 
95 public: // overloaded from fframe
96 
99  virtual bool
100  complete() const;
101 
104  virtual size_t
105  need_bytes() const;
106 
110  virtual void
111  validate(uint16_t total_len = 0) const;
112 
116  virtual void
117  initialize();
118 
122  virtual void
124  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
125 
129  virtual uint8_t*
130  payload() const throw (eFrameNoPayload);
131 
135  virtual size_t
136  payloadlen() const throw (eFrameNoPayload);
137 
138 public:
139 
143  uint8_t
144  get_icmp_code() const;
145 
149  void
150  set_icmp_code(uint8_t code);
151 
155  uint8_t
156  get_icmp_type() const;
157 
161  void
162  set_icmp_type(uint8_t type);
163 
164 public: // data structures
165 
166  // pointer to tcp header
167  struct icmpv4_hdr_t *icmp_hdr;
168 
169  // udp payload
170  uint8_t *data;
171 
172  // udp payload length
173  size_t datalen;
174 
175 public:
176 
177  friend std::ostream&
178  operator<< (std::ostream& os, ficmpv4frame const& frame) {
179  os << dynamic_cast<fframe const&>( frame );
180  os << indent(2) << "<ficmpv4frame ";
181  os << "code:" << (int)frame.get_icmp_code() << " ";
182  os << "type:" << (int)frame.get_icmp_type() << " ";
183  os << ">" << std::endl;
184  return os;
185  };
186 };
187 
188 }; // end of namespace
189 
190 #endif
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: ficmpv4frame.cc:81
virtual void validate(uint16_t total_len=0) const
Definition: ficmpv4frame.cc:115
virtual size_t payloadlen() const
Definition: ficmpv4frame.cc:105
Definition: ficmpv4frame.h:20
virtual bool complete() const
Definition: ficmpv4frame.cc:56
Definition: fframe.h:19
Definition: ficmpv4frame.h:19
virtual size_t need_bytes() const
Definition: ficmpv4frame.cc:68
virtual uint8_t * payload() const
Definition: ficmpv4frame.cc:95
Definition: ficmpv4frame.h:37
Definition: ficmpv4frame.h:29
Definition: fframe.h:22
virtual ~ficmpv4frame()
Definition: ficmpv4frame.cc:31
Definition: ficmpv4frame.h:21
Definition: ficmpv4frame.h:25
ficmpv4frame(uint8_t *data, size_t datalen)
Definition: ficmpv4frame.cc:9
Definition: fframe.h:31
virtual void initialize()
Definition: ficmpv4frame.cc:39
void icmpv4_calc_checksum(uint16_t length)
Definition: ficmpv4frame.cc:130