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/bier/bier_bift_table.h>
17 #include <vnet/dpo/drop_dpo.h>
18 #include <vnet/udp/udp.h>
21 #define bier_error(n,s) BIER_INPUT_ERROR_##n,
22 #include <vnet/bier/bier_input_error.def>
27 static char * bier_error_strings[] = {
28 #define bier_error(n,s) s,
29 #include <vnet/bier/bier_input_error.def>
36 bier_bfit_table_t *bier_bift_table;
39 * Forward declare the node
41 vlib_node_registration_t bier_bift_input_node;
44 bier_bift_table_entry_add (bier_bift_id_t id,
47 if (NULL == bier_bift_table)
52 * allocate the table and
53 * set each of the entries therein to a BIER drop
55 bier_bift_table = clib_mem_alloc_aligned(sizeof(*bier_bift_table),
56 CLIB_CACHE_LINE_BYTES);
57 memset(bier_bift_table, 0, sizeof(*bier_bift_table));
59 for (ii = 0; ii < BIER_BIFT_N_ENTRIES; ii++)
61 dpo_stack_from_node(bier_bift_input_node.index,
62 &bier_bift_table->bblt_dpos[ii],
63 drop_dpo_get(DPO_PROTO_BIER));
67 * register to handle packets that arrive on the assigned
70 udp_register_dst_port(vlib_get_main(),
72 bier_bift_input_node.index,
74 udp_register_dst_port(vlib_get_main(),
76 bier_bift_input_node.index,
80 dpo_stack_from_node(bier_bift_input_node.index,
81 &bier_bift_table->bblt_dpos[id],
84 bier_bift_table->bblt_n_entries++;
88 bier_bift_table_entry_remove (bier_bift_id_t id)
90 ASSERT(NULL != bier_bift_table);
92 dpo_reset(&bier_bift_table->bblt_dpos[id]);
94 bier_bift_table->bblt_n_entries--;
96 if (0 == bier_bift_table->bblt_n_entries)
98 udp_unregister_dst_port(vlib_get_main(),
101 udp_unregister_dst_port(vlib_get_main(),
105 clib_mem_free(bier_bift_table);
106 bier_bift_table = NULL;
111 * @brief Packet trace record for BIER input
113 typedef struct bier_bift_input_trace_t_
116 } bier_bift_input_trace_t;
119 bier_bift_input (vlib_main_t * vm,
120 vlib_node_runtime_t * node,
121 vlib_frame_t * from_frame)
123 u32 n_left_from, next_index, * from, * to_next;
125 from = vlib_frame_vector_args (from_frame);
126 n_left_from = from_frame->n_vectors;
127 next_index = node->cached_next_index;
129 while (n_left_from > 0)
133 vlib_get_next_frame (vm, node, next_index,
134 to_next, n_left_to_next);
136 while (n_left_from > 0 && n_left_to_next > 0)
138 bier_bift_id_t *biftp0, bift0;
139 const dpo_id_t *dpo0;
150 b0 = vlib_get_buffer (vm, bi0);
151 biftp0 = vlib_buffer_get_current (b0);
152 vlib_buffer_advance(b0, sizeof(bift0));
153 bift0 = clib_net_to_host_u32(*biftp0);
156 * Do the lookup based on the first 20 bits, i.e. the
157 * encoding of the set, sub-domain and BSL
159 dpo0 = bier_bift_dp_lookup(bift0);
162 * save the TTL for later during egress
164 vnet_buffer(b0)->mpls.ttl = vnet_mpls_uc_get_ttl(bift0);
166 next0 = dpo0->dpoi_next_node;
167 vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
169 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
171 bier_bift_input_trace_t *tr;
173 tr = vlib_add_trace(vm, node, b0, sizeof (*tr));
177 vlib_validate_buffer_enqueue_x1(vm, node, next_index,
178 to_next, n_left_to_next,
182 vlib_put_next_frame(vm, node, next_index, n_left_to_next);
185 vlib_node_increment_counter(vm, bier_bift_input_node.index,
186 BIER_INPUT_ERROR_PKTS_VALID,
187 from_frame->n_vectors);
188 return (from_frame->n_vectors);
192 format_bier_bift_input_trace (u8 * s, va_list * args)
194 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
195 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
196 bier_bift_input_trace_t * t = va_arg (*args, bier_bift_input_trace_t *);
198 s = format (s, "BIFT-ID:[%U]", format_bier_bift_id,
199 vnet_mpls_uc_get_label(t->bift_id));
203 VLIB_REGISTER_NODE (bier_bift_input_node) = {
204 .function = bier_bift_input,
205 .name = "bier-bift-input",
206 /* Takes a vector of packets. */
207 .vector_size = sizeof (u32),
208 .n_errors = BIER_INPUT_N_ERROR,
209 .error_strings = bier_error_strings,
211 .format_trace = format_bier_bift_input_trace,
215 show_bier_bift_cmd (vlib_main_t * vm,
216 unformat_input_t * input,
217 vlib_cli_command_t * cmd)
219 clib_error_t * error = NULL;
220 u32 hdr_len, set, sub_domain;
222 set = hdr_len = sub_domain = ~0;
224 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
225 if (unformat (input, "sd %d", &sub_domain)) {
227 } else if (unformat (input, "set %d", &set)) {
229 } else if (unformat (input, "bsl %d", &hdr_len)) {
234 error = unformat_parse_error (input);
239 if (NULL == bier_bift_table)
241 vlib_cli_output(vm, "no BIFT entries");
249 for (ii = 0; ii < BIER_BIFT_N_ENTRIES; ii++)
251 if (!dpo_is_drop(&bier_bift_table->bblt_dpos[ii]))
253 bier_hdr_len_id_t bsl;
255 bier_bift_id_decode(ii, &set, &sub_domain, &bsl);
257 vlib_cli_output(vm, "set: %d, sub-domain:%d, BSL:%U",
259 format_bier_hdr_len_id, bsl);
260 vlib_cli_output(vm, " %U",
262 &bier_bift_table->bblt_dpos[ii], 0);
270 id = bier_bift_id_encode(set, sub_domain,
271 bier_hdr_bit_len_to_id(hdr_len));
273 if (!dpo_is_drop(&bier_bift_table->bblt_dpos[id]))
275 vlib_cli_output(vm, "set: %d, sub-domain:%d, BSL:%U",
277 format_bier_hdr_len_id, hdr_len);
278 vlib_cli_output(vm, " %U",
280 &bier_bift_table->bblt_dpos[id], 0);
287 VLIB_CLI_COMMAND (show_bier_bift_command, static) = {
288 .path = "show bier bift",
289 .short_help = "show bier bift [set <value> sd <value> bsl <value>]",
290 .function = show_bier_bift_cmd,