2 * Copyright (c) 2019 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/teib/teib.h>
19 teib_add (vlib_main_t * vm,
20 unformat_input_t * input, vlib_cli_command_t * cmd)
22 unformat_input_t _line_input, *line_input = &_line_input;
23 ip46_address_t peer = ip46_address_initializer;
24 ip46_address_t nh = ip46_address_initializer;
25 u32 sw_if_index, nh_table_id;
26 clib_error_t *error = NULL;
32 /* Get a line of input. */
33 if (!unformat_user (input, unformat_line_input, line_input))
36 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
38 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
39 vnet_get_main (), &sw_if_index))
41 else if (unformat (line_input, "peer %U", unformat_ip46_address, &peer))
43 else if (unformat (line_input, "nh %U", unformat_ip46_address, &nh))
45 else if (unformat (line_input, "nh-table-id %d", &nh_table_id))
49 error = clib_error_return (0, "unknown input `%U'",
50 format_unformat_error, line_input);
55 if (~0 == sw_if_index)
57 error = clib_error_return (0, "interface required'",
58 format_unformat_error, line_input);
61 if (ip46_address_is_zero (&peer))
63 error = clib_error_return (0, "peer required'",
64 format_unformat_error, line_input);
67 if (ip46_address_is_zero (&nh))
69 error = clib_error_return (0, "next-hop required'",
70 format_unformat_error, line_input);
74 rv = teib_entry_add (sw_if_index, &peer, nh_table_id, &nh);
78 error = clib_error_return_code (NULL, rv, 0,
80 format_unformat_error, line_input);
84 unformat_free (line_input);
90 VLIB_CLI_COMMAND (teib_create_command, static) = {
91 .path = "create teib",
92 .short_help = "create teib <interface> peer <addr> nh <addr> [nh-table-id <ID>]",
98 teib_del (vlib_main_t * vm,
99 unformat_input_t * input, vlib_cli_command_t * cmd)
101 unformat_input_t _line_input, *line_input = &_line_input;
102 ip46_address_t peer = ip46_address_initializer;
103 clib_error_t *error = NULL;
109 /* Get a line of input. */
110 if (!unformat_user (input, unformat_line_input, line_input))
113 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
115 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
116 vnet_get_main (), &sw_if_index))
118 else if (unformat (line_input, "peer %U", unformat_ip46_address, &peer))
122 error = clib_error_return (0, "unknown input `%U'",
123 format_unformat_error, line_input);
128 if (~0 == sw_if_index)
130 error = clib_error_return (0, "interface required'",
131 format_unformat_error, line_input);
133 if (ip46_address_is_zero (&peer))
135 error = clib_error_return (0, "peer required'",
136 format_unformat_error, line_input);
140 rv = teib_entry_del (sw_if_index, &peer);
144 error = clib_error_return_code (NULL, rv, 0,
146 format_unformat_error, line_input);
150 unformat_free (line_input);
156 VLIB_CLI_COMMAND (teib_delete_command, static) = {
157 .path = "delete teib",
158 .short_help = "delete teib <interface> peer <addr>",
159 .function = teib_del,
164 teib_show_one (index_t nei, void *ctx)
166 vlib_cli_output (ctx, "%U", format_teib_entry, nei);
168 return (WALK_CONTINUE);
172 static clib_error_t *
173 teib_show (vlib_main_t * vm,
174 unformat_input_t * input, vlib_cli_command_t * cmd)
176 teib_walk (teib_show_one, vm);
181 VLIB_CLI_COMMAND (teib_show_command, static) = {
183 .short_help = "show teib",
184 .function = teib_show,
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "gnu")