FD.io VPP  v21.06-1-gbb7418cf9
Vector Packet Processing
bier_imp_node.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/bier/bier_imp.h>
18 #include <vnet/ip/ip4_inlines.h>
19 #include <vnet/ip/ip6_inlines.h>
20 
21 /**
22  * @brief A struct to hold tracing information for the BIER imposition
23  * node.
24  */
25 typedef struct bier_imp_trace_t_
26 {
27  /**
28  * BIER imposition object hit
29  */
31 
32  /**
33  * BIER hdr applied
34  */
37 
42  fib_protocol_t fproto,
43  bier_hdr_proto_id_t bproto)
44 {
45  u32 n_left_from, next_index, * from, * to_next;
46 
47  from = vlib_frame_vector_args (from_frame);
48  n_left_from = from_frame->n_vectors;
49 
50  next_index = node->cached_next_index;
51 
52  while (n_left_from > 0)
53  {
54  u32 n_left_to_next;
55 
56  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
57 
58  while (n_left_from > 0 && n_left_to_next > 0)
59  {
60  vlib_buffer_t * b0;
61  bier_imp_t *bimp0;
62  bier_hdr_t *hdr0;
63  u32 bi0, bii0;
64  u32 next0;
65 
66  bi0 = from[0];
67  to_next[0] = bi0;
68  from += 1;
69  to_next += 1;
70  n_left_from -= 1;
71  n_left_to_next -= 1;
72 
73  b0 = vlib_get_buffer (vm, bi0);
74 
75  bii0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
76  bimp0 = bier_imp_get(bii0);
77 
78  if (FIB_PROTOCOL_IP4 == fproto)
79  {
80  /*
81  * decrement the TTL on ingress to the BIER domain
82  */
84  u32 checksum0;
85 
86  checksum0 = ip0->checksum + clib_host_to_net_u16 (0x0100);
87  checksum0 += checksum0 >= 0xffff;
88 
89  ip0->checksum = checksum0;
90  ip0->ttl -= 1;
91 
92  /*
93  * calculate an entropy
94  */
95  if (0 == vnet_buffer(b0)->ip.flow_hash)
96  {
97  vnet_buffer(b0)->ip.flow_hash =
99  }
100  }
101  if (FIB_PROTOCOL_IP6 == fproto)
102  {
103  /*
104  * decrement the TTL on ingress to the BIER domain
105  */
107 
108  ip0->hop_limit -= 1;
109 
110  /*
111  * calculate an entropy
112  */
113  if (0 == vnet_buffer(b0)->ip.flow_hash)
114  {
115  vnet_buffer(b0)->ip.flow_hash =
117  }
118  }
119 
120  /* Paint the BIER header */
121  vlib_buffer_advance(b0, -(sizeof(bier_hdr_t) +
123  hdr0 = vlib_buffer_get_current(b0);
124 
125  /* RPF check */
126  if (PREDICT_FALSE(BIER_RX_ITF == vnet_buffer(b0)->ip.adj_index[VLIB_RX]))
127  {
128  next0 = 0;
129  }
130  else
131  {
132  clib_memcpy_fast(hdr0, &bimp0->bi_hdr,
133  (sizeof(bier_hdr_t) +
135  /*
136  * Fixup the entropy and protocol, both of which have a
137  * zero value post the paint job
138  */
139  hdr0->bh_oam_dscp_proto |=
140  clib_host_to_net_u16(bproto << BIER_HDR_PROTO_FIELD_SHIFT);
141  hdr0->bh_first_word |=
142  clib_host_to_net_u32((vnet_buffer(b0)->ip.flow_hash &
145 
146  /*
147  * use TTL 64 for the post encap MPLS label/BIFT-ID
148  * this we be decremented in bier_output node.
149  */
150  vnet_buffer(b0)->mpls.ttl = 65;
151 
152  /* next node */
153  next0 = bimp0->bi_dpo[fproto].dpoi_next_node;
154  vnet_buffer(b0)->ip.adj_index[VLIB_TX] =
155  bimp0->bi_dpo[fproto].dpoi_index;
156  }
157 
158  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
159  {
160  bier_imp_trace_t *tr =
161  vlib_add_trace (vm, node, b0, sizeof (*tr));
162  tr->imp = bii0;
163  tr->hdr = *hdr0;
164  }
165 
166  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
167  n_left_to_next, bi0, next0);
168  }
169  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
170  }
171  return from_frame->n_vectors;
172 }
173 
174 static u8 *
175 format_bier_imp_trace (u8 * s, va_list * args)
176 {
177  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
178  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
179  bier_imp_trace_t * t;
180  u32 indent;
181 
182  t = va_arg (*args, bier_imp_trace_t *);
183  indent = format_get_indent (s);
184 
185  s = format (s, "%U", format_bier_imp, t->imp, indent, BIER_SHOW_BRIEF);
186  return (s);
187 }
188 
192 {
193  return (bier_imp_dpo_inline(vm, node, frame,
196 }
197 
199  .name = "bier-imp-ip4",
200  .vector_size = sizeof (u32),
201 
202  .format_trace = format_bier_imp_trace,
203  .n_next_nodes = 1,
204  .next_nodes = {
205  [0] = "bier-drop",
206  }
207 };
208 
212 {
213  return (bier_imp_dpo_inline(vm, node, frame,
216 }
217 
219  .name = "bier-imp-ip6",
220  .vector_size = sizeof (u32),
221 
222  .format_trace = format_bier_imp_trace,
223  .n_next_nodes = 1,
224  .next_nodes = {
225  [0] = "error-drop",
226  }
227 };
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:133
static uword bier_imp_dpo_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame, fib_protocol_t fproto, bier_hdr_proto_id_t bproto)
Definition: bier_imp_node.c:39
u32 bh_first_word
The first nibble is always set to 0101 to ensure that when carried over MPLS, the BIER packet is not ...
Definition: bier_types.h:339
#define CLIB_UNUSED(x)
Definition: clib.h:90
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
vlib_node_registration_t bier_imp_ip6_node
(constructor) VLIB_REGISTER_NODE (bier_imp_ip6_node)
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip4_inlines.h:51
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
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
static u32 format_get_indent(u8 *s)
Definition: format.h:72
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
#define VLIB_NODE_FN(node)
Definition: node.h:202
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
unsigned int u32
Definition: types.h:88
bier_imposition : The BIER imposition object
Definition: bier_imp.h:34
static bier_imp_t * bier_imp_get(index_t bii)
Definition: bier_imp.h:88
#define BIER_HDR_ENTROPY_FIELD_MASK
bier_hdr_t bi_hdr
The Header to impose.
Definition: bier_imp.h:50
description fragment has unexpected format
Definition: map.api:433
A struct to hold tracing information for the BIER imposition node.
Definition: bier_imp_node.c:25
u8 * format_bier_imp(u8 *s, va_list *args)
Definition: bier_imp.c:137
#define BIER_HDR_ENTROPY_FIELD_SHIFT
u16 bh_oam_dscp_proto
The second word comprises: 2 bits of OAM for passive perf measurement 2 reserved bits; 6 bits of DSCP...
Definition: bier_types.h:349
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
#define PREDICT_FALSE(x)
Definition: clib.h:124
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple + flowlabel without the "reverse" bit.
Definition: ip_flow_hash.h:22
#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
#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
struct bier_imp_trace_t_ bier_imp_trace_t
A struct to hold tracing information for the BIER imposition node.
vlib_node_registration_t bier_imp_ip4_node
(constructor) VLIB_REGISTER_NODE (bier_imp_ip4_node)
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
static u8 * format_bier_imp_trace(u8 *s, va_list *args)
u16 n_vectors
Definition: node.h:388
index_t imp
BIER imposition object hit.
Definition: bier_imp_node.c:30
bier_hdr_t hdr
BIER hdr applied.
Definition: bier_imp_node.c:35
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:498
#define always_inline
Definition: rdma_mlx5dv.h:23
vlib_put_next_frame(vm, node, next_index, 0)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
nat44_ei_hairpin_src_next_t next_index
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6_inlines.h:49
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:190
vl_api_address_t ip
Definition: l2.api:558
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
#define BIER_RX_ITF
The BIER inline functions acting on the bier header.
VLIB buffer representation.
Definition: buffer.h:111
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:301
#define vnet_buffer(b)
Definition: buffer.h:437
bier_table_id_t bi_tbl
The BIER table into which to forward the post imposed packet.
Definition: bier_imp.h:63
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
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
#define BIER_HDR_PROTO_FIELD_SHIFT
dpo_id_t bi_dpo[FIB_PROTOCOL_IP_MAX]
The DPO contributed from the resolving BIER table.
Definition: bier_imp.h:45
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
Definition: defs.h:46