Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
fsctpframe.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 
6 /*
7  * fsctpframe.h
8  *
9  * Created on: 07.12.2012
10  * Author: andreas
11  */
12 
13 #ifndef FSCTPFRAME_H
14 #define FSCTPFRAME_H 1
15 
16 #include <endian.h>
17 #ifndef htobe16
18  #include "../endian_conversion.h"
19 #endif
20 
21 #include "../fframe.h"
22 #include "../caddress.h"
23 
24 namespace rofl
25 {
26 
27 class eSctpFrameBase : public eFrameBase {};
30 
31 
32 class fsctpframe : public fframe {
33 public:
34  /* TCP constants and definitions */
35  struct sctp_hdr_t {
36  uint16_t sport;
37  uint16_t dport;
38  uint32_t verification_tag;
39  uint32_t checksum;
40  uint8_t data[0];
41  } __attribute__((packed));
42 
43  /* SCTP chunk header */
45  uint16_t type;
46  uint16_t len;
47  uint32_t value;
48  } __attribute__((packed));
49 
50  /* for SCTP checksum calculation */
51  struct ip_pseudo_hdr_t {
52  uint32_t src;
53  uint32_t dst;
54  uint8_t reserved;
55  uint8_t proto;
56  uint16_t len;
57  } __attribute__((packed));
58 
59  enum sctp_ip_proto_t {
60  SCTP_IP_PROTO = 132,
61  };
62 
63 public:
64 
65 
69  fsctpframe(
70  uint8_t *_data,
71  size_t _datalen);
72 
73 
77  virtual
78  ~fsctpframe();
79 
80 
84  void
86  caddress_in4 const& ip_src,
87  caddress_in4 const& ip_dst,
88  uint8_t ip_proto,
89  uint16_t length);
90 
91 public: // overloaded from fframe
92 
95  virtual bool
96  complete() const;
97 
100  virtual size_t
101  need_bytes() const;
102 
106  virtual void
107  validate(uint16_t total_len = 0) const;
108 
112  virtual void
113  initialize();
114 
118  virtual void
120  uint8_t *data, size_t datalen) throw (eFrameOutOfRange);
121 
125  virtual uint8_t*
126  payload() const throw (eFrameNoPayload);
127 
131  virtual size_t
132  payloadlen() const throw (eFrameNoPayload);
133 
134 public:
135 
138  uint16_t
139  get_sport() const;
140 
143  void
144  set_sport(uint16_t port);
145 
148  uint16_t
149  get_dport() const;
150 
153  void
154  set_dport(uint16_t port);
155 
156 public: // data structures
157 
158  // pointer to tcp header
159  struct sctp_hdr_t *sctp_hdr;
160 
161  // udp payload
162  uint8_t *data;
163 
164  // udp payload length
165  size_t datalen;
166 
167 public:
168 
169  friend std::ostream&
170  operator<< (std::ostream& os, fsctpframe const& frame) {
171  os << dynamic_cast<fframe const&>( frame );
172  os << indent(2) << "<fsctpframe ";
173  os << "dport:" << (int)frame.get_dport() << " ";
174  os << "sport:" << (int)frame.get_sport() << " ";
175  os << ">" << std::endl;
176  return os;
177  };
178 };
179 
180 }; // end of namespace
181 
182 #endif /* FSCTPFRAME_H_ */
Definition: fsctpframe.h:29
Definition: fsctpframe.h:35
virtual void payload_insert(uint8_t *data, size_t datalen)
Definition: fsctpframe.cc:87
fsctpframe(uint8_t *_data, size_t _datalen)
Definition: fsctpframe.cc:16
Definition: fsctpframe.h:44
Definition: fframe.h:21
Definition: fsctpframe.h:27
Definition: fframe.h:19
Definition: fsctpframe.h:51
virtual size_t need_bytes() const
Definition: fsctpframe.cc:72
Definition: fsctpframe.h:32
virtual size_t payloadlen() const
Definition: fsctpframe.cc:108
virtual void initialize()
Definition: fsctpframe.cc:37
Definition: caddress.h:415
virtual ~fsctpframe()
Definition: fsctpframe.cc:29
Definition: fframe.h:20
virtual void validate(uint16_t total_len=0) const
Definition: fsctpframe.cc:118
virtual bool complete() const
Definition: fsctpframe.cc:58
virtual uint8_t * payload() const
Definition: fsctpframe.cc:98
Definition: fframe.h:22
Definition: logging.h:76
void sctp_calc_checksum(caddress_in4 const &ip_src, caddress_in4 const &ip_dst, uint8_t ip_proto, uint16_t length)
Definition: fsctpframe.cc:132
Definition: fsctpframe.h:28
Definition: fframe.h:31