FD.io VPP  v19.01.3-6-g70449b9b9
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;
45  u32 node_index = nsh_md2_ioam_export_node.index;
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 =
60  vlib_node_add_next (vm, nsh_input_node->index, node_index);
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* */
140 VLIB_CLI_COMMAND (set_nsh_md2_ioam_ipfix_command, static) =
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  */
vl_api_address_t src
Definition: vxlan_gbp.api:32
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static void ioam_export_reset_next_node(ioam_export_main_t *em)
Definition: ioam_export.h:99
u32 export_process_node_index
Definition: ioam_export.h:78
#define NULL
Definition: clib.h:58
u32 index
Definition: node.h:304
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
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)
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
ip4_address_t ipfix_collector
Definition: ioam_export.h:57
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
vlib_node_registration_t nsh_md2_ioam_export_node
(constructor) VLIB_REGISTER_NODE (nsh_md2_ioam_export_node)
format_function_t format_ip4_address
Definition: format.h:75
unformat_function_t unformat_ip4_address
Definition: format.h:70
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
#define clib_error_return(e, args...)
Definition: error.h:99
static clib_error_t * nsh_md2_ioam_export_init(vlib_main_t *vm)
unsigned int u32
Definition: types.h:88
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
struct _unformat_input_t unformat_input_t
void nsh_md2_set_next_ioam_export_override(uword next)
Definition: nsh.c:2442
vnet_main_t * vnet_main
Definition: ioam_export.h:73
vl_api_address_union_t src_address
Definition: ip_types.api:44
vlib_node_registration_t nsh_input_node
(constructor) VLIB_REGISTER_NODE (nsh_input_node)
Definition: nsh.c:2374
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
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
Definition: ioam_export.h:148
#define IPFIX_NSH_MD2_IOAM_EXPORT_ID
vlib_main_t * vlib_main
Definition: ioam_export.h:72
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
ioam_export_main_t nsh_md2_ioam_export_main
vlib_main_t * vm
Definition: buffer.c:301
ip4_address_t src_address
Definition: ioam_export.h:58
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:155
struct _vlib_node_registration vlib_node_registration_t
u64 uword
Definition: types.h:112
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)
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
Definition: ioam_export.h:170
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
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:170