Revised OpenFlow Library  v0.6.0dev
 All Classes Files Functions Variables Friends Groups Pages
cofstats.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 /*
6  * cofstats.h
7  *
8  * Created on: 11.10.2012
9  * Author: andreas
10  */
11 
12 #ifndef COFSTATS_H
13 #define COFSTATS_H 1
14 
15 #include "rofl/common/croflexception.h"
16 #include "rofl/common/cmemory.h"
17 #include "rofl/common/openflow/cofmatch.h"
18 
19 namespace rofl {
20 namespace openflow {
21 
22 class eOFstatsBase : public RoflException {};
23 class eOFstatsTooShort : public eOFstatsBase {};
24 
25 
26 class cofstats
27 {
28 /*
29  * data structures
30  */
31 private:
32 
33  std::string info;
34 
35 protected:
36 
37  cmemory packed; // packed cofstats body
38 
39 public:
40 
41  cmemory body; // fixed part of OpenFlow statistics body
42  cofmatch match; // match for flow/aggregate statistics requests
43 
44 
45  union {
46  uint8_t *ofsu_body;
47  /* OFPST_DESC */
48  // empty desc stats body in request
49  struct openflow12::ofp_desc_stats *ofsu_desc_reply;
50 
51  /* OFPST_FLOW */
52  struct openflow12::ofp_flow_stats_request *ofsu_flow_stats_request;
53  struct openflow12::ofp_flow_stats *ofsu_flow_stats_reply;
54 
55  /* OFPST_AGGREGATE */
56  struct openflow12::ofp_aggregate_stats_request *ofsu_aggr_stats_request;
57  struct openflow12::ofp_aggregate_stats_reply *ofsu_aggr_stats_reply;
58 
59  /* OFPST_TABLE */
60  // empty table stats body in request
61  struct openflow12::ofp_table_stats *ofsu_table_stats_reply;
62 
63  /* OFPST_PORT */
64  struct openflow12::ofp_port_stats_request *ofsu_port_stats_request;
65  struct openflow12::ofp_port_stats *ofsu_port_stats_reply;
66 
67  /* OFPST_QUEUE */
68  struct openflow12::ofp_queue_stats_request *ofsu_queue_stats_request;
69  struct openflow12::ofp_queue_stats *ofsu_queue_stats_reply;
70 
71  /* OFPST_GROUP */
72  struct openflow12::ofp_group_stats_request *ofsu_group_stats_request;
73  struct openflow12::ofp_group_stats *ofsu_group_stats_reply;
74 
75  /* OFPST_GROUP_DESC */
76  // empty group desc stats body in request
77  struct openflow12::ofp_group_desc_stats *ofsu_group_desc_stats_reply;
78 
79  /* OFPST_GROUP_FEATURES */
80  // empty group features stats body in request
81  struct openflow12::ofp_group_features_stats *ofsu_group_features_stats_reply;
82 
83  /* OFPST_EXPERIMENTER */
84  struct openflow12::ofp_experimenter_stats_header *ofsu_expr_stats_header;
85  } ofs_ofsu;
86 
87 #define ofs_body ofs_ofsu.ofsu_body
88 
89 // empty
90 #define ofs_desc_reply ofs_ofsu.ofsu_desc_reply
91 #define ofs_flow_stats_request ofs_ofsu.ofsu_flow_stats_request
92 #define ofs_flow_stats ofs_ofsu.ofsu_flow_stats_reply
93 #define ofs_aggr_stats_request ofs_ofsu.ofsu_aggr_stats_request
94 #define ofs_aggr_stats ofs_ofsu.ofsu_aggr_stats_reply
95 // empty
96 #define ofs_table_stats ofs_ofsu.ofsu_table_stats_reply
97 #define ofs_port_stats_request ofs_ofsu.ofsu_port_stats_request
98 #define ofs_port_stats ofs_ofsu.ofsu_port_stats_reply
99 #define ofs_queue_stats_request ofs_ofsu.ofsu_queue_stats_request
100 #define ofs_queue_stats ofs_ofsu.ofsu_queue_stats_reply
101 #define ofs_group_stats_request ofs_ofsu.ofsu_group_stats_request
102 #define ofs_group_stats ofs_ofsu.ofsu_group_stats_reply
103 // empty
104 #define ofs_group_desc_stats ofs_ofsu.ofsu_group_desc_stats_reply
105 // empty
106 #define ofs_group_features_stats ofs_ofsu.ofsu_group_features_stats_reply
107 // empty
108 #define ofs_experimenter_stats ofs_ofsu.ofsu_expr_stats_header
109 
110 
111 #define OFS_FLOW_STATS_STATIC_HDR_LEN 32 // without struct ofp_match
112 #define OFS_AGGR_STATS_STATIC_HDR_LEN 32 // without struct ofp_match
113 
114 
115 
116 /*
117  * methods
118  */
119 public:
120 
124  cofstats(
125  size_t bodylen = 0);
126 
130  virtual
131  ~cofstats();
132 
136  virtual size_t
137  length();
138 
142  virtual cmemory&
143  pack();
144 
148  virtual void
149  unpack(
150  uint8_t *buf,
151  size_t buflen)
152  throw (eOFstatsTooShort);
153 
157  virtual const char*
158  c_str();
159 };
160 
161 
162 
164  public cofstats
165 {
166 public:
171  cofstats(OFS_FLOW_STATS_STATIC_HDR_LEN)
172  {
173  ofs_flow_stats_request = (struct openflow12::ofp_flow_stats_request*)body.somem();
174  };
178  virtual
183  virtual size_t
184  length()
185  {
186  return (body.memlen() + match.length());
187  };
191  virtual cmemory&
192  pack()
193  {
194  packed.resize(length());
195  memcpy(packed.somem(), body.somem(), body.memlen());
196  match.pack(packed.somem() + body.memlen(), match.length());
197  return packed;
198  };
199 };
200 
201 
202 
204  public cofstats
205 {
206 public:
211  cofstats(sizeof(struct openflow12::ofp_flow_stats))
212  {
213  ofs_flow_stats = (struct openflow12::ofp_flow_stats*)body.somem();
214  };
218  virtual
220 };
221 
222 
223 
224 
226  public cofstats
227 {
228 private:
229  std::string info;
230 
231 public:
236  cofstats(OFS_AGGR_STATS_STATIC_HDR_LEN)
237  {
238  ofs_aggr_stats_request = (struct openflow12::ofp_aggregate_stats_request*)body.somem();
239  };
240  cofstats_aggregate_request(uint8_t* buf, size_t buflen) :
241  cofstats(OFS_AGGR_STATS_STATIC_HDR_LEN)
242  {
243  unpack(buf, buflen);
244  };
248  virtual
253  virtual size_t
254  length()
255  {
256  return (body.memlen() + match.length());
257  };
261  virtual cmemory&
262  pack()
263  {
264  packed.resize(length());
265  memcpy(packed.somem(), body.somem(), body.memlen());
266  match.pack(packed.somem() + body.memlen(), match.length());
267  return packed;
268  };
272  virtual void
273  unpack(uint8_t *buf, size_t buflen) throw (eOFstatsTooShort)
274  {
275  if (buflen < sizeof(struct openflow12::ofp_aggregate_stats_request))
276  {
277  throw eOFstatsTooShort();
278  }
279  body.assign(buf, OFS_AGGR_STATS_STATIC_HDR_LEN);
280  ofs_aggr_stats_request = (struct openflow12::ofp_aggregate_stats_request*)body.somem();
281  match.clear();
282  match.unpack(buf + OFS_AGGR_STATS_STATIC_HDR_LEN,
283  buflen - OFS_AGGR_STATS_STATIC_HDR_LEN);
284  };
288  virtual const char*
289  c_str()
290  {
291 #if 0
292  std::stringstream ss;
293  info.assign(vas("cofstats_aggregate_request(%p) table-id: %d out_port: 0x%x out_group: 0x%x "
294  "cookie: 0x%llx cookie-mask: 0x%llx ",
295  this,
296  ofs_aggr_stats_request->table_id,
297  be32toh(ofs_aggr_stats_request->out_port),
298  be32toh(ofs_aggr_stats_request->out_group),
299  be64toh(ofs_aggr_stats_request->cookie),
300  be64toh(ofs_aggr_stats_request->cookie_mask)));
301  //info.append(match.c_str());
302 #endif
303  return info.c_str();
304  };
305 };
306 
307 
308 
310  public cofstats
311 {
312 public:
317  cofstats(sizeof(struct openflow12::ofp_aggregate_stats_reply))
318  {
319  ofs_aggr_stats = (struct openflow12::ofp_aggregate_stats_reply*)body.somem();
320  };
324  virtual
326 };
327 
328 }; // end of namespace openflow
329 }; // end of namespace rofl
330 
331 #endif /* COFSTATS_H */
cofstats_aggregate_request()
Definition: cofstats.h:235
Definition: openflow12.h:1391
cofstats_aggregate_reply()
Definition: cofstats.h:316
Definition: cofstats.h:26
Definition: openflow12.h:1466
cofstats_flow_request()
Definition: cofstats.h:170
Definition: openflow12.h:1491
cofstats_flow_reply()
Definition: cofstats.h:210
virtual ~cofstats_aggregate_request()
Definition: cofstats.h:249
Definition: openflow12.h:1649
size_t memlen() const
Returns length of allocated memory area.
Definition: cmemory.cc:109
Definition: openflow12.h:1426
Definition: cofstats.h:23
uint8_t * somem() const
Returns pointer to start of allocated memory area.
Definition: cmemory.cc:101
Definition: openflow12.h:1505
Definition: cofmatch.h:35
Definition: openflow12.h:1529
virtual ~cofstats_flow_reply()
Definition: cofstats.h:219
Definition: openflow12.h:1328
virtual uint8_t * resize(size_t len)
Resizes allocated memory area by calling C-function realloc().
Definition: cmemory.cc:253
Definition: openflow12.h:1349
Definition: cofstats.h:163
Definition: cofstats.h:203
C++ abstraction for malloc'ed memory areas.
Definition: cmemory.h:44
Definition: openflow12.h:1318
Definition: openflow12.h:1519
virtual void assign(uint8_t *buf, size_t buflen)
Overwrites memory area with plain buffer specified. Resizes internal memory as necessary.
Definition: cmemory.cc:241
Definition: cofstats.h:22
Definition: openflow12.h:1655
virtual ~cofstats_flow_request()
Definition: cofstats.h:179
Definition: openflow12.h:1455
virtual ~cofstats_aggregate_reply()
Definition: cofstats.h:325
Definition: croflexception.h:27