libfluid
The ONF OpenFlow driver
of13common.hh
1 #ifndef OF13OPENFLOW_COMMON_H
2 #define OF13OPENFLOW_COMMON_H 1
3 
4 #include <vector>
5 #include <string>
6 
7 #include "fluid/ofcommon/common.hh"
8 #include "fluid/util/util.h"
9 #include "openflow-13.h"
10 #include "of13action.hh"
11 #include "of13instruction.hh"
12 
13 namespace fluid_msg {
14 
15 namespace of13 {
16 
17 class HelloElem {
18 protected:
19  uint16_t type_;
20  uint16_t length_;
21 public:
22  HelloElem() {
23  }
24  HelloElem(uint16_t type, uint16_t length);
25  ~HelloElem() {
26  }
27  bool operator==(const HelloElem &other) const;
28  bool operator!=(const HelloElem &other) const;
29  uint16_t type() {
30  return this->type_;
31  }
32  uint16_t length() {
33  return this->length_;
34  }
35  void type(uint16_t type) {
36  this->type_ = type;
37  }
38  void length(uint16_t length) {
39  this->length_ = length;
40  }
41 };
42 
44 private:
45  std::list<uint32_t> bitmaps_;
46 public:
48  : HelloElem(of13::OFPHET_VERSIONBITMAP,
49  sizeof(struct of13::ofp_hello_elem_versionbitmap)) {
50  }
51  HelloElemVersionBitmap(std::list<uint32_t> bitmap);
52  bool operator==(const HelloElemVersionBitmap &other) const;
53  bool operator!=(const HelloElemVersionBitmap &other) const;
54  size_t pack(uint8_t* buffer);
55  of_error unpack(uint8_t *data);
56  std::list<uint32_t> bitmaps() {
57  return this->bitmaps_;
58  }
59  void bitmaps(std::list<uint32_t> bitmaps) {
60  this->bitmaps_ = bitmaps;
61  }
62  void add_bitmap(uint32_t bitmap);
63 };
64 
65 class Port: public PortCommon {
66 private:
67  uint32_t port_no_;
68  uint32_t curr_speed_;
69  uint32_t max_speed_;
70 public:
71  Port();
72  Port(uint32_t port_no, EthAddress hw_addr, std::string name,
73  uint32_t config, uint32_t state, uint32_t curr, uint32_t advertised,
74  uint32_t supported, uint32_t peer, uint32_t curr_speed,
75  uint32_t max_speed);
76  ~Port() {
77  }
78  bool operator==(const Port &other) const;
79  bool operator!=(const Port &other) const;
80  size_t pack(uint8_t* buffer);
81  of_error unpack(uint8_t* buffer);
82  uint32_t port_no() {
83  return this->port_no_;
84  }
85  uint32_t curr_speed() {
86  return this->curr_speed_;
87  }
88  uint32_t max_speed() {
89  return this->max_speed_;
90  }
91  void port_no(uint32_t port_no) {
92  this->port_no_ = port_no;
93  }
94  void curr_speed(uint32_t curr_speed) {
95  this->curr_speed_ = curr_speed;
96  }
97  void max_speed(uint32_t max_speed) {
98  this->max_speed_ = max_speed;
99  }
100 };
101 
103 public:
105  : QueuePropRate(of13::OFPQT_MIN_RATE) {
106  }
107  QueuePropMinRate(uint16_t rate);
108  ~QueuePropMinRate() {
109  }
110  virtual bool equals(const QueueProperty & other);
111  virtual QueuePropMinRate* clone() {
112  return new QueuePropMinRate(*this);
113  }
114  size_t pack(uint8_t* buffer);
115  of_error unpack(uint8_t* buffer);
116 };
117 
119 public:
121  : QueuePropRate(of13::OFPQT_MAX_RATE) {
122  }
123  QueuePropMaxRate(uint16_t rate);
124  ~QueuePropMaxRate() {
125  }
126  virtual bool equals(const QueueProperty & other);
127  virtual QueuePropMaxRate* clone() {
128  return new QueuePropMaxRate(*this);
129  }
130  size_t pack(uint8_t* buffer);
131  of_error unpack(uint8_t* buffer);
132 };
133 
135 protected:
136  uint32_t experimenter_;
137 public:
139  }
140  QueueExperimenter(uint32_t experimenter);
141  ~QueueExperimenter() {
142  }
143  virtual QueueExperimenter* clone() {
144  return new QueueExperimenter(*this);
145  }
146  size_t pack(uint8_t* buffer);
147  of_error unpack(uint8_t* buffer);
148  uint32_t get_experimenter() {
149  return this->experimenter_;
150  }
151  void set_experimenter(uint32_t experimenter) {
152  this->experimenter_ = experimenter;
153  }
154 };
155 
156 /* Queue description*/
158 private:
159  uint32_t port_;
160 public:
161  PacketQueue();
162  PacketQueue(uint32_t queue_id, uint32_t port);
163  PacketQueue(uint32_t queue_id, uint32_t port, QueuePropertyList properties);
164  ~PacketQueue() {
165  }
166  bool operator==(const PacketQueue &other) const;
167  bool operator!=(const PacketQueue &other) const;
168  size_t pack(uint8_t* buffer);
169  of_error unpack(uint8_t* buffer);
170  uint32_t port() {
171  return this->port_;
172  }
173  void port(uint32_t port) {
174  this->port_ = port;
175  }
176 };
177 
178 class Bucket {
179 private:
180  uint16_t length_;
181  uint16_t weight_;
182  uint32_t watch_port_;
183  uint32_t watch_group_;
184  ActionSet actions_;
185 public:
186  Bucket();
187  Bucket(uint16_t weight, uint32_t watch_port, uint32_t watch_group);
188  Bucket(uint16_t weight, uint32_t watch_port, uint32_t watch_group,
189  ActionSet actions);
190  ~Bucket() {
191  }
192  bool operator==(const Bucket &other) const;
193  bool operator!=(const Bucket &other) const;
194  size_t pack(uint8_t* buffer);
195  of_error unpack(uint8_t* buffer);
196  uint16_t len() {
197  return this->length_;
198  }
199  uint16_t weight() {
200  return this->weight_;
201  }
202  uint32_t watch_port() {
203  return this->watch_port_;
204  }
205  uint32_t watch_group() {
206  return this->watch_group_;
207  }
208  ActionSet get_actions() {
209  return this->actions_;
210  }
211  void weight(uint16_t weight) {
212  this->weight_ = weight;
213  }
214  void watch_port(uint32_t watch_port) {
215  this->watch_port_ = watch_port;
216  }
217  void watch_group(uint32_t watch_group) {
218  this->watch_group_ = watch_group;
219  }
220  void actions(ActionSet actions);
221  void add_action(Action &action);
222  void add_action(Action* action);
223 };
224 
225 class FlowStats: public FlowStatsCommon {
226 private:
227  uint16_t flags_;
228  of13::Match match_;
229  InstructionSet instructions_;
230 public:
231  FlowStats();
232  FlowStats(uint8_t table_id, uint32_t duration_sec, uint32_t duration_nsec,
233  uint16_t priority, uint16_t idle_timeout, uint16_t hard_timeout,
234  uint16_t flags, uint64_t cookie, uint64_t packet_count,
235  uint64_t byte_count);
236  ~FlowStats() {
237  }
238  bool operator==(const FlowStats &other) const;
239  bool operator!=(const FlowStats &other) const;
240  size_t pack(uint8_t* buffer);
241  of_error unpack(uint8_t* buffer);
242  uint16_t get_flags() {
243  return this->flags_;
244  }
245  void set_flags(uint16_t flags) {
246  this->flags_ = flags;
247  }
248  void match(of13::Match match);
249  of13::Match match() {
250  return this->match_;
251  }
252  OXMTLV * get_oxm_field(uint8_t field);
253  void instructions(InstructionSet instructions);
254  void add_instruction(Instruction* inst);
255 };
256 
258 public:
259  TableStats();
260  TableStats(uint8_t table_id, uint32_t active_count, uint64_t lookup_count,
261  uint64_t matched_count);
262  ~TableStats() {
263  }
264  size_t pack(uint8_t* buffer);
265  of_error unpack(uint8_t* buffer);
266 };
267 
268 class PortStats: public PortStatsCommon {
269 private:
270  uint32_t port_no_;
271  uint32_t duration_sec_;
272  uint32_t duration_nsec_;
273 public:
274  PortStats();
275  PortStats(uint32_t port_no, struct port_rx_tx_stats tx_stats,
276  struct port_err_stats err_stats, uint64_t collisions,
277  uint32_t duration_sec, uint32_t duration_nsec);
278  ~PortStats() {
279  }
280  bool operator==(const PortStats &other) const;
281  bool operator!=(const PortStats &other) const;
282  size_t pack(uint8_t* buffer);
283  of_error unpack(uint8_t* buffer);
284  uint32_t port_no() {
285  return this->port_no_;
286  }
287  uint32_t duration_sec() {
288  return this->duration_sec_;
289  }
290  uint32_t duration_nsec() {
291  return this->duration_nsec_;
292  }
293  void port_no(uint32_t port_no) {
294  this->port_no_ = port_no;
295  }
296  void duration_sec(uint32_t duration_sec) {
297  this->duration_sec_ = duration_sec;
298  }
299  void duration_nsec(uint32_t duration_nsec) {
300  this->duration_nsec_ = duration_nsec;
301  }
302 };
303 
305 private:
306  uint32_t port_no_;
307  uint32_t duration_sec_;
308  uint32_t duration_nsec_;
309 public:
310  QueueStats();
311  QueueStats(uint32_t port_no, uint32_t queue_id, uint64_t tx_bytes,
312  uint64_t tx_packets, uint64_t tx_errors, uint32_t duration_sec,
313  uint32_t duration_nsec);
314  ~QueueStats() {
315  }
316  bool operator==(const QueueStats &other) const;
317  bool operator!=(const QueueStats &other) const;
318  size_t pack(uint8_t* buffer);
319  of_error unpack(uint8_t* buffer);
320  uint32_t port_no() {
321  return this->port_no_;
322  }
323  uint32_t duration_sec() {
324  return this->duration_sec_;
325  }
326  uint32_t duration_nsec() {
327  return this->duration_nsec_;
328  }
329  void port_no(uint32_t port_no) {
330  this->port_no_ = port_no;
331  }
332  void duration_sec(uint32_t duration_sec) {
333  this->duration_sec_ = duration_sec;
334  }
335  void duration_nsec(uint32_t duration_nsec) {
336  this->duration_nsec_ = duration_nsec;
337  }
338 };
339 
340 class BucketStats {
341 private:
342  uint64_t packet_count_;
343  uint64_t byte_count_;
344 public:
345  BucketStats();
346  BucketStats(uint64_t packet_count, uint64_t byte_count);
347  ~BucketStats() {
348  }
349  bool operator==(const BucketStats &other) const;
350  bool operator!=(const BucketStats &other) const;
351  size_t pack(uint8_t* buffer);
352  of_error unpack(uint8_t* buffer);
353  uint64_t packet_count() {
354  return this->packet_count_;
355  }
356  uint64_t byte_count() {
357  return this->byte_count_;
358  }
359 };
360 
361 class GroupStats {
362 private:
363  uint16_t length_;
364  uint32_t group_id_;
365  uint32_t ref_count_;
366  uint64_t packet_count_;
367  uint64_t byte_count_;
368  uint32_t duration_sec_;
369  uint32_t duration_nsec_;
370  std::vector<BucketStats> bucket_stats_;
371 public:
372  GroupStats()
373  : length_(sizeof(struct of13::ofp_group_stats)) {
374  }
375  GroupStats(uint32_t group_id, uint32_t ref_count, uint64_t packet_count,
376  uint64_t byte_count, uint32_t duration_sec, uint32_t duration_nsec);
377  GroupStats(uint32_t group_id, uint32_t ref_count, uint64_t packet_count,
378  uint64_t byte_count, uint32_t duration_sec, uint32_t duration_nsec,
379  std::vector<BucketStats> bucket_stats);
380  ~GroupStats() {
381  }
382  bool operator==(const GroupStats &other) const;
383  bool operator!=(const GroupStats &other) const;
384  size_t pack(uint8_t* buffer);
385  of_error unpack(uint8_t* buffer);
386  uint16_t length() {
387  return this->length_;
388  }
389  uint32_t group_id() {
390  return this->group_id_;
391  }
392  uint32_t ref_count() {
393  return this->ref_count_;
394  }
395  uint64_t packet_count() {
396  return this->packet_count_;
397  }
398  uint64_t byte_count() {
399  return this->byte_count_;
400  }
401  uint32_t duration_sec() {
402  return this->duration_sec_;
403  }
404  uint32_t duration_nsec() {
405  return this->duration_nsec_;
406  }
407  void group_id(uint32_t group_id) {
408  this->group_id_ = group_id;
409  }
410  void ref_count(uint32_t ref_count) {
411  this->ref_count_ = ref_count;
412  }
413  void packet_count(uint64_t packet_count) {
414  this->packet_count_ = packet_count;
415  }
416  void byte_count(uint64_t byte_count) {
417  this->byte_count_ = byte_count;
418  }
419  void duration_sec(uint32_t duration_sec) {
420  this->duration_sec_ = duration_sec;
421  }
422  void duration_nsec(uint64_t duration_nsec) {
423  this->duration_nsec_ = duration_nsec;
424  }
425  void bucket_stats(std::vector<BucketStats> bucket_stats);
426  void add_bucket_stat(BucketStats stat);
427 };
428 
429 class GroupDesc {
430 private:
431  uint16_t length_;
432  uint8_t type_;
433  uint32_t group_id_;
434  std::vector<of13::Bucket> buckets_;
435 public:
436  GroupDesc()
437  : length_(sizeof(struct of13::ofp_group_desc_stats)) {
438  }
439  GroupDesc(uint8_t type, uint32_t group_id);
440  GroupDesc(uint8_t type, uint32_t group_id,
441  std::vector<of13::Bucket> buckets);
442  ~GroupDesc() {
443  }
444  bool operator==(const GroupDesc &other) const;
445  bool operator!=(const GroupDesc &other) const;
446  size_t pack(uint8_t* buffer);
447  of_error unpack(uint8_t* buffer);
448  uint16_t length() {
449  return this->length_;
450  }
451  uint8_t type() {
452  return this->type_;
453  }
454  uint32_t group_id() {
455  return this->group_id_;
456  }
457  std::vector<of13::Bucket> buckets() {
458  return this->buckets_;
459  }
460  void type(uint8_t type) {
461  this->type_ = type;
462  }
463  void group_id(uint32_t group_id) {
464  this->group_id_ = group_id;
465  }
466  void buckets(std::vector<Bucket> buckets);
467  void add_bucket(Bucket bucket);
468  size_t buckets_len();
469 };
470 
472 private:
473  uint32_t types_;
474  uint32_t capabilities_;
475  uint32_t max_groups_[4];
476  uint32_t actions_[4];
477 public:
478  GroupFeatures() {
479  }
480  GroupFeatures(uint32_t types, uint32_t capabilities, uint32_t max_groups[4],
481  uint32_t actions[4]);
482  ~GroupFeatures() {
483  }
484  bool operator==(const GroupFeatures &other) const;
485  bool operator!=(const GroupFeatures &other) const;
486  size_t pack(uint8_t* buffer);
487  of_error unpack(uint8_t* buffer);
488  uint32_t types() {
489  return this->types_;
490  }
491  uint32_t capabilities() {
492  return this->capabilities_;
493  }
494  uint32_t* max_groups() {
495  return this->max_groups_;
496  }
497  uint32_t* actions() {
498  return this->actions_;
499  }
500  void types(uint32_t types) {
501  this->types_ = types;
502  }
503  void capabilities(uint32_t capabilities) {
504  this->capabilities_ = capabilities;
505  }
506  void max_groups(uint32_t max_groups[4]) {
507  memcpy(this->max_groups_, max_groups, 16);
508  }
509  void actions(uint32_t actions[4]) {
510  memcpy(this->actions_, actions, 16);
511  }
512 };
513 
515 protected:
516  uint16_t type_;
517  uint16_t length_;
518  uint8_t padding_;
519 public:
521  : length_(sizeof(struct ofp_table_feature_prop_header)),
522  padding_(4) {
523  }
524  TableFeatureProp(uint16_t type);
525  virtual ~TableFeatureProp() {
526  }
527  virtual bool equals(const TableFeatureProp & other);
528  virtual bool operator==(const TableFeatureProp &other) const;
529  virtual bool operator!=(const TableFeatureProp &other) const;
530  virtual TableFeatureProp* clone() {
531  return new TableFeatureProp(*this);
532  }
533  virtual size_t pack(uint8_t* buffer);
534  virtual of_error unpack(uint8_t* buffer);
535  uint16_t type() {
536  return this->type_;
537  }
538  uint16_t length() {
539  return this->length_;
540  }
541  uint8_t padding() {
542  return this->padding_;
543  }
544  void type(uint16_t type) {
545  this->type_ = type;
546  }
547  void length(uint16_t length) {
548  this->length_ = length;
549  }
550  static bool delete_all(TableFeatureProp * prop) {
551  delete prop;
552  return true;
553  }
554 };
555 
557 private:
558  std::vector<Instruction> instruction_ids_;
559 public:
561  : TableFeatureProp() {
562  }
563  TableFeaturePropInstruction(uint16_t type)
564  : TableFeatureProp(type) {
565  }
566  TableFeaturePropInstruction(uint16_t type,
567  std::vector<Instruction> instruction_ids);
569  }
570  virtual bool equals(const TableFeatureProp & other);
571  virtual TableFeaturePropInstruction* clone() {
572  return new TableFeaturePropInstruction(*this);
573  }
574  size_t pack(uint8_t* buffer);
575  of_error unpack(uint8_t* buffer);
576  std::vector<Instruction> instruction_ids() {
577  return this->instruction_ids_;
578  }
579  void instruction_ids(std::vector<Instruction> instruction_ids);
580 };
581 
583 private:
584  std::vector<uint8_t> next_table_ids_;
585 public:
587  : TableFeatureProp() {
588  }
589  TableFeaturePropNextTables(uint16_t type)
590  : TableFeatureProp(type) {
591  }
592  TableFeaturePropNextTables(uint16_t type,
593  std::vector<uint8_t> next_table_ids);
595  }
596  virtual bool equals(const TableFeatureProp & other);
597  virtual TableFeaturePropNextTables* clone() {
598  return new TableFeaturePropNextTables(*this);
599  }
600  size_t pack(uint8_t* buffer);
601  of_error unpack(uint8_t* buffer);
602  std::vector<uint8_t> next_table_ids() {
603  return this->next_table_ids_;
604  }
605  void table_ids(std::vector<uint8_t> table_ids);
606 };
607 
609 private:
610  std::vector<Action> action_ids_;
611 public:
613  : TableFeatureProp() {
614  }
615  TableFeaturePropActions(uint16_t type)
616  : TableFeatureProp(type) {
617  }
618  TableFeaturePropActions(uint16_t type, std::vector<Action> action_ids);
620  }
621  virtual bool equals(const TableFeatureProp & other);
622  virtual TableFeaturePropActions* clone() {
623  return new TableFeaturePropActions(*this);
624  }
625  size_t pack(uint8_t* buffer);
626  of_error unpack(uint8_t* buffer);
627  std::vector<Action> action_ids() {
628  return this->action_ids_;
629  }
630  void action_ids(std::vector<Action> action_ids);
631 };
632 
634 private:
635  std::vector<uint32_t> oxm_ids_;
636 public:
638  : TableFeatureProp() {
639  }
640  TableFeaturePropOXM(uint16_t type)
641  : TableFeatureProp(type) {
642  }
643  TableFeaturePropOXM(uint16_t type, std::vector<uint32_t> oxm_ids);
645  }
646  virtual bool equals(const TableFeatureProp & other);
647  virtual TableFeaturePropOXM* clone() {
648  return new TableFeaturePropOXM(*this);
649  }
650  size_t pack(uint8_t* buffer);
651  of_error unpack(uint8_t* buffer);
652  void oxm_ids(std::vector<uint32_t> oxm_ids);
653 };
654 
656 protected:
657  uint32_t experimenter_;
658  uint32_t exp_type_;
659 public:
661  : TableFeatureProp() {
662  }
663  TableFeaturePropExperimenter(uint16_t type)
664  : TableFeatureProp(type) {
665  }
666  TableFeaturePropExperimenter(uint16_t type, uint32_t experimenter,
667  uint32_t exp_type);
669  }
670  virtual bool equals(const TableFeatureProp & other);
671  size_t pack(uint8_t* buffer);
672  of_error unpack(uint8_t* buffer);
673 };
674 
676 private:
677  uint16_t length_;
678  std::list<TableFeatureProp*> property_list_;
679 public:
681  : length_(0) {
682  }
683  TablePropertiesList(std::list<TableFeatureProp*> property_list);
685  TablePropertiesList& operator=(TablePropertiesList other);
687  bool operator==(const TablePropertiesList &other) const;
688  bool operator!=(const TablePropertiesList &other) const;
689  size_t pack(uint8_t* buffer);
690  of_error unpack(uint8_t* buffer);
691  friend void swap(TablePropertiesList& first, TablePropertiesList& second);
692  uint16_t length() {
693  return this->length_;
694  }
695  std::list<TableFeatureProp*> property_list() {
696  return this->property_list_;
697  }
698  void property_list(std::list<TableFeatureProp*> property_list);
699  void length(uint16_t length) {
700  this->length_ = length;
701  }
702  void add_property(TableFeatureProp* prop);
703 };
704 
706 private:
707  uint16_t length_;
708  uint8_t table_id_;
709  std::string name_;
710  uint64_t metadata_match_;
711  uint64_t metadata_write_;
712  uint32_t config_;
713  uint32_t max_entries_;
714  TablePropertiesList properties_;
715 public:
716  TableFeatures()
717  : length_(sizeof(struct of13::ofp_table_features)) {
718  }
719  TableFeatures(uint8_t table_id, std::string name, uint64_t metadata_match,
720  uint64_t metadata_write, uint32_t config, uint32_t max_entries);
721  ~TableFeatures() {
722  }
723  bool operator==(const TableFeatures &other) const;
724  bool operator!=(const TableFeatures &other) const;
725  size_t pack(uint8_t* buffer);
726  of_error unpack(uint8_t* buffer);
727  uint16_t length();
728  uint8_t table_id() {
729  return this->table_id_;
730  }
731  std::string name() {
732  return this->name_;
733  }
734  uint64_t metadata_match() {
735  return this->metadata_match_;
736  }
737  uint64_t metadata_write() {
738  return this->metadata_write_;
739  }
740  uint32_t config() {
741  return this->config_;
742  }
743  uint32_t max_entries() {
744  return this->max_entries_;
745  }
746  TablePropertiesList properties() {
747  return this->properties_;
748  }
749  void table_id(uint8_t table_id) {
750  this->table_id_ = table_id;
751  }
752  void name(std::string name) {
753  this->name_ = name;
754  }
755  void metadata_match(uint64_t metadata_match) {
756  this->metadata_match_ = metadata_match;
757  }
758  void properties(TablePropertiesList properties);
759  void add_table_prop(TableFeatureProp* prop);
760  static TableFeatureProp* make_table_feature_prop(uint16_t type);
761 };
762 
763 } //End of namespace of13
764 } //End of namespace fluid_msg
765 
766 #endif