FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
nsh_md2_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  * nsh_md2_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 
28 #include <nsh/nsh.h>
30 
31 
33 
34 
37 /* Action function shared between message handler and debug CLI */
38 int
40  u8 is_disable,
41  ip4_address_t * collector_address,
43 {
44  vlib_main_t *vm = em->vlib_main;
47 
48  if (is_disable == 0)
49  {
50  if (em->my_hbh_slot == ~0)
51  {
52  /* Hook this export node to nsh-input */
53  nsh_input_node = vlib_get_node_by_name (vm, (u8 *) "nsh-input");
54  if (!nsh_input_node)
55  {
56  /* node does not exist give up */
57  return (-1);
58  }
59  em->my_hbh_slot =
61  }
62  if (1 == ioam_export_header_create (em, collector_address, src_address))
63  {
66  /* Turn on the export buffer check process */
68 
69  }
70  else
71  {
72  return (-2);
73  }
74  }
75  else
76  {
77  nsh_md2_set_next_ioam_export_override (0); // VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP
78  ioam_export_header_cleanup (em, collector_address, src_address);
80  /* Turn off the export buffer check process */
82 
83  }
84 
85  return 0;
86 }
87 
88 
89 
90 static clib_error_t *
92  unformat_input_t * input,
93  vlib_cli_command_t * cmd)
94 {
96  ip4_address_t collector, src;
97  u8 is_disable = 0;
98 
99  collector.as_u32 = 0;
100  src.as_u32 = 0;
101 
103  {
104  if (unformat (input, "collector %U", unformat_ip4_address, &collector))
105  ;
106  else if (unformat (input, "src %U", unformat_ip4_address, &src))
107  ;
108  else if (unformat (input, "disable"))
109  is_disable = 1;
110  else
111  break;
112  }
113 
114  if (collector.as_u32 == 0)
115  return clib_error_return (0, "collector address required");
116 
117  if (src.as_u32 == 0)
118  return clib_error_return (0, "src address required");
119 
120  em->ipfix_collector.as_u32 = collector.as_u32;
121  em->src_address.as_u32 = src.as_u32;
122 
123  vlib_cli_output (vm, "Collector %U, src address %U",
126 
127  /* Turn on the export timer process */
128  // vlib_process_signal_event (vm, flow_report_process_node.index,
129  //1, 0);
130  if (0 !=
131  nsh_md2_ioam_export_enable_disable (em, is_disable, &collector, &src))
132  {
133  return clib_error_return (0, "Unable to set ioam nsh-md2 export");
134  }
135 
136  return 0;
137 }
138 
139 /* *INDENT-OFF* */
141 {
142 .path = "set nsh-md2-ioam export ipfix",
143 .short_help = "set nsh-md2-ioam export ipfix collector <ip4-address> src <ip4-address>",
145 };
146 /* *INDENT-ON* */
147 
148 
149 #define IPFIX_NSH_MD2_IOAM_EXPORT_ID 274 // TODO: Move this to ioam/ioam_export.h
150 static clib_error_t *
152 {
154  clib_error_t *error = 0;
155 
157  em->unix_time_0 = (u32) time (0); /* Store starting time */
158  em->vlib_time_0 = vlib_time_now (vm);
159 
160  em->my_hbh_slot = ~0;
161  em->vlib_main = vm;
162  em->vnet_main = vnet_get_main ();
164 
165  return error;
166 }
167 
169 
170 
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "gnu")
176  * End:
177  */
ioam_export.h
api.h
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
nsh_md2_ioam.h
next
u16 * next
Definition: nat44_ei_out2in.c:718
nsh_md2_ioam_export_enable_disable
int nsh_md2_ioam_export_enable_disable(ioam_export_main_t *em, u8 is_disable, ip4_address_t *collector_address, ip4_address_t *src_address)
Definition: nsh_md2_ioam_export.c:39
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
nsh_input_node
vlib_node_registration_t nsh_input_node
(constructor) VLIB_REGISTER_NODE (nsh_input_node)
Definition: nsh_node.c:912
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
ioam_export_main_t::vlib_time_0
f64 vlib_time_0
Definition: ioam_export.h:71
error
Definition: cJSON.c:88
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
ioam_export_main_t::unix_time_0
u32 unix_time_0
Definition: ioam_export.h:70
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
uword
u64 uword
Definition: types.h:112
IPFIX_NSH_MD2_IOAM_EXPORT_ID
#define IPFIX_NSH_MD2_IOAM_EXPORT_ID
Definition: nsh_md2_ioam_export.c:149
nsh_md2_ioam_export_init
static clib_error_t * nsh_md2_ioam_export_init(vlib_main_t *vm)
Definition: nsh_md2_ioam_export.c:151
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
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
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
nsh_md2_ioam_export_node
vlib_node_registration_t nsh_md2_ioam_export_node
(constructor) VLIB_REGISTER_NODE (nsh_md2_ioam_export_node)
Definition: nsh_md2_ioam_node.c:133
set_nsh_md2_ioam_export_ipfix_command_fn
static clib_error_t * set_nsh_md2_ioam_export_ipfix_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: nsh_md2_ioam_export.c:91
nsh.h
ioam_export_reset_next_node
static void ioam_export_reset_next_node(ioam_export_main_t *em)
Definition: ioam_export.h:101
set_nsh_md2_ioam_ipfix_command
static vlib_cli_command_t set_nsh_md2_ioam_ipfix_command
(constructor) VLIB_CLI_COMMAND (set_nsh_md2_ioam_ipfix_command)
Definition: nsh_md2_ioam_export.c:140
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
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
nsh_md2_set_next_ioam_export_override
void nsh_md2_set_next_ioam_export_override(uword next)
Definition: nsh.c:177
ioam_export_main_t::vlib_main
vlib_main_t * vlib_main
Definition: ioam_export.h:74
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
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
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
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
nsh_md2_ioam_export_main
ioam_export_main_t nsh_md2_ioam_export_main
Definition: nsh_md2_ioam_export.c:32