libfluid
The ONF OpenFlow driver
of13meter.hh
1 #ifndef OPENFLOW_METER_H
2 #define OPENFLOW_METER_H
3 
4 #include <stddef.h>
5 #include "openflow-13.h"
6 #include <list>
7 #include <vector>
8 
9 namespace fluid_msg {
10 
11 namespace of13 {
12 
13 class MeterBand {
14 protected:
15  uint16_t type_;
16  uint16_t len_;
17  uint32_t rate_;
18  uint32_t burst_size_;
19 public:
20  MeterBand();
21  MeterBand(uint16_t type, uint32_t rate, uint32_t burst_size);
22  virtual ~MeterBand() {
23  }
24  virtual bool equals(const MeterBand & other);
25  virtual MeterBand* clone() {
26  return new MeterBand(*this);
27  }
28  virtual size_t pack(uint8_t* buffer);
29  virtual of_error unpack(uint8_t* buffer);
30  uint16_t type() {
31  return this->type_;
32  }
33  uint16_t len() {
34  return this->len_;
35  }
36  uint32_t rate() {
37  return this->rate_;
38  }
39  uint32_t burst_size() {
40  return this->burst_size_;
41  }
42  void type(uint16_t type) {
43  this->type_ = type;
44  }
45  void rate(uint32_t rate) {
46  this->rate_ = rate;
47  }
48  void burst_size(uint32_t burst_size) {
49  this->burst_size_ = burst_size;
50  }
51  static bool delete_all(MeterBand * band) {
52  delete band;
53  return true;
54  }
55  static MeterBand * make_meter_band(uint16_t type);
56 };
57 
59 private:
60  uint16_t length_;
61  std::list<MeterBand*> band_list_;
62 public:
64  : length_(0) {
65  }
66  MeterBandList(std::list<MeterBand*> band_list);
67  MeterBandList(const MeterBandList &other);
68  MeterBandList& operator=(MeterBandList other);
69  ~MeterBandList();
70  bool operator==(const MeterBandList &other) const;
71  bool operator!=(const MeterBandList &other) const;
72  size_t pack(uint8_t* buffer);
73  of_error unpack(uint8_t* buffer);
74  friend void swap(MeterBandList& first, MeterBandList& second);
75  uint16_t length() {
76  return this->length_;
77  }
78  void add_band(MeterBand *band);
79  void length(uint16_t length) {
80  this->length_ = length;
81  }
82 };
83 
84 class MeterBandDrop: public MeterBand {
85 public:
86  MeterBandDrop();
87  MeterBandDrop(uint32_t rate, uint32_t burst_size);
88  ~MeterBandDrop() {
89  }
90  virtual MeterBandDrop* clone() {
91  return new MeterBandDrop(*this);
92  }
93  size_t pack(uint8_t* buffer);
94  of_error unpack(uint8_t* buffer);
95 };
96 
98 private:
99  uint8_t prec_level_;
100 public:
102  MeterBandDSCPRemark(uint32_t rate, uint32_t burst_size, uint8_t prec_level);
104  }
105  virtual bool equals(const MeterBand & other);
106  size_t pack(uint8_t* buffer);
107  of_error unpack(uint8_t* buffer);
108  virtual MeterBandDSCPRemark* clone() {
109  return new MeterBandDSCPRemark(*this);
110  }
111  uint8_t prec_level() {
112  return this->prec_level_;
113  }
114  void prec_level(uint8_t prec_level) {
115  this->prec_level_ = prec_level;
116  }
117 };
118 
120 protected:
121  uint32_t experimenter_;
122 public:
124  MeterBandExperimenter(uint32_t rate, uint32_t burst_size,
125  uint32_t experimenter);
127  }
128  virtual bool equals(const MeterBand & other);
129  virtual MeterBandExperimenter* clone() {
130  return new MeterBandExperimenter(*this);
131  }
132  size_t pack(uint8_t* buffer);
133  of_error unpack(uint8_t* buffer);
134  uint32_t experimenter() {
135  return this->experimenter_;
136  }
137  void experimenter(uint32_t experimenter) {
138  this->experimenter_ = experimenter;
139  }
140 };
141 
142 class MeterConfig {
143 private:
144  uint16_t length_;
145  uint16_t flags_;
146  uint32_t meter_id_;
147  MeterBandList bands_;
148 public:
149  MeterConfig();
150  MeterConfig(uint16_t flags, uint32_t meter_id);
151  MeterConfig(uint16_t flags, uint32_t meter_id, MeterBandList bands);
152  ~MeterConfig() {
153  }
154  bool operator==(const MeterConfig &other) const;
155  bool operator!=(const MeterConfig &other) const;
156  size_t pack(uint8_t* buffer);
157  of_error unpack(uint8_t* buffer);
158  uint16_t length() {
159  return this->length_;
160  }
161  uint16_t flags() {
162  return this->flags_;
163  }
164  uint32_t meter_id() {
165  return this->meter_id_;
166  }
167  MeterBandList bands() {
168  return this->bands_;
169  }
170  void bands(MeterBandList bands);
171  void add_band(MeterBand* band);
172 };
173 
175 private:
176  uint32_t max_meter_;
177  uint32_t band_types_;
178  uint32_t capabilities_;
179  uint8_t max_bands_;
180  uint8_t max_color_;
181 public:
182  MeterFeatures();
183  MeterFeatures(uint32_t max_meter, uint32_t band_types,
184  uint32_t capabilities, uint8_t max_bands, uint8_t max_color);
185  ~MeterFeatures() {
186  }
187  bool operator==(const MeterFeatures &other) const;
188  bool operator!=(const MeterFeatures &other) const;
189  size_t pack(uint8_t* buffer);
190  of_error unpack(uint8_t* buffer);
191  uint32_t max_meter() {
192  return this->max_meter_;
193  }
194  uint32_t band_types() {
195  return this->band_types_;
196  }
197  uint32_t capabilities() {
198  return this->capabilities_;
199  }
200  uint8_t max_bands() {
201  return this->max_bands_;
202  }
203  uint8_t max_color() {
204  return this->max_color_;
205  }
206  void max_meter(uint32_t max_meter) {
207  this->max_meter_ = max_meter;
208  }
209  void banc_types(uint32_t band_types) {
210  this->band_types_ = band_types;
211  }
212  void capabilities(uint32_t capabilities) {
213  this->capabilities_ = capabilities;
214  }
215  void max_bands(uint8_t max_bands) {
216  this->max_bands_ = max_bands;
217  }
218  void max_color(uint8_t max_color) {
219  this->max_color_ = max_color;
220  }
221 };
222 
223 class BandStats {
224 private:
225  uint64_t packet_band_count_;
226  uint64_t byte_band_count_;
227 public:
228  BandStats();
229  BandStats(uint64_t packet_band_count, uint64_t byte_band_count);
230  ~BandStats() {
231  }
232  bool operator==(const BandStats &other) const;
233  bool operator!=(const BandStats &other) const;
234  size_t pack(uint8_t* buffer);
235  of_error unpack(uint8_t* buffer);
236  uint64_t packet_band_count() {
237  return this->packet_band_count_;
238  }
239  uint64_t byte_band_count() {
240  return this->byte_band_count_;
241  }
242 };
243 
244 class MeterStats {
245 private:
246  uint32_t meter_id_;
247  uint16_t len_;
248  uint32_t flow_count_;
249  uint64_t packet_in_count_;
250  uint64_t byte_in_count_;
251  uint32_t duration_sec_;
252  uint32_t duration_nsec_;
253  std::vector<BandStats> band_stats_;
254 
255 public:
256  MeterStats();
257  MeterStats(uint32_t meter_id, uint32_t flow_count, uint64_t packet_in_count,
258  uint64_t byte_in_count, uint32_t duration_sec, uint32_t duration_nsec);
259  MeterStats(uint32_t meter_id, uint32_t flow_count, uint64_t packet_in_count,
260  uint64_t byte_in_count, uint32_t duration_sec, uint32_t duration_nsec,
261  std::vector<BandStats> band_stats);
262  ~MeterStats() {
263  }
264  bool operator==(const MeterStats &other) const;
265  bool operator!=(const MeterStats &other) const;
266  size_t pack(uint8_t* buffer);
267  of_error unpack(uint8_t* buffer);
268  uint32_t meter_id() {
269  return this->meter_id_;
270  }
271  uint16_t len() {
272  return this->len_;
273  }
274  uint64_t packet_in_count() {
275  return this->packet_in_count_;
276  }
277  uint64_t byte_in_count() {
278  return this->byte_in_count_;
279  }
280  uint32_t duration_sec() {
281  return this->duration_sec_;
282  }
283  uint32_t duration_nsec() {
284  return this->duration_nsec_;
285  }
286  std::vector<BandStats> band_stats() {
287  return this->band_stats_;
288  }
289  void meter_id(uint32_t meter_id) {
290  this->meter_id_ = meter_id;
291  }
292  void packet_in_count(uint64_t packet_in_count) {
293  this->packet_in_count_ = packet_in_count;
294  }
295  void byte_in_count(uint64_t byte_in_count) {
296  this->byte_in_count_ = byte_in_count;
297  }
298  void duration_sec(uint32_t duration_sec) {
299  this->duration_sec_ = duration_sec;
300  }
301  void duration_nsec(uint64_t duration_nsec) {
302  this->duration_nsec_ = duration_nsec;
303  }
304  void band_stats(std::vector<BandStats> band_stats);
305 
306  void add_band_stats(BandStats stats);
307 };
308 
309 } //End of namespace of13
310 
311 } //End of namespace fluid_msg
312 #endif