blob: c66090f3cba01aad5b582275a07d32c68e121d24 [file] [log] [blame]
Neale Rannsd792d9c2017-10-21 10:53:20 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#include <vnet/vnet.h>
17#include <vnet/mpls/mpls.h>
18
19#include <vnet/bier/bier_table.h>
20#include <vnet/bier/bier_types.h>
21#include <vnet/bier/bier_update.h>
22
23clib_error_t *
24vnet_bier_table_cmd (vlib_main_t * vm,
25 unformat_input_t * input,
26 vlib_cli_command_t * cmd)
27{
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,
32 };
33 u32 is_add = 0;
34
35 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
36 if (unformat (input, "del")) {
37 is_add = 0;
38 } else if (unformat (input, "add")) {
39 is_add = 1;
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)) {
44 } else {
45 error = unformat_parse_error (input);
46 goto done;
47 }
48 }
49
50 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
51 // FIXME
52 bti.bti_type = BIER_TABLE_MPLS_SPF;
53
54 if (is_add)
55 {
56 bier_table_add_or_lock(&bti, local_label);
57 }
58 else
59 {
60 bier_table_unlock(&bti);
61 }
62
63done:
64 return (error);
65}
66
67VLIB_CLI_COMMAND (bier_table_command) = {
68 .path = "bier table",
69 .short_help = "Add/delete BIER Tables",
70 .function = vnet_bier_table_cmd,
71};
72
73clib_error_t *
74vnet_bier_route_cmd (vlib_main_t * vm,
75 unformat_input_t * input,
76 vlib_cli_command_t * cmd)
77{
78 clib_error_t * error = NULL;
Neale Ranns93149bb2017-11-15 10:44:07 -080079 fib_route_path_t *brps = NULL, brp = {
Neale Rannsd792d9c2017-10-21 10:53:20 -070080 .frp_flags = FIB_ROUTE_PATH_BIER_FMASK,
81 };
Neale Ranns70ed8ae2017-11-15 12:54:46 -080082 u32 hdr_len, payload_proto;
Neale Rannsd792d9c2017-10-21 10:53:20 -070083 bier_table_id_t bti = {
84 };
Neale Rannsd792d9c2017-10-21 10:53:20 -070085 bier_bp_t bp;
Neale Rannsd792d9c2017-10-21 10:53:20 -070086 u32 add = 1;
87
Neale Ranns70ed8ae2017-11-15 12:54:46 -080088 payload_proto = DPO_PROTO_BIER;
89
Neale Rannsd792d9c2017-10-21 10:53:20 -070090 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
91 if (unformat (input, "del")) {
92 add = 0;
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)) {
Neale Ranns70ed8ae2017-11-15 12:54:46 -080097 } else if (unformat (input, "via %U",
98 unformat_fib_route_path,
99 &brp, &payload_proto)) {
Neale Rannsd792d9c2017-10-21 10:53:20 -0700100 } else {
101 error = unformat_parse_error (input);
102 goto done;
103 }
104 }
105
Neale Ranns93149bb2017-11-15 10:44:07 -0800106 vec_add1(brps, brp);
Neale Rannsd792d9c2017-10-21 10:53:20 -0700107 bti.bti_hdr_len = bier_hdr_bit_len_to_id(hdr_len);
108 // FIXME
109 bti.bti_type = BIER_TABLE_MPLS_SPF;
110
111 if (add)
112 {
113 bier_table_route_add(&bti, bp, &brp);
114 }
115 else
116 {
117 bier_table_route_remove(&bti, bp, &brp);
118 }
119
120done:
Neale Ranns93149bb2017-11-15 10:44:07 -0800121 vec_free(brps);
Neale Rannsd792d9c2017-10-21 10:53:20 -0700122 return (error);
123}
124
125VLIB_CLI_COMMAND (bier_route_command) = {
Neale Ranns6cfe6432017-11-22 03:05:29 -0800126 .path = "bier route",
127 .short_help = "bier route 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>]",
Neale Rannsd792d9c2017-10-21 10:53:20 -0700128 .function = vnet_bier_route_cmd,
129};
130
131static clib_error_t *
132show_bier_fib_command_fn (vlib_main_t * vm,
133 unformat_input_t * input,
134 vlib_cli_command_t * cmd)
135{
136 bier_show_flags_t flags;
137 index_t bti, bei;
138 bier_bp_t bp;
139
140 bp = BIER_BP_INVALID;
141 bti = bei = INDEX_INVALID;
Neale Ranns93149bb2017-11-15 10:44:07 -0800142 flags = BIER_SHOW_BRIEF;
Neale Rannsd792d9c2017-10-21 10:53:20 -0700143
144 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
145 if (unformat (input, "%d %d", &bti, &bp))
146 {
147 flags = BIER_SHOW_DETAIL;
148 }
149 else if (unformat (input, "%d", &bti))
150 {
151 flags = BIER_SHOW_DETAIL;
152 }
153 else
154 {
155 break;
156 }
157 }
158
159 if (INDEX_INVALID == bti)
160 {
161 bier_table_show_all(vm, flags);
162 }
163 else
164 {
165 if (!pool_is_free_index(bier_table_pool, bti))
166 {
167 if (BIER_BP_INVALID == bp)
168 {
169 vlib_cli_output (vm, "%U", format_bier_table, bti, flags);
170 }
171 else
172 {
173 vlib_cli_output (vm, "%U", format_bier_table_entry, bti, bp);
174 }
175 }
176 }
177 return (NULL);
178}
179
180VLIB_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,
184};