FD.io VPP  v19.01.3-6-g70449b9b9
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 sematically 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 recoed for a BIER output
56  */
57 typedef struct bier_output_trace_t_
58 {
63 
64 static uword
66  vlib_node_runtime_t * node,
67  vlib_frame_t * from_frame)
68 {
70  u32 n_left_from, next_index, * from, * to_next;
71  u32 thread_index;
72 
73  thread_index = vm->thread_index;
74  from = vlib_frame_vector_args (from_frame);
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 
86  vlib_get_next_frame (vm, node, next_index,
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 squirelled 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,
120  vlib_buffer_length_in_chain (vm, b0));
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 
170  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
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 };
#define CLIB_UNUSED(x)
Definition: clib.h:82
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:220
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:177
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
u32 thread_index
Definition: main.h:179
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
static u8 * format_bier_output_trace(u8 *s, va_list *args)
Definition: bier_output.c:185
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
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
bier_output_error_t
Definition: bier_output.c:41
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:267
unsigned char u8
Definition: types.h:56
#define foreach_bier_output_next
Definition: bier_output.c:31
A Variable length BitString.
Definition: bier_types.h:278
i64 word
Definition: types.h:111
unsigned int u32
Definition: types.h:88
static void bier_hdr_hton(bier_hdr_t *bier_hdr)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:214
#define PREDICT_FALSE(x)
Definition: clib.h:111
#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:338
An outgoing BIER mask.
Definition: bier_fmask.h:99
mpls_label_t bfm_label
The MPLS label to paint on the header during forwarding.
Definition: bier_fmask.h:129
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
static char * bier_output_error_strings[]
Definition: bier_output.c:22
vlib_node_registration_t bier_output_node
Forward declaration.
Definition: bier_output.c:51
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:420
vlib_main_t * vm
Definition: buffer.c:301
Packet trace recoed for a BIER output.
Definition: bier_output.c:57
bier_fmask_flags_t bfm_flags
operational/state flags on the fmask
Definition: bier_fmask.h:113
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:452
vlib_combined_counter_main_t bier_fmask_counters
Stats for each BIER fmask object.
Definition: bier_fmask.c:43
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:537
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:233
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
mpls_label_t bfm_label
Definition: bier_output.c:61
struct _vlib_node_registration vlib_node_registration_t
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
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
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
A collection of combined counters.
Definition: counter.h:188
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
bier_output_next_t
Definition: bier_output.c:34
static void bier_bit_string_logical_and_string(const bier_bit_string_t *src, bier_bit_string_t *dest)
#define vnet_buffer(b)
Definition: buffer.h:368
dpo_id_t bfm_dpo
The index into the adj table for the adj that this fmask resolves via.
Definition: bier_fmask.h:145
static uword bier_output(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: bier_output.c:65
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:180
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:117
static void bier_bit_string_init_from_hdr(bier_hdr_t *bier_hdr, bier_bit_string_t *bit_string)
struct bier_output_trace_t_ bier_output_trace_t
Packet trace recoed for a BIER output.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:62