Stat segment / client: show run" works now
[vpp.git] / src / vpp / stats / stats.h
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __included_stats_h__
16 #define __included_stats_h__
17
18 #include <time.h>
19 #include <vlib/vlib.h>
20 #include <vnet/vnet.h>
21 #include <vnet/interface.h>
22 #include <pthread.h>
23 #include <vlib/threads.h>
24 #include <vnet/fib/fib_table.h>
25 #include <vnet/mfib/mfib_table.h>
26 #include <vlib/unix/unix.h>
27 #include <vlibmemory/api.h>
28 #include <vlibapi/api_helper_macros.h>
29 #include <svm/queue.h>
30 #include <svm/ssvm.h>
31
32 typedef struct
33 {
34   volatile u32 lock;
35   volatile u32 release_hint;
36   u32 thread_index;
37   u32 count;
38   int tag;
39 } data_structure_lock_t;
40
41 /**
42  * @brief stats request registration indexes
43  *
44  */
45 /* from .../vnet/vnet/ip/lookup.c. Yuck */
46 /* *INDENT-OFF* */
47 typedef CLIB_PACKED (struct
48 {
49   ip4_address_t address;
50   u32 address_length: 6;
51   u32 index:         26;
52 }) ip4_route_t;
53 /* *INDENT-ON* */
54
55 typedef struct
56 {
57   ip6_address_t address;
58   u32 address_length;
59   u32 index;
60 } ip6_route_t;
61
62 typedef struct
63 {
64   ip4_route_t *ip4routes;
65   ip6_route_t *ip6routes;
66   mfib_prefix_t *mroutes;
67   fib_table_t **fibs;
68   mfib_table_t **mfibs;
69   hash_pair_t **pvec;
70   uword *results;
71 } do_ip46_fibs_t;
72
73 typedef struct
74 {
75   u16 msg_id;
76   u32 size;
77   u32 client_index;
78   u32 context;
79   i32 retval;
80 } client_registration_reply_t;
81
82 typedef enum
83 {
84 #define stats_reg(n) IDX_##n,
85 #include <vpp/stats/stats.reg>
86 #undef stats_reg
87   STATS_REG_N_IDX,
88 } stats_reg_index_t;
89
90 typedef struct
91 {
92   //Standard client information
93   uword *client_hash;
94   vpe_client_registration_t *clients;
95   u32 item;
96
97 } vpe_client_stats_registration_t;
98
99
100 typedef struct
101 {
102   void *mheap;
103   pthread_t thread_self;
104   pthread_t thread_handle;
105
106   u32 stats_poll_interval_in_seconds;
107   u32 enable_poller;
108
109   /*
110    * stats_registrations is a vector, indexed by
111    * IDX_xxxx_COUNTER generated for each streaming
112    * stat a client can register for. (see stats.reg)
113    *
114    * The values in the vector refer to pools.
115    *
116    * The pool is of type vpe_client_stats_registration_t
117    *
118    * This typedef consists of:
119    *
120    * u32 item: This is the instance of the IDX_xxxx_COUNTER a
121    *           client is interested in.
122    * vpe_client_registration_t *clients: The list of clients interested.
123    *
124    * e.g.
125    * stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS] refers to a pool
126    * containing elements:
127    *
128    * u32 item = sw_if_index1
129    * clients = ["clienta","clientb"]
130    *
131    * When clients == NULL the pool element is freed. When the pool is empty
132    *
133    * ie
134    * 0 == pool_elts(stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS]
135    *
136    * then there is no need to process INTERFACE_SIMPLE_COUNTERS
137    *
138    * Note that u32 item = ~0 is the simple case for ALL interfaces or fibs.
139    *
140    */
141
142   uword **stats_registration_hash;
143   vpe_client_stats_registration_t **stats_registrations;
144
145   /* control-plane data structure lock */
146   data_structure_lock_t *data_structure_lock;
147
148   /* bail out of FIB walk if set */
149   clib_longjmp_t jmp_buf;
150
151   /* Vectors for Distribution funcs: do_ip4_fibs and do_ip6_fibs. */
152   do_ip46_fibs_t do_ip46_fibs;
153
154   /*
155      Working vector vars so as to not thrash memory allocator.
156      Has effect of making "static"
157    */
158   vpe_client_stats_registration_t **regs_tmp;
159   vpe_client_registration_t **clients_tmp;
160
161   /* statistics segment */
162   ssvm_private_t stat_segment;
163   uword *counter_vector_by_name;
164   clib_spinlock_t *stat_segment_lockp;
165
166   /* Pointers to scalar stats maintained by the stat thread */
167   f64 *input_rate_ptr;
168   f64 *last_runtime_ptr;
169   f64 *last_runtime_stats_clear_ptr;
170   f64 *vector_rate_ptr;
171   u64 last_input_packets;
172
173   /* Pointers to vector stats maintained by the stat thread */
174   u8 *serialized_nodes;
175   vlib_main_t **stat_vms;
176   vlib_node_t ***node_dups;
177
178   f64 *vectors_per_node;
179   f64 *vector_rate_in;
180   f64 *vector_rate_out;
181   f64 *vector_rate_drop;
182   f64 *vector_rate_punt;
183
184   /* convenience */
185   vlib_main_t *vlib_main;
186   vnet_main_t *vnet_main;
187   vnet_interface_main_t *interface_main;
188   api_main_t *api_main;
189 } stats_main_t;
190
191 extern stats_main_t stats_main;
192
193 #define STAT_SEGMENT_OPAQUE_LOCK        0
194 #define STAT_SEGMENT_OPAQUE_DIR         1
195 #define STAT_SEGMENT_OPAQUE_EPOCH       2
196
197 typedef enum
198 {
199   STAT_DIR_TYPE_ILLEGAL = 0,
200   STAT_DIR_TYPE_SCALAR_POINTER,
201   STAT_DIR_TYPE_VECTOR_POINTER,
202   STAT_DIR_TYPE_COUNTER_VECTOR,
203   STAT_DIR_TYPE_ERROR_INDEX,
204   STAT_DIR_TYPE_SERIALIZED_NODES,
205 } stat_directory_type_t;
206
207 typedef struct
208 {
209   stat_directory_type_t type;
210   void *value;
211 } stat_segment_directory_entry_t;
212
213 void do_stat_segment_updates (stats_main_t * sm);
214
215 #endif /* __included_stats_h__ */
216
217 /*
218  * fd.io coding-style-patch-verification: ON
219  *
220  * Local Variables:
221  * eval: (c-set-style "gnu")
222  * End:
223  */