Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofinstructions.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 COFINSTRUCTIONS_H
6 #define COFINSTRUCTIONS_H 1
7 
8 #include <assert.h>
9 #include <map>
10 #include <algorithm>
11 #include "rofl/common/croflexception.h"
12 #include "rofl/common/openflow/cofinstruction.h"
13 
14 namespace rofl {
15 namespace openflow {
16 
17 class eInstructionsBase : public RoflException {};
21 
22 
23 
25 {
26 public:
27 
32  uint8_t ofp_version = openflow::OFP_VERSION_UNKNOWN);
33 
37  virtual
38  ~cofinstructions();
39 
44  cofinstructions const& instructions);
45 
50  operator= (
51  cofinstructions const& instructions);
52 
56  bool
57  operator== (
58  cofinstructions const& instructions);
59 
60 
61 public:
62 
66  void
67  set_version(uint8_t ofp_version) {
68  this->ofp_version = ofp_version;
69  for (std::map<uint16_t, cofinstruction*>::iterator
70  it = instmap.begin(); it != instmap.end(); ++it) {
71  it->second->set_version(ofp_version);
72  }
73  };
74 
78  uint8_t
79  get_version() const { return ofp_version; };
80 
84  std::map<uint16_t, cofinstruction*>&
85  set_instructions() { return instmap; };
86 
90  const std::map<uint16_t, cofinstruction*>&
91  get_instructions() const { return instmap; };
92 
93 public:
94 
98  size_t
99  length() const;
100 
104  void
105  pack(
106  uint8_t* buf, size_t buflen);
107 
111  void
112  unpack(
113  uint8_t *buf, size_t buflen);
114 
118  void
119  check_prerequisites() const;
120 
121 public:
122 
123  /*
124  * Generic
125  */
127  add_inst(uint16_t type);
128 
130  set_inst(uint16_t type);
131 
132  const cofinstruction&
133  get_inst(uint16_t type) const;
134 
135  void
136  drop_inst(uint16_t type);
137 
138  bool
139  has_inst(uint16_t type) const;
140 
141 
142  /*
143  * Goto-Table
144  */
146  add_inst_goto_table();
147 
149  set_inst_goto_table();
150 
152  get_inst_goto_table() const;
153 
154  void
155  drop_inst_goto_table();
156 
157  bool
158  has_inst_goto_table() const;
159 
160 
161  /*
162  * Write-Metadata
163  */
165  add_inst_write_metadata();
166 
168  set_inst_write_metadata();
169 
171  get_inst_write_metadata() const;
172 
173  void
174  drop_inst_write_metadata();
175 
176  bool
177  has_inst_write_metadata() const;
178 
179 
180  /*
181  * Write-Actions
182  */
184  add_inst_write_actions();
185 
187  set_inst_write_actions();
188 
190  get_inst_write_actions() const;
191 
192  void
193  drop_inst_write_actions();
194 
195  bool
196  has_inst_write_actions() const;
197 
198 
199  /*
200  * Apply-Actions
201  */
203  add_inst_apply_actions();
204 
206  set_inst_apply_actions();
207 
209  get_inst_apply_actions() const;
210 
211  void
212  drop_inst_apply_actions();
213 
214  bool
215  has_inst_apply_actions() const;
216 
217 
218  /*
219  * Clear-Actions
220  */
222  add_inst_clear_actions();
223 
225  set_inst_clear_actions();
226 
228  get_inst_clear_actions() const;
229 
230  void
231  drop_inst_clear_actions();
232 
233  bool
234  has_inst_clear_actions() const;
235 
236 
237  /*
238  * Meter
239  */
241  add_inst_meter();
242 
244  set_inst_meter();
245 
246  const cofinstruction_meter&
247  get_inst_meter() const;
248 
249  void
250  drop_inst_meter();
251 
252  bool
253  has_inst_meter() const;
254 
255 
256  /*
257  * Experimenter
258  */
260  add_inst_experimenter();
261 
263  set_inst_experimenter();
264 
266  get_inst_experimenter() const;
267 
268  void
269  drop_inst_experimenter();
270 
271  bool
272  has_inst_experimenter() const;
273 
274 
278  void
279  clear();
280 
281 
282 
283 public:
284 
285  friend std::ostream&
286  operator<< (std::ostream& os, cofinstructions const& inlist) {
287  os << indent(0) << "<cofintructions ofp-version:" << (int)inlist.ofp_version << " >" << std::endl;
288  for (std::map<uint16_t, cofinstruction*>::const_iterator
289  it = inlist.instmap.begin(); it != inlist.instmap.end(); ++it) {
290  indent i(2);
291  switch (it->second->get_type()) {
292  case openflow::OFPIT_GOTO_TABLE:
293  os << inlist.get_inst_goto_table(); break;
294  case openflow::OFPIT_WRITE_METADATA:
295  os << inlist.get_inst_write_metadata(); break;
296  case openflow::OFPIT_WRITE_ACTIONS:
297  os << inlist.get_inst_write_actions(); break;
298  case openflow::OFPIT_APPLY_ACTIONS:
299  os << inlist.get_inst_apply_actions(); break;
300  case openflow::OFPIT_CLEAR_ACTIONS:
301  os << inlist.get_inst_clear_actions(); break;
302  case openflow::OFPIT_METER:
303  os << inlist.get_inst_meter(); break;
304  case openflow::OFPIT_EXPERIMENTER:
305  os << inlist.get_inst_experimenter(); break;
306  default:
307  os << *(it->second); break;
308  }
309  }
310  return os;
311  };
312 
313 private:
314 
315  uint8_t ofp_version;
316  std::map<uint16_t, cofinstruction*> instmap;
317 
318 };
319 
320 }; // end of namespace openflow
321 }; // end of namespace rofl
322 
323 #endif
Definition: cofinstructions.h:20
Definition: cofinstruction.h:788
Definition: cofinstruction.h:449
Definition: cofinstructions.h:17
Definition: cofinstruction.h:302
Definition: cofinstructions.h:24
Definition: cofinstructions.h:19
Definition: cofinstructions.h:18
Definition: cofinstruction.h:38
Definition: cofinstruction.h:663
Definition: logging.h:76
Definition: cofinstruction.h:400
Definition: cofinstruction.h:351
Definition: cofinstruction.h:548
Definition: croflexception.h:27