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 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
36 if (unformat (input, "del")) {
38 } else if (unformat (input, "add")) {
40 } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
41 } else if (unformat (input, "set %d", &bti.bti_set)) {
42 } else if (unformat (input, "bsl %d", &hdr_len)) {
43 } else if (unformat (input, "mpls %d", &local_label)) {
45 error = unformat_parse_error (input);
50 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
52 bti.bti_type = BIER_TABLE_MPLS_SPF;
56 bier_table_add_or_lock(&bti, local_label);
60 bier_table_unlock(&bti);
67 VLIB_CLI_COMMAND (bier_table_command) = {
69 .short_help = "Add/delete BIER Tables",
70 .function = vnet_bier_table_cmd,
74 vnet_bier_route_cmd (vlib_main_t * vm,
75 unformat_input_t * input,
76 vlib_cli_command_t * cmd)
78 clib_error_t * error = NULL;
79 fib_route_path_t *brps = NULL, brp = {
80 .frp_flags = FIB_ROUTE_PATH_BIER_FMASK,
82 u32 hdr_len, payload_proto;
83 bier_table_id_t bti = {
88 payload_proto = DPO_PROTO_BIER;
90 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
91 if (unformat (input, "del")) {
93 } else if (unformat (input, "sd %d", &bti.bti_sub_domain)) {
94 } else if (unformat (input, "set %d", &bti.bti_set)) {
95 } else if (unformat (input, "bsl %d", &hdr_len)) {
96 } else if (unformat (input, "bp %d", &bp)) {
97 } else if (unformat (input, "via %U",
98 unformat_fib_route_path,
99 &brp, &payload_proto)) {
101 error = unformat_parse_error (input);
107 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
109 bti.bti_type = BIER_TABLE_MPLS_SPF;
113 bier_table_route_add(&bti, bp, &brp);
117 bier_table_route_remove(&bti, bp, &brp);
125 VLIB_CLI_COMMAND (bier_route_command) = {
126 .path = "bier route 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>]",
127 .short_help = "Add/delete BIER Routes",
128 .function = vnet_bier_route_cmd,
131 static clib_error_t *
132 show_bier_fib_command_fn (vlib_main_t * vm,
133 unformat_input_t * input,
134 vlib_cli_command_t * cmd)
136 bier_show_flags_t flags;
140 bp = BIER_BP_INVALID;
141 bti = bei = INDEX_INVALID;
142 flags = BIER_SHOW_BRIEF;
144 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
145 if (unformat (input, "%d %d", &bti, &bp))
147 flags = BIER_SHOW_DETAIL;
149 else if (unformat (input, "%d", &bti))
151 flags = BIER_SHOW_DETAIL;
159 if (INDEX_INVALID == bti)
161 bier_table_show_all(vm, flags);
165 if (!pool_is_free_index(bier_table_pool, bti))
167 if (BIER_BP_INVALID == bp)
169 vlib_cli_output (vm, "%U", format_bier_table, bti, flags);
173 vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp);
180 VLIB_CLI_COMMAND (show_bier_fib_command, static) = {
181 .path = "show bier fib",
182 .short_help = "show bier fib [table-index] [bit-position]",
183 .function = show_bier_fib_command_fn,