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;
32 if (!unformat_user (input, unformat_line_input, line_input))
35 if (!unformat(line_input, "%U", unformat_ip46_prefix, &prefix, &plen, IP46_TYPE_ANY, &plen))
36 return clib_error_return (0, "invalid vip prefix: '%U'",
37 format_unformat_error, line_input);
39 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
41 if (unformat(line_input, "new_len %d", &new_len))
43 else if (unformat(line_input, "del"))
45 else if (unformat(line_input, "encap gre4"))
47 else if (unformat(line_input, "encap gre6"))
50 return clib_error_return (0, "parse error: '%U'",
51 format_unformat_error, line_input);
54 unformat_free (line_input);
57 if (ip46_prefix_is_ip4(&prefix, plen)) {
58 type = (gre4)?LB_VIP_TYPE_IP4_GRE4:LB_VIP_TYPE_IP4_GRE6;
60 type = (gre4)?LB_VIP_TYPE_IP6_GRE4:LB_VIP_TYPE_IP6_GRE6;
63 lb_garbage_collection();
67 if ((ret = lb_vip_add(&prefix, plen, type, new_len, &index))) {
68 return clib_error_return (0, "lb_vip_add error %d", ret);
70 vlib_cli_output(vm, "lb_vip_add ok %d", index);
73 if ((ret = lb_vip_find_index(&prefix, plen, &index)))
74 return clib_error_return (0, "lb_vip_find_index error %d", ret);
75 else if ((ret = lb_vip_del(index)))
76 return clib_error_return (0, "lb_vip_del error %d", ret);
81 VLIB_CLI_COMMAND (lb_vip_command, static) =
84 .short_help = "lb vip <prefix> [encap (gre6|gre4)] [new_len <n>] [del]",
85 .function = lb_vip_command_fn,
89 lb_as_command_fn (vlib_main_t * vm,
90 unformat_input_t * input, vlib_cli_command_t * cmd)
92 unformat_input_t _line_input, *line_input = &_line_input;
93 ip46_address_t vip_prefix, as_addr;
95 ip46_address_t *as_array = 0;
100 if (!unformat_user (input, unformat_line_input, line_input))
103 if (!unformat(line_input, "%U", unformat_ip46_prefix, &vip_prefix, &vip_plen, IP46_TYPE_ANY))
104 return clib_error_return (0, "invalid as address: '%U'",
105 format_unformat_error, line_input);
107 if ((ret = lb_vip_find_index(&vip_prefix, vip_plen, &vip_index)))
108 return clib_error_return (0, "lb_vip_find_index error %d", ret);
110 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
112 if (unformat(line_input, "%U", unformat_ip46_address, &as_addr, IP46_TYPE_ANY)) {
113 vec_add1(as_array, as_addr);
114 } else if (unformat(line_input, "del")) {
118 return clib_error_return (0, "parse error: '%U'",
119 format_unformat_error, line_input);
123 if (!vec_len(as_array)) {
125 return clib_error_return (0, "No AS address provided");
128 lb_garbage_collection();
129 clib_warning("vip index is %d", vip_index);
132 if ((ret = lb_vip_del_ass(vip_index, as_array, vec_len(as_array)))) {
134 return clib_error_return (0, "lb_vip_del_ass error %d", ret);
137 if ((ret = lb_vip_add_ass(vip_index, as_array, vec_len(as_array)))) {
139 return clib_error_return (0, "lb_vip_add_ass error %d", ret);
147 VLIB_CLI_COMMAND (lb_as_command, static) =
150 .short_help = "lb as <vip-prefix> [<address> [<address> [...]]] [del]",
151 .function = lb_as_command_fn,
154 static clib_error_t *
155 lb_conf_command_fn (vlib_main_t * vm,
156 unformat_input_t * input, vlib_cli_command_t * cmd)
158 lb_main_t *lbm = &lb_main;
159 unformat_input_t _line_input, *line_input = &_line_input;
160 ip4_address_t ip4 = lbm->ip4_src_address;
161 ip6_address_t ip6 = lbm->ip6_src_address;
162 u32 per_cpu_sticky_buckets = lbm->per_cpu_sticky_buckets;
163 u32 per_cpu_sticky_buckets_log2 = 0;
164 u32 flow_timeout = lbm->flow_timeout;
167 if (!unformat_user (input, unformat_line_input, line_input))
170 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
172 if (unformat(line_input, "ip4-src-address %U", unformat_ip4_address, &ip4))
174 else if (unformat(line_input, "ip6-src-address %U", unformat_ip6_address, &ip6))
176 else if (unformat(line_input, "buckets %d", &per_cpu_sticky_buckets))
178 else if (unformat(line_input, "buckets-log2 %d", &per_cpu_sticky_buckets_log2)) {
179 if (per_cpu_sticky_buckets_log2 >= 32)
180 return clib_error_return (0, "buckets-log2 value is too high");
181 per_cpu_sticky_buckets = 1 << per_cpu_sticky_buckets_log2;
182 } else if (unformat(line_input, "timeout %d", &flow_timeout))
185 return clib_error_return (0, "parse error: '%U'",
186 format_unformat_error, line_input);
189 unformat_free (line_input);
191 lb_garbage_collection();
193 if ((ret = lb_conf(&ip4, &ip6, per_cpu_sticky_buckets, flow_timeout)))
194 return clib_error_return (0, "lb_conf error %d", ret);
199 VLIB_CLI_COMMAND (lb_conf_command, static) =
202 .short_help = "lb conf [ip4-src-address <addr>] [ip6-src-address <addr>] [buckets <n>] [timeout <s>]",
203 .function = lb_conf_command_fn,
206 static clib_error_t *
207 lb_show_command_fn (vlib_main_t * vm,
208 unformat_input_t * input, vlib_cli_command_t * cmd)
210 vlib_cli_output(vm, "%U", format_lb_main);
215 VLIB_CLI_COMMAND (lb_show_command, static) =
218 .short_help = "show lb",
219 .function = lb_show_command_fn,
222 static clib_error_t *
223 lb_show_vips_command_fn (vlib_main_t * vm,
224 unformat_input_t * input, vlib_cli_command_t * cmd)
226 unformat_input_t line_input;
227 lb_main_t *lbm = &lb_main;
231 if (!unformat_user (input, unformat_line_input, &line_input))
234 if (unformat(&line_input, "verbose"))
237 pool_foreach(vip, lbm->vips, {
238 vlib_cli_output(vm, "%U\n", verbose?format_lb_vip_detailed:format_lb_vip, vip);
241 unformat_free (&line_input);
245 VLIB_CLI_COMMAND (lb_show_vips_command, static) =
247 .path = "show lb vips",
248 .short_help = "show lb vips [verbose]",
249 .function = lb_show_vips_command_fn,