Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
ftcpframe.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 FTCPFRAME_H
6 #define FTCPFRAME_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 eTcpFrameBase : public eFrameBase {};
22 
23 
24 class ftcpframe : public fframe {
25 public:
26  /* TCP constants and definitions */
27  struct tcp_hdr_t {
28  uint16_t sport;
29  uint16_t dport;
30  uint32_t seqno;
31  uint32_t ackno;
32 #ifdef __BIG_ENDIAN
33  uint16_t offset : 4; // =5 => 5 32bit words (= 20 bytes), >5 => options appended
34  uint16_t reserved : 3;
35  uint16_t ns : 1;
36  /* byte */
37  uint16_t cwr : 1;
38  uint16_t ece : 1;
39  uint16_t urg : 1;
40  uint16_t ack : 1;
41  uint16_t psh : 1;
42  uint16_t rst : 1;
43  uint16_t syn : 1;
44  uint16_t fin : 1;
45 #elif __LITTLE_ENDIAN
46  uint16_t cwr : 1;
47  uint16_t ece : 1;
48  uint16_t urg : 1;
49  uint16_t ack : 1;
50  uint16_t psh : 1;
51  uint16_t rst : 1;
52  uint16_t syn : 1;
53  uint16_t fin : 1;
54  /* byte */
55  uint16_t offset : 4; // =5 => 5 32bit words (= 20 bytes), >5 => options appended
56  uint16_t reserved : 3;
57  uint16_t ns : 1;
58 #endif
59  uint16_t wnd;
60  uint16_t checksum;
61  uint16_t urgent;
62  uint8_t data[0];
63  } __attribute__((packed));
64 
65  /* for UDP checksum calculation */
66  struct ip_pseudo_hdr_t {
67  uint32_t src;
68  uint32_t dst;
69  uint8_t reserved;
70  uint8_t proto;
71  uint16_t len;
72  } __attribute__((packed));
73 
74  enum tcp_ip_proto_t {
75  TCP_IP_PROTO = 6,
76  };
77 
78 public:
79 
80 
84  ftcpframe(
85  uint8_t *_data,
86  size_t _datalen);
87 
88 
92  virtual
93  ~ftcpframe();
94 
95 
99  void
101  caddress_in4 const& ip_src,
102  caddress_in4 const& ip_dst,
103  uint8_t ip_proto,
104  uint16_t length);
105 
106 public: // overloaded from fframe
107 
110  virtual bool
111  complete() const;
112 
115  virtual size_t
116  need_bytes() const;
117 
121  virtual void
122  validate(uint16_t total_len = 0) const;
123 
127  virtual void
128  initialize();
129 
133  virtual void
135  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
136 
140  virtual uint8_t*
141  payload() const throw (eFrameNoPayload);
142 
146  virtual size_t
147  payloadlen() const throw (eFrameNoPayload);
148 
151  uint16_t
152  get_sport() const;
153 
156  void
157  set_sport(uint16_t port);
158 
161  uint16_t
162  get_dport() const;
163 
166  void
167  set_dport(uint16_t port);
168 
169 public: // data structures
170 
171  // pointer to tcp header
172  struct tcp_hdr_t *tcp_hdr;
173 
174  // udp payload
175  uint8_t *data;
176 
177  // udp payload length
178  size_t datalen;
179 
180 public:
181 
182  friend std::ostream&
183  operator<< (std::ostream& os, ftcpframe const& frame) {
184  os << dynamic_cast<fframe const&>( frame );
185  os << indent(2) << "<ftcpframe ";
186  os << "sport:" << (int)frame.get_sport() << " ";
187  os << "dport:" << (int)frame.get_dport() << " ";
188  os << ">" << std::endl;
189  return os;
190  };
191 };
192 
193 }; // end of namespace
194 
195 #endif
Definition: ftcpframe.h:19
Definition: ftcpframe.h:21
virtual uint8_t * payload() const
Definition: ftcpframe.cc:94
void tcp_calc_checksum(caddress_in4 const &ip_src, caddress_in4 const &ip_dst, uint8_t ip_proto, uint16_t length)
Definition: ftcpframe.cc:128
Definition: fframe.h:21
virtual void initialize()
Definition: ftcpframe.cc:30
Definition: ftcpframe.h:20
Definition: fframe.h:19
Definition: ftcpframe.h:66
virtual size_t need_bytes() const
Definition: ftcpframe.cc:62
virtual bool complete() const
Definition: ftcpframe.cc:47
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: ftcpframe.cc:78
Definition: caddress.h:415
Definition: fframe.h:20
virtual void validate(uint16_t total_len=0) const
Definition: ftcpframe.cc:114
virtual size_t payloadlen() const
Definition: ftcpframe.cc:104
Definition: fframe.h:22
Definition: logging.h:76
ftcpframe(uint8_t *_data, size_t _datalen)
Definition: ftcpframe.cc:9
Definition: ftcpframe.h:24
Definition: ftcpframe.h:27
Definition: fframe.h:31
virtual ~ftcpframe()
Definition: ftcpframe.cc:22