virtio: Add RX queue full statisitics
[vpp.git] / src / plugins / ioam / lib-trace / trace_api.c
1 /*
2  * Copyright (c) 2016 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 /*
16  *------------------------------------------------------------------
17  * trace_api.c - iOAM Trace related APIs to create
18  *               and maintain profiles
19  *------------------------------------------------------------------
20  */
21
22 #include <vnet/vnet.h>
23 #include <vnet/plugin/plugin.h>
24 #include <ioam/lib-trace/trace_util.h>
25 #include <ioam/lib-trace/trace_config.h>
26 #include <vlibapi/api_helper_macros.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29
30 /* define message IDs */
31 #include <ioam/lib-trace/trace.api_enum.h>
32 #include <ioam/lib-trace/trace.api_types.h>
33
34 static void vl_api_trace_profile_add_t_handler
35   (vl_api_trace_profile_add_t * mp)
36 {
37   int rv = 0;
38   vl_api_trace_profile_add_reply_t *rmp;
39   trace_profile *profile = NULL;
40
41   profile = trace_profile_find ();
42   if (profile)
43     {
44       rv =
45         trace_profile_create (profile, mp->trace_type, mp->num_elts,
46                               mp->trace_tsp, ntohl (mp->node_id),
47                               ntohl (mp->app_data));
48       if (rv != 0)
49         goto ERROROUT;
50     }
51   else
52     {
53       rv = -3;
54     }
55 ERROROUT:
56   REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
57 }
58
59
60 static void vl_api_trace_profile_del_t_handler
61   (vl_api_trace_profile_del_t * mp)
62 {
63   int rv = 0;
64   vl_api_trace_profile_del_reply_t *rmp;
65
66   clear_trace_profiles ();
67
68   REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
69 }
70
71 static void vl_api_trace_profile_show_config_t_handler
72   (vl_api_trace_profile_show_config_t * mp)
73 {
74   vl_api_trace_profile_show_config_reply_t *rmp;
75   int rv = 0;
76   trace_profile *profile = trace_profile_find ();
77   if (profile->valid)
78     {
79       REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
80                     rmp->trace_type = profile->trace_type;
81                     rmp->num_elts = profile->num_elts;
82                     rmp->trace_tsp = profile->trace_tsp;
83                     rmp->node_id = htonl (profile->node_id);
84                     rmp->app_data = htonl (profile->app_data);
85         );
86     }
87   else
88     {
89       REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
90                     rmp->trace_type = 0;
91                     rmp->num_elts = 0; rmp->trace_tsp = 0;
92                     rmp->node_id = 0; rmp->app_data = 0;
93         );
94     }
95 }
96
97 #include <ioam/lib-trace/trace.api.c>
98 static clib_error_t *
99 trace_init (vlib_main_t * vm)
100 {
101   trace_main_t *sm = &trace_main;
102
103   bzero (sm, sizeof (trace_main));
104   (void) trace_util_init ();
105
106   sm->vlib_main = vm;
107   sm->vnet_main = vnet_get_main ();
108
109   /* Ask for a correctly-sized block of API message decode slots */
110   sm->msg_id_base = setup_message_id_table ();
111
112   return 0;
113 }
114
115 VLIB_INIT_FUNCTION (trace_init);
116
117 /*
118  * fd.io coding-style-patch-verification: ON
119  *
120  * Local Variables:
121  * eval: (c-set-style "gnu")
122  * End:
123  */