FD.io VPP  v18.07-34-g55fbdb9
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/ip.h>
19 
20 /**
21  * @brief A struct to hold tracing information for the BIER imposition
22  * node.
23  */
24 typedef struct bier_imp_trace_t_
25 {
26  /**
27  * BIER imposition object hit
28  */
30 
31  /**
32  * BIER hdr applied
33  */
36 
39  vlib_node_runtime_t * node,
40  vlib_frame_t * from_frame,
41  fib_protocol_t fproto,
42  bier_hdr_proto_id_t bproto)
43 {
44  u32 n_left_from, next_index, * from, * to_next;
45 
46  from = vlib_frame_vector_args (from_frame);
47  n_left_from = from_frame->n_vectors;
48 
49  next_index = node->cached_next_index;
50 
51  while (n_left_from > 0)
52  {
53  u32 n_left_to_next;
54 
55  vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
56 
57  while (n_left_from > 0 && n_left_to_next > 0)
58  {
59  vlib_buffer_t * b0;
60  bier_imp_t *bimp0;
61  bier_hdr_t *hdr0;
62  u32 bi0, bii0;
63  u32 next0;
64 
65  bi0 = from[0];
66  to_next[0] = bi0;
67  from += 1;
68  to_next += 1;
69  n_left_from -= 1;
70  n_left_to_next -= 1;
71 
72  b0 = vlib_get_buffer (vm, bi0);
73 
74  bii0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
75  bimp0 = bier_imp_get(bii0);
76 
77  if (FIB_PROTOCOL_IP4 == fproto)
78  {
79  /*
80  * decrement the TTL on ingress to the BIER domain
81  */
83  u32 checksum0;
84 
85  checksum0 = ip0->checksum + clib_host_to_net_u16 (0x0100);
86  checksum0 += checksum0 >= 0xffff;
87 
88  ip0->checksum = checksum0;
89  ip0->ttl -= 1;
90 
91  /*
92  * calculate an entropy
93  */
94  if (0 == vnet_buffer(b0)->ip.flow_hash)
95  {
96  vnet_buffer(b0)->ip.flow_hash =
98  }
99  }
100  if (FIB_PROTOCOL_IP6 == fproto)
101  {
102  /*
103  * decrement the TTL on ingress to the BIER domain
104  */
106 
107  ip0->hop_limit -= 1;
108 
109  /*
110  * calculate an entropy
111  */
112  if (0 == vnet_buffer(b0)->ip.flow_hash)
113  {
114  vnet_buffer(b0)->ip.flow_hash =
116  }
117  }
118 
119  /* Paint the BIER header */
120  vlib_buffer_advance(b0, -(sizeof(bier_hdr_t) +
122  hdr0 = vlib_buffer_get_current(b0);
123  clib_memcpy(hdr0, &bimp0->bi_hdr,
124  (sizeof(bier_hdr_t) +
126  /*
127  * Fixup the entropy and protocol, both of which have a
128  * zero value post the paint job
129  */
130  hdr0->bh_oam_dscp_proto |=
131  clib_host_to_net_u16(bproto << BIER_HDR_PROTO_FIELD_SHIFT);
132  hdr0->bh_first_word |=
133  clib_host_to_net_u32((vnet_buffer(b0)->ip.flow_hash &
136 
137  /*
138  * use TTL 64 for the post enacp MPLS label/BIFT-ID
139  * this we be decremeted in bier_output node.
140  */
141  vnet_buffer(b0)->mpls.ttl = 65;
142 
143  /* next node */
144  next0 = bimp0->bi_dpo[fproto].dpoi_next_node;
145  vnet_buffer(b0)->ip.adj_index[VLIB_TX] =
146  bimp0->bi_dpo[fproto].dpoi_index;
147 
148  if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
149  {
150  bier_imp_trace_t *tr =
151  vlib_add_trace (vm, node, b0, sizeof (*tr));
152  tr->imp = bii0;
153  tr->hdr = *hdr0;
154  }
155 
156  vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
157  n_left_to_next, bi0, next0);
158  }
159  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
160  }
161  return from_frame->n_vectors;
162 }
163 
164 static u8 *
165 format_bier_imp_trace (u8 * s, va_list * args)
166 {
167  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
168  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
169  bier_imp_trace_t * t;
170  u32 indent;
171 
172  t = va_arg (*args, bier_imp_trace_t *);
173  indent = format_get_indent (s);
174 
175  s = format (s, "%U", format_bier_imp, t->imp, indent, BIER_SHOW_BRIEF);
176  return (s);
177 }
178 
179 static uword
181  vlib_node_runtime_t * node,
182  vlib_frame_t * frame)
183 {
184  return (bier_imp_dpo_inline(vm, node, frame,
187 }
188 
190  .function = bier_imp_ip4,
191  .name = "bier-imp-ip4",
192  .vector_size = sizeof (u32),
193 
194  .format_trace = format_bier_imp_trace,
195  .n_next_nodes = 1,
196  .next_nodes = {
197  [0] = "error-drop",
198  }
199 };
201 
202 static uword
204  vlib_node_runtime_t * node,
205  vlib_frame_t * frame)
206 {
207  return (bier_imp_dpo_inline(vm, node, frame,
210 }
211 
213  .function = bier_imp_ip6,
214  .name = "bier-imp-ip6",
215  .vector_size = sizeof (u32),
216 
217  .format_trace = format_bier_imp_trace,
218  .n_next_nodes = 1,
219  .next_nodes = {
220  [0] = "error-drop",
221  }
222 };
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:38
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:79
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.h:287
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 u32 format_get_indent(u8 *s)
Definition: format.h:72
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static uword bier_imp_ip6(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
bier_imposition : The BIER imposition object
Definition: bier_imp.h:34
#define always_inline
Definition: clib.h:92
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
A struct to hold tracing information for the BIER imposition node.
Definition: bier_imp_node.c:24
u8 * format_bier_imp(u8 *s, va_list *args)
Definition: bier_imp.c:137
#define BIER_HDR_ENTROPY_FIELD_SHIFT
unsigned int u32
Definition: types.h:88
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
#define VLIB_NODE_FUNCTION_MULTIARCH(node, fn)
Definition: node.h:194
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:202
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6.h:430
#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
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:153
static u8 * format_bier_imp_trace(u8 *s, va_list *args)
u16 n_vectors
Definition: node.h:380
vlib_main_t * vm
Definition: buffer.c:294
index_t imp
BIER imposition object hit.
Definition: bier_imp_node.c:29
#define clib_memcpy(a, b, c)
Definition: string.h:75
bier_hdr_t hdr
BIER hdr applied.
Definition: bier_imp_node.c:34
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
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: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
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
Definition: lookup.h:69
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
static uword bier_imp_ip4(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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
#define vnet_buffer(b)
Definition: buffer.h:360
bier_table_id_t bi_tbl
The BIER table into which to forward the post imposed packet.
Definition: bier_imp.h:63
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:180
#define BIER_HDR_PROTO_FIELD_SHIFT
dpo_id_t bi_dpo[FIB_PROTOCOL_IP_MAX]
The DPO contirubted from the resolving BIER table.
Definition: bier_imp.h:45
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 vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57