Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofflowmod.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 COFFLOWMOD_H
6 #define COFFLOWMOD_H 1
7 
8 #include <string>
9 #include <vector>
10 #include <algorithm>
11 #include <endian.h>
12 #include <strings.h>
13 
14 #include "rofl/common/croflexception.h"
15 #include "rofl/common/cmemory.h"
16 #include "rofl/common/caddress.h"
17 #include "rofl/common/openflow/cofmatch.h"
18 #include "rofl/common/openflow/cofaction.h"
19 #include "rofl/common/openflow/cofinstruction.h"
20 #include "rofl/common/openflow/cofinstructions.h"
21 #include "rofl/common/openflow/coxmatch.h"
22 
23 namespace rofl {
24 namespace openflow {
25 
26 class eFlowModBase : public RoflException {}; // error base class cflowentry
27 class eFlowModInvalid : public eFlowModBase {}; // invalid parameter
28 class eFlowModOutOfMem : public eFlowModBase {}; // out of memory
29 
30 
31 class cofflowmod {
32 public:
33 
37  cofflowmod(
38  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN);
39 
43  virtual
44  ~cofflowmod();
45 
49  cofflowmod(
50  const cofflowmod& fe);
51 
55  cofflowmod&
56  operator= (
57  const cofflowmod& fe);
58 
62  void
63  clear();
64 
68  void
69  check_prerequisites() const;
70 
71 public: // setter methods for ofp_flow_mod structure
72 
76  void
77  set_version(uint8_t ofp_version) {
78  this->ofp_version = ofp_version;
79  match.set_version(ofp_version);
80  actions.set_version(ofp_version);
81  instructions.set_version(ofp_version);
82  };
83 
87  uint8_t
88  get_version() const { return ofp_version; };
89 
94  set_match() { return match; };
95 
100  get_match() const { return match; };
101 
106  set_actions() { return actions; };
107 
112  get_actions() const { return actions; };
113 
118  set_instructions() { return instructions; };
119 
124  get_instructions() const { return instructions; };
125 
129  void
130  set_command(uint8_t command) { this->command = command; };
131 
135  uint8_t
136  get_command() const { return command; };
137 
141  void
142  set_table_id(uint8_t table_id) { this->table_id = table_id; }
143 
146  uint8_t
147  get_table_id() const { return table_id; };
148 
152  void
153  set_idle_timeout(uint16_t idle_timeout) { this->idle_timeout = idle_timeout; };
154 
158  uint16_t
159  get_idle_timeout() const { return idle_timeout; };
160 
164  void
165  set_hard_timeout(uint16_t hard_timeout) { this->hard_timeout = hard_timeout; };
166 
169  uint16_t
170  get_hard_timeout() const { return hard_timeout; };
171 
175  void
176  set_cookie(uint64_t cookie) { this->cookie = cookie; };
177 
181  uint64_t
182  get_cookie() const { return cookie; };
183 
187  void
188  set_cookie_mask(uint64_t cookie_mask) { this->cookie_mask = cookie_mask; };
189 
193  uint64_t
194  get_cookie_mask() const { return cookie_mask; };
195 
199  void
200  set_priority(uint16_t priority) { this->priority = priority; };
201 
205  uint16_t
206  get_priority() const { return priority; };
207 
211  void
212  set_buffer_id(uint32_t buffer_id) { this->buffer_id = buffer_id; };
213 
217  uint32_t
218  get_buffer_id() const { return buffer_id; };
219 
223  void
224  set_out_port(uint32_t out_port) { this->out_port = out_port; };
225 
229  uint32_t
230  get_out_port() const { return out_port; };
231 
235  void
236  set_out_group(uint32_t out_group) { this->out_group = out_group; };
237 
241  uint32_t
242  get_out_group() const { return out_group; };
243 
247  void
248  set_flags(uint16_t flags) { this->flags = flags; };
249 
253  uint16_t
254  get_flags() const { return flags; };
255 
256 public:
257 
261  virtual size_t
262  length() const;
263 
267  virtual void
268  pack(
269  uint8_t *buf, size_t buflen);
270 
274  virtual void
275  unpack(
276  uint8_t *buf, size_t buflen);
277 
278 
279 public:
280 
281  friend std::ostream&
282  operator<< (std::ostream& os, cofflowmod const& fe) {
283  os << rofl::indent(0) << "<cofflowmod ofp-version:" << (int)fe.get_version() << " >" << std::endl;
284 
285  switch (fe.get_command()) {
286  case rofl::openflow::OFPFC_ADD:
287  os << rofl::indent(2) << "<command: ADD >" << std::endl; break;
288  case rofl::openflow::OFPFC_DELETE:
289  os << rofl::indent(2) << "<command: DELETE >" << std::endl; break;
290  case rofl::openflow::OFPFC_DELETE_STRICT:
291  os << rofl::indent(2) << "<command: DELETE-STRICT >"<< std::endl; break;
292  case rofl::openflow::OFPFC_MODIFY:
293  os << rofl::indent(2) << "<command: MODIFY >" << std::endl; break;
294  case rofl::openflow::OFPFC_MODIFY_STRICT:
295  os << rofl::indent(2) << "<command: MODIFY-STRICT >"<< std::endl; break;
296  default:
297  os << rofl::indent(2) << "<command: UNKNOWN >" << std::endl; break;
298  }
299 
300  os << std::hex;
301  os << rofl::indent(2) << "<cookie: 0x" << (unsigned long long)fe.get_cookie() << " >" << std::endl;
302  os << rofl::indent(2) << "<cookie-mask: 0x" << (unsigned long long)fe.get_cookie_mask() << " >" << std::endl;
303  os << std::dec;
304  os << rofl::indent(2) << "<table-id: " << (unsigned int)fe.get_table_id() << " >" << std::endl;
305  os << rofl::indent(2) << "<idle-timeout: " << (unsigned int)fe.get_idle_timeout() << " >" << std::endl;
306  os << rofl::indent(2) << "<hard-timeout: " << (unsigned int)fe.get_hard_timeout() << " >" << std::endl;
307 
308  os << std::hex;
309  os << rofl::indent(2) << "<priority: 0x" << (unsigned int)fe.get_priority() << " >" << std::endl;
310  os << rofl::indent(2) << "<buffer-id: 0x" << (unsigned int)fe.get_buffer_id() << " >" << std::endl;
311  os << rofl::indent(2) << "<out-port: 0x" << (unsigned int)fe.get_out_port() << " >" << std::endl;
312  os << rofl::indent(2) << "<out-group: 0x" << (unsigned int)fe.get_out_group() << " >" << std::endl;
313  os << rofl::indent(2) << "<flags: 0x" << (unsigned int)fe.get_flags() << " >" << std::endl;
314  os << std::dec;
315 
316  rofl::indent i(2);
317  os << fe.get_match();
318 
319  switch (fe.get_version()) {
320  case rofl::openflow10::OFP_VERSION: {
321  os << fe.get_actions();
322  } break;
323  case rofl::openflow12::OFP_VERSION:
324  case rofl::openflow13::OFP_VERSION: {
325  os << fe.get_instructions();
326  } break;
327  }
328 
329  return os;
330  };
331 
332 private: // data structures
333 
334  uint8_t ofp_version;
335 
336  cofmatch match;
337  cofactions actions; // for OFP 1.0 only
338  cofinstructions instructions;
339 
340  uint8_t command;
341  uint8_t table_id;
342  uint16_t idle_timeout;
343  uint16_t hard_timeout;
344  uint64_t cookie;
345  uint64_t cookie_mask;
346  uint16_t priority;
347  uint32_t buffer_id;
348  uint32_t out_port;
349  uint32_t out_group;
350  uint16_t flags;
351 
352  struct ofp10_flow_mod {
353  struct rofl::openflow10::ofp_match match;
354  uint64_t cookie;
355  uint16_t command;
356  uint16_t idle_timeout;
357  uint16_t hard_timeout;
358  uint16_t priority;
359  uint32_t buffer_id;
360  uint16_t out_port;
361  uint16_t flags;
362  uint8_t actions[0];
363  } __attribute__((packed));
364 
365  struct ofp13_flow_mod {
366  uint64_t cookie;
367  uint64_t cookie_mask;
368  uint8_t table_id;
369  uint8_t command;
370  uint16_t idle_timeout;
371  uint16_t hard_timeout;
372  uint16_t priority;
373  uint32_t buffer_id;
374  uint32_t out_port;
375  uint32_t out_group;
376  uint16_t flags;
377  uint8_t pad[2];
378  uint8_t match[0];
379  //uint8_t instructions[0];
380  } __attribute__((packed));
381 };
382 
383 }; // end of namespace openflow
384 }; // end of namespace rofl
385 
386 #endif
Definition: cofflowmod.h:26
Definition: cofactions.h:22
Definition: cofinstructions.h:24
Definition: cofmatch.h:35
Definition: openflow10.h:551
Definition: cofflowmod.h:27
Definition: cofflowmod.h:31
Definition: logging.h:76
Definition: cofflowmod.h:28
Definition: croflexception.h:27