FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
gbp_fwd_dpo.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>
18 
19 #include <vnet/ethernet/ethernet.h>
20 
21 
22 #ifndef CLIB_MARCH_VARIANT
23 /**
24  * The 'DB' of GBP FWD DPOs.
25  * There is one per-proto
26  */
28 
29 /**
30  * DPO type registered for these GBP FWD
31  */
33 
34 /**
35  * @brief pool of all interface DPOs
36  */
38 
39 static gbp_fwd_dpo_t *
41 {
42  gbp_fwd_dpo_t *gfd;
43 
44  pool_get (gbp_fwd_dpo_pool, gfd);
45 
46  return (gfd);
47 }
48 
49 static inline gbp_fwd_dpo_t *
51 {
53 
54  return (gbp_fwd_dpo_get (dpo->dpoi_index));
55 }
56 
57 static inline index_t
59 {
60  return (gfd - gbp_fwd_dpo_pool);
61 }
62 
63 static void
65 {
66  gbp_fwd_dpo_t *gfd;
67 
68  gfd = gbp_fwd_dpo_get_from_dpo (dpo);
69  gfd->gfd_locks++;
70 }
71 
72 static void
74 {
75  gbp_fwd_dpo_t *gfd;
76 
77  gfd = gbp_fwd_dpo_get_from_dpo (dpo);
78  gfd->gfd_locks--;
79 
80  if (0 == gfd->gfd_locks)
81  {
83  pool_put (gbp_fwd_dpo_pool, gfd);
84  }
85 }
86 
87 void
89 {
90  gbp_fwd_dpo_t *gfd;
91 
92  if (INDEX_INVALID == gbp_fwd_dpo_db[dproto])
93  {
94  gfd = gbp_fwd_dpo_alloc ();
95 
96  gfd->gfd_proto = dproto;
97 
98  gbp_fwd_dpo_db[dproto] = gbp_fwd_dpo_get_index (gfd);
99  }
100  else
101  {
102  gfd = gbp_fwd_dpo_get (gbp_fwd_dpo_db[dproto]);
103  }
104 
105  dpo_set (dpo, gbp_fwd_dpo_type, dproto, gbp_fwd_dpo_get_index (gfd));
106 }
107 
108 u8 *
109 format_gbp_fwd_dpo (u8 * s, va_list * ap)
110 {
111  index_t index = va_arg (*ap, index_t);
112  CLIB_UNUSED (u32 indent) = va_arg (*ap, u32);
113  gbp_fwd_dpo_t *gfd = gbp_fwd_dpo_get (index);
114 
115  return (format (s, "gbp-fwd-dpo: %U", format_dpo_proto, gfd->gfd_proto));
116 }
117 
118 const static dpo_vft_t gbp_fwd_dpo_vft = {
120  .dv_unlock = gbp_fwd_dpo_unlock,
121  .dv_format = format_gbp_fwd_dpo,
122 };
123 
124 /**
125  * @brief The per-protocol VLIB graph nodes that are assigned to a glean
126  * object.
127  *
128  * this means that these graph nodes are ones from which a glean is the
129  * parent object in the DPO-graph.
130  */
131 const static char *const gbp_fwd_dpo_ip4_nodes[] = {
132  "ip4-gbp-fwd-dpo",
133  NULL,
134 };
135 
136 const static char *const gbp_fwd_dpo_ip6_nodes[] = {
137  "ip6-gbp-fwd-dpo",
138  NULL,
139 };
140 
141 const static char *const *const gbp_fwd_dpo_nodes[DPO_PROTO_NUM] = {
144 };
145 
148 {
149  return (gbp_fwd_dpo_type);
150 }
151 
152 static clib_error_t *
154 {
155  dpo_proto_t dproto;
156 
157  FOR_EACH_DPO_PROTO (dproto)
158  {
159  gbp_fwd_dpo_db[dproto] = INDEX_INVALID;
160  }
161 
162  gbp_fwd_dpo_type = dpo_register_new_type (&gbp_fwd_dpo_vft,
164 
165  return (NULL);
166 }
167 
169 #endif /* CLIB_MARCH_VARIANT */
170 
171 typedef struct gbp_fwd_dpo_trace_t_
172 {
176 
177 typedef enum
178 {
183 
186  vlib_node_runtime_t * node,
187  vlib_frame_t * from_frame, fib_protocol_t fproto)
188 {
189  u32 n_left_from, next_index, *from, *to_next;
190 
191  from = vlib_frame_vector_args (from_frame);
192  n_left_from = from_frame->n_vectors;
193 
194  next_index = node->cached_next_index;
195 
196  while (n_left_from > 0)
197  {
198  u32 n_left_to_next;
199 
200  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
201 
202  while (n_left_from > 0 && n_left_to_next > 0)
203  {
204  const dpo_id_t *next_dpo0;
205  vlib_buffer_t *b0;
206  sclass_t sclass0;
207  u32 bi0, next0;
208 
209  bi0 = from[0];
210  to_next[0] = bi0;
211  from += 1;
212  to_next += 1;
213  n_left_from -= 1;
214  n_left_to_next -= 1;
215 
216  b0 = vlib_get_buffer (vm, bi0);
217 
218  sclass0 = vnet_buffer2 (b0)->gbp.sclass;
219  next_dpo0 = gbp_epg_dpo_lookup (sclass0, fproto);
220 
221  if (PREDICT_TRUE (NULL != next_dpo0))
222  {
223  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = next_dpo0->dpoi_index;
224  next0 = GBP_FWD_FWD;
225  }
226  else
227  {
228  next0 = GBP_FWD_DROP;
229  }
230 
231  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
232  {
234 
235  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
236  tr->sclass = sclass0;
237  tr->dpo_index = (NULL != next_dpo0 ?
238  next_dpo0->dpoi_index : ~0);
239  }
240 
241  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
242  n_left_to_next, bi0, next0);
243  }
244  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
245  }
246  return from_frame->n_vectors;
247 }
248 
249 static u8 *
250 format_gbp_fwd_dpo_trace (u8 * s, va_list * args)
251 {
252  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
253  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
254  gbp_fwd_dpo_trace_t *t = va_arg (*args, gbp_fwd_dpo_trace_t *);
255 
256  s = format (s, " sclass:%d dpo:%d", t->sclass, t->dpo_index);
257 
258  return s;
259 }
260 
262  vlib_node_runtime_t * node,
263  vlib_frame_t * from_frame)
264 {
265  return (gbp_fwd_dpo_inline (vm, node, from_frame, FIB_PROTOCOL_IP4));
266 }
267 
269  vlib_node_runtime_t * node,
270  vlib_frame_t * from_frame)
271 {
272  return (gbp_fwd_dpo_inline (vm, node, from_frame, FIB_PROTOCOL_IP6));
273 }
274 
275 /* *INDENT-OFF* */
277  .name = "ip4-gbp-fwd-dpo",
278  .vector_size = sizeof (u32),
279  .format_trace = format_gbp_fwd_dpo_trace,
280  .n_next_nodes = GBP_FWD_N_NEXT,
281  .next_nodes =
282  {
283  [GBP_FWD_DROP] = "ip4-drop",
284  [GBP_FWD_FWD] = "ip4-dvr-dpo",
285  }
286 };
288  .name = "ip6-gbp-fwd-dpo",
289  .vector_size = sizeof (u32),
290  .format_trace = format_gbp_fwd_dpo_trace,
291  .n_next_nodes = GBP_FWD_N_NEXT,
292  .next_nodes =
293  {
294  [GBP_FWD_DROP] = "ip6-drop",
295  [GBP_FWD_FWD] = "ip6-dvr-dpo",
296  }
297 };
298 /* *INDENT-ON* */
299 
300 /*
301  * fd.io coding-style-patch-verification: ON
302  *
303  * Local Variables:
304  * eval: (c-set-style "gnu")
305  * End:
306  */
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:124
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:406
u16 sclass_t
Definition: gbp_types.h:25
#define CLIB_UNUSED(x)
Definition: clib.h:83
A virtual function table regisitered for a DPO type.
Definition: dpo.h:401
gbp_fwd_next_t
Definition: gbp_fwd_dpo.c:177
static index_t gbp_fwd_dpo_db[DPO_PROTO_NUM]
The &#39;DB&#39; of GBP FWD DPOs.
Definition: gbp_fwd_dpo.c:27
#define vnet_buffer2(b)
Definition: buffer.h:424
#define PREDICT_TRUE(x)
Definition: clib.h:113
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
static clib_error_t * gbp_fwd_dpo_module_init(vlib_main_t *vm)
Definition: gbp_fwd_dpo.c:153
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static uword gbp_fwd_dpo_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, fib_protocol_t fproto)
Definition: gbp_fwd_dpo.c:185
#define VLIB_NODE_FN(node)
Definition: node.h:202
u16 gfd_locks
number of locks.
Definition: gbp_fwd_dpo.h:36
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static gbp_fwd_dpo_t * gbp_fwd_dpo_alloc(void)
Definition: gbp_fwd_dpo.c:40
vlib_node_registration_t ip6_gbp_fwd_dpo_node
(constructor) VLIB_REGISTER_NODE (ip6_gbp_fwd_dpo_node)
Definition: gbp_fwd_dpo.c:287
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define always_inline
Definition: clib.h:99
static const char *const gbp_fwd_dpo_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a glean object.
Definition: gbp_fwd_dpo.c:131
unsigned int u32
Definition: types.h:88
static const dpo_id_t * gbp_epg_dpo_lookup(sclass_t sclass, fib_protocol_t fproto)
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:342
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
dpo_type_t dpoi_type
the type
Definition: dpo.h:174
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
struct gbp_fwd_dpo_trace_t_ gbp_fwd_dpo_trace_t
#define PREDICT_FALSE(x)
Definition: clib.h:112
static gbp_fwd_dpo_t * gbp_fwd_dpo_get_from_dpo(const dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:50
#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
static u8 * format_gbp_fwd_dpo_trace(u8 *s, va_list *args)
Definition: gbp_fwd_dpo.c:250
static gbp_fwd_dpo_t * gbp_fwd_dpo_get(index_t index)
Definition: gbp_fwd_dpo.h:49
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
dpo_type_t gbp_fwd_dpo_get_type(void)
Definition: gbp_fwd_dpo.c:147
u16 n_vectors
Definition: node.h:397
u8 * format_gbp_fwd_dpo(u8 *s, va_list *ap)
Definition: gbp_fwd_dpo.c:109
vlib_main_t * vm
Definition: buffer.c:323
vlib_node_registration_t ip4_gbp_fwd_dpo_node
(constructor) VLIB_REGISTER_NODE (ip4_gbp_fwd_dpo_node)
Definition: gbp_fwd_dpo.c:276
void gbp_fwd_dpo_add_or_lock(dpo_proto_t dproto, dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:88
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:456
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:186
static index_t gbp_fwd_dpo_get_index(gbp_fwd_dpo_t *gfd)
Definition: gbp_fwd_dpo.c:58
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
#define ASSERT(truth)
static void gbp_fwd_dpo_unlock(dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:73
static dpo_type_t gbp_fwd_dpo_type
DPO type registered for these GBP FWD.
Definition: gbp_fwd_dpo.c:32
gbp_fwd_dpo_t * gbp_fwd_dpo_pool
pool of all interface DPOs
Definition: gbp_fwd_dpo.c:37
static void gbp_fwd_dpo_lock(dpo_id_t *dpo)
Definition: gbp_fwd_dpo.c:64
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:55
static const char *const gbp_fwd_dpo_ip6_nodes[]
Definition: gbp_fwd_dpo.c:136
Definition: defs.h:47
#define DPO_PROTO_NUM
Definition: dpo.h:70
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:186
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
VLIB buffer representation.
Definition: buffer.h:102
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
u8 * format_dpo_proto(u8 *s, va_list *args)
format a DPO protocol
Definition: dpo.c:178
The GBP FWD DPO.
Definition: gbp_fwd_dpo.h:26
#define vnet_buffer(b)
Definition: buffer.h:365
static const char *const *const gbp_fwd_dpo_nodes[DPO_PROTO_NUM]
Definition: gbp_fwd_dpo.c:141
#define FOR_EACH_DPO_PROTO(_proto)
Definition: dpo.h:82
dpo_proto_t gfd_proto
The protocol of packets using this DPO.
Definition: gbp_fwd_dpo.h:31
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85