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 "ip6_ioam_e2e.h"
30 ioam_e2e_main_t ioam_e2e_main;
32 static u8 * ioam_e2e_trace_handler (u8 * s,
33 ip6_hop_by_hop_option_t *opt)
35 ioam_e2e_option_t * e2e = (ioam_e2e_option_t *)opt;
40 seqno = clib_net_to_host_u32 (e2e->e2e_hdr.e2e_data);
43 s = format (s, "SeqNo = 0x%Lx", seqno);
48 ioam_e2e_config_handler (void *data, u8 disable)
52 /* Register hanlders if enabled */
55 /* If encap node register for encap handler */
58 if (ip6_hbh_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
59 ioam_seqno_encap_handler,
60 ioam_e2e_trace_handler) < 0)
65 /* If analyze node then register for decap handler */
68 if (ip6_hbh_pop_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
69 ioam_seqno_decap_handler) < 0)
77 /* UnRegister handlers */
78 (void) ip6_hbh_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
79 (void) ip6_hbh_pop_unregister_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE);
84 ioam_e2e_rewrite_handler (u8 *rewrite_string,
87 ioam_e2e_option_t *e2e_option;
89 if (rewrite_string && *rewrite_size == sizeof(ioam_e2e_option_t))
91 e2e_option = (ioam_e2e_option_t *)rewrite_string;
92 e2e_option->hdr.type = HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
93 | HBH_OPTION_TYPE_SKIP_UNKNOWN;
94 e2e_option->hdr.length = sizeof (ioam_e2e_option_t) -
95 sizeof (ip6_hop_by_hop_option_t);
102 ioam_e2e_flow_handler (u32 ctx, u8 add)
104 ioam_e2e_data_t *data;
109 pool_get(ioam_e2e_main.e2e_data, data);
110 data->flow_ctx = ctx;
111 ioam_seqno_init_data(&data->seqno_data);
112 return ((u32) (data - ioam_e2e_main.e2e_data));
116 for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
118 if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
121 data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
122 if (data && (data->flow_ctx == ctx))
124 pool_put_index(ioam_e2e_main.e2e_data, i);
131 static clib_error_t *
132 ioam_show_e2e_cmd_fn (vlib_main_t * vm,
133 unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 ioam_e2e_data_t *e2e_data;
142 s = format(0, "IOAM E2E information: \n");
143 for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
145 if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
148 e2e_data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
149 s = format(s, "Flow name: %s\n", get_flow_name_from_flow_ctx(e2e_data->flow_ctx));
151 s = show_ioam_seqno_cmd_fn(s,
152 &e2e_data->seqno_data,
153 !IOAM_DEAP_ENABLED(e2e_data->flow_ctx));
156 vlib_cli_output(vm, "%v", s);
161 VLIB_CLI_COMMAND (ioam_show_e2e_cmd, static) = {
162 .path = "show ioam e2e ",
163 .short_help = "show ioam e2e information",
164 .function = ioam_show_e2e_cmd_fn,
168 * Init handler E2E headet handling.
169 * Init hanlder registers encap, decap, trace and Rewrite handlers.
171 static clib_error_t *
172 ioam_e2e_init (vlib_main_t * vm)
175 * As of now we have only PPC under E2E header.
177 if (ip6_hbh_config_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
178 ioam_e2e_config_handler) < 0)
180 return (clib_error_create("Registration of "
181 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
184 if (ip6_hbh_add_register_option(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
185 sizeof(ioam_e2e_option_t),
186 ioam_e2e_rewrite_handler) < 0)
188 return (clib_error_create("Registration of "
189 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
192 if (ip6_hbh_flow_handler_register(HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE,
193 ioam_e2e_flow_handler) < 0)
195 return (clib_error_create("Registration of "
196 "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE Flow handler failed"));
199 ioam_e2e_main.vlib_main = vm;
200 ioam_e2e_main.vnet_main = vnet_get_main();
206 * Init function for the E2E lib.
207 * ip6_hop_by_hop_ioam_e2e_init gets called during init.
210 VLIB_INIT_FUNCTION (ioam_e2e_init) =
212 .runs_after = VLIB_INITS("ip6_hop_by_hop_ioam_init"),