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>
19 #define foreach_gbp_fwd \
25 #define _(sym,str) GBP_FWD_ERROR_##sym,
31 static char *gbp_fwd_error_strings[] = {
32 #define _(sym,string) string,
39 #define _(sym,str) GBP_FWD_NEXT_##sym,
46 * per-packet trace data
48 typedef struct gbp_fwd_trace_t_
50 /* per-pkt trace data */
55 VLIB_NODE_FN (gbp_fwd_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
58 u32 n_left_from, *from, *to_next;
62 n_left_from = frame->n_vectors;
63 from = vlib_frame_vector_args (frame);
65 while (n_left_from > 0)
69 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
71 while (n_left_from > 0 && n_left_to_next > 0)
73 u32 bi0, sw_if_index0;
78 next0 = GBP_FWD_NEXT_DROP;
86 b0 = vlib_get_buffer (vm, bi0);
89 * lookup the uplink based on src EPG
91 sclass0 = vnet_buffer2 (b0)->gbp.sclass;
93 sw_if_index0 = gbp_epg_itf_lookup_sclass (sclass0);
95 if (~0 != sw_if_index0)
97 vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
99 next0 = GBP_FWD_NEXT_OUTPUT;
103 * don't know the uplink interface for this EPG => drop
106 if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
108 gbp_fwd_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
110 t->sw_if_index = sw_if_index0;
113 /* verify speculative enqueue, maybe switch current next frame */
114 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
115 to_next, n_left_to_next,
119 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
122 return frame->n_vectors;
125 /* packet trace format function */
127 format_gbp_fwd_trace (u8 * s, va_list * args)
129 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
130 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
131 gbp_fwd_trace_t *t = va_arg (*args, gbp_fwd_trace_t *);
133 s = format (s, "sclass:%d", t->sclass);
139 VLIB_REGISTER_NODE (gbp_fwd_node) = {
141 .vector_size = sizeof (u32),
142 .format_trace = format_gbp_fwd_trace,
143 .type = VLIB_NODE_TYPE_INTERNAL,
145 .n_errors = ARRAY_LEN(gbp_fwd_error_strings),
146 .error_strings = gbp_fwd_error_strings,
148 .n_next_nodes = GBP_FWD_N_NEXT,
151 [GBP_FWD_NEXT_DROP] = "error-drop",
152 [GBP_FWD_NEXT_OUTPUT] = "l2-output",
158 * fd.io coding-style-patch-verification: ON
161 * eval: (c-set-style "gnu")