FD.io VPP  v21.10.1-2-g0a485f517
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 <vnet/format_fns.h>
30 
31 /* define message IDs */
32 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_enum.h>
33 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api_types.h>
34 
35 #define REPLY_MSG_ID_BASE sm->msg_id_base
37 
40 
42 /* Action function shared between message handler and debug CLI */
43 int
45  u8 is_disable,
46  ip4_address_t * collector_address,
48 {
49  vlib_main_t *vm = em->vlib_main;
51  vlib_node_t *vxlan_gpe_decap_ioam_node = NULL;
52 
53  if (is_disable == 0)
54  {
55  if (em->my_hbh_slot == ~0)
56  {
57  /* Hook this export node to vxlan-gpe-decap-ioam-v4 */
58  vxlan_gpe_decap_ioam_node =
59  vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-decap-ioam-v4");
60  if (!vxlan_gpe_decap_ioam_node)
61  {
62  /* node does not exist give up */
63  return (-1);
64  }
65  em->my_hbh_slot =
66  vlib_node_add_next (vm, vxlan_gpe_decap_ioam_node->index,
67  node_index);
68  }
69  if (1 == ioam_export_header_create (em, collector_address, src_address))
70  {
73  /* Turn on the export buffer check process */
75 
76  }
77  else
78  {
79  return (-2);
80  }
81  }
82  else
83  {
85  ioam_export_header_cleanup (em, collector_address, src_address);
87  /* Turn off the export buffer check process */
89 
90  }
91 
92  return 0;
93 }
94 
95 /* API message handler */
98 {
99  vl_api_vxlan_gpe_ioam_export_enable_disable_reply_t *rmp;
101  int rv;
102 
104  (ip4_address_t *)
105  mp->collector_address,
106  (ip4_address_t *)
107  mp->src_address);
108 
109  REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY);
110 } /* API message handler */
111 
112 static clib_error_t *
114  unformat_input_t * input,
115  vlib_cli_command_t * cmd)
116 {
118  ip4_address_t collector, src;
119  u8 is_disable = 0;
120 
121  collector.as_u32 = 0;
122  src.as_u32 = 0;
123 
125  {
126  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
127  ;
128  else if (unformat (input, "src %U", unformat_ip4_address, &src))
129  ;
130  else if (unformat (input, "disable"))
131  is_disable = 1;
132  else
133  break;
134  }
135 
136  if (collector.as_u32 == 0)
137  return clib_error_return (0, "collector address required");
138 
139  if (src.as_u32 == 0)
140  return clib_error_return (0, "src address required");
141 
142  em->ipfix_collector.as_u32 = collector.as_u32;
143  em->src_address.as_u32 = src.as_u32;
144 
145  vlib_cli_output (vm, "Collector %U, src address %U",
148 
149  /* Turn on the export timer process */
150  // vlib_process_signal_event (vm, flow_report_process_node.index,
151  //1, 0);
152  if (0 !=
153  vxlan_gpe_ioam_export_enable_disable (em, is_disable, &collector, &src))
154  {
155  return clib_error_return (0, "Unable to set ioam vxlan-gpe export");
156  }
157 
158  return 0;
159 }
160 
161 /* *INDENT-OFF* */
163 {
164 .path = "set vxlan-gpe-ioam export ipfix",
165 .short_help = "set vxlan-gpe-ioam export ipfix collector <ip4-address> src <ip4-address>",
167 };
168 /* *INDENT-ON* */
169 
170 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.api.c>
171 static clib_error_t *
173 {
175 
177 
178  /* Ask for a correctly-sized block of API message decode slots */
180  em->unix_time_0 = (u32) time (0); /* Store starting time */
181  em->vlib_time_0 = vlib_time_now (vm);
182 
183  em->my_hbh_slot = ~0;
184  em->vlib_main = vm;
185  em->vnet_main = vnet_get_main ();
187 
188  return 0;
189 }
190 
192 
193 
194 /*
195  * fd.io coding-style-patch-verification: ON
196  *
197  * Local Variables:
198  * eval: (c-set-style "gnu")
199  * End:
200  */
ioam_export.h
vxlan_gpe_set_next_override
void vxlan_gpe_set_next_override(uword next)
Definition: vxlan_gpe_ioam.c:555
api.h
set_vxlan_gpe_ioam_ipfix_command
static vlib_cli_command_t set_vxlan_gpe_ioam_ipfix_command
(constructor) VLIB_CLI_COMMAND (set_vxlan_gpe_ioam_ipfix_command)
Definition: vxlan_gpe_ioam_export.c:162
vlib_node_add_next
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1177
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
vxlan_gpe_ioam_export_main
ioam_export_main_t vxlan_gpe_ioam_export_main
Definition: vxlan_gpe_ioam_export.c:38
vl_api_vxlan_gpe_ioam_export_enable_disable_t::collector_address
vl_api_ip4_address_t collector_address
Definition: vxlan_gpe_ioam_export.api:33
VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP
@ VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP
Definition: vxlan_gpe_ioam.h:170
next
u16 * next
Definition: nat44_ei_out2in.c:718
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
node_index
node node_index
Definition: interface_output.c:440
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_process_signal_event
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1019
vxlan_gpe_ioam.h
ioam_export_main_t::vlib_time_0
f64 vlib_time_0
Definition: ioam_export.h:71
vxlan_export_node
vlib_node_registration_t vxlan_export_node
(constructor) VLIB_REGISTER_NODE (vxlan_export_node)
Definition: vxlan_gpe_node.c:148
vxlan_gpe.h
VXLAN GPE definitions.
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vl_api_vxlan_gpe_ioam_export_enable_disable_t::src_address
vl_api_ip4_address_t src_address
Definition: vxlan_gpe_ioam_export.api:34
ioam_export_main_t::unix_time_0
u32 unix_time_0
Definition: ioam_export.h:70
vl_api_vxlan_gpe_ioam_export_enable_disable_t::is_disable
bool is_disable
Definition: vxlan_gpe_ioam_export.api:30
vlib_node_t::index
u32 index
Definition: node.h:269
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
ioam_export_main_t::msg_id_base
u16 msg_id_base
Definition: ioam_export.h:50
uword
u64 uword
Definition: types.h:112
ioam_export_thread_buffer_init
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
Definition: ioam_export.h:172
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
src
vl_api_address_t src
Definition: gre.api:54
ip4_address_t
Definition: ip4_packet.h:50
vxlan_gpe_ioam_export_enable_disable
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)
Definition: vxlan_gpe_ioam_export.c:44
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
ioam_export_main_t::export_process_node_index
u32 export_process_node_index
Definition: ioam_export.h:80
plugin.h
vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler
static void vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler(vl_api_vxlan_gpe_ioam_export_enable_disable_t *mp)
Definition: vxlan_gpe_ioam_export.c:97
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
format_fns.h
ioam_export_reset_next_node
static void ioam_export_reset_next_node(ioam_export_main_t *em)
Definition: ioam_export.h:101
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
api_helper_macros.h
ioam_export_main_t
Definition: ioam_export.h:47
ioam_export_main_t::my_hbh_slot
uword my_hbh_slot
Definition: ioam_export.h:79
IPFIX_VXLAN_IOAM_EXPORT_ID
#define IPFIX_VXLAN_IOAM_EXPORT_ID
Definition: ioam_export.h:205
ioam_export_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ioam_export.h:74
vxlan_gpe_ioam_export_init
static clib_error_t * vxlan_gpe_ioam_export_init(vlib_main_t *vm)
Definition: vxlan_gpe_ioam_export.c:172
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vl_api_vxlan_gpe_ioam_export_enable_disable_t
Definition: vxlan_gpe_ioam_export.api:22
ioam_export_main_t::vnet_main
vnet_main_t * vnet_main
Definition: ioam_export.h:75
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
ioam_export_header_create
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
ioam_export_header_cleanup
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
rv
int __clib_unused rv
Definition: application.c:491
unformat_ip4_address
unformat_function_t unformat_ip4_address
Definition: format.h:68
ioam_export_thread_buffer_free
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
Definition: ioam_export.h:150
vlib_time_now
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:327
set_vxlan_gpe_ioam_export_ipfix_command_fn
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)
Definition: vxlan_gpe_ioam_export.c:113
vnet.h
ioam_export_main_t::src_address
ip4_address_t src_address
Definition: ioam_export.h:60
src_address
vl_api_address_union_t src_address
Definition: ip_types.api:122
vlib_cli_command_t
Definition: cli.h:92
ioam_export_main_t::ipfix_collector
ip4_address_t ipfix_collector
Definition: ioam_export.h:59
ioam_export_main_t::set_id
u16 set_id
Definition: ioam_export.h:51
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137