Line data Source code
1 : /* 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: 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 : #include <vat/vat.h> 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> 23 : 24 : #define __plugin_msg_base graph_test_main.msg_id_base 25 : #include <vlibapi/vat_helper_macros.h> 26 : 27 : #include <vnet/format_fns.h> 28 : #include <tracedump/graph.api_enum.h> 29 : #include <tracedump/graph.api_types.h> 30 : #include <vlibmemory/vlib.api_types.h> 31 : 32 : typedef struct 33 : { 34 : u16 msg_id_base; 35 : u32 ping_id; 36 : vat_main_t *vat_main; 37 : } graph_test_main_t; 38 : 39 : graph_test_main_t graph_test_main; 40 : 41 : 42 : uword 43 0 : api_unformat_node_index (unformat_input_t * input, va_list * args) 44 : { 45 0 : u32 *result = va_arg (*args, u32 *); 46 : 47 0 : return unformat (input, "%u", result); 48 : } 49 : 50 : 51 : static void 52 0 : vl_api_graph_node_get_reply_t_handler (vl_api_graph_node_get_reply_t * mp) 53 : { 54 0 : vat_main_t *vam = &vat_main; 55 : 56 0 : clib_warning ("Next node index: %u\n", mp->cursor); 57 0 : vam->result_ready = 1; 58 0 : } 59 : 60 : int 61 0 : api_graph_node_get (vat_main_t * vam) 62 : { 63 0 : graph_test_main_t *gtm = &graph_test_main; 64 0 : unformat_input_t *i = vam->input; 65 : vl_api_graph_node_get_t *mp; 66 : vl_api_control_ping_t *mp_ping; 67 : u32 node_index; 68 : char *node_name; 69 : u32 flags; 70 : bool want_arcs; 71 : 72 0 : if (vam->json_output) 73 : { 74 0 : clib_warning ("JSON output not supported for graph_node_get"); 75 0 : return -99; 76 : } 77 : 78 0 : node_index = ~0; 79 0 : node_name = 0; 80 0 : flags = 0; 81 0 : want_arcs = false; 82 : 83 0 : while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) 84 : { 85 0 : if (unformat (i, "node_index %u", &node_index)) 86 : ; 87 0 : else if (unformat (i, "node_name %s", &node_name)) 88 : ; 89 0 : else if (unformat (i, "want_arcs")) 90 0 : want_arcs = true; 91 0 : else if (unformat (i, "trace_supported")) 92 0 : flags |= NODE_FLAG_TRACE_SUPPORTED; 93 0 : else if (unformat (i, "input")) 94 0 : flags |= NODE_FLAG_TRACE_SUPPORTED; 95 0 : else if (unformat (i, "drop")) 96 0 : flags |= NODE_FLAG_IS_DROP; 97 0 : else if (unformat (i, "ouptput")) 98 0 : flags |= NODE_FLAG_IS_OUTPUT; 99 0 : else if (unformat (i, "punt")) 100 0 : flags |= NODE_FLAG_IS_PUNT; 101 0 : else if (unformat (i, "handoff")) 102 0 : flags |= NODE_FLAG_IS_HANDOFF; 103 0 : else if (unformat (i, "no_free")) 104 0 : flags |= NODE_FLAG_FRAME_NO_FREE_AFTER_DISPATCH; 105 0 : else if (unformat (i, "polling")) 106 0 : flags |= NODE_FLAG_SWITCH_FROM_INTERRUPT_TO_POLLING_MODE; 107 0 : else if (unformat (i, "interrupt")) 108 0 : flags |= NODE_FLAG_SWITCH_FROM_POLLING_TO_INTERRUPT_MODE; 109 : else 110 : { 111 0 : clib_warning ("Unknown input: %U\n", format_unformat_error, i); 112 0 : return -99; 113 : } 114 : } 115 : 116 0 : M (GRAPH_NODE_GET, mp); 117 0 : mp->index = htonl (node_index); 118 0 : mp->flags = htonl (flags); 119 0 : mp->want_arcs = want_arcs; 120 : 121 0 : if (node_name && node_name[0]) 122 0 : clib_strncpy ((char *) mp->name, node_name, sizeof (mp->name) - 1); 123 : 124 0 : int ret = 0; 125 0 : S (mp); 126 : 127 0 : if (!gtm->ping_id) 128 0 : gtm->ping_id = 129 0 : vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC)); 130 : 131 0 : mp_ping = vl_msg_api_alloc_as_if_client (sizeof (*mp_ping)); 132 0 : mp_ping->_vl_msg_id = htons (gtm->ping_id); 133 0 : mp_ping->client_index = vam->my_client_index; 134 : 135 0 : S (mp_ping); 136 0 : W (ret); 137 : 138 0 : return ret; 139 : } 140 : 141 : void 142 0 : vl_api_graph_node_details_t_handler (vl_api_graph_node_details_t * mp) 143 : { 144 0 : vat_main_t *vam = &vat_main; 145 : u32 n_arcs; 146 : int i; 147 : 148 0 : fformat (vam->ofp, 149 : "Node: %s Index:%d Flags:0x%x\n", 150 0 : mp->name, ntohl (mp->index), ntohl (mp->flags)); 151 : 152 0 : n_arcs = ntohl (mp->n_arcs); 153 0 : for (i = 0; i < n_arcs; ++i) 154 : { 155 0 : u32 node_index = ntohl (mp->arcs_out[i]); 156 0 : fformat (vam->ofp, " next: %d\n", node_index); 157 : } 158 0 : } 159 : 160 : void 161 0 : vl_api_graph_node_details_t_handler_json (vl_api_graph_node_details_t * mp) 162 : { 163 0 : clib_error ("graph_node_details JSON not supported"); 164 0 : } 165 : 166 : /* Override generated plugin register symbol */ 167 : #define vat_plugin_register graph_test_vat_plugin_register 168 : #include <tracedump/graph.api_test.c> 169 : 170 : static clib_error_t * 171 0 : graph_api_hookup_shim (vlib_main_t * vm) 172 : { 173 0 : graph_test_vat_plugin_register (&vat_main); 174 0 : return 0; 175 : } 176 : 177 1119 : VLIB_API_INIT_FUNCTION (graph_api_hookup_shim); 178 : 179 : /* 180 : * fd.io coding-style-patch-verification: ON 181 : * 182 : * Local Variables: 183 : * eval: (c-set-style "gnu") 184 : * End: 185 : */