FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
gbp_fwd_node.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 #define foreach_gbp_fwd \
20  _(DROP, "drop") \
21  _(OUTPUT, "output")
22 
23 typedef enum
24 {
25 #define _(sym,str) GBP_FWD_ERROR_##sym,
27 #undef _
30 
31 static char *gbp_fwd_error_strings[] = {
32 #define _(sym,string) string,
34 #undef _
35 };
36 
37 typedef enum
38 {
39 #define _(sym,str) GBP_FWD_NEXT_##sym,
41 #undef _
44 
45 /**
46  * per-packet trace data
47  */
48 typedef struct gbp_fwd_trace_t_
49 {
50  /* per-pkt trace data */
54 
57 {
58  u32 n_left_from, *from, *to_next;
60 
61  next_index = 0;
62  n_left_from = frame->n_vectors;
64 
65  while (n_left_from > 0)
66  {
67  u32 n_left_to_next;
68 
69  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
70 
71  while (n_left_from > 0 && n_left_to_next > 0)
72  {
73  u32 bi0, sw_if_index0;
74  gbp_fwd_next_t next0;
75  vlib_buffer_t *b0;
76  sclass_t sclass0;
77 
78  next0 = GBP_FWD_NEXT_DROP;
79  bi0 = from[0];
80  to_next[0] = bi0;
81  from += 1;
82  to_next += 1;
83  n_left_from -= 1;
84  n_left_to_next -= 1;
85 
86  b0 = vlib_get_buffer (vm, bi0);
87 
88  /*
89  * lookup the uplink based on src EPG
90  */
91  sclass0 = vnet_buffer2 (b0)->gbp.sclass;
92 
93  sw_if_index0 = gbp_epg_itf_lookup_sclass (sclass0);
94 
95  if (~0 != sw_if_index0)
96  {
97  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index0;
98 
99  next0 = GBP_FWD_NEXT_OUTPUT;
100  }
101  /*
102  * else
103  * don't know the uplink interface for this EPG => drop
104  */
105 
106  if (PREDICT_FALSE ((b0->flags & VLIB_BUFFER_IS_TRACED)))
107  {
108  gbp_fwd_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
109  t->sclass = sclass0;
110  t->sw_if_index = sw_if_index0;
111  }
112 
113  /* verify speculative enqueue, maybe switch current next frame */
115  to_next, n_left_to_next,
116  bi0, next0);
117  }
118 
119  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
120  }
121 
122  return frame->n_vectors;
123 }
124 
125 /* packet trace format function */
126 static u8 *
127 format_gbp_fwd_trace (u8 * s, va_list * args)
128 {
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 *);
132 
133  s = format (s, "sclass:%d", t->sclass);
134 
135  return s;
136 }
137 
138 /* *INDENT-OFF* */
140  .name = "gbp-fwd",
141  .vector_size = sizeof (u32),
142  .format_trace = format_gbp_fwd_trace,
144 
145  .n_errors = ARRAY_LEN(gbp_fwd_error_strings),
146  .error_strings = gbp_fwd_error_strings,
147 
148  .n_next_nodes = GBP_FWD_N_NEXT,
149 
150  .next_nodes = {
151  [GBP_FWD_NEXT_DROP] = "error-drop",
152  [GBP_FWD_NEXT_OUTPUT] = "l2-output",
153  },
154 };
155 /* *INDENT-ON* */
156 
157 /*
158  * fd.io coding-style-patch-verification: ON
159  *
160  * Local Variables:
161  * eval: (c-set-style "gnu")
162  * End:
163  */
gbp_fwd_next_t
gbp_fwd_next_t
Definition: gbp_fwd_dpo.c:177
gbp_fwd_node
vlib_node_registration_t gbp_fwd_node
(constructor) VLIB_REGISTER_NODE (gbp_fwd_node)
Definition: gbp_fwd_node.c:139
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
GBP_FWD_N_NEXT
@ GBP_FWD_N_NEXT
Definition: gbp_fwd_node.c:42
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
format_gbp_fwd_trace
static u8 * format_gbp_fwd_trace(u8 *s, va_list *args)
Definition: gbp_fwd_node.c:127
gbp.h
gbp_fwd_error_t
gbp_fwd_error_t
Definition: gbp_fwd_node.c:23
gbp_fwd_trace_t_
per-packet trace data
Definition: gbp_fwd_node.c:48
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vnet_buffer2
#define vnet_buffer2(b)
Definition: buffer.h:505
vlib_frame_t
Definition: node.h:372
gbp_fwd_trace_t_::sw_if_index
u32 sw_if_index
Definition: gbp_fwd_node.c:52
gbp_fwd_next_t
gbp_fwd_next_t
Definition: gbp_fwd_node.c:37
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
l2_input.h
vlib_validate_buffer_enqueue_x1
#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:224
sclass_t
u16 sclass_t
Definition: gbp_types.h:25
gbp_epg_itf_lookup_sclass
static u32 gbp_epg_itf_lookup_sclass(sclass_t sclass)
Definition: gbp_endpoint_group.h:125
format
description fragment has unexpected format
Definition: map.api:433
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
gbp_fwd_trace_t
struct gbp_fwd_trace_t_ gbp_fwd_trace_t
per-packet trace data
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
u8
unsigned char u8
Definition: types.h:56
gbp_fwd_trace_t_::sclass
sclass_t sclass
Definition: gbp_fwd_node.c:51
gbp_fwd_error_strings
static char * gbp_fwd_error_strings[]
Definition: gbp_fwd_node.c:31
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#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:395
foreach_gbp_fwd
#define foreach_gbp_fwd
Definition: gbp_fwd_node.c:19
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
GBP_FWD_N_ERROR
@ GBP_FWD_N_ERROR
Definition: gbp_fwd_node.c:28
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169