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:
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 <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vnet/pg/pg.h>
19 #include <vppinfra/error.h>
21 #include <vnet/ip/ip.h>
23 #include <vppinfra/hash.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/elog.h>
27 #include <vnet/ip/ip6_hop_by_hop.h>
28 #include <vnet/plugin/plugin.h>
30 #include "ip6_ioam_e2e.h"
32 ioam_e2e_main_t ioam_e2e_main;
34 static u8 * ioam_e2e_trace_handler (u8 * s,
35 ip6_hop_by_hop_option_t *opt)
37 ioam_e2e_option_t * e2e = (ioam_e2e_option_t *)opt;
42 seqno = clib_net_to_host_u32 (e2e->e2e_data);
45 s = format (s, "SeqNo = 0x%Lx", seqno);
50 ioam_e2e_config_handler (void *data, u8 disable)
54 /* Register hanlders if enabled */
57 /* If encap node register for encap handler */
60 if (ip6_hbh_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
61 ioam_seqno_encap_handler,
62 ioam_e2e_trace_handler) < 0)
67 /* If analyze node then register for decap handler */
70 if (ip6_hbh_pop_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
71 ioam_seqno_decap_handler) < 0)
79 /* UnRegister handlers */
80 (void) ip6_hbh_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
81 (void) ip6_hbh_pop_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
86 ioam_e2e_rewrite_handler (u8 *rewrite_string,
89 ioam_e2e_option_t *e2e_option;
91 if (rewrite_string && *rewrite_size == sizeof(ioam_e2e_option_t))
93 e2e_option = (ioam_e2e_option_t *)rewrite_string;
94 e2e_option->hdr.type = HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
95 | HBH_OPTION_TYPE_SKIP_UNKNOWN;
96 e2e_option->hdr.length = sizeof (ioam_e2e_option_t) -
97 sizeof (ip6_hop_by_hop_option_t);
104 ioam_e2e_flow_handler (u32 ctx, u8 add)
106 ioam_e2e_data_t *data;
111 pool_get(ioam_e2e_main.e2e_data, data);
112 data->flow_ctx = ctx;
113 ioam_seqno_init_bitmap(&data->seqno_data);
114 return ((u32) (data - ioam_e2e_main.e2e_data));
118 for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
120 if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
123 data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
124 if (data && (data->flow_ctx == ctx))
126 pool_put_index(ioam_e2e_main.e2e_data, i);
133 static clib_error_t *
134 ioam_show_e2e_cmd_fn (vlib_main_t * vm,
135 unformat_input_t * input,
136 vlib_cli_command_t * cmd)
138 ioam_e2e_data_t *e2e_data;
144 s = format(0, "IOAM E2E information: \n");
145 for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
147 if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
150 e2e_data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
151 s = format(s, "Flow name: %s\n", get_flow_name_from_flow_ctx(e2e_data->flow_ctx));
153 s = show_ioam_seqno_cmd_fn(s,
154 &e2e_data->seqno_data,
155 !IOAM_DEAP_ENABLED(e2e_data->flow_ctx));
158 vlib_cli_output(vm, "%v", s);
163 VLIB_CLI_COMMAND (ioam_show_e2e_cmd, static) = {
164 .path = "show ioam e2e ",
165 .short_help = "show ioam e2e information",
166 .function = ioam_show_e2e_cmd_fn,
170 * This routine exists to convince the vlib plugin framework that
171 * we haven't accidentally copied a random .dll into the plugin directory.
173 * Also collects global variable pointers passed from the vpp engine
176 vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h,
179 clib_error_t * error = 0;
181 ioam_e2e_main.vlib_main = vm;
182 ioam_e2e_main.vnet_main = h->vnet_main;
187 * Init handler E2E headet handling.
188 * Init hanlder registers encap, decap, trace and Rewrite handlers.
190 static clib_error_t *
191 ioam_e2e_init (vlib_main_t * vm)
193 clib_error_t * error;
195 if ((error = vlib_call_init_function (vm, ip6_hop_by_hop_ioam_init)))
201 * As of now we have only PPC under E2E header.
203 if (ip6_hbh_config_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
204 ioam_e2e_config_handler) < 0)
206 return (clib_error_create("Registration of "
207 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
210 if (ip6_hbh_add_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
211 sizeof(ioam_e2e_option_t),
212 ioam_e2e_rewrite_handler) < 0)
214 return (clib_error_create("Registration of "
215 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
218 if (ip6_hbh_flow_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
219 ioam_e2e_flow_handler) < 0)
221 return (clib_error_create("Registration of "
222 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE Flow handler failed"));
229 * Init function for the E2E lib.
230 * ip6_hop_by_hop_ioam_e2e_init gets called during init.
232 VLIB_INIT_FUNCTION (ioam_e2e_init);