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.
16 #include <vnet/vnet.h>
17 #include <vnet/mpls/mpls.h>
19 #include <vnet/bier/bier_table.h>
20 #include <vnet/bier/bier_types.h>
21 #include <vnet/bier/bier_update.h>
24 vnet_bier_table_cmd (vlib_main_t * vm,
25 unformat_input_t * input,
26 vlib_cli_command_t * cmd)
28 u32 hdr_len, local_label;
29 clib_error_t * error = 0;
30 bier_table_id_t bti = {
31 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
35 local_label = MPLS_LABEL_INVALID;
37 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
38 if (unformat (input, "del")) {
40 } else if (unformat (input, "add")) {
42 } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
43 } else if (unformat (input, "set %d", &bti.bti_set)) {
44 } else if (unformat (input, "bsl %d", &hdr_len)) {
45 } else if (unformat (input, "mpls %d", &local_label)) {
47 error = unformat_parse_error (input);
52 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
54 bti.bti_type = BIER_TABLE_MPLS_SPF;
58 bier_table_add_or_lock(&bti, local_label);
62 bier_table_unlock(&bti);
69 VLIB_CLI_COMMAND (bier_table_command) = {
71 .short_help = "bier table [add|del] sd <sub-domain> set <SET> bsl <bit-string-length> [mpls <label>]",
72 .function = vnet_bier_table_cmd,
76 vnet_bier_route_cmd (vlib_main_t * vm,
77 unformat_input_t * input,
78 vlib_cli_command_t * cmd)
80 clib_error_t * error = NULL;
81 fib_route_path_t *brps = NULL, brp = {
82 .frp_flags = FIB_ROUTE_PATH_BIER_FMASK,
84 u32 hdr_len, payload_proto;
85 bier_table_id_t bti = {
86 .bti_ecmp = BIER_ECMP_TABLE_ID_MAIN,
91 payload_proto = DPO_PROTO_BIER;
93 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
94 if (unformat (input, "del")) {
96 } else if (unformat (input, "add")) {
98 } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
99 } else if (unformat (input, "set %d", &bti.bti_set)) {
100 } else if (unformat (input, "bsl %d", &hdr_len)) {
101 } else if (unformat (input, "bp %d", &bp)) {
102 } else if (unformat (input, "via %U",
103 unformat_fib_route_path,
104 &brp, &payload_proto)) {
106 error = unformat_parse_error (input);
112 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
114 bti.bti_type = BIER_TABLE_MPLS_SPF;
118 bier_table_route_path_add(&bti, bp, brps);
122 bier_table_route_path_remove(&bti, bp, brps);
130 VLIB_CLI_COMMAND (bier_route_command) = {
131 .path = "bier route",
132 .short_help = "bier route [add|del] sd <sud-domain> set <set> bsl <bit-string-length> bp <bit-position> via [next-hop-address] [next-hop-interface] [next-hop-table <value>] [weight <value>] [preference <value>] [udp-encap-id <value>] [ip4-lookup-in-table <value>] [ip6-lookup-in-table <value>] [mpls-lookup-in-table <value>] [resolve-via-host] [resolve-via-connected] [rx-ip4 <interface>] [out-labels <value value value>]",
133 .function = vnet_bier_route_cmd,
136 static clib_error_t *
137 show_bier_fib_command_fn (vlib_main_t * vm,
138 unformat_input_t * input,
139 vlib_cli_command_t * cmd)
141 bier_show_flags_t flags;
145 bp = BIER_BP_INVALID;
146 bti = bei = INDEX_INVALID;
147 flags = BIER_SHOW_BRIEF;
149 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
150 if (unformat (input, "%d %d", &bti, &bp))
152 flags = BIER_SHOW_DETAIL;
154 else if (unformat (input, "%d", &bti))
156 flags = BIER_SHOW_DETAIL;
164 if (INDEX_INVALID == bti)
166 bier_table_show_all(vm, flags);
170 if (!pool_is_free_index(bier_table_pool, bti))
172 if (BIER_BP_INVALID == bp)
174 vlib_cli_output (vm, "%U", format_bier_table, bti, flags);
178 vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp);
185 VLIB_CLI_COMMAND (show_bier_fib_command, static) = {
186 .path = "show bier fib",
187 .short_help = "show bier fib [table-index] [bit-position]",
188 .function = show_bier_fib_command_fn,