FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
ip6_ioam_e2e.c
Go to the documentation of this file.
1 /*
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:
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 <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vnet/pg/pg.h>
19 #include <vppinfra/error.h>
20 
21 #include <vnet/ip/ip.h>
22 
23 #include <vppinfra/hash.h>
24 #include <vppinfra/error.h>
25 #include <vppinfra/elog.h>
26 
27 #include <vnet/ip/ip6_hop_by_hop.h>
28 #include "ip6_ioam_e2e.h"
29 
31 
34 {
35  ioam_e2e_option_t * e2e = (ioam_e2e_option_t *)opt;
36  u32 seqno = 0;
37 
38  if (e2e)
39  {
40  seqno = clib_net_to_host_u32 (e2e->e2e_hdr.e2e_data);
41  }
42 
43  s = format (s, "SeqNo = 0x%Lx", seqno);
44  return s;
45 }
46 
47 int
49 {
50  int *analyse = data;
51 
52  /* Register hanlders if enabled */
53  if (!disable)
54  {
55  /* If encap node register for encap handler */
56  if (0 == *analyse)
57  {
61  {
62  return (-1);
63  }
64  }
65  /* If analyze node then register for decap handler */
66  else
67  {
70  {
71  return (-1);
72  }
73  }
74  return 0;
75  }
76 
77  /* UnRegister handlers */
80  return 0;
81 }
82 
83 int
84 ioam_e2e_rewrite_handler (u8 *rewrite_string,
85  u8 *rewrite_size)
86 {
87  ioam_e2e_option_t *e2e_option;
88 
89  if (rewrite_string && *rewrite_size == sizeof(ioam_e2e_option_t))
90  {
91  e2e_option = (ioam_e2e_option_t *)rewrite_string;
92  e2e_option->hdr.type = HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
94  e2e_option->hdr.length = sizeof (ioam_e2e_option_t) -
95  sizeof (ip6_hop_by_hop_option_t);
96  return(0);
97  }
98  return(-1);
99 }
100 
101 u32
103 {
105  u16 i;
106 
107  if (add)
108  {
109  pool_get(ioam_e2e_main.e2e_data, data);
110  data->flow_ctx = ctx;
112  return ((u32) (data - ioam_e2e_main.e2e_data));
113  }
114 
115  /* Delete case */
116  for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
117  {
118  if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
119  continue;
120 
121  data = pool_elt_at_index(ioam_e2e_main.e2e_data, i);
122  if (data && (data->flow_ctx == ctx))
123  {
124  pool_put_index(ioam_e2e_main.e2e_data, i);
125  return (0);
126  }
127  }
128  return 0;
129 }
130 
131 static clib_error_t *
133  unformat_input_t * input,
134  vlib_cli_command_t * cmd)
135 {
136  ioam_e2e_data_t *e2e_data;
137  u8 *s = 0;
138  int i;
139 
140  vec_reset_length(s);
141 
142  s = format(0, "IOAM E2E information: \n");
143  for (i = 0; i < vec_len(ioam_e2e_main.e2e_data); i++)
144  {
145  if (pool_is_free_index(ioam_e2e_main.e2e_data, i))
146  continue;
147 
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));
150 
152  &e2e_data->seqno_data,
153  !IOAM_DEAP_ENABLED(e2e_data->flow_ctx));
154  }
155 
156  vlib_cli_output(vm, "%v", s);
157  return 0;
158 }
159 
160 
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,
165 };
166 
167 /*
168  * Init handler E2E headet handling.
169  * Init hanlder registers encap, decap, trace and Rewrite handlers.
170  */
171 static clib_error_t *
173 {
174  clib_error_t * error;
175 
177  {
178  return(error);
179  }
180 
181  /*
182  * As of now we have only PPC under E2E header.
183  */
186  {
187  return (clib_error_create("Registration of "
188  "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
189  }
190 
192  sizeof(ioam_e2e_option_t),
194  {
195  return (clib_error_create("Registration of "
196  "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE for rewrite failed"));
197  }
198 
201  {
202  return (clib_error_create("Registration of "
203  "HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE Flow handler failed"));
204  }
205 
206  ioam_e2e_main.vlib_main = vm;
207  ioam_e2e_main.vnet_main = vnet_get_main();
208 
209  return (0);
210 }
211 
212 /*
213  * Init function for the E2E lib.
214  * ip6_hop_by_hop_ioam_e2e_init gets called during init.
215  */
int ioam_seqno_encap_handler(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt)
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
int ip6_hbh_register_option(u8 option, int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt), u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt))
Definition: ip6_forward.c:2624
int ioam_seqno_decap_handler(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt)
void ioam_seqno_init_data(ioam_seqno_data *data)
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 data[128]
Definition: ipsec.api:248
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
unsigned char u8
Definition: types.h:56
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
int ip6_hbh_flow_handler_register(u8 option, u32 ioam_flow_handler(u32 flow_ctx, u8 add))
int ip6_hbh_pop_unregister_option(u8 option)
static u8 * ioam_e2e_trace_handler(u8 *s, ip6_hop_by_hop_option_t *opt)
Definition: ip6_ioam_e2e.c:32
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
#define HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
int ip6_hbh_pop_register_option(u8 option, int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt))
vnet_main_t * vnet_main
Definition: ip6_ioam_e2e.h:38
unsigned int u32
Definition: types.h:88
#define clib_error_create(args...)
Definition: error.h:96
#define vlib_call_init_function(vm, x)
Definition: init.h:260
int ip6_hbh_unregister_option(u8 option)
Definition: ip6_forward.c:2648
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static clib_error_t * ioam_e2e_init(vlib_main_t *vm)
Definition: ip6_ioam_e2e.c:172
vlib_main_t * vlib_main
Definition: ip6_ioam_e2e.h:37
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
u32 ioam_e2e_flow_handler(u32 ctx, u8 add)
Definition: ip6_ioam_e2e.c:102
vlib_main_t * vm
Definition: buffer.c:312
int ip6_hbh_config_handler_register(u8 option, int config_handler(void *data, u8 disable))
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
ioam_seqno_data seqno_data
Definition: ip6_ioam_e2e.h:32
ioam_e2e_main_t ioam_e2e_main
Definition: ip6_ioam_e2e.c:30
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:311
u8 * show_ioam_seqno_cmd_fn(u8 *s, ioam_seqno_data *seqno_data, u8 enc)
u8 * get_flow_name_from_flow_ctx(u32 flow_ctx)
int ioam_e2e_config_handler(void *data, u8 disable)
Definition: ip6_ioam_e2e.c:48
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static clib_error_t * ip6_hop_by_hop_ioam_init(vlib_main_t *vm)
static clib_error_t * ioam_show_e2e_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_ioam_e2e.c:132
ioam_e2e_data_t * e2e_data
Definition: ip6_ioam_e2e.h:36
int ioam_e2e_rewrite_handler(u8 *rewrite_string, u8 *rewrite_size)
Definition: ip6_ioam_e2e.c:84
#define HBH_OPTION_TYPE_SKIP_UNKNOWN
#define IOAM_DEAP_ENABLED(opaque_data)
int ip6_hbh_add_register_option(u8 option, u8 size, int rewrite_options(u8 *rewrite_string, u8 *rewrite_size))
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:725