FD.io VPP  v18.01.2-1-g9b554f3
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  */
52 
53 /**
54  * @brief Packet trace recoed for a BIER output
55  */
56 typedef struct bier_output_trace_t_
57 {
61 
62 static uword
64  vlib_node_runtime_t * node,
65  vlib_frame_t * from_frame)
66 {
67  u32 n_left_from, next_index, * from, * to_next;
68 
69  from = vlib_frame_vector_args (from_frame);
70  n_left_from = from_frame->n_vectors;
71 
72  // vnet_buffer(b0)->sw_if_index[VLIB_TX] = d0->tx_fib_index;
73 
74  /*
75  * objection your honour! speculation!
76  */
77  next_index = node->cached_next_index;
78 
79  while (n_left_from > 0)
80  {
81  u32 n_left_to_next;
82 
83  vlib_get_next_frame (vm, node, next_index,
84  to_next, n_left_to_next);
85 
86  while (n_left_from > 0 && n_left_to_next > 0)
87  {
88  bier_output_next_t next0;
90  vlib_buffer_t * b0;
91  bier_fmask_t *bfm0;
92  mpls_label_t *h0;
93  bier_hdr_t *bh0;
94  u32 bfmi0;
95  u32 bi0;
96 
97  bi0 = from[0];
98  to_next[0] = bi0;
99  from += 1;
100  to_next += 1;
101  n_left_from -= 1;
102  n_left_to_next -= 1;
103 
104  b0 = vlib_get_buffer (vm, bi0);
105  bh0 = vlib_buffer_get_current (b0);
107 
108  /*
109  * In the BIER Lookup node we squirelled away the
110  * BIER fmask index as the adj index
111  */
112  bfmi0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
113  bfm0 = bier_fmask_get(bfmi0);
114 
115  /*
116  * perform the logical AND of the packet's mask with
117  * that of the fmask objects, to reset the bits that
118  * are only on the shortest path the the fmask NH.
119  */
122  &bbs);
123 
124  /*
125  * this is the last time we touch the BIER header
126  * so flip to network order
127  */
128  bier_hdr_hton(bh0);
129 
130  /*
131  * paint the BIER peer's label
132  */
133  if (!(bfm0->bfm_flags & BIER_FMASK_FLAG_DISP))
134  {
135  /*
136  * since a BIFT value and a MPLS label are formated the
137  * same, this painting works OK.
138  */
139  vlib_buffer_advance(b0, -(word)sizeof(mpls_label_t));
140  h0 = vlib_buffer_get_current(b0);
141 
142  h0[0] = bfm0->bfm_label;
143  vnet_mpls_uc_set_ttl(h0, vnet_buffer(b0)->mpls.ttl - 1);
144  h0[0] = clib_host_to_net_u32(h0[0]);
145  }
146 
147  /*
148  * setup next graph node
149  */
150  next0 = bfm0->bfm_dpo.dpoi_next_node;
151  vnet_buffer(b0)->ip.adj_index[VLIB_TX] = bfm0->bfm_dpo.dpoi_index;
152 
154  {
156 
157  tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
158  tr->next_index = next0;
159  tr->bfm_index = bfmi0;
160  }
161 
162  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
163  to_next, n_left_to_next,
164  bi0, next0);
165  }
166 
167  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
168  }
169 
171  BIER_OUTPUT_ERROR_NONE,
172  from_frame->n_vectors);
173  return (from_frame->n_vectors);
174 }
175 
176 static u8 *
177 format_bier_output_trace (u8 * s, va_list * args)
178 {
179  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
180  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
181  bier_output_trace_t * t = va_arg (*args, bier_output_trace_t *);
182 
183  s = format (s, " next [%d], BFM index %d",
184  t->next_index, t->bfm_index);
185  return s;
186 }
187 
189  .function = bier_output,
190  .name = "bier-output",
191  /* Takes a vector of packets. */
192  .vector_size = sizeof (u32),
193 
194  .n_errors = BIER_OUTPUT_N_ERROR,
195  .error_strings = bier_output_error_strings,
196 
197  .n_next_nodes = BIER_OUTPUT_N_NEXT,
198  .next_nodes = {
199  [BIER_OUTPUT_NEXT_DROP] = "bier-drop",
200  },
201 
202  .format_trace = format_bier_output_trace,
203 };
#define CLIB_UNUSED(x)
Definition: clib.h:79
static bier_fmask_t * bier_fmask_get(u32 index)
Definition: bier_fmask.h:168
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:24
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
struct _vlib_node_registration vlib_node_registration_t
static u8 * format_bier_output_trace(u8 *s, va_list *args)
Definition: bier_output.c:177
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:114
bier_output_error_t
Definition: bier_output.c:41
#define foreach_bier_output_next
Definition: bier_output.c:31
A Variable length BitString.
Definition: bier_types.h:323
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:195
#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:124
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1158
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
u16 n_vectors
Definition: node.h:344
vlib_main_t * vm
Definition: buffer.c:283
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:93
Packet trace recoed for a BIER output.
Definition: bier_output.c:56
bier_fmask_flags_t bfm_flags
operational/state flags on the fmask
Definition: bier_fmask.h:108
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
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:456
unsigned int u32
Definition: types.h:88
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:208
u64 uword
Definition: types.h:112
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
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:373
i64 word
Definition: types.h:111
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:182
unsigned char u8
Definition: types.h:56
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
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 vnet_mpls_uc_set_ttl(mpls_label_t *label_exp_s_ttl, u32 ttl)
Definition: packet.h:118
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:326
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
dpo_id_t bfm_dpo
The index into the adj table for the adj that this fmask resolves via.
Definition: bier_fmask.h:140
static uword bier_output(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: bier_output.c:63
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:178
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:75
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