Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofbuckets.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 COFBUCKETLIST_H
6 #define COFBUCKETLIST_H 1
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 #include <endian.h>
12 #ifndef htobe16
13  #include "../endian_conversion.h"
14 #endif
15 
16 #include "rofl/common/openflow/openflow.h"
17 #include "rofl/common/openflow/cofbucket.h"
18 
19 namespace rofl {
20 namespace openflow {
21 
22 class eBucketsBase : public RoflException {};
23 class eBucketsInval : public eBucketsBase {};
24 class eBucketsNotFound : public eBucketsBase {};
25 class eBucketsOutOfRange : public eBucketsBase {};
26 
27 
29 {
30  uint8_t ofp_version;
31  std::map<uint32_t, cofbucket> buckets;
32 
33 public: // methods
34 
38  cofbuckets(
39  uint8_t ofp_version = openflow::OFP_VERSION_UNKNOWN);
40 
44  virtual
45  ~cofbuckets();
46 
50  cofbuckets(
51  cofbuckets const& buckets);
52 
56  cofbuckets&
57  operator= (
58  cofbuckets const& buckets);
59 
63  bool
64  operator== (
65  cofbuckets const& buckets);
66 
70  uint8_t
71  get_version() const { return ofp_version; };
72 
76  void
77  set_version(uint8_t ofp_version) { this->ofp_version = ofp_version; };
78 
82  std::map<uint32_t, cofbucket>&
83  set_buckets() { return buckets; };
84 
88  std::map<uint32_t, cofbucket> const&
89  get_buckets() const { return buckets; };
90 
91 public:
92 
96  cofbucket&
97  add_bucket(uint32_t bucket_id);
98 
102  void
103  drop_bucket(uint32_t bucket_id);
104 
108  cofbucket&
109  set_bucket(uint32_t bucket_id);
110 
114  cofbucket const&
115  get_bucket(uint32_t bucket_id) const;
116 
120  bool
121  has_bucket(uint32_t bucket_id);
122 
123 public:
124 
128  void
129  clear() { buckets.clear(); };
130 
134  void
135  check_prerequisites() const;
136 
137 public:
138 
142  virtual size_t
143  length() const;
144 
148  uint8_t*
149  pack(uint8_t* buf, size_t buflen);
150 
154  void
155  unpack(uint8_t* buf, size_t buflen);
156 
157 
158 private:
159 
162  void
163  unpack_of13(uint8_t* buf, size_t buflen);
164 
167  uint8_t*
168  pack_of13(uint8_t* buf, size_t buflen);
169 
170 public:
171 
172  friend std::ostream&
173  operator<< (std::ostream& os, cofbuckets const& buckets) {
174  switch (buckets.get_version()) {
175  case rofl::openflow::OFP_VERSION_UNKNOWN: {
176  os << indent(0) << "<cofbuckets ";
177  os << "ofp-version:" << (int)buckets.ofp_version << " >" << std::endl;
178 
179  } break;
180  case rofl::openflow12::OFP_VERSION:
181  case rofl::openflow13::OFP_VERSION: {
182  os << indent(0) << "<cofbuckets ";
183  os << "ofp-version:" << (int)buckets.ofp_version << " ";
184  os << "#buckets:" << buckets.buckets.size() << " >" << std::endl;
185  indent i(2);
186  for (std::map<uint32_t, cofbucket>::const_iterator
187  it = buckets.buckets.begin(); it != buckets.buckets.end(); ++it) {
188  os << it->second;
189  }
190 
191  } break;
192  default:
193  throw eBadVersion();
194  }
195  return os;
196  };
197 };
198 
199 }; // end of namespace
200 }; // end of namespace
201 
202 #endif
Definition: croflexception.h:73
Definition: cofbuckets.h:22
Definition: cofbucket.h:32
Definition: cofbuckets.h:28
Definition: cofbuckets.h:24
Definition: logging.h:76
Definition: cofbuckets.h:25
Definition: cofbuckets.h:23
Definition: croflexception.h:27