FD.io VPP  v17.01.1-3-gc6833f8
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 <vlibsocket/api.h>
28 #include <vnet/ip/ip6_hop_by_hop.h>
29 
30 
31 /* define message IDs */
33 
34 /* define message structures */
35 #define vl_typedefs
37 #undef vl_typedefs
38 
39 /* define generated endian-swappers */
40 #define vl_endianfun
42 #undef vl_endianfun
43 
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #define vl_printfun
48 #undef vl_printfun
49 
50 /* Get the API version number */
51 #define vl_api_version(n,v) static u32 api_version=(v);
53 #undef vl_api_version
54 
55 /*
56  * A handy macro to set up a message reply.
57  * Assumes that the following variables are available:
58  * mp - pointer to request message
59  * rmp - pointer to reply message type
60  * rv - return value
61  */
62 
63 #define REPLY_MACRO(t) \
64 do { \
65  unix_shared_memory_queue_t * q = \
66  vl_api_client_index_to_input_queue (mp->client_index); \
67  if (!q) \
68  return; \
69  \
70  rmp = vl_msg_api_alloc (sizeof (*rmp)); \
71  rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \
72  rmp->context = mp->context; \
73  rmp->retval = ntohl(rv); \
74  \
75  vl_msg_api_send_shmem (q, (u8 *)&rmp); \
76 } while(0);
77 
78 
79 /* List of message types that this plugin understands */
80 
81 #define foreach_ioam_export_plugin_api_msg \
82 _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable)
83 
84 /* Action function shared between message handler and debug CLI */
85 
86 int
88  u8 is_disable,
89  ip4_address_t * collector_address,
90  ip4_address_t * src_address)
91 {
92  vlib_main_t *vm = em->vlib_main;
93 
94  if (is_disable == 0)
95  {
96  if (1 == ioam_export_header_create (em, collector_address, src_address))
97  {
100  /* Turn on the export buffer check process */
102 
103  }
104  else
105  {
106  return (-2);
107  }
108  }
109  else
110  {
112  ioam_export_header_cleanup (em, collector_address, src_address);
114  /* Turn off the export buffer check process */
116 
117  }
118 
119  return 0;
120 }
121 
122 /* API message handler */
125 {
128  int rv;
129 
130  rv = ioam_export_ip6_enable_disable (sm, (int) (mp->is_disable),
131  (ip4_address_t *)
132  mp->collector_address,
133  (ip4_address_t *) mp->src_address);
134 
135  REPLY_MACRO (VL_API_IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY);
136 }
137 
138 /* Set up the API message handling tables */
139 static clib_error_t *
141 {
143 #define _(N,n) \
144  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
145  #n, \
146  vl_api_##n##_t_handler, \
147  vl_noop_handler, \
148  vl_api_##n##_t_endian, \
149  vl_api_##n##_t_print, \
150  sizeof(vl_api_##n##_t), 1);
152 #undef _
153 
154  return 0;
155 }
156 
157 #define vl_msg_name_crc_list
159 #undef vl_msg_name_crc_list
160 
161 static void
163 {
164 #define _(id,n,crc) \
165  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
166  foreach_vl_msg_name_crc_ioam_export;
167 #undef _
168 }
169 
170 static clib_error_t *
172  unformat_input_t * input,
173  vlib_cli_command_t * cmd)
174 {
176  ip4_address_t collector, src;
177  u8 is_disable = 0;
178 
179  collector.as_u32 = 0;
180  src.as_u32 = 0;
181 
183  {
184  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
185  ;
186  else if (unformat (input, "src %U", unformat_ip4_address, &src))
187  ;
188  else if (unformat (input, "disable"))
189  is_disable = 1;
190  else
191  break;
192  }
193 
194  if (collector.as_u32 == 0)
195  return clib_error_return (0, "collector address required");
196 
197  if (src.as_u32 == 0)
198  return clib_error_return (0, "src address required");
199 
200  em->ipfix_collector.as_u32 = collector.as_u32;
201  em->src_address.as_u32 = src.as_u32;
202 
203  vlib_cli_output (vm, "Collector %U, src address %U",
206 
207  /* Turn on the export timer process */
208  // vlib_process_signal_event (vm, flow_report_process_node.index,
209  //1, 0);
210  ioam_export_ip6_enable_disable (em, is_disable, &collector, &src);
211 
212  return 0;
213 }
214 
215 /* *INDENT-OFF* */
216 VLIB_CLI_COMMAND (set_ipfix_command, static) =
217 {
218 .path = "set ioam export ipfix",.short_help =
219  "set ioam export ipfix collector <ip4-address> src <ip4-address>",.
221 /* *INDENT-ON* */
222 
223 
224 static clib_error_t *
226 {
228  clib_error_t *error = 0;
229  u8 *name;
230  u32 node_index = export_node.index;
231  vlib_node_t *ip6_hbyh_node = NULL;
232 
233  em->vlib_main = vm;
234  em->vnet_main = vnet_get_main ();
235 
236  name = format (0, "ioam_export_%08x%c", api_version, 0);
237 
238  /* Ask for a correctly-sized block of API message decode slots */
240  ((char *) name, VL_MSG_FIRST_AVAILABLE);
241  em->unix_time_0 = (u32) time (0); /* Store starting time */
242  em->vlib_time_0 = vlib_time_now (vm);
243 
244  error = ioam_export_plugin_api_hookup (vm);
245 
246  /* Add our API messages to the global name_crc hash table */
248 
249  /* Hook this export node to ip6-hop-by-hop */
250  ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop");
251  em->my_hbh_slot = vlib_node_add_next (vm, ip6_hbyh_node->index, node_index);
252  vec_free (name);
253 
254  return error;
255 }
256 
258 
259 /*
260  * fd.io coding-style-patch-verification: ON
261  *
262  * Local Variables:
263  * eval: (c-set-style "gnu")
264  * End:
265  */
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
void ip6_hbh_set_next_override(uword next)
Definition: ip6_forward.c:2764
u32 export_process_node_index
Definition: ioam_export.h:73
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define NULL
Definition: clib.h:55
u32 index
Definition: node.h:237
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:182
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:216
format_function_t format_ip4_address
Definition: format.h:79
ip4_address_t ipfix_collector
Definition: ioam_export.h:53
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:87
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1063
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:171
api_main_t api_main
Definition: api_shared.c:39
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define foreach_ioam_export_plugin_api_msg
Definition: ioam_export.c:81
unformat_function_t unformat_ip4_address
Definition: format.h:76
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:931
#define REPLY_MACRO(t)
Definition: ioam_export.c:63
vlib_node_registration_t export_node
(constructor) VLIB_REGISTER_NODE (export_node)
Definition: node.c:41
static clib_error_t * ioam_export_init(vlib_main_t *vm)
Definition: ioam_export.c:225
vnet_main_t * vnet_main
Definition: ioam_export.h:69
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:207
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:576
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
Definition: ioam_export.h:130
vlib_main_t * vlib_main
Definition: ioam_export.h:68
static clib_error_t * ioam_export_plugin_api_hookup(vlib_main_t *vm)
Definition: ioam_export.c:140
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
ip4_address_t src_address
Definition: ioam_export.h:54
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
unsigned char u8
Definition: types.h:56
static void vl_api_ioam_export_ip6_enable_disable_t_handler(vl_api_ioam_export_ip6_enable_disable_t *mp)
Definition: ioam_export.c:124
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
Definition: ioam_export.h:152
u16 vl_msg_api_get_msg_ids(char *name, int n)
Definition: api_shared.c:1309
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
ioam_export_main_t ioam_export_main
Definition: ioam_export.h:76
static void setup_message_id_table(ioam_export_main_t *sm, api_main_t *am)
Definition: ioam_export.c:162