libfluid
The ONF OpenFlow driver
common.hh
1 #ifndef OPENFLOW_COMMON_H
2 #define OPENFLOW_COMMON_H 1
3 
4 #include <vector>
5 #include <string>
6 #include "action.hh"
7 #include "fluid/util/util.h"
8 #include "fluid/util/ethaddr.hh"
9 #include "fluid/util/ipaddr.hh"
10 
11 namespace fluid_msg {
12 
13 class PortCommon {
14 protected:
15  EthAddress hw_addr_;
16  std::string name_;
17  uint32_t config_;
18  uint32_t state_;
19  uint32_t curr_;
20  uint32_t advertised_;
21  uint32_t supported_;
22  uint32_t peer_;
23 public:
24  PortCommon();
25  PortCommon(EthAddress hw_addr, std::string name, uint32_t config,
26  uint32_t state, uint32_t curr, uint32_t advertised, uint32_t supported,
27  uint32_t peer);
28  ~PortCommon() {
29  }
30  bool operator==(const PortCommon &other) const;
31  bool operator!=(const PortCommon &other) const;
32  EthAddress hw_addr() {
33  return this->hw_addr_;
34  }
35  std::string name() {
36  return this->name_;
37  }
38  uint32_t config() {
39  return this->config_;
40  }
41  uint32_t state() {
42  return this->state_;
43  }
44  uint32_t curr() {
45  return this->curr_;
46  }
47  uint32_t advertised() {
48  return this->advertised_;
49  }
50  uint32_t supported() {
51  return this->supported_;
52  }
53  uint32_t peer() {
54  return this->peer_;
55  }
56  void hw_addr(EthAddress hw_addr) {
57  this->hw_addr_ = hw_addr;
58  }
59  void name(std::string name) {
60  this->name_ = name;
61  }
62  void config(uint32_t config) {
63  this->config_ = config;
64  }
65  void state(uint32_t state) {
66  this->state_ = state;
67  }
68  void curr(uint32_t curr) {
69  this->curr_ = curr;
70  }
71  void advertised(uint32_t advertised) {
72  this->advertised_ = advertised;
73  }
74  void supported(uint32_t supported) {
75  this->supported_ = supported;
76  }
77  void peer(uint32_t peer) {
78  this->peer_ = peer;
79  }
80 
81 };
82 
84 protected:
85  uint16_t property_;
86  uint16_t len_;
87 public:
88  QueueProperty();
89  QueueProperty(uint16_t property);
90  virtual ~QueueProperty() {
91  }
92  ;
93  virtual bool equals(const QueueProperty & other);
94  virtual bool operator==(const QueueProperty &other) const;
95  virtual bool operator!=(const QueueProperty &other) const;
96  virtual QueueProperty* clone() {
97  return new QueueProperty(*this);
98  }
99  virtual size_t pack(uint8_t* buffer);
100  virtual of_error unpack(uint8_t* buffer);
101  uint16_t property() {
102  return this->property_;
103  }
104  uint16_t len() {
105  return this->len_;
106  }
107  void property(uint16_t property) {
108  this->property_ = property;
109  }
110  static QueueProperty* make_queue_of10_property(uint16_t property);
111  static QueueProperty* make_queue_of13_property(uint16_t property);
112  static bool delete_all(QueueProperty * prop) {
113  delete prop;
114  return true;
115  }
116 };
117 
119 private:
120  uint16_t length_;
121  std::list<QueueProperty*> property_list_;
122 public:
124  : length_(0) {
125  }
126  ;
127  QueuePropertyList(std::list<QueueProperty*> prop_list);
128  QueuePropertyList(const QueuePropertyList &other);
129  QueuePropertyList& operator=(QueuePropertyList other);
131  bool operator==(const QueuePropertyList &other) const;
132  bool operator!=(const QueuePropertyList &other) const;
133  size_t pack(uint8_t* buffer);
134  of_error unpack10(uint8_t* buffer);
135  of_error unpack13(uint8_t* buffer);
136  friend void swap(QueuePropertyList& first, QueuePropertyList& second);
137  uint16_t length() {
138  return this->length_;
139  }
140  std::list<QueueProperty*> property_list() {
141  return this->property_list_;
142  }
143  void add_property(QueueProperty *prop);
144  void length(uint16_t length) {
145  this->length_ = length;
146  }
147 };
148 
150 protected:
151  uint16_t rate_;
152 public:
153  QueuePropRate();
154  QueuePropRate(uint16_t property);
155  QueuePropRate(uint16_t property, uint16_t rate);
156  ~QueuePropRate() {
157  }
158  ;
159  virtual bool equals(const QueueProperty & other);
160  virtual QueuePropRate* clone() {
161  return new QueuePropRate(*this);
162  }
163  uint16_t rate() {
164  return this->rate_;
165  }
166  void rate(uint16_t rate) {
167  this->rate_ = rate;
168  }
169 };
170 
171 class SwitchDesc {
172 private:
173  std::string mfr_desc_;
174  std::string hw_desc_;
175  std::string sw_desc_;
176  std::string serial_num_;
177  std::string dp_desc_;
178 public:
179  SwitchDesc() {
180  }
181  ;
182  SwitchDesc(std::string mfr_desc, std::string hw_desc, std::string sw_desc,
183  std::string serial_num, std::string dp_desc);
184  ~SwitchDesc() {
185  }
186  ;
187  bool operator==(const SwitchDesc &other) const;
188  bool operator!=(const SwitchDesc &other) const;
189  size_t pack(uint8_t* buffer);
190  of_error unpack(uint8_t* buffer);
191  std::string mfr_desc() {
192  return this->mfr_desc_;
193  }
194  std::string hw_desc() {
195  return this->hw_desc_;
196  }
197  std::string sw_desc() {
198  return this->sw_desc_;
199  }
200  std::string serial_num() {
201  return this->serial_num_;
202  }
203  std::string dp_desc() {
204  return this->dp_desc_;
205  }
206  void mfr_desc(std::string mfr_desc) {
207  this->mfr_desc_ = mfr_desc;
208  }
209  void hw_desc(std::string hw_desc) {
210  this->hw_desc_ = hw_desc;
211  }
212  void sw_desc(std::string sw_desc) {
213  this->sw_desc_ = sw_desc;
214  }
215  void serial_num(std::string serial_num) {
216  this->serial_num_ = serial_num;
217  }
218  void dp_desc(std::string dp_desc) {
219  this->dp_desc_ = dp_desc;
220  }
221 
222 };
223 
224 /* Queue description*/
226 protected:
227  uint32_t queue_id_;
228  uint16_t len_;
229  QueuePropertyList properties_;
230 public:
232  PacketQueueCommon(uint32_t queue_id);
233  virtual ~PacketQueueCommon() {
234  }
235  ;
236  bool operator==(const PacketQueueCommon &other) const;
237  bool operator!=(const PacketQueueCommon &other) const;
238  uint32_t queue_id() {
239  return this->queue_id_;
240  }
241  uint16_t len() {
242  return this->len_;
243  }
244  void queue_id(uint32_t queue_id) {
245  this->queue_id_ = queue_id;
246  }
247  void property(QueuePropertyList properties);
248  void add_property(QueueProperty* qp);
249 };
250 
252 protected:
253  uint16_t length_;
254  uint8_t table_id_;
255  uint32_t duration_sec_;
256  uint32_t duration_nsec_;
257  uint16_t priority_;
258  uint16_t idle_timeout_;
259  uint16_t hard_timeout_;
260  uint64_t cookie_;
261  uint64_t packet_count_;
262  uint64_t byte_count_;
263 public:
264  FlowStatsCommon();
265  FlowStatsCommon(uint8_t table_id, uint32_t duration_sec,
266  uint32_t duration_nsec, uint16_t priority, uint16_t idle_timeout,
267  uint16_t hard_timeout, uint64_t cookie, uint64_t packet_count,
268  uint64_t byte_count);
269  ~FlowStatsCommon() {
270  }
271  ;
272  bool operator==(const FlowStatsCommon &other) const;
273  bool operator!=(const FlowStatsCommon &other) const;
274  uint16_t length() {
275  return this->length_;
276  }
277  uint8_t table_id() {
278  return this->table_id_;
279  }
280  uint32_t duration_sec() {
281  return this->duration_sec_;
282  }
283  uint32_t duration_nsec() {
284  return this->duration_nsec_;
285  }
286  uint16_t priority() {
287  return this->priority_;
288  }
289  uint16_t idle_timeout() {
290  return this->idle_timeout_;
291  }
292  uint16_t hard_timeout() {
293  return this->hard_timeout_;
294  }
295  uint64_t cookie() {
296  return this->cookie_;
297  }
298  uint64_t packet_count() {
299  return this->packet_count_;
300  }
301  uint64_t byte_count() {
302  return this->byte_count_;
303  }
304  void table_id(uint8_t table_id) {
305  this->table_id_ = table_id;
306  }
307  void duration_sec(uint32_t duration_sec) {
308  this->duration_sec_ = duration_sec;
309  }
310  void duration_nsec(uint32_t duration_nsec) {
311  this->duration_nsec_ = duration_nsec;
312  }
313  void priority(uint16_t priority) {
314  this->priority_ = priority;
315  }
316  void idle_timeout(uint16_t idle_timeout) {
317  this->idle_timeout_ = idle_timeout;
318  }
319  void hard_timeout(uint16_t hard_timeout) {
320  this->hard_timeout_ = hard_timeout;
321  }
322  void cookie(uint64_t cookie) {
323  this->cookie_ = cookie;
324  }
325  void packet_count(uint16_t packet_count) {
326  this->packet_count_ = packet_count;
327  }
328  void byte_count(uint64_t byte_count) {
329  this->byte_count_ = byte_count;
330  }
331 };
332 
334 protected:
335  uint8_t table_id_;
336  uint32_t active_count_;
337  uint64_t lookup_count_;
338  uint64_t matched_count_;
339 public:
341  TableStatsCommon(uint8_t table_id, uint32_t active_count,
342  uint64_t lookup_count, uint64_t matched_count);
343  ~TableStatsCommon() {
344  }
345  ;
346  bool operator==(const TableStatsCommon &other) const;
347  bool operator!=(const TableStatsCommon &other) const;
348  uint8_t table_id() {
349  return this->table_id_;
350  }
351  uint32_t active_count() {
352  return this->active_count_;
353  }
354  uint64_t lookup_count() {
355  return this->lookup_count_;
356  }
357  uint64_t matched_count() {
358  return this->matched_count_;
359  }
360  void table_id(uint8_t table_id) {
361  this->table_id_ = table_id;
362  }
363  void active_count(uint32_t active_count) {
364  this->active_count_ = active_count;
365  }
366  void lookup_count(uint64_t lookup_count) {
367  this->lookup_count_ = lookup_count;
368  }
369  void matched_count(uint64_t matched_count) {
370  this->matched_count_ = matched_count;
371  }
372 };
373 
375  uint64_t rx_packets; /* Number of received packets. */
376  uint64_t tx_packets; /* Number of transmitted packets. */
377  uint64_t rx_bytes; /* Number of received bytes. */
378  uint64_t tx_bytes; /* Number of transmitted bytes. */
379  uint64_t rx_dropped; /* Number of packets dropped by RX. */
380  uint64_t tx_dropped; /* Number of packets dropped by TX. */
381 
382  bool operator==(const struct port_rx_tx_stats other) const {
383  return ((this->rx_packets == other.rx_packets)
384  && (this->tx_packets == other.tx_packets)
385  && (this->rx_bytes == other.rx_bytes)
386  && (this->tx_bytes == other.tx_bytes)
387  && (this->rx_dropped == other.rx_dropped)
388  && (this->tx_dropped == other.tx_dropped));
389  }
390 };
391 
393  uint64_t rx_errors; /* Number of receive errors. This is a super-set
394  of more specific receive errors and should be
395  greater than or equal to the sum of all
396  rx_*_err values. */
397  uint64_t tx_errors; /* Number of transmit errors. This is a super-set
398  of more specific transmit errors and should be
399  greater than or equal to the sum of all
400  tx_*_err values (none currently defined.) */
401  uint64_t rx_frame_err; /* Number of frame alignment errors. */
402  uint64_t rx_over_err; /* Number of packets with RX overrun. */
403  uint64_t rx_crc_err; /* Number of CRC errors. */
404 
405  bool operator==(const struct port_err_stats other) const {
406  return ((this->rx_errors == other.rx_errors)
407  && (this->tx_errors == other.tx_errors)
408  && (this->rx_frame_err == other.rx_frame_err)
409  && (this->rx_over_err == other.rx_over_err)
410  && (this->rx_crc_err == other.rx_crc_err));
411  }
412 };
413 
415 protected:
416  struct port_rx_tx_stats rx_tx_stats;
417  struct port_err_stats err_stats;
418  uint64_t collisions_; /* Number of collisions. */
419 public:
420  PortStatsCommon();
421  PortStatsCommon(struct port_rx_tx_stats rx_tx_stats,
422  struct port_err_stats err_stats, uint64_t collisions);
423  ~PortStatsCommon() {
424  }
425  ;
426  bool operator==(const PortStatsCommon &other) const;
427  bool operator!=(const PortStatsCommon &other) const;
428  size_t pack(uint8_t* buffer);
429  of_error unpack(uint8_t* buffer);
430  uint64_t rx_packets() {
431  return this->rx_tx_stats.rx_packets;
432  }
433  uint64_t tx_packets() {
434  return this->rx_tx_stats.tx_packets;
435  }
436  uint64_t rx_bytes() {
437  return this->rx_tx_stats.rx_bytes;
438  }
439  uint64_t tx_bytes() {
440  return this->rx_tx_stats.tx_bytes;
441  }
442  uint64_t rx_dropped() {
443  return this->rx_tx_stats.rx_dropped;
444  }
445  uint64_t tx_dropped() {
446  return this->rx_tx_stats.tx_dropped;
447  }
448  uint64_t rx_errors() {
449  return this->err_stats.rx_errors;
450  }
451  uint64_t tx_errors() {
452  return this->err_stats.tx_errors;
453  }
454  uint64_t rx_frame_err() {
455  return this->err_stats.rx_frame_err;
456  }
457  uint64_t rx_over_err() {
458  return this->err_stats.rx_over_err;
459  }
460  uint64_t rx_crc_err() {
461  return this->err_stats.rx_crc_err;
462  }
463  uint64_t collisions() {
464  return this->collisions_;
465  }
466  void rx_packets(uint64_t rx_packets) {
467  this->rx_tx_stats.rx_packets = rx_packets;
468  }
469  void tx_packets(uint64_t tx_packets) {
470  this->rx_tx_stats.tx_packets = tx_packets;
471  }
472  void rx_bytes(uint64_t rx_bytes) {
473  this->rx_tx_stats.rx_bytes = rx_bytes;
474  }
475  void tx_bytes(uint64_t tx_bytes) {
476  this->rx_tx_stats.tx_bytes = tx_bytes;
477  }
478  void rx_dropped(uint64_t rx_dropped) {
479  this->rx_tx_stats.rx_dropped = rx_dropped;
480  }
481  void tx_dropped(uint64_t tx_dropped) {
482  this->rx_tx_stats.tx_dropped = tx_dropped;
483  }
484  void rx_errors(uint64_t rx_errors) {
485  this->err_stats.rx_errors = rx_errors;
486  }
487  void tx_errors(uint64_t tx_errors) {
488  this->err_stats.tx_errors = tx_errors;
489  }
490  void rx_frame_err(uint64_t rx_frame_err) {
491  this->err_stats.rx_frame_err = rx_frame_err;
492  }
493  void rx_over_err(uint64_t rx_over_err) {
494  this->err_stats.rx_over_err = rx_over_err;
495  }
496  void rx_crc_err(uint64_t rx_crc_err) {
497  this->err_stats.rx_crc_err = rx_crc_err;
498  }
499  void collisions(uint64_t collisions) {
500  this->collisions_ = collisions;
501  }
502 };
503 
505 protected:
506  uint32_t queue_id_;
507  uint64_t tx_bytes_;
508  uint64_t tx_packets_;
509  uint64_t tx_errors_;
510 public:
512  QueueStatsCommon(uint32_t queue_id, uint64_t tx_bytes, uint64_t tx_packets,
513  uint64_t tx_errors);
514  ~QueueStatsCommon() {
515  }
516  ;
517  bool operator==(const QueueStatsCommon &other) const;
518  bool operator!=(const QueueStatsCommon &other) const;
519  uint32_t queue_id() {
520  return this->queue_id_;
521  }
522  uint64_t tx_bytes() {
523  return this->tx_bytes_;
524  }
525  uint64_t tx_packets() {
526  return this->tx_packets_;
527  }
528  uint64_t tx_errors() {
529  return this->tx_errors_;
530  }
531  void queue_id(uint32_t queue_id) {
532  this->queue_id_ = queue_id;
533  }
534  void tx_bytes(uint64_t tx_bytes) {
535  this->tx_bytes_ = tx_bytes;
536  }
537  void tx_packets(uint64_t tx_packets) {
538  this->tx_packets_ = tx_packets;
539  }
540  void tx_errors(uint64_t tx_errors) {
541  this->tx_errors_ = tx_errors;
542  }
543 };
544 
545 } //End of namespace fluid_msg
546 
547 #endif