Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofports.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 COFPORTS_H_
6 #define COFPORTS_H_ 1
7 
8 #include <algorithm>
9 
10 #include "rofl/common/croflexception.h"
11 #include "rofl/common/openflow/openflow.h"
12 #include "rofl/common/openflow/cofport.h"
13 
14 namespace rofl {
15 namespace openflow {
16 
17 class ePortsBase : public RoflException {}; // base error class cofinlist
18 class ePortsInval : public ePortsBase {}; // invalid parameter
19 class ePortsNotFound : public ePortsBase {}; // element not found
20 class ePortsOutOfRange : public ePortsBase {}; // out of range
21 
22 class cofports
23 {
24  uint8_t ofp_version;
25  std::map<uint32_t, cofport*> ports;
26 
27 public: // methods
28 
32  cofports(
33  uint8_t ofp_version = openflow::OFP_VERSION_UNKNOWN);
34 
38  virtual
39  ~cofports();
40 
44  cofports(
45  uint8_t ofp_version, uint8_t *buf, size_t buflen);
46 
50  cofports(
51  cofports const& ports);
52 
56  cofports&
57  operator= (
58  cofports const& ports);
59 
63  cofports&
64  operator+= (
65  cofports const& ports);
66 
67 public:
68 
72  void
73  clear();
74 
75 
79  void
80  unpack(uint8_t *buf, size_t buflen);
81 
82 
86  void
87  pack(uint8_t* buf, size_t buflen);
88 
89 
93  size_t
94  length() const;
95 
96 public:
97 
101  uint8_t
102  get_version() const { return ofp_version; };
103 
107  void
108  set_version(uint8_t ofp_version) { this->ofp_version = ofp_version; };
109 
113  std::map<uint32_t, cofport*>&
114  set_ports() { return ports; };
115 
119  std::map<uint32_t, cofport*> const&
120  get_ports() const { return ports; };
121 
122 public:
123 
127  cofport&
128  add_port(uint32_t portno);
129 
133  cofport&
134  set_port(uint32_t portno);
135 
139  cofport&
140  set_port(const std::string& devname);
141 
145  cofport&
146  set_port(const rofl::caddress_ll& hwaddr);
147 
151  cofport const&
152  get_port(uint32_t portno) const;
153 
157  cofport const&
158  get_port(const std::string& devname) const;
159 
163  cofport const&
164  get_port(const rofl::caddress_ll& hwaddr) const;
165 
169  void
170  drop_port(uint32_t portno);
171 
175  void
176  drop_port(const std::string& devname);
177 
181  void
182  drop_port(const rofl::caddress_ll& hwaddr);
183 
187  bool
188  has_port(uint32_t portno) const;
189 
193  bool
194  has_port(const std::string& devname) const;
195 
199  bool
200  has_port(const rofl::caddress_ll& hwaddr) const;
201 
202 public:
203 
204  friend std::ostream&
205  operator<< (std::ostream& os, cofports const& ports) {
206  os << rofl::indent(0) << "<cofports #ports:" << (int)ports.get_ports().size() << " >" << std::endl;;
207  rofl::indent i(2);
208  for (std::map<uint32_t, cofport*>::const_iterator
209  it = ports.get_ports().begin(); it != ports.get_ports().end(); ++it) {
210  os << *(it->second);
211  }
212  return os;
213  };
214 };
215 
216 }; // end of namespace openflow
217 }; // end of namespace rofl
218 
219 #endif
Definition: cofports.h:19
Definition: caddress.h:152
Definition: cofports.h:20
Definition: cofports.h:22
Definition: cofports.h:17
Definition: cofports.h:18
Definition: logging.h:76
Definition: cofport.h:52
size_t length() const
Definition: cofports.cc:94
Definition: croflexception.h:27