2 * Copyright (c) 2018 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 <plugins/gbp/gbp.h>
17 #include <vnet/l2/l2_input.h>
20 * Grouping of global data for the GBP source EPG classification feature
22 typedef struct gbp_fwd_main_t_
25 * Next nodes for L2 output features
27 u32 l2_input_feat_next[32];
30 static gbp_fwd_main_t gbp_fwd_main;
32 #define foreach_gbp_fwd \
38 #define _(sym,str) GBP_FWD_ERROR_##sym,
44 static char *gbp_fwd_error_strings[] = {
45 #define _(sym,string) string,
52 #define _(sym,str) GBP_FWD_NEXT_##sym,
59 * per-packet trace data
61 typedef struct gbp_fwd_trace_t_
63 /* per-pkt trace data */
69 gbp_fwd (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame)
71 u32 n_left_from, *from, *to_next;
75 n_left_from = frame->n_vectors;
76 from = vlib_frame_vector_args (frame);
78 while (n_left_from > 0)
82 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
84 while (n_left_from > 0 && n_left_to_next > 0)
86 u32 bi0, sw_if_index0, src_epg;
90 next0 = GBP_FWD_NEXT_DROP;
98 b0 = vlib_get_buffer (vm, bi0);
101 * lookup the uplink based on src EPG
103 src_epg = vnet_buffer2 (b0)->gbp.src_epg;
105 sw_if_index0 = gbp_epg_itf_lookup (src_epg);
107 if (~0 != sw_if_index0)
109 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
111 next0 = GBP_FWD_NEXT_OUTPUT;
115 * don't know the uplink interface for this EPG => drop
118 if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
120 gbp_fwd_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
121 t->src_epg = src_epg;
122 t->sw_if_index = sw_if_index0;
125 /* verify speculative enqueue, maybe switch current next frame */
126 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
127 to_next, n_left_to_next,
131 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
134 return frame->n_vectors;
137 /* packet trace format function */
139 format_gbp_fwd_trace (u8 * s, va_list * args)
141 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
142 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
143 gbp_fwd_trace_t *t = va_arg (*args, gbp_fwd_trace_t *);
145 s = format (s, "src-epg:%d", t->src_epg);
151 VLIB_REGISTER_NODE (gbp_fwd_node) = {
154 .vector_size = sizeof (u32),
155 .format_trace = format_gbp_fwd_trace,
156 .type = VLIB_NODE_TYPE_INTERNAL,
158 .n_errors = ARRAY_LEN(gbp_fwd_error_strings),
159 .error_strings = gbp_fwd_error_strings,
161 .n_next_nodes = GBP_FWD_N_NEXT,
164 [GBP_FWD_NEXT_DROP] = "error-drop",
165 [GBP_FWD_NEXT_OUTPUT] = "l2-output",
169 VLIB_NODE_FUNCTION_MULTIARCH (gbp_fwd_node, gbp_fwd);
173 static clib_error_t *
174 gbp_fwd_init (vlib_main_t * vm)
176 gbp_fwd_main_t *gpm = &gbp_fwd_main;
178 /* Initialize the feature next-node indices */
179 feat_bitmap_init_next_nodes (vm,
182 l2input_get_feat_names (),
183 gpm->l2_input_feat_next);
188 VLIB_INIT_FUNCTION (gbp_fwd_init);
191 * fd.io coding-style-patch-verification: ON
194 * eval: (c-set-style "gnu")