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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __included_stats_h__
16 #define __included_stats_h__
19 #include <vlib/vlib.h>
20 #include <vnet/vnet.h>
21 #include <vnet/interface.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>
32 /* Default socket to exchange segment fd */
33 #define STAT_SEGMENT_SOCKET_FILE "/run/vpp/stats.sock"
38 volatile u32 release_hint;
42 } data_structure_lock_t;
45 * @brief stats request registration indexes
48 /* from .../vnet/vnet/ip/lookup.c. Yuck */
50 typedef CLIB_PACKED (struct
52 ip4_address_t address;
53 u32 address_length: 6;
60 ip6_address_t address;
67 ip4_route_t *ip4routes;
68 ip6_route_t *ip6routes;
69 mfib_prefix_t *mroutes;
83 } client_registration_reply_t;
87 #define stats_reg(n) IDX_##n,
88 #include <vpp/stats/stats.reg>
95 //Standard client information
97 vpe_client_registration_t *clients;
100 } vpe_client_stats_registration_t;
106 pthread_t thread_self;
107 pthread_t thread_handle;
109 u32 stats_poll_interval_in_seconds;
113 * stats_registrations is a vector, indexed by
114 * IDX_xxxx_COUNTER generated for each streaming
115 * stat a client can register for. (see stats.reg)
117 * The values in the vector refer to pools.
119 * The pool is of type vpe_client_stats_registration_t
121 * This typedef consists of:
123 * u32 item: This is the instance of the IDX_xxxx_COUNTER a
124 * client is interested in.
125 * vpe_client_registration_t *clients: The list of clients interested.
128 * stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS] refers to a pool
129 * containing elements:
131 * u32 item = sw_if_index1
132 * clients = ["clienta","clientb"]
134 * When clients == NULL the pool element is freed. When the pool is empty
137 * 0 == pool_elts(stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS]
139 * then there is no need to process INTERFACE_SIMPLE_COUNTERS
141 * Note that u32 item = ~0 is the simple case for ALL interfaces or fibs.
145 uword **stats_registration_hash;
146 vpe_client_stats_registration_t **stats_registrations;
148 /* control-plane data structure lock */
149 data_structure_lock_t *data_structure_lock;
151 /* bail out of FIB walk if set */
152 clib_longjmp_t jmp_buf;
154 /* Vectors for Distribution funcs: do_ip4_fibs and do_ip6_fibs. */
155 do_ip46_fibs_t do_ip46_fibs;
158 Working vector vars so as to not thrash memory allocator.
159 Has effect of making "static"
161 vpe_client_stats_registration_t **regs_tmp;
162 vpe_client_registration_t **clients_tmp;
164 /* statistics segment */
165 ssvm_private_t stat_segment;
166 uword *counter_vector_by_name;
167 clib_spinlock_t *stat_segment_lockp;
168 clib_socket_t *socket;
171 /* Pointers to scalar stats maintained by the stat thread */
173 f64 *last_runtime_ptr;
174 f64 *last_runtime_stats_clear_ptr;
175 f64 *vector_rate_ptr;
176 u64 last_input_packets;
178 /* Pointers to vector stats maintained by the stat thread */
179 u8 *serialized_nodes;
180 vlib_main_t **stat_vms;
181 vlib_node_t ***node_dups;
183 f64 *vectors_per_node;
185 f64 *vector_rate_out;
186 f64 *vector_rate_drop;
187 f64 *vector_rate_punt;
190 vlib_main_t *vlib_main;
191 vnet_main_t *vnet_main;
192 vnet_interface_main_t *interface_main;
193 api_main_t *api_main;
196 extern stats_main_t stats_main;
198 #define STAT_SEGMENT_OPAQUE_LOCK 0
199 #define STAT_SEGMENT_OPAQUE_DIR 1
200 #define STAT_SEGMENT_OPAQUE_EPOCH 2
204 STAT_DIR_TYPE_ILLEGAL = 0,
205 STAT_DIR_TYPE_SCALAR_POINTER,
206 STAT_DIR_TYPE_VECTOR_POINTER,
207 STAT_DIR_TYPE_COUNTER_VECTOR,
208 STAT_DIR_TYPE_ERROR_INDEX,
209 STAT_DIR_TYPE_SERIALIZED_NODES,
210 } stat_directory_type_t;
214 stat_directory_type_t type;
216 } stat_segment_directory_entry_t;
218 void do_stat_segment_updates (stats_main_t * sm);
220 #endif /* __included_stats_h__ */
223 * fd.io coding-style-patch-verification: ON
226 * eval: (c-set-style "gnu")