Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofinstruction.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 COFINST_H
6 #define COFINST_H 1
7 
8 #include <set>
9 #include <vector>
10 #include <algorithm>
11 #include <endian.h>
12 #include <pthread.h>
13 #ifndef htobe16
14  #include "../endian_conversion.h"
15 #endif
16 
17 #include "rofl/common/openflow/openflow.h"
18 #include "rofl/common/cmemory.h"
19 #include "rofl/common/croflexception.h"
20 #include "rofl/common/thread_helper.h"
21 #include "rofl/common/openflow/cofactions.h"
22 
23 
24 namespace rofl {
25 namespace openflow {
26 
27 /* error classes */
28 class eInstructionBase : public RoflException {}; // error base class for class cofinstruction
29 class eInstructionInval : public eInstructionBase {}; // invalid parameter
30 class eInstructionNotFound : public eInstructionBase {}; // not found
31 class eInstructionBadLen : public eInstructionBase {}; // bad length
32 class eInstructionInvalType : public eInstructionBase {}; // invalid instruction type
33 class eInstructionHeaderInval : public eInstructionBase {}; // invalid instruction header
34 class eInstructionActionNotFound : public eInstructionBase {}; // action not found in instruction
35 class eInstructionBadExperimenter : public eInstructionBase {}; // unknown experimenter instruction
36 
37 
39 public:
40 
45  uint8_t ofp_version = openflow::OFP_VERSION_UNKNOWN,
46  uint16_t type = 0,
47  const rofl::cmemory& body = rofl::cmemory((size_t)0));
48 
53  cofinstruction const& inst);
54 
58  virtual
59  ~cofinstruction();
60 
65  operator= (
66  const cofinstruction& inst);
67 
71  bool
72  operator== (
73  const cofinstruction& inst);
74 
75 
76 public:
77 
81  virtual size_t
82  length() const;
83 
84 
88  virtual void
89  pack(
90  uint8_t* buf, size_t buflen);
91 
95  virtual void
96  unpack(
97  uint8_t* buf, size_t buflen);
98 
102  virtual void
103  check_prerequisites() const {};
104 
105 public:
106 
110  void
111  set_version(uint8_t ofp_version) { this->ofp_version = ofp_version; };
112 
116  uint8_t
117  get_version() const { return ofp_version; };
118 
122  void
123  set_type(uint16_t type) { this->type = type; };
124 
128  uint16_t
129  get_type() const { return type; };
130 
131 
135  void
136  set_length(uint16_t len) { this->len = len; };
137 
141  uint16_t
142  get_length() const { return len; };
143 
148  set_body() { return body; };
149 
153  const rofl::cmemory&
154  get_body() const { return body; };
155 
156 public:
157 
158  friend std::ostream&
159  operator<< (std::ostream& os, cofinstruction const& inst) {
160  os << rofl::indent(0) << "<cofinstruction ";
161  os << "type: 0x" << std::hex << (int)inst.get_type() << std::dec << " ";
162  os << "length: " << (int)inst.length() << " ";
163  os << ">" << std::endl;
164  if (not inst.get_body().empty()) {
165  rofl::indent i(2); os << inst.get_body();
166  }
167  return os;
168  };
169 
171  public:
172  cofinst_find_type(uint16_t type) :
173  type(type) { };
174 
175  bool operator() (cofinstruction const& inst) {
176  return (inst.get_type() == type);
177  };
178 
179  bool operator() (std::pair<uint16_t, cofinstruction*> const& p) {
180  return (p.second->get_type() == type);
181  };
182 
183  uint16_t type;
184  };
185 
186 
187 private:
188 
189  uint8_t ofp_version;
190  uint16_t type;
191  mutable uint16_t len;
192  rofl::cmemory body;
193 
194 };
195 
196 
197 
199 public:
200 
205  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
206  uint16_t type = 0,
208  cofinstruction(ofp_version, type),
209  actions(actions) {
210  this->actions.set_version(ofp_version);
211  };
212 
216  virtual
218 
223  const cofinstruction_actions& inst) {
224  *this = inst;
225  };
226 
231  operator= (
232  const cofinstruction_actions& inst) {
233  if (this == &inst)
234  return *this;
235 
236  cofinstruction::operator= (inst);
237  actions = inst.actions;
238 
239  return *this;
240  };
241 
242 public:
243 
248  set_actions() { return actions; };
249 
254  get_actions() const { return actions; };
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 
281  virtual void
282  check_prerequisites() const {
283  actions.check_prerequisites();
284  };
285 
286 public:
287  friend std::ostream&
288  operator<< (std::ostream& os, cofinstruction_actions const& inst) {
289  os << rofl::indent(0) << "<cofinstruction_actions >" << std::endl;
290  { rofl::indent i(2); os << dynamic_cast<cofinstruction const&>( inst ); }
291  { rofl::indent i(4); os << inst.actions; }
292  return os;
293  };
294 
295 private:
296 
298 };
299 
300 
301 
303 public:
304 
309  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
311  cofinstruction_actions(ofp_version, rofl::openflow13::OFPIT_APPLY_ACTIONS, actions) {};
312 
316  virtual
318 
323  const cofinstruction_apply_actions& inst) {
324  *this = inst;
325  };
326 
331  operator= (
332  const cofinstruction_apply_actions& inst) {
333  if (this == &inst)
334  return *this;
335  cofinstruction_actions::operator= (inst);
336  return *this;
337  }
338 
339 public:
340 
341  friend std::ostream&
342  operator<< (std::ostream& os, const cofinstruction_apply_actions& inst) {
343  os << rofl::indent(0) << "<cofinstruction_apply_actions >" << std::endl;
344  { rofl::indent i(2); os << dynamic_cast<const cofinstruction_actions&>( inst ); }
345  return os;
346  };
347 };
348 
349 
350 
352 public:
353 
358  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
360  cofinstruction_actions(ofp_version, rofl::openflow13::OFPIT_WRITE_ACTIONS, actions) {};
361 
365  virtual
367 
372  const cofinstruction_write_actions& inst) {
373  *this = inst;
374  };
375 
380  operator= (
381  const cofinstruction_write_actions& inst) {
382  if (this == &inst)
383  return *this;
384  cofinstruction_actions::operator= (inst);
385  return *this;
386  }
387 
388 public:
389 
390  friend std::ostream&
391  operator<< (std::ostream& os, const cofinstruction_write_actions& inst) {
392  os << rofl::indent(0) << "<cofinstruction_write_actions >" << std::endl;
393  { rofl::indent i(2); os << dynamic_cast<const cofinstruction_actions&>( inst ); }
394  return os;
395  };
396 };
397 
398 
399 
401 public:
402 
407  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
409  cofinstruction_actions(ofp_version, rofl::openflow13::OFPIT_CLEAR_ACTIONS, actions) {};
410 
414  virtual
416 
421  const cofinstruction_clear_actions& inst) {
422  *this = inst;
423  };
424 
429  operator= (
430  const cofinstruction_clear_actions& inst) {
431  if (this == &inst)
432  return *this;
433  cofinstruction_actions::operator= (inst);
434  return *this;
435  }
436 
437 public:
438 
439  friend std::ostream&
440  operator<< (std::ostream& os, const cofinstruction_clear_actions& inst) {
441  os << rofl::indent(0) << "<cofinstruction_clear_actions >" << std::endl;
442  { rofl::indent i(2); os << dynamic_cast<const cofinstruction_actions&>( inst ); }
443  return os;
444  };
445 };
446 
447 
448 
450 public:
451 
456  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
457  uint8_t table_id = 0) :
458  cofinstruction(ofp_version, rofl::openflow13::OFPIT_GOTO_TABLE),
459  table_id(table_id) {};
460 
464  virtual
466 
471  const cofinstruction_goto_table& inst) {
472  *this = inst;
473  };
474 
479  operator= (
480  const cofinstruction_goto_table& inst) {
481  if (this == &inst)
482  return *this;
483 
484  cofinstruction::operator= (inst);
485  table_id = inst.table_id;
486 
487  return *this;
488  };
489 
490 public:
491 
495  uint8_t
496  get_table_id() const { return table_id; };
497 
501  void
502  set_table_id(uint8_t table_id) { this->table_id = table_id; };
503 
504 public:
505 
509  virtual size_t
510  length() const;
511 
515  virtual void
516  pack(
517  uint8_t* buf, size_t buflen);
518 
522  virtual void
523  unpack(
524  uint8_t* buf, size_t buflen);
525 
529  virtual void
530  check_prerequisites() const;
531 
532 public:
533  friend std::ostream&
534  operator<< (std::ostream& os, cofinstruction_goto_table const& inst) {
535  os << rofl::indent(0) << "<cofinstruction_goto_table >" << std::endl;
536  { rofl::indent i(2); os << dynamic_cast<const cofinstruction&>( inst ); }
537  os << rofl::indent(4) << "<table-id:" << (int)inst.get_table_id() << " >" << std::endl;
538  return os;
539  };
540 
541 public:
542 
543  uint8_t table_id;
544 };
545 
546 
547 
549 public:
554  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
555  uint64_t metadata = 0,
556  uint64_t metadata_mask = 0) :
557  cofinstruction(ofp_version, rofl::openflow13::OFPIT_WRITE_METADATA),
558  metadata(metadata),
559  metadata_mask(metadata_mask) {};
560 
564  virtual
566 
571  const cofinstruction_write_metadata& inst) {
572  *this = inst;
573  };
574 
579  operator= (
580  const cofinstruction_write_metadata& inst) {
581  if (this == &inst)
582  return *this;
583 
584  cofinstruction::operator= (inst);
585  metadata = inst.metadata;
586  metadata_mask = inst.metadata_mask;
587 
588  return *this;
589  };
590 
591 public:
592 
596  uint64_t
597  get_metadata() const { return metadata; };
598 
602  void
603  set_metadata(uint64_t metadata) { this->metadata = metadata; };
604 
608  uint64_t
609  get_metadata_mask() const { return metadata_mask; };
610 
614  void
615  set_metadata_mask(uint64_t metadata_mask) { this->metadata_mask = metadata_mask; };
616 
617 public:
618 
622  virtual size_t
623  length() const;
624 
628  virtual void
629  pack(
630  uint8_t* buf, size_t buflen);
631 
635  virtual void
636  unpack(
637  uint8_t* buf, size_t buflen);
638 
639 public:
640 
641  friend std::ostream&
642  operator<< (std::ostream& os, cofinstruction_write_metadata const& inst) {
643  os << rofl::indent(0) << "<cofinstruction_write_metadata >" << std::endl;
644  { rofl::indent i(2); os << dynamic_cast<const cofinstruction&>( inst ); }
645  os << std::hex;
646  os << indent(4) << "<metadata: 0x" << (unsigned long long)inst.get_metadata() << " >" << std::endl;
647  os << indent(4) << "<metadata-mask: 0x" << (unsigned long long)inst.get_metadata_mask() << " >" << std::endl;
648  os << std::dec;
649  return os;
650  };
651 
652 private:
653 
654  uint64_t metadata;
655  uint64_t metadata_mask;
656 };
657 
658 
659 
660 
661 
662 
664 public:
665 
670  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
671  uint32_t exp_id = 0,
672  const rofl::cmemory& exp_body = rofl::cmemory((size_t)0)) :
673  cofinstruction(ofp_version, rofl::openflow13::OFPIT_EXPERIMENTER),
674  exp_id(exp_id),
675  exp_body(exp_body) {};
676 
680  virtual
682 
687  const cofinstruction_experimenter& inst) {
688  *this = inst;
689  };
690 
695  operator= (
696  const cofinstruction_experimenter& inst) {
697  if (this == &inst)
698  return *this;
699 
700  cofinstruction::operator= (inst);
701  exp_id = inst.exp_id;
702  exp_body = inst.exp_body;
703 
704  return *this;
705  };
706 
707 public:
708 
712  uint32_t
713  get_exp_id() const { return exp_id; };
714 
718  void
719  set_exp_id(uint32_t exp_id) { this->exp_id = exp_id; };
720 
724  const rofl::cmemory&
725  get_exp_body() const { return exp_body; };
726 
731  set_exp_body() { return exp_body; };
732 
733 
737  const rofl::cmemory&
738  get_body() const { return exp_body; };
739 
744  set_body() { return exp_body; };
745 
746 public:
747 
751  virtual size_t
752  length() const;
753 
757  virtual void
758  pack(
759  uint8_t* buf, size_t buflen);
760 
764  virtual void
765  unpack(
766  uint8_t* buf, size_t buflen);
767 
768 public:
769 
770  friend std::ostream&
771  operator<< (std::ostream& os, cofinstruction_experimenter const& inst) {
772  os << rofl::indent(0) << "<cofinstruction_experimenter >" << std::endl;
773  { rofl::indent i(2); os << dynamic_cast<const cofinstruction&>( inst ); }
774  os << rofl::indent(4) << "<exp-id: 0x" << std::hex << inst.get_exp_id() << std::dec << " >" << std::endl;
775  { rofl::indent i(4); os << inst.get_exp_body(); }
776  return os;
777  };
778 
779 private:
780 
781  uint32_t exp_id;
782  rofl::cmemory exp_body;
783 };
784 
785 
786 
787 
789 {
790 public:
791 
796  uint8_t ofp_version = rofl::openflow::OFP_VERSION_UNKNOWN,
797  uint32_t meter_id = 0) :
798  cofinstruction(ofp_version, rofl::openflow13::OFPIT_METER),
799  meter_id(meter_id) {};
800 
804  virtual
805  ~cofinstruction_meter() {};
806 
811  const cofinstruction_meter& inst) {
812  *this = inst;
813  };
814 
819  operator= (
820  const cofinstruction_meter& inst) {
821  if (this == &inst)
822  return *this;
823 
824  cofinstruction::operator= (inst);
825  meter_id = inst.meter_id;
826 
827  return *this;
828  };
829 
830 public:
831 
835  void
836  set_meter_id(uint32_t meter_id) { this->meter_id = meter_id; };
837 
841  uint32_t
842  get_meter_id() const { return meter_id; };
843 
844 public:
845 
849  virtual size_t
850  length() const;
851 
855  virtual void
856  pack(
857  uint8_t* buf, size_t buflen);
858 
862  virtual void
863  unpack(
864  uint8_t* buf, size_t buflen);
865 
866 public:
867 
868  friend std::ostream&
869  operator<< (std::ostream& os, cofinstruction_meter const& inst) {
870  os << "<cofinstruction_meter >" << std::endl;
871  { rofl::indent i(2); os << dynamic_cast<cofinstruction const&>( inst ); }
872  os << rofl::indent(4) << "<meter-id: 0x" << std::hex << inst.get_meter_id() << " >" << std::endl;
873  return os;
874  };
875 
876 private:
877 
878  uint32_t meter_id;
879 };
880 
881 }; // end of namespace openflow
882 }; // end of namespace rofl
883 
884 #endif
885 
886 
887 
rofl::cmemory & set_body()
Shadows cofinst::set_body() intentionally.
Definition: cofinstruction.h:744
Definition: cofinstruction.h:35
const rofl::cmemory & get_body() const
Shadows cofinst::get_body() intentionally.
Definition: cofinstruction.h:738
Definition: cofinstruction.h:788
Definition: cofinstruction.h:449
Definition: cofactions.h:22
Definition: cofinstruction.h:302
Definition: cofinstruction.h:33
Definition: cofinstruction.h:32
Definition: cofinstruction.h:31
Definition: cofinstruction.h:34
Definition: cofinstruction.h:38
Definition: cofinstruction.h:663
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: cofinstruction.h:198
Definition: logging.h:76
Definition: cofinstruction.h:30
Definition: cofinstruction.h:28
Definition: cofinstruction.h:29
Definition: cofinstruction.h:400
Definition: cofinstruction.h:351
virtual bool empty() const
Returns boolean value empty/non empty.
Definition: cmemory.h:372
Definition: cofinstruction.h:548
Definition: croflexception.h:27