ROFL-pipeline  v0.6.0dev
of1x_statistics_pp.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_PP_H__
6 #define __OF1X_STATISTICS_PP_H__
7 
8 #include <assert.h>
9 #include "rofl.h"
10 #include "../../../util/pp_guard.h" //Never forget to include the guard
11 
12 #include "of1x_statistics.h"
13 
14 //Platform stuff
15 #include "../../../platform/lock.h"
16 #include "../../../platform/likely.h"
17 #include "../../../platform/memory.h"
18 #include "../../../platform/packet.h"
19 #include "../../../platform/atomic_operations.h"
20 #include "../of1x_async_events_hooks.h"
21 
22 
30 //Flow
31 static inline void __of1x_stats_flow_update_match(unsigned int tid, of1x_stats_flow_t* stats, uint64_t bytes_rx){
32 
33  __of1x_stats_flow_tid_t* s = &stats->s.__internal[tid];
34 
35  assert(tid < ROFL_PIPELINE_MAX_TIDS);
36 
37  if(unlikely(tid == ROFL_PIPELINE_LOCKED_TID)){
38  platform_atomic_inc64(&s->packet_count, stats->mutex);
39  platform_atomic_add64(&s->byte_count, bytes_rx, stats->mutex);
40  }else{
41  s->packet_count++;
42  s->byte_count+=bytes_rx;
43  }
44 }
45 
46 //Flow table
47 static inline void __of1x_stats_table_update_match(unsigned int tid, of1x_stats_table_t* stats){
48 
49  __of1x_stats_table_tid_t* s = &stats->s.__internal[tid];
50 
51  assert(tid < ROFL_PIPELINE_MAX_TIDS);
52 
53  if(unlikely(tid == ROFL_PIPELINE_LOCKED_TID)){
54  platform_atomic_inc64(&s->lookup_count,stats->mutex);
55  platform_atomic_inc64(&s->matched_count,stats->mutex);
56  }else{
57  s->lookup_count++;
58  s->matched_count++;
59  }
60 }
61 
62 static inline void __of1x_stats_table_update_no_match(unsigned int tid, of1x_stats_table_t* stats){
63 
64  assert(tid < ROFL_PIPELINE_MAX_TIDS);
65 
66  if(unlikely(tid == ROFL_PIPELINE_LOCKED_TID)){
67  platform_atomic_inc64(&stats->s.__internal[tid].lookup_count,stats->mutex);
68  }else{
69  stats->s.__internal[tid].lookup_count++;
70  }
71 }
72 
73 //Group
74 static void __of1x_stats_group_update(unsigned int tid, of1x_stats_group_t *gr_stats, uint64_t bytes){
75 
76  __of1x_stats_group_tid_t* s = &gr_stats->s.__internal[tid];
77 
78  assert(tid < ROFL_PIPELINE_MAX_TIDS);
79 
80  if(unlikely(tid == ROFL_PIPELINE_LOCKED_TID)){
81  platform_atomic_inc64(&s->packet_count, gr_stats->mutex);
82  platform_atomic_add64(&s->byte_count, bytes, gr_stats->mutex);
83  }else{
84  s->packet_count++;
85  s->byte_count += bytes;
86  }
87 
88 }
89 
90 //Bucket
91 static void __of1x_stats_bucket_update(unsigned int tid, __of1x_stats_bucket_t* bc_stats, uint64_t bytes){
92 
93  __of1x_stats_bucket_tid_t* s = &bc_stats->s.__internal[tid];
94 
95  assert(tid < ROFL_PIPELINE_MAX_TIDS);
96 
97  if(unlikely(tid == ROFL_PIPELINE_LOCKED_TID)){
98  platform_atomic_inc64(&s->packet_count, bc_stats->mutex);
99  platform_atomic_add64(&s->byte_count, bytes, bc_stats->mutex);
100  }else{
101  s->packet_count++;
102  s->byte_count += bytes;
103  }
104 }
105 
106 #endif //OF1X_STATISTICS_PP_H
void platform_atomic_add64(uint64_t *counter, uint64_t value, platform_mutex_t *mutex)
Performs an atomic addition to the counter (64 bit type).
ROFL_BEGIN_DECLS void platform_atomic_inc64(uint64_t *counter, platform_mutex_t *mutex)
Performs an atomic increment to the counter (64 bit type).
OpenFlow v1.0, 1.2 and 1.3.2 statistics subsystem.