FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
ioam_export.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  *------------------------------------------------------------------
17  * ioam_export.c - ioam export API / debug CLI handling
18  *------------------------------------------------------------------
19  */
20 
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
24 
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 #include <vnet/ip/ip6_hop_by_hop.h>
28 
29 
30 /* define message IDs */
32 
33 /* define message structures */
34 #define vl_typedefs
36 #undef vl_typedefs
37 
38 /* define generated endian-swappers */
39 #define vl_endianfun
41 #undef vl_endianfun
42 
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
45 #define vl_printfun
47 #undef vl_printfun
48 
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
52 #undef vl_api_version
53 
54 #define REPLY_MSG_ID_BASE sm->msg_id_base
56 
57 /* List of message types that this plugin understands */
58 #define foreach_ioam_export_plugin_api_msg \
59 _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable)
60 
62 
64 
65 /* Action function shared between message handler and debug CLI */
66 
67 int
69  u8 is_disable,
70  ip4_address_t * collector_address,
72 {
73  vlib_main_t *vm = em->vlib_main;
74 
75  if (is_disable == 0)
76  {
77  if (1 == ioam_export_header_create (em, collector_address, src_address))
78  {
81  /* Turn on the export buffer check process */
83 
84  }
85  else
86  {
87  return (-2);
88  }
89  }
90  else
91  {
93  ioam_export_header_cleanup (em, collector_address, src_address);
95  /* Turn off the export buffer check process */
97 
98  }
99 
100  return 0;
101 }
102 
103 /* API message handler */
106 {
107  vl_api_ioam_export_ip6_enable_disable_reply_t *rmp;
109  int rv;
110 
111  rv = ioam_export_ip6_enable_disable (sm, (int) (mp->is_disable),
112  (ip4_address_t *)
113  mp->collector_address,
114  (ip4_address_t *) mp->src_address);
115 
116  REPLY_MACRO (VL_API_IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY);
117 }
118 
119 /* Set up the API message handling tables */
120 static clib_error_t *
122 {
124 #define _(N,n) \
125  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
126  #n, \
127  vl_api_##n##_t_handler, \
128  vl_noop_handler, \
129  vl_api_##n##_t_endian, \
130  vl_api_##n##_t_print, \
131  sizeof(vl_api_##n##_t), 1);
133 #undef _
134 
135  return 0;
136 }
137 
138 #define vl_msg_name_crc_list
140 #undef vl_msg_name_crc_list
141 
142 static void
144 {
145 #define _(id,n,crc) \
146  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
147  foreach_vl_msg_name_crc_ioam_export;
148 #undef _
149 }
150 
151 static clib_error_t *
153  unformat_input_t * input,
154  vlib_cli_command_t * cmd)
155 {
157  ip4_address_t collector, src;
158  u8 is_disable = 0;
159 
160  collector.as_u32 = 0;
161  src.as_u32 = 0;
162 
164  {
165  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
166  ;
167  else if (unformat (input, "src %U", unformat_ip4_address, &src))
168  ;
169  else if (unformat (input, "disable"))
170  is_disable = 1;
171  else
172  break;
173  }
174 
175  if (collector.as_u32 == 0)
176  return clib_error_return (0, "collector address required");
177 
178  if (src.as_u32 == 0)
179  return clib_error_return (0, "src address required");
180 
181  em->ipfix_collector.as_u32 = collector.as_u32;
182  em->src_address.as_u32 = src.as_u32;
183 
184  vlib_cli_output (vm, "Collector %U, src address %U",
187 
188  /* Turn on the export timer process */
189  // vlib_process_signal_event (vm, flow_report_process_node.index,
190  //1, 0);
191  ioam_export_ip6_enable_disable (em, is_disable, &collector, &src);
192 
193  return 0;
194 }
195 
196 /* *INDENT-OFF* */
197 VLIB_CLI_COMMAND (set_ipfix_command, static) =
198 {
199 .path = "set ioam export ipfix",.short_help =
200  "set ioam export ipfix collector <ip4-address> src <ip4-address>",.
202 /* *INDENT-ON* */
203 
204 
205 static clib_error_t *
207 {
209  clib_error_t *error = 0;
210  u8 *name;
211  u32 node_index = export_node.index;
212  vlib_node_t *ip6_hbyh_node = NULL;
213 
214  em->vlib_main = vm;
215  em->vnet_main = vnet_get_main ();
218 
219  name = format (0, "ioam_export_%08x%c", api_version, 0);
220 
221  /* Ask for a correctly-sized block of API message decode slots */
223  ((char *) name, VL_MSG_FIRST_AVAILABLE);
224  em->unix_time_0 = (u32) time (0); /* Store starting time */
225  em->vlib_time_0 = vlib_time_now (vm);
226 
227  error = ioam_export_plugin_api_hookup (vm);
228 
229  /* Add our API messages to the global name_crc hash table */
231 
232  /* Hook this export node to ip6-hop-by-hop */
233  ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop");
234  em->my_hbh_slot = vlib_node_add_next (vm, ip6_hbyh_node->index, node_index);
235  vec_free (name);
236 
237  return error;
238 }
239 
241 
242 /*
243  * fd.io coding-style-patch-verification: ON
244  *
245  * Local Variables:
246  * eval: (c-set-style "gnu")
247  * End:
248  */
vl_api_address_t src
Definition: vxlan_gbp.api:32
void ip6_hbh_set_next_override(uword next)
Definition: ip6_forward.c:2560
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static void ioam_export_reset_next_node(ioam_export_main_t *em)
Definition: ioam_export.h:99
u32 export_process_node_index
Definition: ioam_export.h:78
#define NULL
Definition: clib.h:58
u32 index
Definition: node.h:304
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static int ioam_export_header_create(ioam_export_main_t *em, ip4_address_t *collector_address, ip4_address_t *src_address)
Definition: ioam_export.h:233
ip4_address_t ipfix_collector
Definition: ioam_export.h:57
int ioam_export_ip6_enable_disable(ioam_export_main_t *em, u8 is_disable, ip4_address_t *collector_address, ip4_address_t *src_address)
Definition: ioam_export.c:68
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
static clib_error_t * set_ioam_export_ipfix_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ioam_export.c:152
ioam_export_main_t ioam_export_main
Definition: ioam_export.c:61
format_function_t format_ip4_address
Definition: format.h:75
unformat_function_t unformat_ip4_address
Definition: format.h:70
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
#define foreach_ioam_export_plugin_api_msg
Definition: ioam_export.c:58
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
#define IPFIX_IOAM_EXPORT_ID
Definition: ioam_export.h:204
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
struct _unformat_input_t unformat_input_t
static clib_error_t * ioam_export_init(vlib_main_t *vm)
Definition: ioam_export.c:206
vnet_main_t * vnet_main
Definition: ioam_export.h:73
#define REPLY_MACRO(t)
vl_api_address_union_t src_address
Definition: ip_types.api:44
static void ioam_export_header_cleanup(ioam_export_main_t *em, ip4_address_t *collector_address, ip4_address_t *src_address)
Definition: ioam_export.h:224
u8 name[64]
Definition: memclnt.api:152
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
Definition: ioam_export.h:148
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
vlib_main_t * vlib_main
Definition: ioam_export.h:72
static clib_error_t * ioam_export_plugin_api_hookup(vlib_main_t *vm)
Definition: ioam_export.c:121
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:301
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
ip4_address_t src_address
Definition: ioam_export.h:58
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
vlib_node_registration_t export_node
(constructor) VLIB_REGISTER_NODE (export_node)
Definition: node.c:153
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
struct _vlib_node_registration vlib_node_registration_t
static void vl_api_ioam_export_ip6_enable_disable_t_handler(vl_api_ioam_export_ip6_enable_disable_t *mp)
Definition: ioam_export.c:105
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
Definition: ioam_export.h:170
api_main_t api_main
Definition: api_shared.c:35
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
static void setup_message_id_table(ioam_export_main_t *sm, api_main_t *am)
Definition: ioam_export.c:143
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:865