blob: 226b41298ab1f740cc880289ecd6ff3e111a0d4b [file] [log] [blame]
Neale Ranns5f8f6172019-04-18 10:23:56 +00001/*
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:
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
Neale Ranns03ce4622020-02-03 10:55:09 +000016#include <vnet/teib/teib.h>
Neale Ranns5f8f6172019-04-18 10:23:56 +000017
18static clib_error_t *
Neale Ranns03ce4622020-02-03 10:55:09 +000019teib_add (vlib_main_t * vm,
Neale Ranns5f8f6172019-04-18 10:23:56 +000020 unformat_input_t * input, vlib_cli_command_t * cmd)
21{
22 unformat_input_t _line_input, *line_input = &_line_input;
Neale Rannse6b83052020-09-17 12:56:47 +000023 ip_address_t peer = ip_address_initializer;
24 ip_address_t nh = ip_address_initializer;
Neale Ranns5f8f6172019-04-18 10:23:56 +000025 u32 sw_if_index, nh_table_id;
26 clib_error_t *error = NULL;
27 int rv;
28
29 sw_if_index = ~0;
30 nh_table_id = 0;
31
32 /* Get a line of input. */
33 if (!unformat_user (input, unformat_line_input, line_input))
34 return 0;
35
36 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
37 {
38 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
39 vnet_get_main (), &sw_if_index))
40 ;
Neale Ranns256b67b2020-09-02 14:46:53 +000041 else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
Neale Ranns5f8f6172019-04-18 10:23:56 +000042 ;
Neale Rannse6b83052020-09-17 12:56:47 +000043 else if (unformat (line_input, "nh %U", unformat_ip_address, &nh))
Neale Ranns5f8f6172019-04-18 10:23:56 +000044 ;
45 else if (unformat (line_input, "nh-table-id %d", &nh_table_id))
46 ;
47 else
48 {
49 error = clib_error_return (0, "unknown input `%U'",
50 format_unformat_error, line_input);
51 goto done;
52 }
53 }
54
55 if (~0 == sw_if_index)
56 {
57 error = clib_error_return (0, "interface required'",
58 format_unformat_error, line_input);
59 goto done;
60 }
Neale Ranns256b67b2020-09-02 14:46:53 +000061 if (ip_address_is_zero (&peer))
Neale Ranns5f8f6172019-04-18 10:23:56 +000062 {
63 error = clib_error_return (0, "peer required'",
64 format_unformat_error, line_input);
65 goto done;
66 }
Neale Rannse6b83052020-09-17 12:56:47 +000067 if (ip_address_is_zero (&nh))
Neale Ranns5f8f6172019-04-18 10:23:56 +000068 {
69 error = clib_error_return (0, "next-hop required'",
70 format_unformat_error, line_input);
71 goto done;
72 }
73
Neale Rannse6b83052020-09-17 12:56:47 +000074 rv = teib_entry_add (sw_if_index, &peer, nh_table_id, &nh);
Neale Ranns5f8f6172019-04-18 10:23:56 +000075
76 if (rv)
77 {
78 error = clib_error_return_code (NULL, rv, 0,
79 "NRHP error",
80 format_unformat_error, line_input);
81 }
82
83done:
84 unformat_free (line_input);
85
86 return error;
87}
88
89/* *INDENT-OFF* */
Neale Ranns03ce4622020-02-03 10:55:09 +000090VLIB_CLI_COMMAND (teib_create_command, static) = {
91 .path = "create teib",
92 .short_help = "create teib <interface> peer <addr> nh <addr> [nh-table-id <ID>]",
93 .function = teib_add,
Neale Ranns5f8f6172019-04-18 10:23:56 +000094};
95/* *INDENT-ON* */
96
97static clib_error_t *
Neale Ranns03ce4622020-02-03 10:55:09 +000098teib_del (vlib_main_t * vm,
Neale Ranns5f8f6172019-04-18 10:23:56 +000099 unformat_input_t * input, vlib_cli_command_t * cmd)
100{
101 unformat_input_t _line_input, *line_input = &_line_input;
Neale Rannse6b83052020-09-17 12:56:47 +0000102 ip_address_t peer = ip_address_initializer;
Neale Ranns5f8f6172019-04-18 10:23:56 +0000103 clib_error_t *error = NULL;
104 u32 sw_if_index;
105 int rv;
106
107 sw_if_index = ~0;
108
109 /* Get a line of input. */
110 if (!unformat_user (input, unformat_line_input, line_input))
111 return 0;
112
113 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
114 {
115 if (unformat (line_input, "%U", unformat_vnet_sw_interface,
116 vnet_get_main (), &sw_if_index))
117 ;
Neale Ranns256b67b2020-09-02 14:46:53 +0000118 else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
Neale Ranns5f8f6172019-04-18 10:23:56 +0000119 ;
120 else
121 {
122 error = clib_error_return (0, "unknown input `%U'",
123 format_unformat_error, line_input);
124 goto done;
125 }
126 }
127
128 if (~0 == sw_if_index)
129 {
130 error = clib_error_return (0, "interface required'",
131 format_unformat_error, line_input);
132 }
Neale Ranns256b67b2020-09-02 14:46:53 +0000133 if (ip_address_is_zero (&peer))
Neale Ranns5f8f6172019-04-18 10:23:56 +0000134 {
135 error = clib_error_return (0, "peer required'",
136 format_unformat_error, line_input);
137 goto done;
138 }
139
Neale Rannse6b83052020-09-17 12:56:47 +0000140 rv = teib_entry_del (sw_if_index, &peer);
Neale Ranns5f8f6172019-04-18 10:23:56 +0000141
142 if (rv)
143 {
144 error = clib_error_return_code (NULL, rv, 0,
145 "NRHP error",
146 format_unformat_error, line_input);
147 }
148
149done:
150 unformat_free (line_input);
151
152 return error;
153}
154
155/* *INDENT-OFF* */
Neale Ranns03ce4622020-02-03 10:55:09 +0000156VLIB_CLI_COMMAND (teib_delete_command, static) = {
157 .path = "delete teib",
158 .short_help = "delete teib <interface> peer <addr>",
159 .function = teib_del,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000160};
161/* *INDENT-ON* */
162
163static walk_rc_t
Neale Ranns03ce4622020-02-03 10:55:09 +0000164teib_show_one (index_t nei, void *ctx)
Neale Ranns5f8f6172019-04-18 10:23:56 +0000165{
Neale Ranns03ce4622020-02-03 10:55:09 +0000166 vlib_cli_output (ctx, "%U", format_teib_entry, nei);
Neale Ranns5f8f6172019-04-18 10:23:56 +0000167
168 return (WALK_CONTINUE);
169}
170
171
172static clib_error_t *
Neale Ranns03ce4622020-02-03 10:55:09 +0000173teib_show (vlib_main_t * vm,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000174 unformat_input_t * input, vlib_cli_command_t * cmd)
175{
Neale Ranns03ce4622020-02-03 10:55:09 +0000176 teib_walk (teib_show_one, vm);
Neale Ranns5f8f6172019-04-18 10:23:56 +0000177 return (NULL);
178}
179
180/* *INDENT-OFF* */
Neale Ranns03ce4622020-02-03 10:55:09 +0000181VLIB_CLI_COMMAND (teib_show_command, static) = {
182 .path = "show teib",
183 .short_help = "show teib",
184 .function = teib_show,
Neale Ranns5f8f6172019-04-18 10:23:56 +0000185};
186/* *INDENT-ON* */
187
188/*
189 * fd.io coding-style-patch-verification: ON
190 *
191 * Local Variables:
192 * eval: (c-set-style "gnu")
193 * End:
194 */