libfluid
The ONF OpenFlow driver
action.hh
1 #ifndef ACTION_H
2 #define ACTION_H
3 
4 #include <list>
5 #include <set>
6 #include "fluid/util/util.h"
7 #include "openflow-common.hh"
8 
9 namespace fluid_msg {
10 
11 class Action {
12 protected:
13  uint16_t type_;
14  uint16_t length_;
15 public:
16  Action();
17  Action(uint16_t type, uint16_t length);
18  virtual ~Action() {
19  }
20  ;
21  virtual size_t pack(uint8_t *buffer);
22  virtual of_error unpack(uint8_t *buffer);
23  virtual bool equals(const Action & other);
24  virtual bool operator==(const Action &other) const;
25  virtual bool operator!=(const Action &other) const;
26  virtual Action* clone() {
27  return new Action(*this);
28  }
29  virtual uint16_t set_order() const {
30  return 0;
31  }
32  uint16_t type() {
33  return this->type_;
34  }
35  uint16_t length() {
36  return this->length_;
37  }
38  void type(uint16_t type) {
39  this->type_ = type;
40  }
41  void length(uint16_t length) {
42  this->length_ = length;
43  }
44  static Action * make_of10_action(uint16_t type);
45  static Action * make_of13_action(uint16_t type);
46  static bool delete_all(Action * action) {
47  delete action;
48  return true;
49  }
50 
51 };
52 
53 class ActionList {
54 private:
55  uint16_t length_;
56  std::list<Action*> action_list_;
57 public:
58  ActionList()
59  : length_(0) {
60  }
61  ;
62  ActionList(std::list<Action*> action_list);
63  ActionList(const ActionList &other);
64  bool operator==(const ActionList &other) const;
65  bool operator!=(const ActionList &other) const;
66  ActionList& operator=(ActionList other);
67  ~ActionList();
68  size_t pack(uint8_t *buffer);
69  of_error unpack10(uint8_t *buffer);
70  of_error unpack13(uint8_t *buffer);
71  std::list<Action*> action_list() {
72  return this->action_list_;
73  }
74  friend void swap(ActionList& first, ActionList& second);
75  uint16_t length() {
76  return this->length_;
77  }
78  void add_action(Action &action);
79  void add_action(Action *act);
80  void length(uint16_t length) {
81  this->length_ = length;
82  }
83 };
84 
86  bool operator()(Action * lhs, Action* rhs) const {
87  return lhs->set_order() < rhs->set_order();
88  }
89 };
90 
91 class ActionSet {
92 private:
93  uint16_t length_;
94  std::set<Action*, comp_action_set_order> action_set_;
95 public:
96  ActionSet()
97  : length_(0) {
98  }
99  ;
100  ActionSet(std::set<Action*> action_set);
101  ActionSet(const ActionSet &other);
102  bool operator==(const ActionSet &other) const;
103  bool operator!=(const ActionSet &other) const;
104  ActionSet& operator=(ActionSet other);
105  ~ActionSet();
106  size_t pack(uint8_t *buffer);
107  of_error unpack(uint8_t *buffer);
108  friend void swap(ActionSet& first, ActionSet& second);
109  uint16_t length() {
110  return this->length_;
111  }
112  void add_action(Action &action);
113  void add_action(Action *act);
114  void length(uint16_t length) {
115  this->length_ = length;
116  }
117 };
118 
119 } //End of namespace fluid_msg
120 #endif