libfluid
The ONF OpenFlow driver
msg.hh
1 #ifndef MSG_H
2 #define MSG_H 1
3 
4 #include <fluid/util/ethaddr.hh>
5 #include "action.hh"
6 #include "openflow-common.hh"
7 
8 
9 namespace fluid_msg {
10 class Action;
11 }
12 
13 namespace fluid_msg {
17 class OFMsg {
18 protected:
19  uint8_t version_;
20  uint8_t type_;
21  uint16_t length_;
22  uint32_t xid_;
23 public:
24  OFMsg(uint8_t version, uint8_t type);
25  OFMsg(uint8_t version, uint8_t type, uint32_t xid);
26  OFMsg(uint8_t* buffer) {
27  unpack(buffer);
28  }
29  virtual ~OFMsg() {
30  }
31  virtual uint8_t* pack();
32  virtual of_error unpack(uint8_t *buffer);
33  bool operator==(const OFMsg &other) const;
34  bool operator!=(const OFMsg &other) const;
35  uint8_t version() {
36  return this->version_;
37  }
38  uint8_t type() {
39  return this->type_;
40  }
41  //Length is virtual because we need to override
42  //it in some classes where the length is padding
43  // dependent (e.g OpenFlow 1.3 Flow Mod).
44  virtual uint16_t length() {
45  return this->length_;
46  }
47  uint32_t xid() {
48  return this->xid_;
49  }
50  void version(uint8_t version) {
51  this->version_ = version;
52  }
53  void msg_type(uint8_t type) {
54  this->type_ = type;
55  }
56  void length(uint16_t length) {
57  this->length_ = length;
58  }
59  void xid(uint32_t xid) {
60  this->xid_ = xid;
61  }
62  static void free_buffer(uint8_t *buffer) {
63  delete[] buffer;
64  }
65 };
66 
70 class EchoCommon: public OFMsg {
71 private:
72  void *data_;
73  size_t data_len_;
74 public:
75  EchoCommon(uint8_t version, uint8_t type);
76  EchoCommon(uint8_t version, uint8_t type, uint32_t xid)
77  : OFMsg(version, type, xid),
78  data_(NULL),
79  data_len_(0) {
80  }
81  virtual ~EchoCommon();
82  uint8_t* pack();
83  of_error unpack(uint8_t *buffer);
84  bool operator==(const EchoCommon &other) const;
85  bool operator!=(const EchoCommon &other) const;
86  void* data() {
87  return this->data_;
88  }
89  size_t data_len() {
90  return this->data_len_;
91  }
92  void data(void* data, size_t data_len);
93 };
94 
98 class ErrorCommon: public OFMsg {
99 protected:
100  uint16_t err_type_;
101  uint16_t code_;
102  void* data_;
103  size_t data_len_;
104 public:
105  ErrorCommon(uint8_t version, uint8_t type);
106  ErrorCommon(uint8_t version, uint8_t type, uint32_t xid, uint16_t err_type,
107  uint16_t code);
108  ErrorCommon(uint8_t version, uint8_t type, uint32_t xid, uint16_t err_type,
109  uint16_t code, void* data, size_t data_len);
110  virtual ~ErrorCommon();
111  bool operator==(const ErrorCommon &other) const;
112  bool operator!=(const ErrorCommon &other) const;
113  uint8_t* pack();
114  of_error unpack(uint8_t *buffer);
115  uint16_t err_type() {
116  return this->err_type_;
117  }
118  uint16_t code() {
119  return this->code_;
120  }
121  void* data() {
122  return this->data_;
123  }
124  size_t data_len() {
125  return this->data_len_;
126  }
127  void err_type(uint16_t err_type) {
128  this->err_type_ = err_type;
129  }
130  void code(uint16_t code) {
131  this->code_ = code;
132  }
133  void data(void* data, size_t data_len);
134 };
135 
139 class FeaturesReplyCommon: public OFMsg {
140 protected:
141  uint64_t datapath_id_;
142  uint32_t n_buffers_;
143  uint8_t n_tables_;
144  uint32_t capabilities_;
145 public:
146  FeaturesReplyCommon(uint8_t version, uint8_t type);
147  FeaturesReplyCommon(uint8_t version, uint8_t type, uint32_t xid,
148  uint64_t datapath_id, uint32_t n_buffers, uint8_t n_tables,
149  uint32_t capabilities);
150  virtual ~FeaturesReplyCommon() {
151  }
152  bool operator==(const FeaturesReplyCommon &other) const;
153  bool operator!=(const FeaturesReplyCommon &other) const;
154  uint64_t datapath_id() {
155  return this->datapath_id_;
156  }
157  uint32_t n_buffers() {
158  return this->n_buffers_;
159  }
160  uint8_t n_tables() {
161  return this->n_tables_;
162  }
163  uint32_t capabilities() {
164  return this->capabilities_;
165  }
166  void datapath_id(uint64_t datapath_id) {
167  this->datapath_id_ = datapath_id;
168  }
169  void n_buffers(uint32_t n_buffers) {
170  this->n_buffers_ = n_buffers;
171  }
172  void n_tables(uint8_t n_tables) {
173  this->n_tables_ = n_tables;
174  }
175  void capabilities(uint32_t capabilities) {
176  this->capabilities_ = capabilities;
177  }
178 };
179 
183 class SwitchConfigCommon: public OFMsg {
184 private:
185  uint16_t flags_;
186  uint16_t miss_send_len_;
187 public:
188  SwitchConfigCommon(uint8_t version, uint8_t type);
189  SwitchConfigCommon(uint8_t version, uint8_t type, uint32_t xid,
190  uint16_t flags, uint16_t miss_send_len);
191  virtual ~SwitchConfigCommon() {
192  }
193  bool operator==(const SwitchConfigCommon &other) const;
194  bool operator!=(const SwitchConfigCommon &other) const;
195  uint8_t* pack();
196  of_error unpack(uint8_t *buffer);
197  uint16_t flags() {
198  return this->flags_;
199  }
200  uint16_t miss_send_len() {
201  return this->miss_send_len_;
202  }
203  void flags(uint16_t flags) {
204  this->flags_ = flags;
205  }
206  void miss_send_len(uint16_t miss_send_len) {
207  this->miss_send_len_ = miss_send_len;
208  }
209 };
210 
214 class FlowModCommon: public OFMsg {
215 protected:
216  uint64_t cookie_;
217  uint16_t idle_timeout_;
218  uint16_t hard_timeout_;
219  uint16_t priority_;
220  uint32_t buffer_id_;
221  uint16_t flags_;
222 
223 public:
224  FlowModCommon(uint8_t version, uint8_t type);
225  FlowModCommon(uint8_t version, uint8_t type, uint32_t xid, uint64_t cookie,
226  uint16_t idle_timeout, uint16_t hard_timeout,
227  uint16_t priority, uint32_t buffer_id, uint16_t flags);
228  virtual ~FlowModCommon() {
229  }
230  ;
231  bool operator==(const FlowModCommon &other) const;
232  bool operator!=(const FlowModCommon &other) const;
233  uint64_t cookie() {
234  return this->cookie_;
235  }
236  uint16_t idle_timeout() {
237  return this->idle_timeout_;
238  }
239  uint16_t hard_timeout() {
240  return this->hard_timeout_;
241  }
242  uint16_t priority() {
243  return this->priority_;
244  }
245  uint32_t buffer_id() {
246  return this->buffer_id_;
247  }
248  uint16_t flags() {
249  return this->flags_;
250  }
251  void cookie(uint64_t cookie) {
252  this->cookie_ = cookie;
253  }
254  void idle_timeout(uint16_t idle_timeout) {
255  this->idle_timeout_ = idle_timeout;
256  }
257  void hard_timeout(uint16_t hard_timeout) {
258  this->hard_timeout_ = hard_timeout;
259  }
260  void priority(uint16_t priority) {
261  this->priority_ = priority;
262  }
263  void buffer_id(uint32_t buffer_id) {
264  this->buffer_id_ = buffer_id;
265  }
266  void flags(uint16_t flags) {
267  this->flags_ = flags;
268  }
269 };
270 
274 class PacketOutCommon: public OFMsg {
275 protected:
276  uint32_t buffer_id_;
277  uint16_t actions_len_;
278  ActionList actions_;
279  void* data_;
280  size_t data_len_;
281 public:
282  PacketOutCommon(uint8_t version, uint8_t type);
283  PacketOutCommon(uint8_t version, uint16_t type, uint32_t xid,
284  uint32_t buffer_id);
285  virtual ~PacketOutCommon();
286  bool operator==(const PacketOutCommon &other) const;
287  bool operator!=(const PacketOutCommon &other) const;
288  uint32_t buffer_id() {
289  return this->buffer_id_;
290  }
291  uint16_t actions_len() {
292  return this->actions_len_;
293  }
294  ActionList actions() {
295  return this->actions_;
296  }
297  size_t data_len() {
298  return this->data_len_;
299  }
300  void* data() {
301  return this->data_;
302  }
303  void buffer_id(uint32_t buffer_id) {
304  this->buffer_id_ = buffer_id;
305  }
306  void actions(ActionList actions);
307  void add_action(Action &action);
308  void add_action(Action *action);
309  void data(void* data, size_t len);
310 };
311 
315 class PacketInCommon: public OFMsg {
316 protected:
317  uint32_t buffer_id_;
318  uint16_t total_len_;
319  uint8_t reason_;
320  size_t data_len_;
321  void* data_;
322 public:
323  PacketInCommon(uint8_t version, uint8_t type);
324  PacketInCommon(uint8_t version, uint8_t type, uint32_t xid,
325  uint32_t buffer_id, uint16_t total_len, uint8_t reason);
326  virtual ~PacketInCommon();
327  bool operator==(const PacketInCommon &other) const;
328  bool operator!=(const PacketInCommon &other) const;
329  uint32_t buffer_id() {
330  return this->buffer_id_;
331  }
332  uint16_t total_len() {
333  return this->total_len_;
334  }
335  uint8_t reason() {
336  return this->reason_;
337  }
338  void* data() {
339  return this->data_;
340  }
341  size_t data_len() {
342  return this->data_len_;
343  }
344  void buffer_id(uint32_t buffer_id) {
345  this->buffer_id_ = buffer_id;
346  }
347  void total_len(uint16_t total_len) {
348  this->total_len_ = total_len;
349  }
350  void reason(uint8_t reason) {
351  this->reason_ = reason;
352  }
353  void data(void* data, size_t len);
354 };
355 
359 class FlowRemovedCommon: public OFMsg {
360 protected:
361  uint64_t cookie_;
362  uint16_t priority_;
363  uint8_t reason_;
364  uint32_t duration_sec_;
365  uint32_t duration_nsec_;
366  uint16_t idle_timeout_;
367  uint64_t packet_count_;
368  uint64_t byte_count_;
369 public:
370  FlowRemovedCommon(uint8_t version, uint8_t type);
371  FlowRemovedCommon(uint8_t version, uint8_t type, uint32_t xid,
372  uint64_t cookie, uint16_t priority, uint8_t reason,
373  uint32_t duration_sec, uint32_t duration_nsec, uint16_t idle_timeout,
374  uint64_t packet_count, uint64_t byte_count);
375  virtual ~FlowRemovedCommon() {
376  }
377  bool operator==(const FlowRemovedCommon &other) const;
378  bool operator!=(const FlowRemovedCommon &other) const;
379  uint64_t cookie() {
380  return this->cookie_;
381  }
382  uint16_t priority() {
383  return this->priority_;
384  }
385  uint8_t reason() {
386  return this->reason_;
387  }
388  uint32_t duration_sec() {
389  return this->duration_sec_;
390  }
391  uint32_t duration_nsec() {
392  return this->duration_nsec_;
393  }
394  uint64_t packet_count() {
395  return this->packet_count_;
396  }
397  uint64_t byte_count() {
398  return this->byte_count_;
399  }
400  void cookie(uint64_t cookie) {
401  this->cookie_ = cookie;
402  }
403  void priority(uint16_t priority) {
404  this->priority_ = priority;
405  }
406  void reason(uint8_t reason) {
407  this->reason_ = reason;
408  }
409  void duration_sec(uint32_t duration_sec) {
410  this->duration_sec_ = duration_sec;
411  }
412  void duration_nsec(uint32_t duration_nsec) {
413  this->duration_nsec_ = duration_nsec;
414  }
415  void idle_timeout(uint16_t idle_timeout) {
416  this->idle_timeout_ = idle_timeout;
417  }
418  void packet_count(uint64_t packet_count) {
419  this->packet_count_ = packet_count;
420  }
421  void byte_count(uint64_t byte_count) {
422  this->byte_count_ = byte_count;
423  }
424 };
425 
429 class PortStatusCommon: public OFMsg {
430 protected:
431  uint8_t reason_;
432 public:
433  PortStatusCommon(uint8_t version, uint8_t type);
434  PortStatusCommon(uint8_t version, uint8_t type, uint32_t xid,
435  uint8_t reason);
436  virtual ~PortStatusCommon() {
437  }
438  bool operator==(const PortStatusCommon &other) const;
439  bool operator!=(const PortStatusCommon &other) const;
440  uint8_t reason() {
441  return this->reason_;
442  }
443  void reason(uint8_t reason) {
444  this->reason_ = reason;
445  }
446 };
447 
451 class PortModCommon: public OFMsg {
452 protected:
453  EthAddress hw_addr_;
454  uint32_t config_;
455  uint32_t mask_;
456  uint32_t advertise_;
457 public:
458  PortModCommon(uint8_t version, uint8_t type);
459  PortModCommon(uint8_t version, uint8_t type, uint32_t xid,
460  EthAddress hw_addr, uint32_t config, uint32_t mask, uint32_t advertise);
461  virtual ~PortModCommon() {
462  }
463  bool operator==(const PortModCommon &other) const;
464  bool operator!=(const PortModCommon &other) const;
465  EthAddress hw_addr() {
466  return this->hw_addr_;
467  }
468  uint32_t config() {
469  return this->config_;
470  }
471  uint32_t mask() {
472  return this->mask_;
473  }
474  uint32_t advertise() {
475  return this->advertise_;
476  }
477  void hw_addr(EthAddress hw_addr) {
478  this->hw_addr_ = hw_addr;
479  }
480  void config(uint32_t config) {
481  this->config_ = config;
482  }
483  void mask(uint32_t mask) {
484  this->mask_ = mask;
485  }
486  void advertise(uint32_t advertise) {
487  this->advertise_ = advertise;
488  }
489 };
490 
491 } //End of namespace fluid_msg
492 #endif
493