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:
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.
20 lb_bypass_command_fn (vlib_main_t * vm,
21 unformat_input_t * input, vlib_cli_command_t * cmd)
23 unformat_input_t _line_input, *line_input = &_line_input;
24 ip46_address_t vip_prefix, as_addr;
30 if (!unformat_user (input, unformat_line_input, line_input))
33 if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY))
34 return clib_error_return (0, "invalid vip prefix: '%U'",
35 format_unformat_error, line_input);
37 if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index)))
38 return clib_error_return (0, "lb_vip_find_index error %d", ret);
40 if (!unformat(line_input, "%U", unformat_ip46_address, &as_addr, IP46_TYPE_ANY))
41 return clib_error_return (0, "invalid as address: '%U'",
42 format_unformat_error, line_input);
44 if (unformat(line_input, "disable"))
47 if ((ret = lb_as_lookup_bypass(vip_index, &as_addr, disable)))
48 return clib_error_return (0, "lb_as_lookup_bypass error %d", ret);
53 VLIB_CLI_COMMAND (lb_bypass_command, static) =
56 .short_help = "lb bypass <prefix> <address> [disable]",
57 .function = lb_bypass_command_fn,
61 lb_vip_command_fn (vlib_main_t * vm,
62 unformat_input_t * input, vlib_cli_command_t * cmd)
64 unformat_input_t _line_input, *line_input = &_line_input;
65 ip46_address_t prefix;
73 if (!unformat_user (input, unformat_line_input, line_input))
76 if (!unformat(line_input, "%U", unformat_ip46_prefix, &prefix, &plen, IP46_TYPE_ANY, &plen))
77 return clib_error_return (0, "invalid vip prefix: '%U'",
78 format_unformat_error, line_input);
80 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
82 if (unformat(line_input, "new_len %d", &new_len))
84 else if (unformat(line_input, "del"))
86 else if (unformat(line_input, "encap gre4"))
88 else if (unformat(line_input, "encap gre6"))
91 return clib_error_return (0, "parse error: '%U'",
92 format_unformat_error, line_input);
95 unformat_free (line_input);
98 if (ip46_prefix_is_ip4(&prefix, plen)) {
99 type = (gre4)?LB_VIP_TYPE_IP4_GRE4:LB_VIP_TYPE_IP4_GRE6;
101 type = (gre4)?LB_VIP_TYPE_IP6_GRE4:LB_VIP_TYPE_IP6_GRE6;
104 lb_garbage_collection();
108 if ((ret = lb_vip_add(&prefix, plen, type, new_len, &index))) {
109 return clib_error_return (0, "lb_vip_add error %d", ret);
111 vlib_cli_output(vm, "lb_vip_add ok %d", index);
114 if ((ret = lb_vip_find_index(&prefix, plen, &index)))
115 return clib_error_return (0, "lb_vip_find_index error %d", ret);
116 else if ((ret = lb_vip_del(index)))
117 return clib_error_return (0, "lb_vip_del error %d", ret);
122 VLIB_CLI_COMMAND (lb_vip_command, static) =
125 .short_help = "lb vip <prefix> [encap (gre6|gre4)] [new_len <n>] [del]",
126 .function = lb_vip_command_fn,
129 static clib_error_t *
130 lb_as_command_fn (vlib_main_t * vm,
131 unformat_input_t * input, vlib_cli_command_t * cmd)
133 unformat_input_t _line_input, *line_input = &_line_input;
134 ip46_address_t vip_prefix, as_addr;
136 ip46_address_t *as_array = 0;
141 if (!unformat_user (input, unformat_line_input, line_input))
144 if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY))
145 return clib_error_return (0, "invalid as address: '%U'",
146 format_unformat_error, line_input);
148 if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index)))
149 return clib_error_return (0, "lb_vip_find_index error %d", ret);
151 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
153 if (unformat(line_input, "%U", unformat_ip46_address, &as_addr, IP46_TYPE_ANY)) {
154 vec_add1(as_array, as_addr);
155 } else if (unformat(line_input, "del")) {
159 return clib_error_return (0, "parse error: '%U'",
160 format_unformat_error, line_input);
164 if (!vec_len(as_array)) {
166 return clib_error_return (0, "No AS address provided");
169 lb_garbage_collection();
170 clib_warning("vip index is %d", vip_index);
173 if ((ret = lb_vip_del_ass(vip_index, as_array, vec_len(as_array)))) {
175 return clib_error_return (0, "lb_vip_del_ass error %d", ret);
178 if ((ret = lb_vip_add_ass(vip_index, as_array, vec_len(as_array)))) {
180 return clib_error_return (0, "lb_vip_add_ass error %d", ret);
188 VLIB_CLI_COMMAND (lb_as_command, static) =
191 .short_help = "lb as <vip-prefix> [<address> [<address> [...]]] [del]",
192 .function = lb_as_command_fn,
195 static clib_error_t *
196 lb_conf_command_fn (vlib_main_t * vm,
197 unformat_input_t * input, vlib_cli_command_t * cmd)
199 lb_main_t *lbm = &lb_main;
200 unformat_input_t _line_input, *line_input = &_line_input;
201 ip4_address_t ip4 = lbm->ip4_src_address;
202 ip6_address_t ip6 = lbm->ip6_src_address;
203 u32 per_cpu_sticky_buckets = lbm->per_cpu_sticky_buckets;
204 u32 per_cpu_sticky_buckets_log2 = 0;
205 u32 flow_timeout = lbm->flow_timeout;
208 if (!unformat_user (input, unformat_line_input, line_input))
211 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
213 if (unformat(line_input, "ip4-src-address %U", unformat_ip4_address, &ip4))
215 else if (unformat(line_input, "ip6-src-address %U", unformat_ip6_address, &ip6))
217 else if (unformat(line_input, "buckets %d", &per_cpu_sticky_buckets))
219 else if (unformat(line_input, "buckets-log2 %d", &per_cpu_sticky_buckets_log2)) {
220 if (per_cpu_sticky_buckets_log2 >= 32)
221 return clib_error_return (0, "buckets-log2 value is too high");
222 per_cpu_sticky_buckets = 1 << per_cpu_sticky_buckets_log2;
223 } else if (unformat(line_input, "timeout %d", &flow_timeout))
226 return clib_error_return (0, "parse error: '%U'",
227 format_unformat_error, line_input);
230 unformat_free (line_input);
232 lb_garbage_collection();
234 if ((ret = lb_conf(&ip4, &ip6, per_cpu_sticky_buckets, flow_timeout)))
235 return clib_error_return (0, "lb_conf error %d", ret);
240 VLIB_CLI_COMMAND (lb_conf_command, static) =
243 .short_help = "lb conf [ip4-src-address <addr>] [ip6-src-address <addr>] [buckets <n>] [timeout <s>]",
244 .function = lb_conf_command_fn,
247 static clib_error_t *
248 lb_show_command_fn (vlib_main_t * vm,
249 unformat_input_t * input, vlib_cli_command_t * cmd)
251 vlib_cli_output(vm, "%U", format_lb_main);
256 VLIB_CLI_COMMAND (lb_show_command, static) =
259 .short_help = "show lb",
260 .function = lb_show_command_fn,
263 static clib_error_t *
264 lb_show_vips_command_fn (vlib_main_t * vm,
265 unformat_input_t * input, vlib_cli_command_t * cmd)
267 unformat_input_t line_input;
268 lb_main_t *lbm = &lb_main;
272 if (!unformat_user (input, unformat_line_input, &line_input))
275 if (unformat(&line_input, "verbose"))
278 pool_foreach(vip, lbm->vips, {
279 vlib_cli_output(vm, "%U\n", verbose?format_lb_vip_detailed:format_lb_vip, vip);
282 unformat_free (&line_input);
286 VLIB_CLI_COMMAND (lb_show_vips_command, static) =
288 .path = "show lb vips",
289 .short_help = "show lb vips [verbose]",
290 .function = lb_show_vips_command_fn,