FD.io VPP  v17.07-30-g839fa73
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 #define REPLY_MSG_ID_BASE sm->msg_id_base
58 
59 /* List of message types that this plugin understands */
60 #define foreach_vxlan_gpe_ioam_export_plugin_api_msg \
61 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable)
62 
65 
66 extern void vxlan_gpe_set_next_override (uword next);
67 /* Action function shared between message handler and debug CLI */
68 int
70  u8 is_disable,
71  ip4_address_t * collector_address,
72  ip4_address_t * src_address)
73 {
74  vlib_main_t *vm = em->vlib_main;
75  u32 node_index = vxlan_export_node.index;
76  vlib_node_t *vxlan_gpe_decap_ioam_node = NULL;
77 
78  if (is_disable == 0)
79  {
80  if (em->my_hbh_slot == ~0)
81  {
82  /* Hook this export node to vxlan-gpe-decap-ioam-v4 */
83  vxlan_gpe_decap_ioam_node =
84  vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-decap-ioam-v4");
85  if (!vxlan_gpe_decap_ioam_node)
86  {
87  /* node does not exist give up */
88  return (-1);
89  }
90  em->my_hbh_slot =
91  vlib_node_add_next (vm, vxlan_gpe_decap_ioam_node->index,
92  node_index);
93  }
94  if (1 == ioam_export_header_create (em, collector_address, src_address))
95  {
98  /* Turn on the export buffer check process */
100 
101  }
102  else
103  {
104  return (-2);
105  }
106  }
107  else
108  {
110  ioam_export_header_cleanup (em, collector_address, src_address);
112  /* Turn off the export buffer check process */
114 
115  }
116 
117  return 0;
118 }
119 
120 /* API message handler */
123 {
124  vl_api_vxlan_gpe_ioam_export_enable_disable_reply_t *rmp;
126  int rv;
127 
128  rv = vxlan_gpe_ioam_export_enable_disable (sm, (int) (mp->is_disable),
129  (ip4_address_t *)
130  mp->collector_address,
131  (ip4_address_t *)
132  mp->src_address);
133 
134  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY);
135 } /* API message handler */
136 
137 
138 
139 /* Set up the API message handling tables */
140 static clib_error_t *
142 {
144 #define _(N,n) \
145  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
146  #n, \
147  vl_api_##n##_t_handler, \
148  vl_noop_handler, \
149  vl_api_##n##_t_endian, \
150  vl_api_##n##_t_print, \
151  sizeof(vl_api_##n##_t), 1);
153 #undef _
154 
155  return 0;
156 }
157 
158 #define vl_msg_name_crc_list
160 #undef vl_msg_name_crc_list
161 
162 static void
164 {
165 #define _(id,n,crc) \
166  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
167  foreach_vl_msg_name_crc_vxlan_gpe_ioam_export;
168 #undef _
169 }
170 
171 
172 static clib_error_t *
174  unformat_input_t * input,
175  vlib_cli_command_t * cmd)
176 {
178  ip4_address_t collector, src;
179  u8 is_disable = 0;
180 
181  collector.as_u32 = 0;
182  src.as_u32 = 0;
183 
185  {
186  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
187  ;
188  else if (unformat (input, "src %U", unformat_ip4_address, &src))
189  ;
190  else if (unformat (input, "disable"))
191  is_disable = 1;
192  else
193  break;
194  }
195 
196  if (collector.as_u32 == 0)
197  return clib_error_return (0, "collector address required");
198 
199  if (src.as_u32 == 0)
200  return clib_error_return (0, "src address required");
201 
202  em->ipfix_collector.as_u32 = collector.as_u32;
203  em->src_address.as_u32 = src.as_u32;
204 
205  vlib_cli_output (vm, "Collector %U, src address %U",
208 
209  /* Turn on the export timer process */
210  // vlib_process_signal_event (vm, flow_report_process_node.index,
211  //1, 0);
212  if (0 !=
213  vxlan_gpe_ioam_export_enable_disable (em, is_disable, &collector, &src))
214  {
215  return clib_error_return (0, "Unable to set ioam vxlan-gpe export");
216  }
217 
218  return 0;
219 }
220 
221 /* *INDENT-OFF* */
222 VLIB_CLI_COMMAND (set_vxlan_gpe_ioam_ipfix_command, static) =
223 {
224 .path = "set vxlan-gpe-ioam export ipfix",
225 .short_help = "set vxlan-gpe-ioam export ipfix collector <ip4-address> src <ip4-address>",
227 };
228 /* *INDENT-ON* */
229 
230 
231 static clib_error_t *
233 {
235  clib_error_t *error = 0;
236  u8 *name;
237 
239 
240  name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
241 
242  /* Ask for a correctly-sized block of API message decode slots */
244  ((char *) name, VL_MSG_FIRST_AVAILABLE);
245  em->unix_time_0 = (u32) time (0); /* Store starting time */
246  em->vlib_time_0 = vlib_time_now (vm);
247 
249 
250  /* Add our API messages to the global name_crc hash table */
252 
253  em->my_hbh_slot = ~0;
254  em->vlib_main = vm;
255  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  */
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:837
#define foreach_vxlan_gpe_ioam_export_plugin_api_msg
static clib_error_t * vxlan_gpe_ioam_export_init(vlib_main_t *vm)
vlib_node_registration_t vxlan_export_node
(constructor) VLIB_REGISTER_NODE (vxlan_export_node)
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static void ioam_export_reset_next_node(ioam_export_main_t *em)
Definition: ioam_export.h:97
u32 export_process_node_index
Definition: ioam_export.h:76
#define NULL
Definition: clib.h:55
u32 index
Definition: node.h:238
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:192
VXLAN GPE definitions.
struct _vlib_node_registration vlib_node_registration_t
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)
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:231
ip4_address_t ipfix_collector
Definition: ioam_export.h:55
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1081
format_function_t format_ip4_address
Definition: format.h:79
unformat_function_t unformat_ip4_address
Definition: format.h:76
#define IPFIX_VXLAN_IOAM_EXPORT_ID
Definition: ioam_export.h:203
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define clib_error_return(e, args...)
Definition: error.h:99
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:946
struct _unformat_input_t unformat_input_t
vnet_main_t * vnet_main
Definition: ioam_export.h:71
#define REPLY_MACRO(t)
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:222
static clib_error_t * vxlan_gpe_ioam_export_plugin_api_hookup(vlib_main_t *vm)
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
Definition: ioam_export.h:146
vlib_main_t * vlib_main
Definition: ioam_export.h:70
api_main_t api_main
Definition: api_shared.c:35
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:340
static void setup_message_id_table(ioam_export_main_t *sm, api_main_t *am)
ip4_address_t src_address
Definition: ioam_export.h:56
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)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
#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
unsigned char u8
Definition: types.h:56
ioam_export_main_t vxlan_gpe_ioam_export_main
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
Definition: ioam_export.h:168
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
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:169
static void vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler(vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp)