libfluid
The ONF OpenFlow driver
of13instruction.hh
1 #ifndef OPENFLOW_INSTRUCTION_H
2 #define OPENFLOW_INSTRUCTION_H
3 
4 #include "of13action.hh"
5 #include "openflow-13.h"
6 #include <list>
7 #include <set>
8 
9 namespace fluid_msg {
10 
11 namespace of13 {
12 
13 class Instruction {
14 protected:
15  uint16_t type_;
16  uint16_t length_;
17 public:
18  Instruction();
19  Instruction(uint16_t type, uint16_t length);
20  virtual ~Instruction() {
21  }
22  virtual bool equals(const Instruction & other);
23  virtual bool operator==(const Instruction &other) const;
24  virtual bool operator!=(const Instruction &other) const;
25  virtual uint16_t set_order() const {
26  return 0;
27  }
28  virtual Instruction* clone() {
29  return new Instruction(*this);
30  }
31  virtual size_t pack(uint8_t* buffer);
32  virtual of_error unpack(uint8_t* buffer);
33  uint16_t type() {
34  return this->type_;
35  }
36  uint16_t length() {
37  return this->length_;
38  }
39  void type(uint16_t type) {
40  this->type_ = type;
41  }
42  void length(uint16_t length) {
43  this->length_ = length;
44  }
45  static Instruction* make_instruction(uint16_t type);
46 };
47 
49  bool operator()(Instruction* lhs, Instruction* rhs) const {
50  return lhs->set_order() < rhs->set_order();
51  }
52 };
53 
55 private:
56  uint16_t length_;
57  std::set<Instruction*, comp_inst_set_order> instruction_set_;
58 public:
60  : length_(0) {
61  }
62  InstructionSet(std::set<Instruction*> instruction_set);
63  InstructionSet(const InstructionSet &other);
64  InstructionSet& operator=(InstructionSet other);
65  ~InstructionSet();
66  bool operator==(const InstructionSet &other) const;
67  bool operator!=(const InstructionSet &other) const;
68  size_t pack(uint8_t* buffer);
69  of_error unpack(uint8_t* buffer);
70  friend void swap(InstructionSet& first, InstructionSet& second);
71  uint16_t length() {
72  return this->length_;
73  }
74  void add_instruction(Instruction &inst);
75  void add_instruction(Instruction *inst);
76  void length(uint16_t length) {
77  this->length_ = length;
78  }
79 };
80 
81 class GoToTable: public Instruction {
82 private:
83  uint8_t table_id_;
84  const uint16_t set_order_;
85 public:
86  GoToTable()
87  : Instruction(of13::OFPIT_GOTO_TABLE,
88  sizeof(struct of13::ofp_instruction_goto_table)),
89  set_order_(60) {
90  }
91  GoToTable(uint8_t table_id);
92  ~GoToTable() {
93  }
94  uint16_t set_order() const {
95  return this->set_order_;
96  }
97  virtual bool equals(const Instruction & other);
98  virtual GoToTable* clone() {
99  return new GoToTable(*this);
100  }
101  size_t pack(uint8_t* buffer);
102  of_error unpack(uint8_t* buffer);
103  uint8_t table_id() {
104  return this->table_id_;
105  }
106  void table_id(uint8_t table_id) {
107  this->table_id_ = table_id;
108  }
109 };
110 
111 class WriteMetadata: public Instruction {
112 private:
113  uint64_t metadata_;
114  uint64_t metadata_mask_;
115  const uint16_t set_order_;
116 public:
117  WriteMetadata()
118  : Instruction(of13::OFPIT_WRITE_METADATA,
119  sizeof(struct of13::ofp_instruction_write_metadata)),
120  set_order_(50) {
121  }
122  WriteMetadata(uint64_t metadata, uint64_t metadata_mask);
123  ~WriteMetadata() {
124  }
125  uint16_t set_order() const {
126  return this->set_order_;
127  }
128  virtual bool equals(const Instruction & other);
129  virtual WriteMetadata* clone() {
130  return new WriteMetadata(*this);
131  }
132  size_t pack(uint8_t* buffer);
133  of_error unpack(uint8_t* buffer);
134  uint64_t metadata() {
135  return this->metadata_;
136  }
137  uint64_t metadata_mask() {
138  return this->metadata_mask_;
139  }
140  void metadata(uint64_t metadata) {
141  this->metadata_ = metadata;
142  }
143  void metadata_mask(uint64_t metadata_mask) {
144  this->metadata_mask_ = metadata_mask;
145  }
146 };
147 
148 class WriteActions: public Instruction {
149 private:
150  ActionSet actions_;
151  const uint16_t set_order_;
152 public:
153  WriteActions()
154  : Instruction(of13::OFPIT_WRITE_ACTIONS,
155  sizeof(struct of13::ofp_instruction_actions)),
156  set_order_(40) {
157  }
158  WriteActions(ActionSet actions);
159  ~WriteActions() {
160  }
161  uint16_t set_order() const {
162  return this->set_order_;
163  }
164  virtual bool equals(const Instruction & other);
165  size_t pack(uint8_t* buffer);
166  virtual WriteActions* clone() {
167  return new WriteActions(*this);
168  }
169  of_error unpack(uint8_t* buffer);
170  ActionSet actions() {
171  return this->actions_;
172  }
173  void actions(ActionSet actions);
174  void add_action(Action &action);
175  void add_action(Action* action);
176 };
177 
178 class ApplyActions: public Instruction {
179 private:
180  ActionList actions_;
181  const uint16_t set_order_;
182 public:
183  ApplyActions()
184  : Instruction(of13::OFPIT_APPLY_ACTIONS,
185  sizeof(struct of13::ofp_instruction_actions)),
186  set_order_(20) {
187  }
188  ApplyActions(ActionList actions);
189  ~ApplyActions() {
190  }
191  uint16_t set_order() const {
192  return this->set_order_;
193  }
194  virtual bool equals(const Instruction & other);
195  virtual ApplyActions* clone() {
196  return new ApplyActions(*this);
197  }
198  size_t pack(uint8_t* buffer);
199  of_error unpack(uint8_t* buffer);
200  ActionList actions() {
201  return this->actions_;
202  }
203  void actions(ActionList actions);
204  void add_action(Action &action);
205  void add_action(Action* action);
206 };
207 
208 class ClearActions: public Instruction {
209 private:
210  const uint16_t set_order_;
211 public:
212  ClearActions()
213  : Instruction(of13::OFPIT_CLEAR_ACTIONS,
214  sizeof(struct of13::ofp_instruction) + 4),
215  set_order_(30) {
216  }
217  ~ClearActions() {
218  }
219  uint16_t set_order() const {
220  return this->set_order_;
221  }
222  virtual ClearActions* clone() {
223  return new ClearActions(*this);
224  }
225  size_t pack(uint8_t* buffer);
226  of_error unpack(uint8_t* buffer);
227 };
228 
229 class Meter: public Instruction {
230 private:
231  uint32_t meter_id_;
232  const uint16_t set_order_;
233 public:
234  Meter()
235  : Instruction(of13::OFPIT_METER,
236  sizeof(struct of13::ofp_instruction_meter)),
237  set_order_(10) {
238  }
239  Meter(uint32_t meter_id);
240  ~Meter() {
241  }
242  uint16_t set_order() const {
243  return this->set_order_;
244  }
245  virtual bool equals(const Instruction & other);
246  virtual Meter* clone() {
247  return new Meter(*this);
248  }
249  size_t pack(uint8_t* buffer);
250  of_error unpack(uint8_t* buffer);
251  uint32_t meter_id() {
252  return this->meter_id_;
253  }
254  void meter_id(uint32_t meter_id) {
255  this->meter_id_ = meter_id;
256  }
257 };
258 
260 protected:
261  uint32_t experimenter_;
262 public:
264  }
265  InstructionExperimenter(uint32_t experimenter);
267  }
268  virtual bool equals(const Instruction & other);
269  virtual InstructionExperimenter* clone() {
270  return new InstructionExperimenter(*this);
271  }
272  size_t pack(uint8_t* buffer);
273  of_error unpack(uint8_t* buffer);
274  uint32_t experimenter() {
275  return this->experimenter_;
276  }
277  void experimenter(uint32_t experimenter) {
278  this->experimenter_ = experimenter;
279  }
280 };
281 
282 }
283 
284 } //End of namespace fluid_msg
285 #endif