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_fmask.h>
19 #include <vnet/bier/bier_hdr_inlines.h>
20 #include <vlib/vlib.h>
22 static char * bier_output_error_strings[] = {
23 #define bier_error(n,s) s,
24 #include <vnet/bier/bier_output_error.def>
29 * Keep these values sematically the same as BIER output
31 #define foreach_bier_output_next \
35 #define _(s,n) BIER_OUTPUT_NEXT_##s,
36 foreach_bier_output_next
42 #define bier_error(n,s) BIER_OUTPUT_ERROR_##n,
43 #include <vnet/bier/bier_output_error.def>
46 } bier_output_error_t;
51 vlib_node_registration_t bier_output_node;
54 * @brief Packet trace recoed for a BIER output
56 typedef struct bier_output_trace_t_
60 } bier_output_trace_t;
63 bier_output (vlib_main_t * vm,
64 vlib_node_runtime_t * node,
65 vlib_frame_t * from_frame)
67 u32 n_left_from, next_index, * from, * to_next;
69 from = vlib_frame_vector_args (from_frame);
70 n_left_from = from_frame->n_vectors;
72 // vnet_buffer(b0)->sw_if_index[VLIB_TX] = d0->tx_fib_index;
75 * objection your honour! speculation!
77 next_index = node->cached_next_index;
79 while (n_left_from > 0)
83 vlib_get_next_frame (vm, node, next_index,
84 to_next, n_left_to_next);
86 while (n_left_from > 0 && n_left_to_next > 0)
88 bier_output_next_t next0;
89 bier_bit_string_t bbs;
103 b0 = vlib_get_buffer (vm, bi0);
104 bh0 = vlib_buffer_get_current (b0);
105 bier_bit_string_init_from_hdr(bh0, &bbs);
108 * In the BIER Lookup node we squirelled away the
109 * BIER fmask index as the adj index
111 bfmi0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
112 bfm0 = bier_fmask_get(bfmi0);
115 * perform the logical AND of the packet's mask with
116 * that of the fmask objects, to reset the bits that
117 * are only on the shortest path the the fmask NH.
119 bier_bit_string_logical_and_string(
120 &bfm0->bfm_bits.bfmb_input_reset_string,
124 * this is the last time we touch the BIER header
125 * so flip to network order
130 * paint the BIER peer's label
132 if (!(bfm0->bfm_flags & BIER_FMASK_FLAG_DISP))
134 vlib_buffer_advance(b0, -(word)sizeof(mpls_label_t));
135 h0 = vlib_buffer_get_current(b0);
136 h0[0] = bfm0->bfm_label;
140 * setup next graph node
142 next0 = bfm0->bfm_dpo.dpoi_next_node;
143 vnet_buffer(b0)->ip.adj_index[VLIB_TX] = bfm0->bfm_dpo.dpoi_index;
145 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
147 bier_output_trace_t *tr;
149 tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
150 tr->next_index = next0;
151 tr->bfm_index = bfmi0;
154 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
155 to_next, n_left_to_next,
159 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
162 vlib_node_increment_counter (vm, bier_output_node.index,
163 BIER_OUTPUT_ERROR_NONE,
164 from_frame->n_vectors);
165 return (from_frame->n_vectors);
169 format_bier_output_trace (u8 * s, va_list * args)
171 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
172 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
173 bier_output_trace_t * t = va_arg (*args, bier_output_trace_t *);
175 s = format (s, " next [%d], BFM index %d",
176 t->next_index, t->bfm_index);
180 VLIB_REGISTER_NODE (bier_output_node) = {
181 .function = bier_output,
182 .name = "bier-output",
183 /* Takes a vector of packets. */
184 .vector_size = sizeof (u32),
186 .n_errors = BIER_OUTPUT_N_ERROR,
187 .error_strings = bier_output_error_strings,
189 .n_next_nodes = BIER_OUTPUT_N_NEXT,
191 [BIER_OUTPUT_NEXT_DROP] = "bier-drop",
194 .format_trace = format_bier_output_trace,