FD.io VPP  v18.07.1-19-g511ce25
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 {
62 
63 static uword
65  vlib_node_runtime_t * node,
66  vlib_frame_t * from_frame)
67 {
69  u32 n_left_from, next_index, * from, * to_next;
70  u32 thread_index;
71 
72  thread_index = vm->thread_index;
73  from = vlib_frame_vector_args (from_frame);
74  n_left_from = from_frame->n_vectors;
75 
76  /*
77  * objection your honour! speculation!
78  */
79  next_index = node->cached_next_index;
80 
81  while (n_left_from > 0)
82  {
83  u32 n_left_to_next;
84 
85  vlib_get_next_frame (vm, node, next_index,
86  to_next, n_left_to_next);
87 
88  while (n_left_from > 0 && n_left_to_next > 0)
89  {
90  bier_output_next_t next0;
92  vlib_buffer_t * b0;
93  bier_fmask_t *bfm0;
94  mpls_label_t *h0;
95  bier_hdr_t *bh0;
96  u32 bfmi0;
97  u32 bi0;
98 
99  bi0 = from[0];
100  to_next[0] = bi0;
101  from += 1;
102  to_next += 1;
103  n_left_from -= 1;
104  n_left_to_next -= 1;
105 
106  b0 = vlib_get_buffer (vm, bi0);
107  bh0 = vlib_buffer_get_current (b0);
109 
110  /*
111  * In the BIER Lookup node we squirelled away the
112  * BIER fmask index as the adj index
113  */
114  bfmi0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
115  bfm0 = bier_fmask_get(bfmi0);
116 
118  cm, thread_index, bfmi0, 1,
119  vlib_buffer_length_in_chain (vm, b0));
120 
121  /*
122  * perform the logical AND of the packet's mask with
123  * that of the fmask objects, to reset the bits that
124  * are only on the shortest path the the fmask NH.
125  */
128  &bbs);
129 
130  /*
131  * this is the last time we touch the BIER header
132  * so flip to network order
133  */
134  bier_hdr_hton(bh0);
135 
136  /*
137  * paint the BIER peer's label
138  */
139  if (!(bfm0->bfm_flags & BIER_FMASK_FLAG_DISP))
140  {
141  /*
142  * since a BIFT value and a MPLS label are formated the
143  * same, this painting works OK.
144  */
145  vlib_buffer_advance(b0, -(word)sizeof(mpls_label_t));
146  h0 = vlib_buffer_get_current(b0);
147 
148  h0[0] = bfm0->bfm_label;
149 
150  ((char*)h0)[3]= vnet_buffer(b0)->mpls.ttl - 1;
151  }
152 
153  /*
154  * setup next graph node
155  */
156  next0 = bfm0->bfm_dpo.dpoi_next_node;
157  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = bfm0->bfm_dpo.dpoi_index;
158 
159  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
160  {
162 
163  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
164  tr->next_index = next0;
165  tr->bfm_index = bfmi0;
166  }
167 
168  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
169  to_next, n_left_to_next,
170  bi0, next0);
171  }
172 
173  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
174  }
175 
177  BIER_OUTPUT_ERROR_NONE,
178  from_frame->n_vectors);
179  return (from_frame->n_vectors);
180 }
181 
182 static u8 *
183 format_bier_output_trace (u8 * s, va_list * args)
184 {
185  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
186  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
187  bier_output_trace_t * t = va_arg (*args, bier_output_trace_t *);
188 
189  s = format (s, " next [%d], BFM index %d",
190  t->next_index, t->bfm_index);
191  return s;
192 }
193 
195  .function = bier_output,
196  .name = "bier-output",
197  /* Takes a vector of packets. */
198  .vector_size = sizeof (u32),
199 
200  .n_errors = BIER_OUTPUT_N_ERROR,
201  .error_strings = bier_output_error_strings,
202 
203  .n_next_nodes = BIER_OUTPUT_N_NEXT,
204  .next_nodes = {
205  [BIER_OUTPUT_NEXT_DROP] = "bier-drop",
206  },
207 
208  .format_trace = format_bier_output_trace,
209 };
#define CLIB_UNUSED(x)
Definition: clib.h:79
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:213
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:183
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:250
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:202
#define PREDICT_FALSE(x)
Definition: clib.h:105
#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
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:1168
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:153
u16 n_vectors
Definition: node.h:380
vlib_main_t * vm
Definition: buffer.c:294
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:454
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:492
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:215
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
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:267
A collection of combined counters.
Definition: counter.h:181
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:360
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:64
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:111
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:57