FD.io VPP  v21.10.1-2-g0a485f517
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 
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 
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 };
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
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
bier_hdr_t_::bh_oam_dscp_proto
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_PROTO_IPV4
@ BIER_HDR_PROTO_IPV4
Definition: bier_types.h:185
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
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
ip4_inlines.h
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip6_header_t::hop_limit
u8 hop_limit
Definition: ip6_packet.h:307
BIER_RX_ITF
#define BIER_RX_ITF
The BIER inline functions acting on the bier header.
Definition: bier_hdr_inlines.h:32
bier_imp_get
static bier_imp_t * bier_imp_get(index_t bii)
Definition: bier_imp.h:88
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
bier_hdr_inlines.h
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
bier_imp_ip6_node
vlib_node_registration_t bier_imp_ip6_node
(constructor) VLIB_REGISTER_NODE (bier_imp_ip6_node)
Definition: bier_imp_node.c:218
vlib_frame_t
Definition: node.h:372
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
BIER_SHOW_BRIEF
@ BIER_SHOW_BRIEF
Definition: bier_types.h:26
ip4_header_t
Definition: ip4_packet.h:87
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
bier_imp_t_
bier_imposition : The BIER imposition object
Definition: bier_imp.h:34
bier_imp_trace_t_::hdr
bier_hdr_t hdr
BIER hdr applied.
Definition: bier_imp_node.c:35
BIER_HDR_PROTO_FIELD_SHIFT
#define BIER_HDR_PROTO_FIELD_SHIFT
Definition: bier_hdr_inlines.h:57
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
ip6_compute_flow_hash
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6_inlines.h:49
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
bier_imp_t_::bi_tbl
bier_table_id_t bi_tbl
The BIER table into which to forward the post imposed packet.
Definition: bier_imp.h:63
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
IP_FLOW_HASH_DEFAULT
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple + flowlabel without the "reverse" bit.
Definition: ip_flow_hash.h:22
uword
u64 uword
Definition: types.h:112
bier_imp.h
ip4_header_t::checksum
u16 checksum
Definition: ip4_packet.h:118
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
bier_table_id_t_::bti_hdr_len
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
ip6_inlines.h
bier_imp_t_::bi_hdr
bier_hdr_t bi_hdr
The Header to impose.
Definition: bier_imp.h:50
bier_hdr_proto_id_t
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
format_bier_imp_trace
static u8 * format_bier_imp_trace(u8 *s, va_list *args)
Definition: bier_imp_node.c:175
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
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
BIER_HDR_PROTO_IPV6
@ BIER_HDR_PROTO_IPV6
Definition: bier_types.h:186
bier_imp_ip4_node
vlib_node_registration_t bier_imp_ip4_node
(constructor) VLIB_REGISTER_NODE (bier_imp_ip4_node)
Definition: bier_imp_node.c:198
format
description fragment has unexpected format
Definition: map.api:433
format_get_indent
static u32 format_get_indent(u8 *s)
Definition: format.h:72
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
ip4_header_t::ttl
u8 ttl
Definition: ip4_packet.h:112
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
bier_imp_trace_t
struct bier_imp_trace_t_ bier_imp_trace_t
A struct to hold tracing information for the BIER imposition node.
format_bier_imp
u8 * format_bier_imp(u8 *s, va_list *args)
Definition: bier_imp.c:137
ip4_compute_flow_hash
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip4_inlines.h:51
ip6_header_t
Definition: ip6_packet.h:294
BIER_HDR_ENTROPY_FIELD_MASK
#define BIER_HDR_ENTROPY_FIELD_MASK
Definition: bier_hdr_inlines.h:41
vlib_main_t
Definition: main.h:102
bier_imp_t_::bi_dpo
dpo_id_t bi_dpo[FIB_PROTOCOL_IP_MAX]
The DPO contributed from the resolving BIER table.
Definition: bier_imp.h:45
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
bier_imp_dpo_inline
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
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
ip
vl_api_address_t ip
Definition: l2.api:558
bier_imp_trace_t_::imp
index_t imp
BIER imposition object hit.
Definition: bier_imp_node.c:30
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
bier_imp_trace_t_
A struct to hold tracing information for the BIER imposition node.
Definition: bier_imp_node.c:25
bier_hdr_t_::bh_first_word
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
vlib_node_runtime_t
Definition: node.h:454
bier_hdr_len_id_to_num_bytes
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
from
from
Definition: nat44_ei_hairpinning.c:415
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
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
BIER_HDR_ENTROPY_FIELD_SHIFT
#define BIER_HDR_ENTROPY_FIELD_SHIFT
Definition: bier_hdr_inlines.h:46
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169