2 * Copyright (c) 2020 cisco
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.
17 #include <vlibapi/api.h>
18 #include <vlibmemory/api.h>
19 #include <vppinfra/error.h>
20 #include <vppinfra/time_range.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vpp-api/client/stat_client.h>
24 #define __plugin_msg_base graph_test_main.msg_id_base
25 #include <vlibapi/vat_helper_macros.h>
27 #include <vnet/format_fns.h>
28 #include <tracedump/graph.api_enum.h>
29 #include <tracedump/graph.api_types.h>
30 #include <vpp/api/vpe.api_types.h>
39 graph_test_main_t graph_test_main;
43 api_unformat_node_index (unformat_input_t * input, va_list * args)
45 u32 *result = va_arg (*args, u32 *);
47 return unformat (input, "%u", result);
52 vl_api_graph_node_get_reply_t_handler (vl_api_graph_node_get_reply_t * mp)
54 vat_main_t *vam = &vat_main;
56 clib_warning ("Next node index: %u\n", mp->cursor);
57 vam->result_ready = 1;
61 api_graph_node_get (vat_main_t * vam)
63 graph_test_main_t *gtm = &graph_test_main;
64 unformat_input_t *i = vam->input;
65 vl_api_graph_node_get_t *mp;
66 vl_api_control_ping_t *mp_ping;
74 clib_warning ("JSON output not supported for graph_node_get");
83 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
85 if (unformat (i, "node_index %u", &node_index))
87 else if (unformat (i, "node_name %s", &node_name))
89 else if (unformat (i, "want_arcs"))
91 else if (unformat (i, "trace_supported"))
92 flags |= NODE_FLAG_TRACE_SUPPORTED;
93 else if (unformat (i, "input"))
94 flags |= NODE_FLAG_TRACE_SUPPORTED;
95 else if (unformat (i, "drop"))
96 flags |= NODE_FLAG_IS_DROP;
97 else if (unformat (i, "ouptput"))
98 flags |= NODE_FLAG_IS_OUTPUT;
99 else if (unformat (i, "punt"))
100 flags |= NODE_FLAG_IS_PUNT;
101 else if (unformat (i, "handoff"))
102 flags |= NODE_FLAG_IS_HANDOFF;
103 else if (unformat (i, "no_free"))
104 flags |= NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH;
105 else if (unformat (i, "polling"))
106 flags |= NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE;
107 else if (unformat (i, "interrupt"))
108 flags |= NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE;
111 clib_warning ("Unknown input: %U\n", format_unformat_error, i);
116 M (GRAPH_NODE_GET, mp);
117 mp->index = htonl (node_index);
118 mp->flags = htonl (flags);
119 mp->want_arcs = want_arcs;
121 if (node_name && node_name[0])
122 clib_strncpy ((char *) mp->name, node_name, sizeof (mp->name) - 1);
129 vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
131 mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping));
132 mp_ping->_vl_msg_id = htons (gtm->ping_id);
133 mp_ping->client_index = vam->my_client_index;
142 vl_api_graph_node_details_t_handler (vl_api_graph_node_details_t * mp)
144 vat_main_t *vam = &vat_main;
149 "Node: %s Index:%d Flags:0x%x\n",
150 mp->name, ntohl (mp->index), ntohl (mp->flags));
152 n_arcs = ntohl (mp->n_arcs);
153 for (i = 0; i < n_arcs; ++i)
155 u32 node_index = ntohl (mp->arcs_out[i]);
156 fformat (vam->ofp, " next: %d\n", node_index);
161 vl_api_graph_node_details_t_handler_json (vl_api_graph_node_details_t * mp)
163 clib_error ("graph_node_details JSON not supported");
166 /* Override generated plugin register symbol */
167 #define vat_plugin_register graph_test_vat_plugin_register
168 #include <tracedump/graph.api_test.c>
170 static clib_error_t *
171 graph_api_hookup_shim (vlib_main_t * vm)
173 graph_test_vat_plugin_register (&vat_main);
177 VLIB_API_INIT_FUNCTION (graph_api_hookup_shim);
180 * fd.io coding-style-patch-verification: ON
183 * eval: (c-set-style "gnu")