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/buffer.h>
18 #include <vnet/bier/bier_table.h>
19 #include <vnet/bier/bier_hdr_inlines.h>
22 #define bier_error(n,s) BIER_INPUT_ERROR_##n,
23 #include <vnet/bier/bier_input_error.def>
28 static char * bier_error_strings[] = {
29 #define bier_error(n,s) s,
30 #include <vnet/bier/bier_input_error.def>
34 typedef enum bier_input_next_t_ {
35 BIER_INPUT_NEXT_BIER_LOOKUP,
40 vlib_node_registration_t bier_input_node;
43 * @brief Packet trace record for BIER input
45 typedef struct bier_input_trace_t_
52 bier_hdr_validate (bier_hdr_t *bier_hdr,
53 bier_hdr_len_id_t expected_length)
57 * - the version field must be 1
58 * - the header length matches the length expected
60 if (PREDICT_FALSE((BIER_HDR_VERSION_1 != bier_hdr_get_version(bier_hdr)) ||
61 (expected_length != bier_hdr_get_len_id(bier_hdr)))) {
69 bier_input (vlib_main_t * vm,
70 vlib_node_runtime_t * node,
71 vlib_frame_t * from_frame)
73 u32 n_left_from, next_index, * from, * to_next;
75 from = vlib_frame_vector_args (from_frame);
76 n_left_from = from_frame->n_vectors;
79 * objection your honour! speculation!
81 next_index = node->cached_next_index;
83 while (n_left_from > 0)
87 vlib_get_next_frame (vm, node, next_index,
88 to_next, n_left_to_next);
90 while (n_left_from > 0 && n_left_to_next > 0)
92 const bier_table_t *bt0;
105 b0 = vlib_get_buffer (vm, bi0);
106 bh0 = vlib_buffer_get_current (b0);
110 * In the MPLS decap node we squirrelled away the
111 * index for the BIER table as the tx adjacency
113 bt_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
114 bt0 = bier_table_get(bt_index0);
116 if (PREDICT_TRUE(bier_hdr_validate(bh0, bt0->bt_id.bti_hdr_len)))
118 next0 = BIER_INPUT_NEXT_BIER_LOOKUP;
120 next0 = BIER_INPUT_NEXT_DROP;
121 b0->error = node->errors[BIER_INPUT_ERROR_INVALID_HEADER];
124 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
126 bier_input_trace_t *tr;
128 tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
129 tr->next_index = next0;
130 tr->bt_index = bt_index0;
133 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
134 to_next, n_left_to_next,
138 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
141 vlib_node_increment_counter (vm, bier_input_node.index,
142 BIER_INPUT_ERROR_PKTS_VALID,
143 from_frame->n_vectors);
144 return (from_frame->n_vectors);
148 format_bier_input_trace (u8 * s, va_list * args)
150 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
151 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
152 bier_input_trace_t * t = va_arg (*args, bier_input_trace_t *);
154 s = format (s, " next [%d], BIER Table index %d",
155 t->next_index, t->bt_index);
159 VLIB_REGISTER_NODE (bier_input_node) = {
160 .function = bier_input,
161 .name = "bier-input",
162 /* Takes a vector of packets. */
163 .vector_size = sizeof (u32),
165 .n_errors = BIER_INPUT_N_ERROR,
166 .error_strings = bier_error_strings,
168 .n_next_nodes = BIER_INPUT_N_NEXT,
170 [BIER_INPUT_NEXT_BIER_LOOKUP] = "bier-lookup",
171 [BIER_INPUT_NEXT_DROP] = "bier-drop",
174 .format_trace = format_bier_input_trace,