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_vip_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 prefix;
31 clib_error_t *error = 0;
33 if (!unformat_user (input, unformat_line_input, line_input))
36 if (!unformat(line_input, "%U", unformat_ip46_prefix, &prefix, &plen, IP46_TYPE_ANY, &plen)) {
37 error = clib_error_return (0, "invalid vip prefix: '%U'",
38 format_unformat_error, line_input);
42 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
44 if (unformat(line_input, "new_len %d", &new_len))
46 else if (unformat(line_input, "del"))
48 else if (unformat(line_input, "encap gre4"))
50 else if (unformat(line_input, "encap gre6"))
53 error = clib_error_return (0, "parse error: '%U'",
54 format_unformat_error, line_input);
60 if (ip46_prefix_is_ip4(&prefix, plen)) {
61 type = (gre4)?LB_VIP_TYPE_IP4_GRE4:LB_VIP_TYPE_IP4_GRE6;
63 type = (gre4)?LB_VIP_TYPE_IP6_GRE4:LB_VIP_TYPE_IP6_GRE6;
66 lb_garbage_collection();
70 if ((ret = lb_vip_add(&prefix, plen, type, new_len, &index))) {
71 error = clib_error_return (0, "lb_vip_add error %d", ret);
74 vlib_cli_output(vm, "lb_vip_add ok %d", index);
77 if ((ret = lb_vip_find_index(&prefix, plen, &index))) {
78 error = clib_error_return (0, "lb_vip_find_index error %d", ret);
80 } else if ((ret = lb_vip_del(index))) {
81 error = clib_error_return (0, "lb_vip_del error %d", ret);
87 unformat_free (line_input);
92 VLIB_CLI_COMMAND (lb_vip_command, static) =
95 .short_help = "lb vip <prefix> [encap (gre6|gre4)] [new_len <n>] [del]",
96 .function = lb_vip_command_fn,
100 lb_as_command_fn (vlib_main_t * vm,
101 unformat_input_t * input, vlib_cli_command_t * cmd)
103 unformat_input_t _line_input, *line_input = &_line_input;
104 ip46_address_t vip_prefix, as_addr;
106 ip46_address_t *as_array = 0;
110 clib_error_t *error = 0;
112 if (!unformat_user (input, unformat_line_input, line_input))
115 if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY)) {
116 error = clib_error_return (0, "invalid as address: '%U'",
117 format_unformat_error, line_input);
121 if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index))) {
122 error = clib_error_return (0, "lb_vip_find_index error %d", ret);
126 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
128 if (unformat(line_input, "%U", unformat_ip46_address, &as_addr, IP46_TYPE_ANY)) {
129 vec_add1(as_array, as_addr);
130 } else if (unformat(line_input, "del")) {
133 error = clib_error_return (0, "parse error: '%U'",
134 format_unformat_error, line_input);
139 if (!vec_len(as_array)) {
140 error = clib_error_return (0, "No AS address provided");
144 lb_garbage_collection();
145 clib_warning("vip index is %d", vip_index);
148 if ((ret = lb_vip_del_ass(vip_index, as_array, vec_len(as_array)))) {
149 error = clib_error_return (0, "lb_vip_del_ass error %d", ret);
153 if ((ret = lb_vip_add_ass(vip_index, as_array, vec_len(as_array)))) {
154 error = clib_error_return (0, "lb_vip_add_ass error %d", ret);
160 unformat_free (line_input);
166 VLIB_CLI_COMMAND (lb_as_command, static) =
169 .short_help = "lb as <vip-prefix> [<address> [<address> [...]]] [del]",
170 .function = lb_as_command_fn,
173 static clib_error_t *
174 lb_conf_command_fn (vlib_main_t * vm,
175 unformat_input_t * input, vlib_cli_command_t * cmd)
177 lb_main_t *lbm = &lb_main;
178 unformat_input_t _line_input, *line_input = &_line_input;
179 ip4_address_t ip4 = lbm->ip4_src_address;
180 ip6_address_t ip6 = lbm->ip6_src_address;
181 u32 per_cpu_sticky_buckets = lbm->per_cpu_sticky_buckets;
182 u32 per_cpu_sticky_buckets_log2 = 0;
183 u32 flow_timeout = lbm->flow_timeout;
185 clib_error_t *error = 0;
187 if (!unformat_user (input, unformat_line_input, line_input))
190 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
192 if (unformat(line_input, "ip4-src-address %U", unformat_ip4_address, &ip4))
194 else if (unformat(line_input, "ip6-src-address %U", unformat_ip6_address, &ip6))
196 else if (unformat(line_input, "buckets %d", &per_cpu_sticky_buckets))
198 else if (unformat(line_input, "buckets-log2 %d", &per_cpu_sticky_buckets_log2)) {
199 if (per_cpu_sticky_buckets_log2 >= 32)
200 return clib_error_return (0, "buckets-log2 value is too high");
201 per_cpu_sticky_buckets = 1 << per_cpu_sticky_buckets_log2;
202 } else if (unformat(line_input, "timeout %d", &flow_timeout))
205 error = clib_error_return (0, "parse error: '%U'",
206 format_unformat_error, line_input);
211 lb_garbage_collection();
213 if ((ret = lb_conf(&ip4, &ip6, per_cpu_sticky_buckets, flow_timeout))) {
214 error = clib_error_return (0, "lb_conf error %d", ret);
219 unformat_free (line_input);
224 VLIB_CLI_COMMAND (lb_conf_command, static) =
227 .short_help = "lb conf [ip4-src-address <addr>] [ip6-src-address <addr>] [buckets <n>] [timeout <s>]",
228 .function = lb_conf_command_fn,
231 static clib_error_t *
232 lb_show_command_fn (vlib_main_t * vm,
233 unformat_input_t * input, vlib_cli_command_t * cmd)
235 vlib_cli_output(vm, "%U", format_lb_main);
240 VLIB_CLI_COMMAND (lb_show_command, static) =
243 .short_help = "show lb",
244 .function = lb_show_command_fn,
247 static clib_error_t *
248 lb_show_vips_command_fn (vlib_main_t * vm,
249 unformat_input_t * input, vlib_cli_command_t * cmd)
251 unformat_input_t line_input;
252 lb_main_t *lbm = &lb_main;
256 if (!unformat_user (input, unformat_line_input, &line_input))
259 if (unformat(&line_input, "verbose"))
262 pool_foreach(vip, lbm->vips, {
263 vlib_cli_output(vm, "%U\n", verbose?format_lb_vip_detailed:format_lb_vip, vip);
266 unformat_free (&line_input);
270 VLIB_CLI_COMMAND (lb_show_vips_command, static) =
272 .path = "show lb vips",
273 .short_help = "show lb vips [verbose]",
274 .function = lb_show_vips_command_fn,