FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bier_bift_table.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 
17 #include <vnet/dpo/drop_dpo.h>
18 #include <vnet/udp/udp_local.h>
19 
20 typedef enum {
21 #define bier_error(n,s) BIER_INPUT_ERROR_##n,
23 #undef bier_error
26 
27 static char * bier_error_strings[] = {
28 #define bier_error(n,s) s,
30 #undef bier_error
31 };
32 
33 /**
34  * Global BIFT table
35  */
37 
38 /**
39  * Forward declare the node
40  */
42 
43 void
45  const dpo_id_t *dpo)
46 {
47  if (NULL == bier_bift_table)
48  {
49  u32 ii;
50 
51  /*
52  * allocate the table and
53  * set each of the entries therein to a BIER drop
54  */
58 
59  for (ii = 0; ii < BIER_BIFT_N_ENTRIES; ii++)
60  {
64  }
65 
66  /*
67  * register to handle packets that arrive on the assigned
68  * UDP port
69  */
71  UDP_DST_PORT_BIER,
73  0);
75  UDP_DST_PORT_BIER,
77  1);
78  }
79 
82  dpo);
83 
85 }
86 
87 void
89 {
90  ASSERT(NULL != bier_bift_table);
91 
93 
95 
97  {
99  UDP_DST_PORT_BIER,
100  0);
102  UDP_DST_PORT_BIER,
103  1);
104 
106  bier_bift_table = NULL;
107  }
108 }
109 
110 /**
111  * @brief Packet trace record for BIER input
112  */
114 {
117 
118 static uword
122 {
123  u32 n_left_from, next_index, * from, * to_next;
124 
126  n_left_from = from_frame->n_vectors;
127  next_index = node->cached_next_index;
128 
129  while (n_left_from > 0)
130  {
131  u32 n_left_to_next;
132 
134  to_next, n_left_to_next);
135 
136  while (n_left_from > 0 && n_left_to_next > 0)
137  {
138  bier_bift_id_t *biftp0, bift0;
139  const dpo_id_t *dpo0;
140  vlib_buffer_t * b0;
141  u32 bi0, next0;
142 
143  bi0 = from[0];
144  to_next[0] = bi0;
145  from += 1;
146  to_next += 1;
147  n_left_from -= 1;
148  n_left_to_next -= 1;
149 
150  b0 = vlib_get_buffer (vm, bi0);
151  biftp0 = vlib_buffer_get_current (b0);
152  vlib_buffer_advance(b0, sizeof(bift0));
153  bift0 = clib_net_to_host_u32(*biftp0);
154 
155  /*
156  * Do the lookup based on the first 20 bits, i.e. the
157  * encoding of the set, sub-domain and BSL
158  */
159  dpo0 = bier_bift_dp_lookup(bift0);
160 
161  /*
162  * save the TTL for later during egress
163  */
164  vnet_buffer(b0)->mpls.ttl = vnet_mpls_uc_get_ttl(bift0);
165 
166  next0 = dpo0->dpoi_next_node;
167  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
168 
169  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
170  {
172 
173  tr = vlib_add_trace(vm, node, b0, sizeof (*tr));
174  tr->bift_id = bift0;
175  }
176 
178  to_next, n_left_to_next,
179  bi0, next0);
180  }
181 
182  vlib_put_next_frame(vm, node, next_index, n_left_to_next);
183  }
184 
186  BIER_INPUT_ERROR_PKTS_VALID,
187  from_frame->n_vectors);
188  return (from_frame->n_vectors);
189 }
190 
191 static u8 *
192 format_bier_bift_input_trace (u8 * s, va_list * args)
193 {
194  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
195  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
196  bier_bift_input_trace_t * t = va_arg (*args, bier_bift_input_trace_t *);
197 
198  s = format (s, "BIFT-ID:[%U]", format_bier_bift_id,
200  return s;
201 }
202 
204  .function = bier_bift_input,
205  .name = "bier-bift-input",
206  /* Takes a vector of packets. */
207  .vector_size = sizeof (u32),
208  .n_errors = BIER_INPUT_N_ERROR,
209  .error_strings = bier_error_strings,
210  .n_next_nodes = 0,
211  .format_trace = format_bier_bift_input_trace,
212 };
213 
214 clib_error_t *
216  unformat_input_t * input,
217  vlib_cli_command_t * cmd)
218 {
219  clib_error_t * error = NULL;
220  u32 hdr_len, set, sub_domain;
221 
222  set = hdr_len = sub_domain = ~0;
223 
224  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
225  if (unformat (input, "sd %d", &sub_domain)) {
226  ;
227  } else if (unformat (input, "set %d", &set)) {
228  ;
229  } else if (unformat (input, "bsl %d", &hdr_len)) {
230  ;
231  }
232  else
233  {
234  error = unformat_parse_error (input);
235  goto done;
236  }
237  }
238 
239  if (NULL == bier_bift_table)
240  {
241  vlib_cli_output(vm, "no BIFT entries");
242  goto done;
243  }
244 
245  if (~0 == set)
246  {
247  u32 ii;
248 
249  for (ii = 0; ii < BIER_BIFT_N_ENTRIES; ii++)
250  {
252  {
253  bier_hdr_len_id_t bsl;
254 
255  bier_bift_id_decode(ii, &set, &sub_domain, &bsl);
256 
257  vlib_cli_output(vm, "set: %d, sub-domain:%d, BSL:%U",
258  set, sub_domain,
260  vlib_cli_output(vm, " %U",
262  &bier_bift_table->bblt_dpos[ii], 0);
263  }
264  }
265  }
266  else
267  {
269 
270  id = bier_bift_id_encode(set, sub_domain,
271  bier_hdr_bit_len_to_id(hdr_len));
272 
274  {
275  vlib_cli_output(vm, "set: %d, sub-domain:%d, BSL:%U",
276  set, sub_domain,
277  format_bier_hdr_len_id, hdr_len);
278  vlib_cli_output(vm, " %U",
280  &bier_bift_table->bblt_dpos[id], 0);
281  }
282  }
283 done:
284  return (error);
285 }
286 
288  .path = "show bier bift",
289  .short_help = "show bier bift [set <value>] [sd <value>] [bsl <value>]",
290  .function = show_bier_bift_cmd,
291 };
dpo_is_drop
int dpo_is_drop(const dpo_id_t *dpo)
The Drop DPO will drop all packets, no questions asked.
Definition: drop_dpo.c:33
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
bier_bift_id_encode
bier_bift_id_t bier_bift_id_encode(bier_table_set_id_t set, bier_table_sub_domain_id_t sd, bier_hdr_len_id_t bsl)
Encode a BIFT-ID as per draft-wijnandsxu-bier-non-mpls-bift-encoding-00.txt.
Definition: bier_types.c:164
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
bier_input_error_t
bier_input_error_t
Definition: bier_bift_table.c:20
bier_input_error.def
bier_bift_input_trace_t_::bift_id
u32 bift_id
Definition: bier_bift_table.c:115
BIER_BIFT_N_ENTRIES
#define BIER_BIFT_N_ENTRIES
Definition: bier_bift_table.h:28
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
bier_bift_dp_lookup
static const dpo_id_t * bier_bift_dp_lookup(bier_bift_id_t key_host_order)
Definition: bier_bift_table.h:54
bier_bift_input_trace_t_
Packet trace record for BIER input.
Definition: bier_bift_table.c:113
bier_bift_table
bier_bfit_table_t * bier_bift_table
Global BIFT table.
Definition: bier_bift_table.c:36
clib_mem_free
static void clib_mem_free(void *p)
Definition: mem.h:311
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
vlib_cli_command_t::path
char * path
Definition: cli.h:96
bier_bfit_table_t_
Definition: bier_bift_table.h:29
unformat_parse_error
#define unformat_parse_error(input)
Definition: format.h:261
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
DPO_PROTO_BIER
@ DPO_PROTO_BIER
Definition: dpo.h:68
vnet_mpls_uc_get_label
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
Definition: packet.h:105
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
unformat_input_t
struct _unformat_input_t unformat_input_t
vlib_frame_t
Definition: node.h:372
drop_dpo.h
format_bier_bift_id
u8 * format_bier_bift_id(u8 *s, va_list *ap)
Definition: bier_types.c:222
error
Definition: cJSON.c:88
bier_bift_input_trace_t
struct bier_bift_input_trace_t_ bier_bift_input_trace_t
Packet trace record for BIER input.
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
set
description can t DF set
Definition: map.api:451
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
bier_bift_id_decode
void bier_bift_id_decode(bier_bift_id_t id, bier_table_set_id_t *set, bier_table_sub_domain_id_t *sd, bier_hdr_len_id_t *bsl)
Definition: bier_types.c:180
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
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
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
bier_bift_table.h
udp_local.h
uword
u64 uword
Definition: types.h:112
show_bier_bift_command
static vlib_cli_command_t show_bier_bift_command
(constructor) VLIB_CLI_COMMAND (show_bier_bift_command)
Definition: bier_bift_table.c:287
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
udp_register_dst_port
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
udp_unregister_dst_port
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:506
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
dpo_stack_from_node
void dpo_stack_from_node(u32 child_node_index, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child parent relationship.
Definition: dpo.c:550
bier_error_strings
static char * bier_error_strings[]
Definition: bier_bift_table.c:27
BIER_INPUT_N_ERROR
@ BIER_INPUT_N_ERROR
Definition: bier_bift_table.c:24
bier_bift_table_entry_remove
void bier_bift_table_entry_remove(bier_bift_id_t id)
Definition: bier_bift_table.c:88
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
format_dpo_id
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject.
Definition: dpo.c:150
bier_hdr_len_id_t
enum bier_hdr_len_id_t_ bier_hdr_len_id_t
bier_hdr_len_id_t enumerator
id
u8 id[64]
Definition: dhcp.api:160
show_bier_bift_cmd
clib_error_t * show_bier_bift_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: bier_bift_table.c:215
bier_bift_input
static uword bier_bift_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: bier_bift_table.c:119
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
format_bier_hdr_len_id
u8 * format_bier_hdr_len_id(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:96
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
bier_hdr_bit_len_to_id
static bier_hdr_len_id_t bier_hdr_bit_len_to_id(u32 bytes)
Definition: bier_types.h:142
bier_bfit_table_t_::bblt_dpos
dpo_id_t bblt_dpos[BIER_BIFT_N_ENTRIES]
Forwarding information for each BIFT ID.
Definition: bier_bift_table.h:34
bier_bift_id_t
u32 bier_bift_id_t
The BIER universal 'label'.
Definition: bier_types.h:458
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
drop_dpo_get
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
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
bier_bift_table_entry_add
void bier_bift_table_entry_add(bier_bift_id_t id, const dpo_id_t *dpo)
Definition: bier_bift_table.c:44
vlib_get_main
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:38
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
bier_bift_input_node
vlib_node_registration_t bier_bift_input_node
Forward declare the node.
Definition: bier_bift_table.c:41
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
bier_bfit_table_t_::bblt_n_entries
u32 bblt_n_entries
The number of entries in the table.
Definition: bier_bift_table.h:39
clib_mem_alloc_aligned
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:261
dpo_id_t_
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:172
vnet_mpls_uc_get_ttl
static u32 vnet_mpls_uc_get_ttl(mpls_label_t label_exp_s_ttl)
Definition: packet.h:120
format_bier_bift_input_trace
static u8 * format_bier_bift_input_trace(u8 *s, va_list *args)
Definition: bier_bift_table.c:192
vlib_node_runtime_t
Definition: node.h:454
vlib_cli_command_t
Definition: cli.h:92
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
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
dpo_reset
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:234
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
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