FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
gbp_fwd.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <plugins/gbp/gbp.h>
17 #include <vnet/l2/l2_input.h>
18 
19 /**
20  * Grouping of global data for the GBP source EPG classification feature
21  */
22 typedef struct gbp_fwd_main_t_
23 {
24  /**
25  * Next nodes for L2 output features
26  */
29 
31 
32 #define foreach_gbp_fwd \
33  _(DROP, "drop") \
34  _(OUTPUT, "output")
35 
36 typedef enum
37 {
38 #define _(sym,str) GBP_FWD_ERROR_##sym,
40 #undef _
43 
44 static char *gbp_fwd_error_strings[] = {
45 #define _(sym,string) string,
47 #undef _
48 };
49 
50 typedef enum
51 {
52 #define _(sym,str) GBP_FWD_NEXT_##sym,
54 #undef _
57 
58 /**
59  * per-packet trace data
60  */
61 typedef struct gbp_fwd_trace_t_
62 {
63  /* per-pkt trace data */
67 
68 static uword
70 {
71  u32 n_left_from, *from, *to_next;
72  u32 next_index;
73 
74  next_index = 0;
75  n_left_from = frame->n_vectors;
76  from = vlib_frame_vector_args (frame);
77 
78  while (n_left_from > 0)
79  {
80  u32 n_left_to_next;
81 
82  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
83 
84  while (n_left_from > 0 && n_left_to_next > 0)
85  {
86  u32 bi0, sw_if_index0, src_epg;
87  gbp_fwd_next_t next0;
88  vlib_buffer_t *b0;
89 
90  next0 = GBP_FWD_NEXT_DROP;
91  bi0 = from[0];
92  to_next[0] = bi0;
93  from += 1;
94  to_next += 1;
95  n_left_from -= 1;
96  n_left_to_next -= 1;
97 
98  b0 = vlib_get_buffer (vm, bi0);
99 
100  /*
101  * lookup the uplink based on src EPG
102  */
103  src_epg = vnet_buffer2 (b0)->gbp.src_epg;
104 
105  sw_if_index0 = gbp_epg_itf_lookup (src_epg);
106 
107  if (~0 != sw_if_index0)
108  {
109  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
110 
111  next0 = GBP_FWD_NEXT_OUTPUT;
112  }
113  /*
114  * else
115  * don't know the uplink interface for this EPG => drop
116  */
117 
118  if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
119  {
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;
123  }
124 
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,
128  bi0, next0);
129  }
130 
131  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
132  }
133 
134  return frame->n_vectors;
135 }
136 
137 /* packet trace format function */
138 static u8 *
139 format_gbp_fwd_trace (u8 * s, va_list * args)
140 {
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 *);
144 
145  s = format (s, "src-epg:%d", t->src_epg);
146 
147  return s;
148 }
149 
150 /* *INDENT-OFF* */
152  .function = gbp_fwd,
153  .name = "gbp-fwd",
154  .vector_size = sizeof (u32),
155  .format_trace = format_gbp_fwd_trace,
156  .type = VLIB_NODE_TYPE_INTERNAL,
157 
158  .n_errors = ARRAY_LEN(gbp_fwd_error_strings),
159  .error_strings = gbp_fwd_error_strings,
160 
161  .n_next_nodes = GBP_FWD_N_NEXT,
162 
163  .next_nodes = {
164  [GBP_FWD_NEXT_DROP] = "error-drop",
165  [GBP_FWD_NEXT_OUTPUT] = "l2-output",
166  },
167 };
168 
170 
171 /* *INDENT-ON* */
172 
173 static clib_error_t *
175 {
177 
178  /* Initialize the feature next-node indices */
180  gbp_fwd_node.index,
183  gpm->l2_input_feat_next);
184 
185  return 0;
186 }
187 
189 
190 /*
191  * fd.io coding-style-patch-verification: ON
192  *
193  * Local Variables:
194  * eval: (c-set-style "gnu")
195  * End:
196  */
static gbp_fwd_main_t gbp_fwd_main
Definition: gbp_fwd.c:30
per-packet trace data
Definition: gbp_fwd.c:61
u16 epg_id_t
Definition: gbp_types.h:21
#define CLIB_UNUSED(x)
Definition: clib.h:82
struct gbp_fwd_main_t_ gbp_fwd_main_t
Grouping of global data for the GBP source EPG classification feature.
#define vnet_buffer2(b)
Definition: buffer.h:413
#define foreach_gbp_fwd
Definition: gbp_fwd.c:32
struct gbp_fwd_trace_t_ gbp_fwd_trace_t
per-packet trace data
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
epg_id_t src_epg
Definition: gbp_fwd.c:64
unsigned char u8
Definition: types.h:56
static u32 gbp_epg_itf_lookup(epg_id_t epg)
gbp_fwd_error_t
Definition: gbp_fwd.c:36
static char * gbp_fwd_error_strings[]
Definition: gbp_fwd.c:44
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
unsigned int u32
Definition: types.h:88
static clib_error_t * gbp_fwd_init(vlib_main_t *vm)
Definition: gbp_fwd.c:174
static uword gbp_fwd(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: gbp_fwd.c:69
#define PREDICT_FALSE(x)
Definition: clib.h:111
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
VLIB_NODE_FUNCTION_MULTIARCH(gbp_fwd_node, gbp_fwd)
u16 n_vectors
Definition: node.h:420
vlib_main_t * vm
Definition: buffer.c:301
static void feat_bitmap_init_next_nodes(vlib_main_t *vm, u32 node_index, u32 num_features, char **feat_names, u32 *next_nodes)
Initialize the feature next-node indexes of a graph node.
Definition: feat_bitmap.h:43
#define ARRAY_LEN(x)
Definition: clib.h:62
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:452
char ** l2input_get_feat_names(void)
Return an array of strings containing graph node names of each feature.
Definition: l2_input.c:60
gbp_fwd_next_t
Definition: gbp_fwd.c:50
static u8 * format_gbp_fwd_trace(u8 *s, va_list *args)
Definition: gbp_fwd.c:139
vlib_node_registration_t gbp_fwd_node
(constructor) VLIB_REGISTER_NODE (gbp_fwd_node)
Definition: gbp_fwd.c:151
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:57
Definition: defs.h:47
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define vnet_buffer(b)
Definition: buffer.h:368
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:117
Grouping of global data for the GBP source EPG classification feature.
Definition: gbp_fwd.c:22
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62
u32 l2_input_feat_next[32]
Next nodes for L2 output features.
Definition: gbp_fwd.c:27