Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofport.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 COFPORT_H
6 #define COFPORT_H 1
7 
8 #include <map>
9 #include <limits>
10 
11 #include <string.h>
12 #include <endian.h>
13 #include <inttypes.h>
14 #ifndef htobe16
15  #include "../endian_conversion.h"
16 #endif
17 
18 #include "rofl/common/openflow/openflow_common.h"
19 #include "rofl/common/openflow/openflow.h"
20 #include "rofl/common/cmemory.h"
21 #include "rofl/common/croflexception.h"
22 #include "rofl/common/caddress.h"
23 #include "rofl/common/openflow/openflow_rofl_exceptions.h"
24 #include "rofl/common/openflow/cofportstats.h"
25 
26 
27 
28 #ifndef OFPP_UNSPECIFIED
29 #define OFPP_UNSPECIFIED 0
30 #endif
31 
32 
33 
34 namespace rofl {
35 namespace openflow {
36 
37 class ePortBase : public RoflException {
38 public:
39  ePortBase(const std::string& __arg) : RoflException(__arg) {};
40 };
41 class ePortInval : public ePortBase {
42 public:
43  ePortInval(const std::string& __arg) : ePortBase(__arg) {};
44 };
45 class ePortNotFound : public ePortBase {
46 public:
47  ePortNotFound(const std::string& __arg) : ePortBase(__arg) {};
48 };
49 
50 
51 
52 class cofport : public cmemory
53 {
54 private: // data structures
55 
56  uint8_t ofp_version; // OpenFlow version of port stored (openflow10::OFP_VERSION, openflow12::OFP_VERSION, ...)
58 
59 public: // data structures
60 
61  union {
62  uint8_t *ofpu_port;
63  struct openflow10::ofp_port *ofpu10_port;
64  struct openflow12::ofp_port *ofpu12_port;
65  struct openflow13::ofp_port *ofpu13_port;
66  } ofp_ofpu;
67 
68 #define ofh_port ofp_ofpu.ofpu_port
69 #define ofh10_port ofp_ofpu.ofpu10_port
70 #define ofh12_port ofp_ofpu.ofpu12_port
71 #define ofh13_port ofp_ofpu.ofpu13_port
72 
73 
74 /*
75  * methods
76  */
77 public:
78 
79 
83  cofport(
84  uint8_t of_version = openflow::OFP_VERSION_UNKNOWN);
85 
86 
90  cofport(
91  uint8_t ofp_version, uint8_t *buf, size_t buflen);
92 
93 
97  cofport(
98  cofport const& port);
99 
100 
104  cofport&
105  operator= (
106  cofport const& port);
107 
108 
112  virtual
113  ~cofport();
114 
115 public:
116 
120  void
121  pack(
122  uint8_t *buf, size_t buflen);
123 
124 
125 
129  void
130  unpack(
131  uint8_t *buf, size_t buflen);
132 
136  size_t
137  length() const;
138 
139 
144  get_port_stats();
145 
146 
150  uint8_t
151  get_version() const;
152 
153 
154 public:
155 
156 
159  uint32_t
160  get_port_no() const;
161 
162 
165  void
166  set_port_no(uint32_t port_no);
167 
168 
171  cmacaddr
172  get_hwaddr() const;
173 
174 
177  void
178  set_hwaddr(cmacaddr const& maddr);
179 
180 
183  std::string
184  get_name() const;
185 
186 
189  void
190  set_name(std::string name);
191 
194  uint32_t
195  get_config() const;
196 
197 
200  void
201  set_config(uint32_t config);
202 
205  uint32_t
206  get_state() const;
207 
208 
211  void
212  set_state(uint32_t state);
213 
214 
217  uint32_t
218  get_curr() const;
219 
220 
223  void
224  set_curr(uint32_t curr);
225 
226 
229  uint32_t
230  get_advertised() const;
231 
232 
235  void
236  set_advertised(uint32_t advertised);
237 
238 
241  uint32_t
242  get_supported() const;
243 
244 
247  void
248  set_supported(uint32_t supported);
249 
250 
253  uint32_t
254  get_peer() const;
255 
256 
259  void
260  set_peer(uint32_t peer);
261 
262 
265  uint32_t
266  get_curr_speed() const;
267 
268 
271  void
272  set_curr_speed(uint32_t curr_speed);
273 
274 
277  uint32_t
278  get_max_speed() const;
279 
280 
283  void
284  set_max_speed(uint32_t max_speed);
285 
286 
290  virtual void
291  link_state_set_blocked();
292 
293 
297  virtual void
298  link_state_clr_blocked();
299 
300 
304  virtual bool
305  link_state_is_blocked() const;
306 
307 
311  virtual void
312  link_state_set_live();
313 
314 
318  virtual void
319  link_state_clr_live();
320 
321 
325  virtual bool
326  link_state_is_live() const;
327 
328 
332  virtual void
333  link_state_set_link_down();
334 
335 
339  virtual void
340  link_state_clr_link_down();
341 
342 
346  virtual bool
347  link_state_is_link_down() const;
348 
349 
353  virtual void
354  link_state_phy_down();
355 
356 
360  virtual void
361  link_state_phy_up();
362 
363 
367  bool
368  link_state_phy_is_up() const;
369 
370 
374  bool
375  config_is_port_down() const;
376 
377 
381  virtual void
382  recv_port_mod(
383  uint32_t config,
384  uint32_t mask,
385  uint32_t advertise);
386 
387 private:
388 
392  virtual uint8_t*
393  resize(size_t len);
394 
395 
399  virtual void
400  recv_port_mod_of10(
401  uint32_t config,
402  uint32_t mask,
403  uint32_t advertise);
404 
405 
409  virtual void
410  recv_port_mod_of12(
411  uint32_t config,
412  uint32_t mask,
413  uint32_t advertise);
414 
415 
419  virtual void
420  recv_port_mod_of13(
421  uint32_t config,
422  uint32_t mask,
423  uint32_t advertise);
424 
425 
426 
427 
428 public:
429 
430 
431  friend std::ostream&
432  operator<< (std::ostream& os, cofport const& port) {
433  switch (port.ofp_version) {
434  case openflow10::OFP_VERSION: {
435  os << indent(0) << "<cofport >" << std::endl;
436  os << indent(2) << "<portno:" << (int)port.get_port_no() << " >" << std::endl;
437  os << indent(2) << "<hwaddr: >" << std::endl;
438  { rofl::indent i(4); os << port.get_hwaddr(); }
439  os << indent(2) << "<name:" << port.get_name() << " >" << std::endl;
440  os << indent(2) << "<config:" << (int)port.get_config() << " >" << std::endl;
441  os << indent(2) << "<state:" << (int)port.get_state() << " >" << std::endl;
442  os << indent(2) << "<curr:" << (int)port.get_curr() << " >" << std::endl;
443  os << indent(2) << "<advertised:" << (int)port.get_advertised() << " >" << std::endl;
444  os << indent(2) << "<supported:" << (int)port.get_supported() << " >" << std::endl;
445  os << indent(2) << "<peer:" << (int)port.get_peer() << " >" << std::endl;
446  } break;
447  case openflow12::OFP_VERSION: {
448  os << indent(0) << "<cofport >" << std::endl;
449  os << indent(2) << "<portno:" << (int)port.get_port_no() << " >" << std::endl;
450  os << indent(2) << "<hwaddr: >" << std::endl;
451  { rofl::indent i(4); os << port.get_hwaddr(); }
452  os << indent(2) << "<name:" << port.get_name() << " >" << std::endl;
453  os << indent(2) << "<config:" << (int)port.get_config() << " >" << std::endl;
454  os << indent(2) << "<state:" << (int)port.get_state() << " >" << std::endl;
455  os << indent(2) << "<curr:" << (int)port.get_curr() << " >" << std::endl;
456  os << indent(2) << "<advertised:" << (int)port.get_advertised() << " >" << std::endl;
457  os << indent(2) << "<supported:" << (int)port.get_supported() << " >" << std::endl;
458  os << indent(2) << "<peer:" << (int)port.get_peer() << " >" << std::endl;
459  os << indent(2) << "<curr-speed:" << (int)port.get_curr_speed() << " >" << std::endl;
460  os << indent(2) << "<max-speed:" << (int)port.get_max_speed() << " >" << std::endl;
461  os << indent(2) << "<state-blocked:" << (int)port.link_state_is_blocked() << " >" << std::endl;
462  os << indent(2) << "<state-live:" << (int)port.link_state_is_live() << " >" << std::endl;
463  os << indent(2) << "<state-link-down:" << (int)port.link_state_is_link_down() << " >" << std::endl;
464  os << indent(2) << "<config-port-down:" << (int)port.config_is_port_down() << " >" << std::endl;
465  } break;
466  case openflow13::OFP_VERSION: {
467  os << indent(0) << "<cofport >" << std::endl;
468  os << indent(2) << "<portno:" << (int)port.get_port_no() << " >" << std::endl;
469  os << indent(2) << "<hwaddr: >" << std::endl;
470  { rofl::indent i(4); os << port.get_hwaddr(); }
471  os << indent(2) << "<name:" << port.get_name() << " >" << std::endl;
472  os << indent(2) << "<config:" << (int)port.get_config() << " >" << std::endl;
473  os << indent(2) << "<state:" << (int)port.get_state() << " >" << std::endl;
474  os << indent(2) << "<curr:" << (int)port.get_curr() << " >" << std::endl;
475  os << indent(2) << "<advertised:" << (int)port.get_advertised() << " >" << std::endl;
476  os << indent(2) << "<supported:" << (int)port.get_supported() << " >" << std::endl;
477  os << indent(2) << "<peer:" << (int)port.get_peer() << " >" << std::endl;
478  os << indent(2) << "<curr-speed:" << (int)port.get_curr_speed() << " >" << std::endl;
479  os << indent(2) << "<max-speed:" << (int)port.get_max_speed() << " >" << std::endl;
480  os << indent(2) << "<state-blocked:" << (int)port.link_state_is_blocked() << " >" << std::endl;
481  os << indent(2) << "<state-live:" << (int)port.link_state_is_live() << " >" << std::endl;
482  os << indent(2) << "<state-link-down:" << (int)port.link_state_is_link_down() << " >" << std::endl;
483  os << indent(2) << "<config-port-down:" << (int)port.config_is_port_down() << " >" << std::endl;
484  } break;
485  default: {
486  os << "<cofport unknown OFP version>" << std::endl;
487  };
488  }
489  return os;
490  };
491 };
492 
493 
495  uint32_t port_no;
496 public:
497  cofport_find_by_port_no(uint32_t _port_no) :
498  port_no(_port_no) {};
499  bool operator() (cofport *ofport) {
500  return (ofport->get_port_no() == port_no);
501  };
502  bool operator() (std::pair<uint32_t, cofport*> const& p) {
503  return (p.second->get_port_no() == port_no);
504  };
505 };
506 
507 
509  std::string port_name;
510 public:
511  cofport_find_by_port_name(std::string _port_name) :
512  port_name(_port_name) {};
513  bool operator() (cofport *ofport) {
514  std::string name(ofport->get_name());
515  return (name == port_name);
516  };
517  bool operator() (std::pair<uint32_t, cofport*> const& p) {
518  std::string name(p.second->get_name());
519  return (name == port_name);
520  };
521 };
522 
523 
524 
526  cmacaddr maddr;
527 public:
528  cofport_find_by_maddr(cmacaddr const& maddr) :
529  maddr(maddr) {};
530  bool operator() (cofport *ofport) {
531  cmacaddr hwaddr(ofport->get_hwaddr());
532  return (maddr == hwaddr);
533  };
534  bool operator() (std::pair<uint32_t, cofport*> const& p) {
535  cmacaddr hwaddr(p.second->get_hwaddr());
536  return (maddr == hwaddr);
537  };
538 };
539 
540 
542 public:
543  cofport_find_port_no(uint32_t port_no) :
544  port_no(port_no) {};
545  bool operator() (cofport const& ofport) {
546  return (ofport.get_port_no() == port_no);
547  };
548  uint32_t port_no;
549 };
550 
551 }; // end of namespace openflow
552 }; // end of namespace rofl
553 
554 #endif
Definition: caddress.h:152
Definition: cofport.h:45
Definition: cofport.h:525
Definition: openflow12.h:288
Definition: openflow10.h:243
Definition: cofport.h:41
void pack(uint8_t *buf, size_t buflen)
Copies content of this cmemory instance to specified buffer.
Definition: cofport.cc:103
void unpack(uint8_t *buf, size_t buflen)
Copies content of specified buffer into this cmemory instance .
Definition: cofport.cc:115
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: cofport.h:37
Definition: cofportstats.h:125
Definition: openflow13.h:116
Definition: logging.h:76
Definition: cofport.h:52
Definition: cofport.h:541
Definition: croflexception.h:27