FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
bier_drop.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 <vnet/buffer.h>
17 #include <vlib/vlib.h>
18 #include <vnet/dpo/dpo.h>
19 
21 
22 typedef struct bier_drop_trace_t_
23 {
26 
27 static void
29  vlib_node_runtime_t * node,
30  vlib_frame_t * frame)
31 {
32  u32 *from, n_left;
33 
34  n_left = frame->n_vectors;
35  from = vlib_frame_vector_args (frame);
36  while (n_left >= 1)
37  {
38  u32 bi0;
39  vlib_buffer_t *b0;
41 
42  bi0 = from[0];
43 
44  b0 = vlib_get_buffer (vm, bi0);
45 
46  if (b0->flags & VLIB_BUFFER_IS_TRACED)
47  {
48  t0 = vlib_add_trace (vm, node, b0, sizeof(*t0));
49 
50  t0->dpi = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
51  }
52  from += 1;
53  n_left -= 1;
54  }
55 }
56 
57 static uword
59  vlib_node_runtime_t * node,
60  vlib_frame_t * frame)
61 {
62  u32 *buffers = vlib_frame_vector_args (frame);
63  uword n_packets = frame->n_vectors;
64 
65  if (node->flags & VLIB_NODE_FLAG_TRACE)
66  bier_drop_trace (vm, node, frame);
67 
68  vlib_error_drop_buffers (vm, node, buffers,
69  /* stride */ 1,
70  n_packets,
71  /* next */ 0,
72  0, // bier_input_node.index,
73  0);
74 
75  return n_packets;
76 }
77 
78 static u8 *
79 format_bier_drop_trace (u8 * s, va_list * args)
80 {
81  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
82  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
83  bier_drop_trace_t *t = va_arg (*args, bier_drop_trace_t *);
84 
85  s = format (s, "dpo-idx %d", t->dpi);
86 
87  return s;
88 }
89 
91 {
92  .function = bier_drop,
93  .name = "bier-drop",
94  .vector_size = sizeof (u32),
95  .format_trace = format_bier_drop_trace,
96  .n_next_nodes = 1,
97  .next_nodes = {
98  [0] = "error-drop",
99  },
100 };
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
#define CLIB_UNUSED(x)
Definition: clib.h:82
static void bier_drop_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: bier_drop.c:28
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
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
uword vlib_error_drop_buffers(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u32 next_buffer_stride, u32 n_buffers, u32 next_index, u32 drop_error_node, u32 drop_error_code)
Definition: error.c:45
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:395
vlib_main_t * vm
Definition: buffer.c:312
struct bier_drop_trace_t_ bier_drop_trace_t
static uword bier_drop(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: bier_drop.c:58
static vlib_node_registration_t bier_drop_node
(constructor) VLIB_REGISTER_NODE (bier_drop_node)
Definition: bier_drop.c:90
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
Definition: defs.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
#define vnet_buffer(b)
Definition: buffer.h:361
u16 flags
Copy of main node flags.
Definition: node.h:507
static u8 * format_bier_drop_trace(u8 *s, va_list *args)
Definition: bier_drop.c:79
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:301
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