Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofmsg_stats.h
1 /*
2  * cofmsg_stats.h
3  *
4  * Created on: 18.03.2013
5  * Author: andi
6  */
7 
8 #ifndef COFMSG_STATS_H_
9 #define COFMSG_STATS_H_ 1
10 
11 #include "rofl/common/openflow/messages/cofmsg.h"
12 
13 namespace rofl {
14 namespace openflow {
15 
19 class cofmsg_stats :
20  public cofmsg
21 {
22 protected:
23 
24  cmemory body; // for experimental statistics messages
25 
26  union {
27  uint8_t* ofhu_stats_request;
28  struct openflow10::ofp_stats_request* ofhu10_stats_request;
29  struct openflow12::ofp_stats_request* ofhu12_stats_request;
30  struct openflow13::ofp_multipart_request* ofhu13_multipart_request;
31  } ofhu;
32 
33 #define ofh_stats_request ofhu.ofhu_stats_request
34 #define ofh10_stats_request ofhu.ofhu10_stats_request
35 #define ofh12_stats_request ofhu.ofhu12_stats_request
36 #define ofh13_multipart_request ofhu.ofhu13_multipart_request
37 
38 public:
39 
40 
45  uint8_t of_version = 0,
46  uint32_t xid = 0,
47  uint16_t stats_type = 0,
48  uint16_t stats_flags = 0,
49  uint8_t *data = (uint8_t*)0,
50  size_t datalen = 0);
51 
52 
57  cofmsg_stats const& stats);
58 
59 
64  operator= (
65  cofmsg_stats const& stats);
66 
67 
71  virtual
72  ~cofmsg_stats();
73 
74 
78  cofmsg_stats(cmemory *memarea);
79 
80 
84  virtual void
85  reset();
86 
87 
91  virtual uint8_t*
92  resize(size_t len);
93 
94 
98  virtual size_t
99  length() const;
100 
101 
105  virtual void
106  pack(uint8_t *buf = (uint8_t*)0, size_t buflen = 0);
107 
108 
112  virtual void
113  unpack(uint8_t *buf, size_t buflen);
114 
115 
118  virtual void
119  validate();
120 
121 
122 public:
123 
124 
128  uint16_t
129  get_stats_type() const;
130 
134  void
135  set_stats_type(uint16_t type);
136 
140  uint16_t
141  get_stats_flags() const;
142 
146  void
147  set_stats_flags(uint16_t flags);
148 
152  cmemory&
153  get_body();
154 
155 public:
156 
157  friend std::ostream&
158  operator<< (std::ostream& os, cofmsg_stats const& msg) {
159  std::string s_flags;
160  switch (msg.get_version()) {
161  case openflow10::OFP_VERSION: {
162  if (msg.get_stats_flags() & openflow10::OFPSF_REPLY_MORE)
163  s_flags.append("MORE ");
164  } break;
165  case openflow12::OFP_VERSION: {
166  if (msg.get_stats_flags() & openflow12::OFPSF_REPLY_MORE)
167  s_flags.append("MORE ");
168  } break;
169  case openflow13::OFP_VERSION: {
170  if (msg.get_stats_flags() & openflow13::OFPMPF_REPLY_MORE)
171  s_flags.append("MORE ");
172  } break;
173  default: {
174  s_flags.append("unsupported OF version");
175  } break;
176  }
177  os << dynamic_cast<cofmsg const&>( msg );
178  os << indent(2) << "<cofmsg_stats ";
179  os << "type:" << (int)msg.get_stats_type() << " ";
180  os << "flags:" << s_flags << " ";
181  os << ">" << std::endl;;
182  return os;
183  };
184 };
185 
186 
188  public cofmsg_stats
189 {
190 public:
191 
196  uint8_t of_version = 0,
197  uint32_t xid = 0,
198  uint16_t stats_type = 0,
199  uint16_t stats_flags = 0,
200  uint8_t *data = (uint8_t*)0,
201  size_t datalen = 0) :
202  cofmsg_stats(of_version, xid, stats_type, stats_flags, data, datalen)
203  {
204  switch (of_version) {
205  case openflow::OFP_VERSION_UNKNOWN: {
206 
207  } break;
208  case openflow10::OFP_VERSION: {
209  set_type(openflow10::OFPT_STATS_REQUEST);
210  } break;
211  case openflow12::OFP_VERSION: {
212  set_type(openflow12::OFPT_STATS_REQUEST);
213  } break;
214  case openflow13::OFP_VERSION: {
215  set_type(openflow13::OFPT_MULTIPART_REQUEST);
216  } break;
217  default:
218  throw eBadVersion();
219  }
220  };
221 
222 
227  cofmsg_stats_request const& request)
228  {
229  *this = request;
230  };
231 
232 
236  cofmsg_stats&
237  operator= (
238  cofmsg_stats_request const& request)
239  {
240  if (this == &request)
241  return *this;
242 
243  cofmsg_stats::operator= (request);
244 
245  return *this;
246  };
247 
248 
252  virtual
254 
255 
259  cofmsg_stats_request(cmemory *memarea) :
260  cofmsg_stats(memarea) {};
261 
262 };
263 
265  public cofmsg_stats
266 {
267 public:
268 
269 
274  uint8_t of_version = 0,
275  uint32_t xid = 0,
276  uint16_t stats_type = 0,
277  uint16_t stats_flags = 0,
278  uint8_t *data = (uint8_t*)0,
279  size_t datalen = 0) :
280  cofmsg_stats(of_version, xid, stats_type, stats_flags, data, datalen)
281  {
282  switch (of_version) {
283  case openflow::OFP_VERSION_UNKNOWN: {
284 
285  } break;
286  case openflow10::OFP_VERSION: {
287  set_type(openflow10::OFPT_STATS_REPLY);
288  } break;
289  case openflow12::OFP_VERSION: {
290  set_type(openflow12::OFPT_STATS_REPLY);
291  } break;
292  case openflow13::OFP_VERSION: {
293  set_type(openflow13::OFPT_MULTIPART_REPLY);
294  } break;
295  default:
296  throw eBadVersion();
297  }
298  };
299 
300 
305  cofmsg_stats_reply const& reply)
306  {
307  *this = reply;
308  };
309 
310 
314  cofmsg_stats&
315  operator= (
316  cofmsg_stats_reply const& reply)
317  {
318  if (this == &reply)
319  return *this;
320 
321  cofmsg_stats::operator= (reply);
322 
323  return *this;
324  };
325 
326 
330  virtual
332 
333 
337  cofmsg_stats_reply(cmemory *memarea) :
338  cofmsg_stats(memarea) {};
339 
340 };
341 
342 typedef cofmsg_stats_request cofmsg_multipart_request;
343 typedef cofmsg_stats_reply cofmsg_multipart_reply;
344 
345 }; // end of namespace openflow
346 }; // end of namespace rofl
347 
348 #endif /* COFMSG_STATS_H_ */
cofmsg_stats(uint8_t of_version=0, uint32_t xid=0, uint16_t stats_type=0, uint16_t stats_flags=0, uint8_t *data=(uint8_t *) 0, size_t datalen=0)
Definition: cofmsg_stats.cc:5
virtual ~cofmsg_stats()
Definition: cofmsg_stats.cc:101
Definition: croflexception.h:73
virtual ~cofmsg_stats_request()
Definition: cofmsg_stats.h:253
virtual void pack(uint8_t *buf=(uint8_t *) 0, size_t buflen=0)
Definition: cofmsg_stats.cc:147
cofmsg_stats_request(uint8_t of_version=0, uint32_t xid=0, uint16_t stats_type=0, uint16_t stats_flags=0, uint8_t *data=(uint8_t *) 0, size_t datalen=0)
Definition: cofmsg_stats.h:195
virtual void reset()
Definition: cofmsg_stats.cc:109
Definition: cofmsg_stats.h:264
virtual void validate()
Definition: cofmsg_stats.cc:214
virtual size_t length() const
Definition: cofmsg_stats.cc:126
Definition: cofmsg_stats.h:187
Definition: cofmsg_stats.h:19
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
virtual void unpack(uint8_t *buf, size_t buflen)
Definition: cofmsg_stats.cc:184
virtual ~cofmsg_stats_reply()
Definition: cofmsg_stats.h:331
cofmsg_stats_reply(uint8_t of_version=0, uint32_t xid=0, uint16_t stats_type=0, uint16_t stats_flags=0, uint8_t *data=(uint8_t *) 0, size_t datalen=0)
Definition: cofmsg_stats.h:273
Definition: logging.h:76
Definition: openflow12.h:1292
Definition: openflow13.h:1026
Definition: openflow10.h:759
Definition: cofmsg.h:62