ROFL-pipeline  v0.6.0dev
of1x_statistics.h
Go to the documentation of this file.
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 __OF1X_STATISTICS_H__
6 #define __OF1X_STATISTICS_H__
7 
8 #include <inttypes.h>
9 #include <sys/time.h>
10 #include <string.h>
11 #include "rofl.h"
12 #include "of1x_group_types.h"
13 #include "../../../platform/lock.h"
14 
15 #define OF1X_STATS_NS_IN_A_SEC 1000000000
16 
24 /*From OpenFlow 1.2 specification, page 50*/
25 /*
26  * Types of statistics:
27  * DESC, FLOW, AGGREGATE, TABLE, PORT, QUEUE, GROUP, GROUP_DESC, GROUP_FEATURES, EXPERIMENTER
28  */
29 
30 /*counters OF 1.2 specification page 13*/
31 
32 //fwd declarations
33 struct of1x_action_group;
35 struct of1x_flow_entry;
36 struct of1x_flow_table;
37 struct of1x_match;
38 struct of1x_match_group;
39 struct of1x_pipeline;
40 
41 //
42 // Inner pipeline stats
43 //
44 
45 /* Flows */
46 //Per thread flow stats
47 typedef struct __of1x_stats_flow_tid{
48  uint64_t packet_count;
49  uint64_t byte_count;
51 
52 //Flow entry stats (internal entry state)
53 typedef struct of1x_stats_flow{
54 
56  __of1x_stats_flow_tid_t counters;
57 
58  //array of counters per thread to be used internally
59  __of1x_stats_flow_tid_t __internal[ROFL_PIPELINE_MAX_TIDS];
60  }s;
61 
62  //And more not so interesting
63  struct timeval initial_time;
64 
65  platform_mutex_t* mutex; //Mutual exclusion stats
67 
68 /* Table */
69 
70 //Per thread table stats
71 typedef struct __of1x_stats_table_tid{
72  uint64_t lookup_count; /* Number of packets looked up in table. */
73  uint64_t matched_count; /* Number of packets that hit table. */
75 
76 //Table stats (table state)
77 typedef struct of1x_stats_table{
78 
80  /* Flow table counters */
81  __of1x_stats_table_tid_t counters;
82 
83  //array of counters per thread to be used internally
84  __of1x_stats_table_tid_t __internal[ROFL_PIPELINE_MAX_TIDS];
85  }s;
86 
87  platform_mutex_t* mutex; //Mutual exclusion only for stats
89 
90 /* Groups */
91 
92 //Bucket
93 typedef struct __of1x_stats_bucket_tid{
94  uint64_t packet_count;
95  uint64_t byte_count;
97 
98 typedef __of1x_stats_bucket_tid_t of1x_stats_bucket_t; //Used only for msgs
99 
100 typedef struct __of1x_stats_bucket{
102  /* Bucket counters */
103  __of1x_stats_bucket_tid_t counters;
104 
105  //array of counters per thread to be used internally
106  __of1x_stats_bucket_tid_t __internal[ROFL_PIPELINE_MAX_TIDS];
107  }s;
108 
109  platform_mutex_t* mutex;
111 
112 //Per group table stats
113 typedef struct __of1x_stats_group_tid{
114  uint64_t packet_count;
115  uint64_t byte_count;
117 
118 //Group stats
119 typedef struct of1x_stats_group{
120 
121  uint32_t ref_count;
122 
124  /* Group counters */
125  __of1x_stats_group_tid_t counters;
126 
127  //array of counters per thread to be used internally
128  __of1x_stats_group_tid_t __internal[ROFL_PIPELINE_MAX_TIDS];
129  }s;
130 
131  platform_mutex_t* mutex;
133 
134 
135 
136 //
137 // Flow stats / Group stats message section
138 //
139 
145  uint8_t table_id;
146  uint16_t priority;
147  uint64_t cookie;
148 
149  uint32_t duration_sec;
150  uint32_t duration_nsec;
151 
152  uint16_t idle_timeout;
153  uint16_t hard_timeout;
154 
155  uint16_t flags;
156 
157  uint64_t packet_count;
158  uint64_t byte_count;
159 
160  struct of1x_match* matches;
161  struct of1x_instruction_group* inst_grp;
162 
163  struct of1x_stats_single_flow_msg* next;
165 
170 typedef struct of1x_stats_flow_msg{
171  uint32_t num_of_entries;
172  of1x_stats_single_flow_msg_t* flows_head;
173  of1x_stats_single_flow_msg_t* flows_tail;
175 
181  uint64_t packet_count;
182  uint64_t byte_count;
183  uint32_t flow_count;
185 
186 
187 typedef struct of1x_stats_group_msg{
188  uint32_t group_id;
189  uint32_t ref_count;
190  uint64_t packet_count;
191  uint64_t byte_count;
192  int num_of_buckets;/*needed?*/
193  of1x_stats_bucket_t *bucket_stats;
194  struct of1x_stats_group_msg *next;
196 
198  uint16_t weight;
199  uint32_t port;
200  uint32_t group;
201  struct of1x_action_group *actions;
202  struct of1x_stats_bucket_desc_msg *next;
204 
206  uint32_t group_id;
207  of1x_group_type_t type;
209  struct of1x_stats_group_desc_msg *next;
211 
214 ROFL_BEGIN_DECLS
215 
216 void __of1x_init_flow_stats(struct of1x_flow_entry * entry);
217 void __of1x_destroy_flow_stats(struct of1x_flow_entry * entry);
218 
219 //msgs
220 void __of1x_push_single_flow_stats_to_msg(of1x_stats_flow_msg_t* msg, of1x_stats_single_flow_msg_t* sfs);
221 of1x_stats_single_flow_msg_t* __of1x_init_stats_single_flow_msg(struct of1x_flow_entry* entry);
222 void __of1x_destroy_stats_single_flow_msg(of1x_stats_single_flow_msg_t* msg);
223 
224 of1x_stats_flow_msg_t* __of1x_init_stats_flow_msg(void);
230 
231 //Push to msg
232 
233 //Aggregate messages
234 of1x_stats_flow_aggregate_msg_t* __of1x_init_stats_flow_aggregate_msg(void);
240 
245 void of1x_stats_flow_get_duration(struct of1x_flow_entry * entry, uint32_t* sec, uint32_t* nsec);
246 
248 
249 static inline void __of1x_stats_flow_consolidate(of1x_stats_flow_t* stats, __of1x_stats_flow_tid_t* c){
250  int i;
251  c->byte_count = c->packet_count = 0x0ULL;
252 
253  for(i=0;i<ROFL_PIPELINE_MAX_TIDS;i++){
254  c->packet_count += stats->s.__internal[i].packet_count;
255  c->byte_count += stats->s.__internal[i].byte_count;
256  }
257 }
258 static inline void __of1x_stats_copy_flow_stats(of1x_stats_flow_t* origin, of1x_stats_flow_t* copy){
259  memcpy(&copy->s.__internal,&origin->s.__internal, sizeof(__of1x_stats_flow_tid_t)*ROFL_PIPELINE_MAX_TIDS);
260  copy->initial_time = origin->initial_time;
261 }
262 
263 void __of1x_stats_table_init(struct of1x_flow_table * table);
264 void __of1x_stats_table_destroy(struct of1x_flow_table * table);
265 
266 static inline void __of1x_stats_table_consolidate(of1x_stats_table_t* stats, __of1x_stats_table_tid_t* c){
267  int i;
268  c->lookup_count = c->matched_count = 0x0ULL;
269 
270  for(i=0;i<ROFL_PIPELINE_MAX_TIDS;i++){
271  c->lookup_count += stats->s.__internal[i].lookup_count;
272  c->matched_count += stats->s.__internal[i].matched_count;
273  }
274 }
275 
276 void __of1x_init_group_stats(of1x_stats_group_t *group_stats);
277 void __of1x_destroy_group_stats(of1x_stats_group_t* group_stats);
278 
279 static inline void __of1x_stats_group_consolidate(of1x_stats_group_t* stats, __of1x_stats_group_tid_t* c){
280  int i;
281  c->byte_count = c->packet_count = 0x0ULL;
282 
283  for(i=0;i<ROFL_PIPELINE_MAX_TIDS;i++){
284  c->packet_count += stats->s.__internal[i].packet_count;
285  c->byte_count += stats->s.__internal[i].byte_count;
286  }
287 }
288 
289 static inline void __of1x_stats_bucket_consolidate(__of1x_stats_bucket_t* stats, __of1x_stats_bucket_tid_t* c){
290  int i;
291  c->byte_count = c->packet_count = 0x0ULL;
292 
293  for(i=0;i<ROFL_PIPELINE_MAX_TIDS;i++){
294  c->packet_count += stats->s.__internal[i].packet_count;
295  c->byte_count += stats->s.__internal[i].byte_count;
296  }
297 }
298 
299 void __of1x_stats_group_inc_reference(of1x_stats_group_t *gr_stats);
300 void __of1x_stats_group_dec_reference(of1x_stats_group_t *gr_stats);
301 
308 of1x_stats_group_msg_t* of1x_get_group_stats(struct of1x_pipeline* pipeline,uint32_t id);
309 
317 
318 void __of1x_init_bucket_stats(__of1x_stats_bucket_t *bc_stats);
319 void __of1x_destroy_buckets_stats(__of1x_stats_bucket_t *bc_stats);
320 
321 /*
322 * External interfaces
323 */
329 of1x_stats_flow_msg_t* of1x_get_flow_stats(struct of1x_pipeline* pipeline, uint8_t table_id, uint32_t cookie, uint32_t cookie_mask, uint32_t out_port, uint32_t out_group, struct of1x_match_group* matchs);
330 
336 of1x_stats_flow_aggregate_msg_t* of1x_get_flow_aggregate_stats(struct of1x_pipeline* pipeline, uint8_t table_id, uint32_t cookie, uint32_t cookie_mask, uint32_t out_port, uint32_t out_group, struct of1x_match_group* matchs);
337 
343 
350 
351 ROFL_END_DECLS
352 
353 #endif
354 
of1x_stats_flow_aggregate_msg_t * of1x_get_flow_aggregate_stats(struct of1x_pipeline *pipeline, uint8_t table_id, uint32_t cookie, uint32_t cookie_mask, uint32_t out_port, uint32_t out_group, struct of1x_match_group *matchs)
Retrieves aggregated flow stats.
OpenFlow v1.0, 1.2 and 1.3.2 flow entry structure.
struct of1x_stats_flow_msg of1x_stats_flow_msg_t
Linked list containing all the individual flow stats.
void __of1x_stats_flow_reset_counts(struct of1x_flow_entry *entry)
of1x_stats_flow_reset_counts
of1x_stats_group_msg_t * of1x_get_group_stats(struct of1x_pipeline *pipeline, uint32_t id)
Retrieves the statistics of a groupReturns a structure with the statistics that needs to be freed by ...
OpenFlow v1.0, 1.2 and 1.3.2 flow table abstraction.
Single flow entry stats message.
enum of1x_group_type of1x_group_type_t
Group type.
Action group (apply-actions) structure.
Definition: of1x_action.h:303
struct of1x_stats_single_flow_msg of1x_stats_single_flow_msg_t
Single flow entry stats message.
of1x_stats_flow_msg_t * of1x_get_flow_stats(struct of1x_pipeline *pipeline, uint8_t table_id, uint32_t cookie, uint32_t cookie_mask, uint32_t out_port, uint32_t out_group, struct of1x_match_group *matchs)
Retrieves individual flow stats.
Linked list containing all the individual flow stats.
void of1x_destroy_stats_flow_aggregate_msg(of1x_stats_flow_aggregate_msg_t *msg)
Destroy aggreagated flow_stats message.
void __of1x_stats_table_destroy(struct of1x_flow_table *table)
Destroys table statistics state.
void __of1x_destroy_flow_stats(struct of1x_flow_entry *entry)
of1x_stats_flow_destroy basically destroys the mutex
void __of1x_stats_table_init(struct of1x_flow_table *table)
Initializes table statistics state.
void of1x_destroy_stats_flow_msg(of1x_stats_flow_msg_t *msg)
Destroy a flow_stats message.
of1x_stats_group_desc_msg_t * of1x_get_group_desc_stats(struct of1x_pipeline *pipeline)
Retrieves a copy of the group and bucket structure.
void of1x_stats_flow_get_duration(struct of1x_flow_entry *entry, uint32_t *sec, uint32_t *nsec)
Get the duration of the flow_entry.
struct of1x_stats_flow_aggregate_msg of1x_stats_flow_aggregate_msg_t
Aggregated flow stats message.
ROFL_BEGIN_DECLS void __of1x_init_flow_stats(struct of1x_flow_entry *entry)
operations in statistics.c
OpenFlow v1.0, 1.2 and 1.3.2 pipeline abstraction data structure.
Definition: of1x_pipeline.h:50
Aggregated flow stats message.
void of1x_destroy_stats_group_msg(of1x_stats_group_msg_t *msg)
Frees memory of statistics messageNeeds to be called after retrieving the statistics of the groups...
void of1x_destroy_group_desc_stats(of1x_stats_group_desc_msg_t *msg)
Frees the memory for a of1x_stats_group_desc_msg_t structure.