FD.io VPP  v18.04-17-g3a0d853
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  vlib_error_drop_buffers (vm, node, buffers,
66  /* stride */ 1,
67  n_packets,
68  /* next */ 0,
69  0, // bier_input_node.index,
70  0);
71 
72  if (node->flags & VLIB_NODE_FLAG_TRACE)
73  bier_drop_trace (vm, node, frame);
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 
90 /* *INDENT-OFF* */
92 {
93  .function = bier_drop,.
94  name = "bier-drop",
95  .vector_size = sizeof (u32),
96  .format_trace = format_bier_drop_trace,
97  .n_next_nodes = 1,
98  .next_nodes = {
99  [0] = "error-drop",
100  },
101 };
#define CLIB_UNUSED(x)
Definition: clib.h:79
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:419
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:44
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u16 n_vectors
Definition: node.h:344
vlib_main_t * vm
Definition: buffer.c:294
struct bier_drop_trace_t_ bier_drop_trace_t
unsigned int u32
Definition: types.h:88
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:91
u64 uword
Definition: types.h:112
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
unsigned char u8
Definition: types.h:56
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
#define vnet_buffer(b)
Definition: buffer.h:372
u16 flags
Copy of main node flags.
Definition: node.h:450
static u8 * format_bier_drop_trace(u8 *s, va_list *args)
Definition: bier_drop.c:79
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:259
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:111
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57