FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
node_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Intel 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  * node_init.c: node march variant startup initialization
17  *
18  * Copyright (c) 2020 Intel Corporation
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #include <sys/types.h>
41 #include <fcntl.h>
42 #include <vlib/vlib.h>
43 
44 static clib_error_t *
46 {
47  clib_error_t *error = 0;
48  unformat_input_t sub_input;
49  u32 *march_variant_by_node = 0;
50  clib_march_variant_type_t march_variant;
52  int i;
53 
54  /* specify prioritization defaults for all graph nodes */
56  {
57  if (unformat (input, "default %U", unformat_vlib_cli_sub_input,
58  &sub_input))
59  {
60  while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT)
61  {
62  if (!unformat (&sub_input, "variant %U",
63  unformat_vlib_node_variant, &march_variant))
64  return clib_error_return (0,
65  "please specify a valid node variant");
66 
67  vec_validate_init_empty (march_variant_by_node,
68  vec_len (vm->node_main.nodes) - 1, ~0);
69  vec_foreach_index (i, march_variant_by_node)
70  march_variant_by_node[i] = march_variant;
72  unformat_free (&sub_input);
73  }
74  }
75  else /* specify prioritization for an individual graph node */
76  if (unformat (input, "%U", unformat_vlib_node, vm, &node_index))
77  {
78  if (unformat (input, "%U", unformat_vlib_cli_sub_input, &sub_input))
79  {
80  while (unformat_check_input (&sub_input) !=
82  {
83  if (!unformat (&sub_input, "variant %U",
84  unformat_vlib_node_variant, &march_variant))
85  return clib_error_return (0,
86  "please specify a valid node variant");
87  vec_validate_init_empty (march_variant_by_node, node_index,
88  ~0);
89  march_variant_by_node[node_index] = march_variant;
90  unformat_free (&sub_input);
91  }
92  }
93  }
94  else
95  {
96  break;
97  }
98  }
99 
100  if (march_variant_by_node)
101  {
102  vec_foreach_index (i, march_variant_by_node)
103  if (march_variant_by_node[i] != ~0)
104  vlib_node_set_march_variant (vm, i, march_variant_by_node[i]);
105  vec_free (march_variant_by_node);
106  }
107  unformat_free (input);
108 
109  return error;
110 }
111 
113 
114 /*
115  * fd.io coding-style-patch-verification: ON
116  *
117  * Local Variables:
118  * eval: (c-set-style "gnu")
119  * End:
120  */
vlib.h
vlib_node_config
static clib_error_t * vlib_node_config(vlib_main_t *vm, unformat_input_t *input)
Definition: node_init.c:45
vlib_node_set_march_variant
int vlib_node_set_march_variant(vlib_main_t *vm, u32 node_index, clib_march_variant_type_t march_variant)
Definition: node.c:823
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_main_t::node_main
vlib_node_main_t node_main
Definition: main.h:173
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
node_index
node node_index
Definition: interface_output.c:440
unformat_input_t
struct _unformat_input_t unformat_input_t
error
Definition: cJSON.c:88
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
unformat_vlib_node
unformat_function_t unformat_vlib_node
Definition: node_funcs.h:1241
vlib_config_function_runtime_t
Definition: init.h:68
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
unformat_vlib_cli_sub_input
uword unformat_vlib_cli_sub_input(unformat_input_t *i, va_list *args)
Definition: cli.c:163
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
clib_march_variant_type_t
clib_march_variant_type_t
Definition: cpu.h:39
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
u32
unsigned int u32
Definition: types.h:88
vlib_node_main_t::node_fn_default_march_variant
u32 node_fn_default_march_variant
Definition: node.h:739
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
i
int i
Definition: flowhash_template.h:376
vlib_node_main_t::nodes
vlib_node_t ** nodes
Definition: node.h:668
unformat_vlib_node_variant
unformat_function_t unformat_vlib_node_variant
Definition: node.h:221
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137