Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofmsg_packet_in.h
1 /*
2  * cofmsg_packet_in.h
3  *
4  * Created on: 18.03.2013
5  * Author: andi
6  */
7 
8 #ifndef COFMSG_PACKET_IN_H_
9 #define COFMSG_PACKET_IN_H_ 1
10 
11 #include "rofl/common/openflow/messages/cofmsg.h"
12 #include "rofl/common/openflow/cofmatch.h"
13 #include "rofl/common/cpacket.h"
14 
15 namespace rofl {
16 namespace openflow {
17 
22  public cofmsg
23 {
24 private:
25 
26  cofmatch match;
27  cpacket packet;
28 
29  union {
30  uint8_t* ofhu_packet_in;
31  struct openflow10::ofp_packet_in* ofhu10_packet_in;
32  struct openflow12::ofp_packet_in* ofhu12_packet_in;
33  struct openflow13::ofp_packet_in* ofhu13_packet_in;
34  } ofhu;
35 
36 #define ofh_packet_in ofhu.ofhu_packet_in
37 #define ofh10_packet_in ofhu.ofhu10_packet_in
38 #define ofh12_packet_in ofhu.ofhu12_packet_in
39 #define ofh13_packet_in ofhu.ofhu13_packet_in
40 
41 #define OFP10_PACKET_IN_STATIC_HDR_LEN (sizeof(struct openflow10::ofp_packet_in) - 2)
42 #define OFP12_PACKET_IN_STATIC_HDR_LEN (sizeof(struct openflow12::ofp_packet_in) - sizeof(struct openflow12::ofp_match)) // length without struct openflow12::ofp_match
43 #define OFP13_PACKET_IN_STATIC_HDR_LEN (sizeof(struct openflow13::ofp_packet_in) - sizeof(struct openflow13::ofp_match)) // length without struct openflow13::ofp_match
44 
45 public:
46 
47 
52  uint8_t of_version = 0,
53  uint32_t xid = 0,
54  uint32_t buffer_id = 0,
55  uint16_t total_len = 0,
56  uint8_t reason = 0,
57  uint8_t table_id = 0,
58  uint64_t of13_cookie = 0, /*OF1.3*/
59  uint16_t of10_in_port = 0, /*OF1.0*/
60  cofmatch const& match = cofmatch(),
61  uint8_t *data = (uint8_t*)0,
62  size_t datalen = 0);
63 
64 
69  cofmsg_packet_in const& packet_in);
70 
71 
76  operator= (
77  cofmsg_packet_in const& packet_in);
78 
79 
83  virtual
85 
86 
90  cofmsg_packet_in(cmemory *memarea);
91 
92 
96  virtual void
97  reset();
98 
99 
103  virtual uint8_t*
104  resize(size_t len);
105 
106 
110  virtual size_t
111  length() const;
112 
113 
117  virtual void
118  pack(uint8_t *buf = (uint8_t*)0, size_t buflen = 0);
119 
120 
124  virtual void
125  unpack(uint8_t *buf, size_t buflen);
126 
127 
130  virtual void
131  validate();
132 
133 
134 public:
135 
136 
140  uint32_t
141  get_buffer_id() const;
142 
146  void
147  set_buffer_id(uint32_t buffer_id);
148 
152  uint16_t
153  get_total_len() const;
154 
158  void
159  set_total_len(uint16_t total_len);
160 
164  uint8_t
165  get_reason() const;
166 
170  void
171  set_reason(uint8_t reason);
172 
176  uint8_t
177  get_table_id() const;
178 
182  void
183  set_table_id(uint8_t table_id);
184 
188  uint16_t
189  get_in_port() const;
190 
194  void
195  set_in_port(uint16_t port_no);
196 
200  uint64_t
201  get_cookie() const;
202 
206  void
207  set_cookie(uint64_t cookie);
208 
212  cofmatch&
213  set_match() { return match; };
214 
218  cofmatch const&
219  get_match() const { return match; };
220 
224  cpacket&
225  set_packet() { return packet; };
226 
230  cpacket const&
231  get_packet() const { return packet; };
232 
233 public:
234 
235  friend std::ostream&
236  operator<< (std::ostream& os, cofmsg_packet_in const& msg) {
237  os << dynamic_cast<cofmsg const&>( msg );
238  os << indent(2) << "<cofmsg_packet_in >" << std::endl;
239  switch (msg.get_version()) {
240  case openflow10::OFP_VERSION: {
241  os << indent(4) << "<in-port:" << (int)msg.get_in_port() << " >" << std::endl;
242  os << indent(4) << "<buffer-id:" << (int)msg.get_buffer_id() << " >" << std::endl;
243  os << indent(4) << "<total-len:" << (int)msg.get_total_len() << " >" << std::endl;
244  switch (msg.get_reason()) {
245  case rofl::openflow10::OFPR_NO_MATCH: {
246  os << indent(4) << "<reason: NO-MATCH >" << std::endl;
247  } break;
248  case rofl::openflow10::OFPR_ACTION: {
249  os << indent(4) << "<reason: ACTION >" << std::endl;
250  } break;
251  default: {
252  os << indent(4) << "<reason:" << (int)msg.get_reason() << " >" << std::endl;
253  };
254  }
255 
256  } break;
257  case openflow12::OFP_VERSION: {
258  os << indent(4) << "<buffer-id:" << (int)msg.get_buffer_id() << " >" << std::endl;
259  os << indent(4) << "<total-len:" << (int)msg.get_total_len() << " >" << std::endl;
260  switch (msg.get_reason()) {
261  case rofl::openflow12::OFPR_NO_MATCH: {
262  os << indent(4) << "<reason: NO-MATCH >" << std::endl;
263  } break;
264  case rofl::openflow12::OFPR_ACTION: {
265  os << indent(4) << "<reason: ACTION >" << std::endl;
266  } break;
267  case rofl::openflow12::OFPR_INVALID_TTL: {
268  os << indent(4) << "<reason: INVALID-TTL >" << std::endl;
269  } break;
270  default: {
271  os << indent(4) << "<reason:" << (int)msg.get_reason() << " >" << std::endl;
272  };
273  }
274  os << indent(4) << "<table-id:" << (int)msg.get_table_id() << " >" << std::endl;
275 
276  } break;
277  case openflow13::OFP_VERSION: {
278  os << indent(4) << "<buffer-id:" << (int)msg.get_buffer_id() << " >" << std::endl;
279  os << indent(4) << "<total-len:" << (int)msg.get_total_len() << " >" << std::endl;
280  switch (msg.get_reason()) {
281  case rofl::openflow13::OFPR_NO_MATCH: {
282  os << indent(4) << "<reason: NO-MATCH >" << std::endl;
283  } break;
284  case rofl::openflow13::OFPR_ACTION: {
285  os << indent(4) << "<reason: ACTION >" << std::endl;
286  } break;
287  case rofl::openflow13::OFPR_INVALID_TTL: {
288  os << indent(4) << "<reason: INVALID-TTL >" << std::endl;
289  } break;
290  default: {
291  os << indent(4) << "<reason:" << (int)msg.get_reason() << " >" << std::endl;
292  };
293  }
294  os << indent(4) << "<table-id: " << (int)msg.get_table_id() << " >" << std::endl;
295  os << indent(4) << "<cookie: 0x" << std::hex << (unsigned long long)msg.get_cookie() << std::dec << " >" << std::endl;
296 
297  } break;
298  default: {
299  os << "<unsupported OF version: " << (int)msg.get_version() << " >" << std::endl;
300  } break;
301  }
302  os << indent(2) << msg.match;
303  os << indent(2) << msg.packet;
304  return os;
305  };
306 };
307 
308 } // end of namespace openflow
309 } // end of namespace rofl
310 
311 #endif /* COFMSG_PACKET_IN_H_ */
uint16_t get_in_port() const
Definition: cofmsg_packet_in.cc:455
virtual void pack(uint8_t *buf=(uint8_t *) 0, size_t buflen=0)
Definition: cofmsg_packet_in.cc:151
virtual void unpack(uint8_t *buf, size_t buflen)
Definition: cofmsg_packet_in.cc:194
Definition: openflow13.h:1678
virtual void validate()
Definition: cofmsg_packet_in.cc:204
Definition: cofmsg_packet_in.h:21
virtual size_t length() const
Definition: cofmsg_packet_in.cc:129
virtual void reset()
Definition: cofmsg_packet_in.cc:111
Definition: cofmatch.h:35
void set_cookie(uint64_t cookie)
Definition: cofmsg_packet_in.cc:499
uint64_t get_cookie() const
Definition: cofmsg_packet_in.cc:484
Definition: openflow10.h:325
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: openflow12.h:591
Definition: cpacket.h:56
void set_in_port(uint16_t port_no)
Definition: cofmsg_packet_in.cc:470
Definition: logging.h:76
cofmsg_packet_in(uint8_t of_version=0, uint32_t xid=0, uint32_t buffer_id=0, uint16_t total_len=0, uint8_t reason=0, uint8_t table_id=0, uint64_t of13_cookie=0, uint16_t of10_in_port=0, cofmatch const &match=cofmatch(), uint8_t *data=(uint8_t *) 0, size_t datalen=0)
Definition: cofmsg_packet_in.cc:5
virtual ~cofmsg_packet_in()
Definition: cofmsg_packet_in.cc:103
Definition: cofmsg.h:62