FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
vxlan_gpe_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  * vxlan_gpe_ioam_export.c - ioam export API / debug CLI handling
18  *------------------------------------------------------------------
19  */
20 
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
25 
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 #include <vlibsocket/api.h>
29 
31 
32 /* define message IDs */
34 
35 /* define message structures */
36 #define vl_typedefs
38 #undef vl_typedefs
39 
40 /* define generated endian-swappers */
41 #define vl_endianfun
43 #undef vl_endianfun
44 
45 /* instantiate all the print functions we know about */
46 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #define vl_printfun
49 #undef vl_printfun
50 
51 /* Get the API version number */
52 #define vl_api_version(n,v) static u32 api_version=(v);
54 #undef vl_api_version
55 
56 /*
57  * A handy macro to set up a message reply.
58  * Assumes that the following variables are available:
59  * mp - pointer to request message
60  * rmp - pointer to reply message type
61  * rv - return value
62  */
63 
64 #define REPLY_MACRO(t) \
65 do { \
66  unix_shared_memory_queue_t * q = \
67  vl_api_client_index_to_input_queue (mp->client_index); \
68  if (!q) \
69  return; \
70  \
71  rmp = vl_msg_api_alloc (sizeof (*rmp)); \
72  rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \
73  rmp->context = mp->context; \
74  rmp->retval = ntohl(rv); \
75  \
76  vl_msg_api_send_shmem (q, (u8 *)&rmp); \
77 } while(0);
78 
79 
80 /* List of message types that this plugin understands */
81 
82 
83 #define foreach_vxlan_gpe_ioam_export_plugin_api_msg \
84 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable)
85 
86 extern void vxlan_gpe_set_next_override (uword next);
87 /* Action function shared between message handler and debug CLI */
88 int
90  u8 is_disable,
91  ip4_address_t * collector_address,
92  ip4_address_t * src_address)
93 {
94  vlib_main_t *vm = em->vlib_main;
95  u32 node_index = vxlan_export_node.index;
96  vlib_node_t *vxlan_gpe_decap_ioam_node = NULL;
97 
98  if (is_disable == 0)
99  {
100  if (em->my_hbh_slot == ~0)
101  {
102  /* Hook this export node to vxlan-gpe-decap-ioam-v4 */
103  vxlan_gpe_decap_ioam_node =
104  vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-decap-ioam-v4");
105  if (!vxlan_gpe_decap_ioam_node)
106  {
107  /* node does not exist give up */
108  return (-1);
109  }
110  em->my_hbh_slot =
111  vlib_node_add_next (vm, vxlan_gpe_decap_ioam_node->index,
112  node_index);
113  }
114  if (1 == ioam_export_header_create (em, collector_address, src_address))
115  {
118  /* Turn on the export buffer check process */
120 
121  }
122  else
123  {
124  return (-2);
125  }
126  }
127  else
128  {
130  ioam_export_header_cleanup (em, collector_address, src_address);
132  /* Turn off the export buffer check process */
134 
135  }
136 
137  return 0;
138 }
139 
140 /* API message handler */
143 {
146  int rv;
147 
148  rv = vxlan_gpe_ioam_export_enable_disable (sm, (int) (mp->is_disable),
149  (ip4_address_t *)
150  mp->collector_address,
151  (ip4_address_t *)
152  mp->src_address);
153 
154  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY);
155 } /* API message handler */
156 
157 
158 
159 /* Set up the API message handling tables */
160 static clib_error_t *
162 {
164 #define _(N,n) \
165  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
166  #n, \
167  vl_api_##n##_t_handler, \
168  vl_noop_handler, \
169  vl_api_##n##_t_endian, \
170  vl_api_##n##_t_print, \
171  sizeof(vl_api_##n##_t), 1);
173 #undef _
174 
175  return 0;
176 }
177 
178 
179 static clib_error_t *
181  unformat_input_t * input,
182  vlib_cli_command_t * cmd)
183 {
185  ip4_address_t collector, src;
186  u8 is_disable = 0;
187 
188  collector.as_u32 = 0;
189  src.as_u32 = 0;
190 
192  {
193  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
194  ;
195  else if (unformat (input, "src %U", unformat_ip4_address, &src))
196  ;
197  else if (unformat (input, "disable"))
198  is_disable = 1;
199  else
200  break;
201  }
202 
203  if (collector.as_u32 == 0)
204  return clib_error_return (0, "collector address required");
205 
206  if (src.as_u32 == 0)
207  return clib_error_return (0, "src address required");
208 
209  em->ipfix_collector.as_u32 = collector.as_u32;
210  em->src_address.as_u32 = src.as_u32;
211 
212  vlib_cli_output (vm, "Collector %U, src address %U",
215 
216  /* Turn on the export timer process */
217  // vlib_process_signal_event (vm, flow_report_process_node.index,
218  //1, 0);
219  if (0 !=
220  vxlan_gpe_ioam_export_enable_disable (em, is_disable, &collector, &src))
221  {
222  return clib_error_return (0, "Unable to set ioam vxlan-gpe export");
223  }
224 
225  return 0;
226 }
227 
228 /* *INDENT-OFF* */
229 VLIB_CLI_COMMAND (set_vxlan_gpe_ioam_ipfix_command, static) =
230 {
231 .path = "set vxlan-gpe-ioam export ipfix",
232 .short_help = "set vxlan-gpe-ioam export ipfix collector <ip4-address> src <ip4-address>",
234 };
235 /* *INDENT-ON* */
236 
237 
238 static clib_error_t *
240 {
242  clib_error_t *error = 0;
243  u8 *name;
244 
245  name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
246 
247  /* Ask for a correctly-sized block of API message decode slots */
249  ((char *) name, VL_MSG_FIRST_AVAILABLE);
250  em->unix_time_0 = (u32) time (0); /* Store starting time */
251  em->vlib_time_0 = vlib_time_now (vm);
252 
254  em->my_hbh_slot = ~0;
255  em->vlib_main = vm;
256  em->vnet_main = vnet_get_main ();
257  vec_free (name);
258 
259  return error;
260 }
261 
263 
264 
265 /*
266  * fd.io coding-style-patch-verification: ON
267  *
268  * Local Variables:
269  * eval: (c-set-style "gnu")
270  * End:
271  */
#define foreach_vxlan_gpe_ioam_export_plugin_api_msg
static clib_error_t * vxlan_gpe_ioam_export_init(vlib_main_t *vm)
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
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
VXLAN GPE definitions.
int vxlan_gpe_ioam_export_enable_disable(ioam_export_main_t *em, u8 is_disable, ip4_address_t *collector_address, ip4_address_t *src_address)
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
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1063
ioam_export_main_t vxlan_gpe_ioam_export_main
Definition: ioam_export.h:77
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
unformat_function_t unformat_ip4_address
Definition: format.h:76
vlib_node_registration_t vxlan_export_node
(constructor) VLIB_REGISTER_NODE (vxlan_export_node)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:931
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
static clib_error_t * vxlan_gpe_ioam_export_plugin_api_hookup(vlib_main_t *vm)
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
#define REPLY_MACRO(t)
#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
static clib_error_t * set_vxlan_gpe_ioam_export_ipfix_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
void vxlan_gpe_set_next_override(uword next)
unsigned int u32
Definition: types.h:88
u64 uword
Definition: types.h:112
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 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
static void vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler(vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp)