Allow individual stats API and introduce stats.api
[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 <vlib/unix/unix.h>
26 #include <vlibmemory/api.h>
27 #include <vlibmemory/unix_shared_memory_queue.h>
28 #include <vlibapi/api_helper_macros.h>
29
30 typedef struct
31 {
32   volatile u32 lock;
33   volatile u32 release_hint;
34   u32 thread_index;
35   u32 count;
36   int tag;
37 } data_structure_lock_t;
38
39 typedef struct
40 {
41   vpe_client_registration_t client;
42   u8 stats_registrations;
43 #define INTERFACE_SIMPLE_COUNTERS (1 << 0)
44 #define INTERFACE_COMBINED_COUNTERS (1 << 1)
45 #define IP4_FIB_COUNTERS (1 << 2)
46 #define IP4_NBR_COUNTERS (1 << 3)
47 #define IP6_FIB_COUNTERS (1 << 4)
48 #define IP6_NBR_COUNTERS (1 << 5)
49
50 } vpe_client_stats_registration_t;
51
52 /* from .../vnet/vnet/ip/lookup.c. Yuck */
53 typedef CLIB_PACKED (struct
54                      {
55                      ip4_address_t address;
56 u32 address_length: 6;
57 u32 index:           26;
58                      }) ip4_route_t;
59
60 typedef struct
61 {
62   ip6_address_t address;
63   u32 address_length;
64   u32 index;
65 } ip6_route_t;
66
67
68 typedef struct
69 {
70   ip4_route_t *ip4routes;
71   ip6_route_t *ip6routes;
72   fib_table_t **fibs;
73   hash_pair_t **pvec;
74   uword *results;
75 } do_ip46_fibs_t;
76
77 typedef struct
78 {
79   void *mheap;
80   pthread_t thread_self;
81   pthread_t thread_handle;
82
83   u32 stats_poll_interval_in_seconds;
84   u32 enable_poller;
85
86   uword *stats_registration_hash;
87   vpe_client_stats_registration_t *stats_registrations;
88   vpe_client_stats_registration_t **regs;
89
90   /* control-plane data structure lock */
91   data_structure_lock_t *data_structure_lock;
92
93   /* bail out of FIB walk if set */
94   clib_longjmp_t jmp_buf;
95
96   /* Vectors for Distribution funcs: do_ip4_fibs and do_ip6_fibs. */
97   do_ip46_fibs_t do_ip46_fibs;
98
99   /* convenience */
100   vlib_main_t *vlib_main;
101   vnet_main_t *vnet_main;
102   vnet_interface_main_t *interface_main;
103   api_main_t *api_main;
104 } stats_main_t;
105
106 stats_main_t stats_main;
107
108 void dslock (stats_main_t * sm, int release_hint, int tag);
109 void dsunlock (stats_main_t * sm);
110
111 #endif /* __included_stats_h__ */
112
113 /*
114  * fd.io coding-style-patch-verification: ON
115  *
116  * Local Variables:
117  * eval: (c-set-style "gnu")
118  * End:
119  */