FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bier_output.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_fmask.h>
20 #include <vlib/vlib.h>
21 
22 static char * bier_output_error_strings[] = {
23 #define bier_error(n,s) s,
25 #undef bier_error
26 };
27 
28 /*
29  * Keep these values semantically the same as BIER output
30  */
31 #define foreach_bier_output_next \
32  _(DROP, "bier-drop")
33 
34 typedef enum {
35 #define _(s,n) BIER_OUTPUT_NEXT_##s,
37 #undef _
40 
41 typedef enum {
42 #define bier_error(n,s) BIER_OUTPUT_ERROR_##n,
44 #undef bier_error
47 
48 /**
49  * Forward declaration
50  */
53 
54 /**
55  * @brief Packet trace record for a BIER output
56  */
57 typedef struct bier_output_trace_t_
58 {
63 
64 static uword
68 {
70  u32 n_left_from, next_index, * from, * to_next;
72 
75  n_left_from = from_frame->n_vectors;
76 
77  /*
78  * objection your honour! speculation!
79  */
80  next_index = node->cached_next_index;
81 
82  while (n_left_from > 0)
83  {
84  u32 n_left_to_next;
85 
87  to_next, n_left_to_next);
88 
89  while (n_left_from > 0 && n_left_to_next > 0)
90  {
91  bier_output_next_t next0;
93  vlib_buffer_t * b0;
94  bier_fmask_t *bfm0;
95  mpls_label_t *h0;
96  bier_hdr_t *bh0;
97  u32 bfmi0;
98  u32 bi0;
99 
100  bi0 = from[0];
101  to_next[0] = bi0;
102  from += 1;
103  to_next += 1;
104  n_left_from -= 1;
105  n_left_to_next -= 1;
106 
107  b0 = vlib_get_buffer (vm, bi0);
108  bh0 = vlib_buffer_get_current (b0);
110 
111  /*
112  * In the BIER Lookup node we squirrelled away the
113  * BIER fmask index as the adj index
114  */
115  bfmi0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
116  bfm0 = bier_fmask_get(bfmi0);
117 
119  cm, thread_index, bfmi0, 1,
121 
122  /*
123  * perform the logical AND of the packet's mask with
124  * that of the fmask objects, to reset the bits that
125  * are only on the shortest path the the fmask NH.
126  */
129  &bbs);
130 
131  /*
132  * this is the last time we touch the BIER header
133  * so flip to network order
134  */
135  bier_hdr_hton(bh0);
136 
137  /*
138  * paint the BIER peer's label
139  */
140  if (!(bfm0->bfm_flags & BIER_FMASK_FLAG_DISP))
141  {
142  /*
143  * since a BIFT value and a MPLS label are formated the
144  * same, this painting works OK.
145  */
146  vlib_buffer_advance(b0, -(word)sizeof(mpls_label_t));
147  h0 = vlib_buffer_get_current(b0);
148 
149  h0[0] = bfm0->bfm_label;
150 
151  ((char*)h0)[3]= vnet_buffer(b0)->mpls.ttl - 1;
152  }
153 
154  /*
155  * setup next graph node
156  */
157  next0 = bfm0->bfm_dpo.dpoi_next_node;
158  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = bfm0->bfm_dpo.dpoi_index;
159 
160  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
161  {
163 
164  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
165  tr->next_index = next0;
166  tr->bfm_index = bfmi0;
167  tr->bfm_label = bfm0->bfm_label;
168  }
169 
171  to_next, n_left_to_next,
172  bi0, next0);
173  }
174 
175  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
176  }
177 
179  BIER_OUTPUT_ERROR_NONE,
180  from_frame->n_vectors);
181  return (from_frame->n_vectors);
182 }
183 
184 static u8 *
185 format_bier_output_trace (u8 * s, va_list * args)
186 {
187  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
188  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
189  bier_output_trace_t * t = va_arg (*args, bier_output_trace_t *);
190 
191  s = format (s, " next [%d], BFM index %d label:%x",
192  t->next_index, t->bfm_index, t->bfm_label);
193  return s;
194 }
195 
197  .function = bier_output,
198  .name = "bier-output",
199  /* Takes a vector of packets. */
200  .vector_size = sizeof (u32),
201 
202  .n_errors = BIER_OUTPUT_N_ERROR,
203  .error_strings = bier_output_error_strings,
204 
205  .n_next_nodes = BIER_OUTPUT_N_NEXT,
206  .next_nodes = {
207  [BIER_OUTPUT_NEXT_DROP] = "bier-drop",
208  },
209 
210  .format_trace = format_bier_output_trace,
211 };
vlib.h
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
bier_hdr_hton
static void bier_hdr_hton(bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:141
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
bier_fmask_bits_t_::bfmb_input_reset_string
bier_bit_string_t bfmb_input_reset_string
each bit in the mask needs to be reference counted and set/cleared on the 0->1 and 1->0 transitions.
Definition: bier_fmask.h:50
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
buffer.h
bier_output_trace_t_::next_index
u32 next_index
Definition: bier_output.c:59
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
bier_output
static uword bier_output(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: bier_output.c:65
bier_output_trace_t
struct bier_output_trace_t_ bier_output_trace_t
Packet trace record for a BIER output.
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
bier_hdr_inlines.h
bier_bit_string_logical_and_string
static void bier_bit_string_logical_and_string(const bier_bit_string_t *src, bier_bit_string_t *dest)
Definition: bier_bit_string.h:84
bier_output_trace_t_
Packet trace record for a BIER output.
Definition: bier_output.c:57
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
bier_output_trace_t_::bfm_index
index_t bfm_index
Definition: bier_output.c:60
BIER_FMASK_FLAG_DISP
@ BIER_FMASK_FLAG_DISP
Definition: bier_fmask.h:86
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
bier_output_error_strings
static char * bier_output_error_strings[]
Definition: bier_output.c:22
bier_fmask_t_::bfm_label
mpls_label_t bfm_label
The MPLS label to paint on the header during forwarding.
Definition: bier_fmask.h:129
bier_fmask_t_::bfm_flags
bier_fmask_flags_t bfm_flags
operational/state flags on the fmask
Definition: bier_fmask.h:113
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
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
index_t
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:43
bier_output_error.def
uword
u64 uword
Definition: types.h:112
bier_output_error_t
bier_output_error_t
Definition: bier_output.c:41
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
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
bier_bit_string_init_from_hdr
static void bier_bit_string_init_from_hdr(bier_hdr_t *bier_hdr, bier_bit_string_t *bit_string)
Definition: bier_hdr_inlines.h:215
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
BIER_OUTPUT_N_NEXT
@ BIER_OUTPUT_N_NEXT
Definition: bier_output.c:38
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
bier_output_next_t
bier_output_next_t
Definition: bier_output.c:34
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
description fragment has unexpected format
Definition: map.api:433
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
BIER_OUTPUT_N_ERROR
@ BIER_OUTPUT_N_ERROR
Definition: bier_output.c:45
bier_fmask_t_::bfm_dpo
dpo_id_t bfm_dpo
The index into the adj table for the adj that this fmask resolves via.
Definition: bier_fmask.h:145
bier_output_trace_t_::bfm_label
mpls_label_t bfm_label
Definition: bier_output.c:61
vlib_main_t
Definition: main.h:102
bier_fmask_t_::bfm_bits
bier_fmask_bits_t bfm_bits
The bits, and their ref counts, that are set on this mask This mask changes as BIER entries link to a...
Definition: bier_fmask.h:119
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
u8
unsigned char u8
Definition: types.h:56
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
format_bier_output_trace
static u8 * format_bier_output_trace(u8 *s, va_list *args)
Definition: bier_output.c:185
word
i64 word
Definition: types.h:111
bier_fmask.h
bier_hdr_t_
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
mpls_label_t
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:26
vlib_node_runtime_t
Definition: node.h:454
bier_fmask_counters
vlib_combined_counter_main_t bier_fmask_counters
Stats for each BIER fmask object.
Definition: bier_fmask.c:43
bier_fmask_t_
An outgoing BIER mask.
Definition: bier_fmask.h:99
from
from
Definition: nat44_ei_hairpinning.c:415
foreach_bier_output_next
#define foreach_bier_output_next
Definition: bier_output.c:31
bier_output_node
vlib_node_registration_t bier_output_node
Forward declaration.
Definition: bier_output.c:51
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
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
bier_bit_string_t_
A Variable length BitString.
Definition: bier_types.h:278
bier_fmask_get
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:177
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
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