FD.io VPP  v18.10-34-gcce845e
Vector Packet Processing
bier_input.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 
18 #include <vnet/bier/bier_table.h>
20 
21 typedef enum {
22 #define bier_error(n,s) BIER_INPUT_ERROR_##n,
24 #undef bier_error
27 
28 static char * bier_error_strings[] = {
29 #define bier_error(n,s) s,
31 #undef bier_error
32 };
33 
34 typedef enum bier_input_next_t_ {
39 
41 
42 /**
43  * @brief Packet trace record for BIER input
44  */
45 typedef struct bier_input_trace_t_
46 {
50 
51 static int
53  bier_hdr_len_id_t expected_length)
54 {
55  /*
56  * checks:
57  * - the version field must be 1
58  * - the header length matches the length expected
59  */
61  (expected_length != bier_hdr_get_len_id(bier_hdr)))) {
62  return (0);
63  }
64 
65  return (1);
66 }
67 
68 static uword
70  vlib_node_runtime_t * node,
71  vlib_frame_t * from_frame)
72 {
73  u32 n_left_from, next_index, * from, * to_next;
74 
75  from = vlib_frame_vector_args (from_frame);
76  n_left_from = from_frame->n_vectors;
77 
78  /*
79  * objection your honour! speculation!
80  */
81  next_index = node->cached_next_index;
82 
83  while (n_left_from > 0)
84  {
85  u32 n_left_to_next;
86 
87  vlib_get_next_frame (vm, node, next_index,
88  to_next, n_left_to_next);
89 
90  while (n_left_from > 0 && n_left_to_next > 0)
91  {
92  const bier_table_t *bt0;
93  vlib_buffer_t * b0;
94  bier_hdr_t * bh0;
95  u32 bi0, next0;
96  u32 bt_index0;
97 
98  bi0 = from[0];
99  to_next[0] = bi0;
100  from += 1;
101  to_next += 1;
102  n_left_from -= 1;
103  n_left_to_next -= 1;
104 
105  b0 = vlib_get_buffer (vm, bi0);
106  bh0 = vlib_buffer_get_current (b0);
107  bier_hdr_ntoh(bh0);
108 
109  /*
110  * In the MPLS decap node we squirelled away the
111  * index for the BIER table as the tx adjacency
112  */
113  bt_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
114  bt0 = bier_table_get(bt_index0);
115 
117  {
119  } else {
120  next0 = BIER_INPUT_NEXT_DROP;
121  b0->error = node->errors[BIER_INPUT_ERROR_INVALID_HEADER];
122  }
123 
124  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
125  {
126  bier_input_trace_t *tr;
127 
128  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
129  tr->next_index = next0;
130  tr->bt_index = bt_index0;
131  }
132 
133  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
134  to_next, n_left_to_next,
135  bi0, next0);
136  }
137 
138  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
139  }
140 
142  BIER_INPUT_ERROR_PKTS_VALID,
143  from_frame->n_vectors);
144  return (from_frame->n_vectors);
145 }
146 
147 static u8 *
148 format_bier_input_trace (u8 * s, va_list * args)
149 {
150  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
151  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
152  bier_input_trace_t * t = va_arg (*args, bier_input_trace_t *);
153 
154  s = format (s, " next [%d], BIER Table index %d",
155  t->next_index, t->bt_index);
156  return s;
157 }
158 
160  .function = bier_input,
161  .name = "bier-input",
162  /* Takes a vector of packets. */
163  .vector_size = sizeof (u32),
164 
165  .n_errors = BIER_INPUT_N_ERROR,
166  .error_strings = bier_error_strings,
167 
168  .n_next_nodes = BIER_INPUT_N_NEXT,
169  .next_nodes = {
170  [BIER_INPUT_NEXT_BIER_LOOKUP] = "bier-lookup",
171  [BIER_INPUT_NEXT_DROP] = "bier-drop",
172  },
173 
174  .format_trace = format_bier_input_trace,
175 };
struct bier_input_trace_t_ bier_input_trace_t
Packet trace record for BIER input.
vlib_node_registration_t bier_input_node
(constructor) VLIB_REGISTER_NODE (bier_input_node)
Definition: bier_input.c:40
#define CLIB_UNUSED(x)
Definition: clib.h:81
static bier_hdr_len_id_t bier_hdr_get_len_id(const bier_hdr_t *bier_hdr)
#define PREDICT_TRUE(x)
Definition: clib.h:108
static int bier_hdr_validate(bier_hdr_t *bier_hdr, bier_hdr_len_id_t expected_length)
Definition: bier_input.c:52
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static bier_table_t * bier_table_get(index_t bti)
Definition: bier_table.h:160
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:472
unsigned char u8
Definition: types.h:56
static uword bier_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: bier_input.c:69
unsigned int u32
Definition: types.h:88
bier_input_next_t_
Definition: bier_input.c:34
bier_input_error_t
Definition: bier_input.c:21
Packet trace record for BIER input.
Definition: bier_input.c:45
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
static u8 * format_bier_input_trace(u8 *s, va_list *args)
Definition: bier_input.c:148
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:205
#define PREDICT_FALSE(x)
Definition: clib.h:107
#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:364
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:138
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1176
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:155
u16 n_vectors
Definition: node.h:401
vlib_main_t * vm
Definition: buffer.c:294
enum bier_hdr_len_id_t_ bier_hdr_len_id_t
bier_hdr_len_id_t enumerator
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:455
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:513
enum bier_input_next_t_ bier_input_next_t
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
struct _vlib_node_registration vlib_node_registration_t
bier_table_id_t bt_id
The identity/key or the table.
Definition: bier_table.h:76
Definition: defs.h:47
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
A BIER Table is the bit-indexed forwarding table.
Definition: bier_table.h:38
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:267
#define vnet_buffer(b)
Definition: buffer.h:344
static char * bier_error_strings[]
Definition: bier_input.c:28
static bier_hdr_version_t bier_hdr_get_version(const bier_hdr_t *bier_hdr)
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:116
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:58
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)