2 * Copyright (c) 2019 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:
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.
16 #include <vnet/vnet.h>
17 #include <builtinurl/builtinurl.h>
18 #include <http_static/http_static.h>
19 #include <vpp/app/version.h>
22 handle_get_version (u8 * request, http_session_t * hs)
26 /* Build some json bullshit */
27 s = format (s, "{\"vpp_details\": {");
28 s = format (s, " \"version\": \"%s\",", VPP_BUILD_VER);
29 s = format (s, " \"build_date\": \"%s\"}}\r\n", VPP_BUILD_DATE);
33 hs->cache_pool_index = ~0;
39 trim_path_from_request (u8 * s, char *path)
42 int trim_length = strlen (path) + 1 /* remove '?' */ ;
44 /* Get rid of the path and question-mark */
45 vec_delete (s, trim_length, 0);
47 /* Tail trim irrelevant browser info */
49 while ((cp - s) < vec_len (s))
54 * Makes request a vector which happens to look
58 _vec_len (s) = cp - s;
66 handle_get_interface_stats (u8 * request, http_session_t * hs)
68 u8 *s = 0, *stats = 0;
71 vnet_sw_interface_t *si;
72 u8 *format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
73 vnet_sw_interface_t * si, int json);
75 vnet_main_t *vnm = vnet_get_main ();
77 trim_path_from_request (request, "interface_stats.json");
81 p = hash_get (vnm->interface_main.hw_interface_by_name, request);
84 clib_warning ("Couldn't find interface '%v'", request);
86 s = format (s, "{\"interface_stats\": {");
87 s = format (s, " \"name\": \"%s\",", request);
88 s = format (s, " \"stats\": \"%s\"", "ERRORUnknownInterface");
89 s = format (s, "}}\r\n");
94 si = vnet_get_sw_interface (vnm, sw_if_index);
96 stats = format_vnet_sw_interface_cntrs (stats, &vnm->interface_main, si,
99 s = format (s, "{\"interface_stats\": {");
100 s = format (s, "\"name\": \"%s\",\n", request);
101 s = format (s, "%s", stats);
102 s = format (s, "}}\n");
108 hs->cache_pool_index = ~0;
114 builtinurl_handler_init (builtinurl_main_t * bm)
117 bm->register_handler (handle_get_version, "version.json",
118 HTTP_BUILTIN_METHOD_GET);
119 bm->register_handler (handle_get_interface_stats,
120 "interface_stats.json", HTTP_BUILTIN_METHOD_POST);
124 * fd.io coding-style-patch-verification: ON
127 * eval: (c-set-style "gnu")