3d30e3797961f1836d0087560b73d994bab02207
[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 <vlibmemory/unix_shared_memory_queue.h>
29 #include <vlibapi/api_helper_macros.h>
30
31 typedef struct
32 {
33   volatile u32 lock;
34   volatile u32 release_hint;
35   u32 thread_index;
36   u32 count;
37   int tag;
38 } data_structure_lock_t;
39
40 /**
41  * @brief stats request registration indexes
42  *
43  */
44 /* from .../vnet/vnet/ip/lookup.c. Yuck */
45 /* *INDENT-OFF* */
46 typedef CLIB_PACKED (struct
47 {
48   ip4_address_t address;
49   u32 address_length: 6;
50   u32 index:         26;
51 }) ip4_route_t;
52 /* *INDENT-ON* */
53
54 /* see interface.api */
55 typedef struct
56 {
57   u32 sw_if_index;
58   u64 drop;
59   u64 punt;
60   u64 rx_ip4;
61   u64 rx_ip6;
62   u64 rx_no_buffer;
63   u64 rx_miss;
64   u64 rx_error;
65   u64 tx_error;
66   u64 rx_mpls;
67 } vnet_simple_counter_t;
68
69 typedef struct
70 {
71   u32 sw_if_index;
72   u64 rx_packets;                       /**< packet counter */
73   u64 rx_bytes;                 /**< byte counter  */
74   u64 tx_packets;                       /**< packet counter */
75   u64 tx_bytes;                 /**< byte counter  */
76 } vnet_combined_counter_t;
77
78 typedef struct
79 {
80   ip6_address_t address;
81   u32 address_length;
82   u32 index;
83 } ip6_route_t;
84
85 typedef struct
86 {
87   ip4_route_t *ip4routes;
88   ip6_route_t *ip6routes;
89   mfib_prefix_t *mroutes;
90   fib_table_t **fibs;
91   mfib_table_t **mfibs;
92   hash_pair_t **pvec;
93   uword *results;
94 } do_ip46_fibs_t;
95
96 typedef struct
97 {
98   u16 msg_id;
99   u32 size;
100   u32 client_index;
101   u32 context;
102   i32 retval;
103 } client_registration_reply_t;
104
105 typedef enum
106 {
107 #define stats_reg(n) IDX_##n,
108 #include <vpp/stats/stats.reg>
109 #undef stats_reg
110   STATS_REG_N_IDX,
111 } stats_reg_index_t;
112
113 typedef struct
114 {
115   //Standard client information
116   uword *client_hash;
117   vpe_client_registration_t *clients;
118   u32 item;
119
120 } vpe_client_stats_registration_t;
121
122
123 typedef struct
124 {
125   void *mheap;
126   pthread_t thread_self;
127   pthread_t thread_handle;
128
129   u32 stats_poll_interval_in_seconds;
130   u32 enable_poller;
131
132   /*
133    * stats_registrations is a vector, indexed by
134    * IDX_xxxx_COUNTER generated for each streaming
135    * stat a client can register for. (see stats.reg)
136    *
137    * The values in the vector refer to pools.
138    *
139    * The pool is of type vpe_client_stats_registration_t
140    *
141    * This typedef consists of:
142    *
143    * u32 item: This is the instance of the IDX_xxxx_COUNTER a
144    *           client is interested in.
145    * vpe_client_registration_t *clients: The list of clients interested.
146    *
147    * e.g.
148    * stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS] refers to a pool
149    * containing elements:
150    *
151    * u32 item = sw_if_index1
152    * clients = ["clienta","clientb"]
153    *
154    * When clients == NULL the pool element is freed. When the pool is empty
155    *
156    * ie
157    * 0 == pool_elts(stats_registrations[IDX_INTERFACE_SIMPLE_COUNTERS]
158    *
159    * then there is no need to process INTERFACE_SIMPLE_COUNTERS
160    *
161    * Note that u32 item = ~0 is the simple case for ALL interfaces or fibs.
162    *
163    */
164
165   uword **stats_registration_hash;
166   vpe_client_stats_registration_t **stats_registrations;
167
168   /* control-plane data structure lock */
169   data_structure_lock_t *data_structure_lock;
170
171   /* bail out of FIB walk if set */
172   clib_longjmp_t jmp_buf;
173
174   /* Vectors for Distribution funcs: do_ip4_fibs and do_ip6_fibs. */
175   do_ip46_fibs_t do_ip46_fibs;
176
177   /*
178      Working vector vars so as to not thrash memory allocator.
179      Has effect of making "static"
180    */
181   vpe_client_stats_registration_t **regs_tmp;
182   vpe_client_registration_t **clients_tmp;
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 #endif /* __included_stats_h__ */
194
195 /*
196  * fd.io coding-style-patch-verification: ON
197  *
198  * Local Variables:
199  * eval: (c-set-style "gnu")
200  * End:
201  */