Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofbucket.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 COFBUCKET_H
6 #define COFBUCKET_H 1
7 
8 #include <string>
9 #include <vector>
10 #include <list>
11 #include <endian.h>
12 #include <ostream>
13 #ifndef htobe16
14  #include "../endian_conversion.h"
15 #endif
16 
17 #include "rofl/common/openflow/openflow.h"
18 #include "rofl/common/croflexception.h"
19 #include "rofl/common/cmemory.h"
20 #include "rofl/common/openflow/cofactions.h"
21 
22 namespace rofl {
23 namespace openflow {
24 
25 /* error classes */
26 class eBucketBase : public RoflException {}; // error base class for class cofbucket
27 class eBucketInval : public eBucketBase {}; // parameter is invalid
28 class eBucketBadLen : public eBucketBase {}; // invalid length
29 
30 
31 
32 class cofbucket {
33 
34  uint8_t ofp_version;
35 
36  uint64_t packet_count; // packet count for this bucket
37  uint64_t byte_count; // byte count for this bucket
38  uint16_t weight;
39  uint32_t watch_port;
40  uint32_t watch_group;
41 
42  cofactions actions; // list of OpenFlow actions
43 
44 public: // per instance methods
45 
49  cofbucket(
50  uint8_t ofp_version = openflow::OFP_VERSION_UNKNOWN,
51  uint16_t weigth = 0,
52  uint32_t watch_port = 0,
53  uint32_t watch_group = 0);
54 
55 
59  cofbucket(
60  uint8_t ofp_version,
61  uint8_t *bucket,
62  size_t bclen);
63 
64 
68  virtual
69  ~cofbucket();
70 
71 
75  cofbucket&
76  operator= (
77  const cofbucket& b);
78 
82  bool
83  operator== (
84  const cofbucket& b);
85 
86 
90  uint8_t*
91  pack(uint8_t* bucket, size_t bclen);
92 
93 
97  void
98  unpack(uint8_t* bucket, size_t bclen);
99 
100 
104  size_t
105  length() const;
106 
107 
111  void
112  get_bucket_stats(
113  cmemory& body);
114 
115 
119  void
120  check_prerequisites() const;
121 
122 public:
123 
127  uint8_t
128  get_version() const { return ofp_version; };
129 
133  void
134  set_version(uint8_t ofp_version) { this->ofp_version = ofp_version; };
135 
139  uint64_t
140  get_packet_count() const { return packet_count; };
141 
145  void
146  set_packet_count(uint64_t packet_count) { this->packet_count = packet_count; };
147 
151  uint64_t
152  get_byte_count() const { return byte_count; };
153 
157  void
158  set_byte_count(uint64_t byte_count) { this->byte_count = byte_count; };
159 
163  void
164  set_weight(uint16_t weight) { this->weight = weight; };
165 
169  uint16_t
170  get_weight() const { return weight; };
171 
175  void
176  set_watch_port(uint32_t watch_port) { this->watch_port = watch_port; };
177 
181  uint32_t
182  get_watch_port() const { return watch_port; };
183 
187  void
188  set_watch_group(uint32_t watch_group) { this->watch_group = watch_group; };
189 
193  uint32_t
194  get_watch_group() const { return watch_group; };
195 
199  cofactions&
200  set_actions() { return actions; };
201 
205  cofactions const&
206  get_actions() const { return actions; };
207 
208 private:
209 
212  uint8_t*
213  pack_of12(uint8_t* buf, size_t buflen);
214 
217  void
218  unpack_of12(uint8_t *buf, size_t buflen);
219 
222  uint8_t*
223  pack_of13(uint8_t* buf, size_t buflen);
224 
227  void
228  unpack_of13(uint8_t *buf, size_t buflen);
229 
230 public:
231 
232  friend std::ostream&
233  operator<< (std::ostream& os, cofbucket const& bucket) {
234  switch (bucket.get_version()) {
235  case rofl::openflow::OFP_VERSION_UNKNOWN: {
236  os << indent(0) << "<cofbucket ";
237  os << "ofp-version:" << (int)bucket.ofp_version << " >" << std::endl;
238  } break;
239  case rofl::openflow12::OFP_VERSION:
240  case rofl::openflow13::OFP_VERSION: {
241  os << indent(0) << "<cofbucket ";
242  os << "ofp-version:" << (int)bucket.ofp_version << " >" << std::endl;
243  os << std::hex;
244  os << indent(2) << "<weight: 0x" << (int)bucket.weight << " >" << std::endl;
245  os << indent(2) << "<watch-group: 0x" << (int)bucket.watch_group << " >" << std::endl;
246  os << indent(2) << "<watch-port: 0x" << (int)bucket.watch_port << " >" << std::endl;
247  os << indent(2) << "<packet-count: 0x" << (int)bucket.packet_count << " >" << std::endl;
248  os << indent(2) << "<byte-count: 0x" << (int)bucket.byte_count << " >" << std::endl;
249  os << std::dec;
250  os << indent(2) << "<actions: >" << std::endl;
251  indent i(4);
252  os << bucket.actions;
253 
254  } break;
255  default: {
256  throw eBadVersion();
257  };
258  }
259  return os;
260  };
261 };
262 
263 }; // end of namespace
264 }; // end of namespace
265 
266 #endif
Definition: croflexception.h:73
Definition: cofbucket.h:32
Definition: cofactions.h:22
Definition: cofbucket.h:27
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: cofbucket.h:28
Definition: logging.h:76
Definition: cofbucket.h:26
Definition: croflexception.h:27