Line data Source code
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_disp_entry.h>
17 : #include <vnet/bier/bier_hdr_inlines.h>
18 :
19 : /**
20 : * @brief A struct to hold tracing information for the MPLS label imposition
21 : * node.
22 : */
23 : typedef struct bier_disp_dispatch_trace_t_
24 : {
25 : /**
26 : * BIER payload protocol used to dispatch
27 : */
28 : bier_hdr_proto_id_t pproto;
29 :
30 : /**
31 : * RPF-ID packet is tagged with
32 : */
33 : u32 rpf_id;
34 : } bier_disp_dispatch_trace_t;
35 :
36 : always_inline uword
37 6 : bier_disp_dispatch_inline (vlib_main_t * vm,
38 : vlib_node_runtime_t * node,
39 : vlib_frame_t * from_frame)
40 : {
41 : u32 n_left_from, next_index, * from, * to_next;
42 :
43 6 : from = vlib_frame_vector_args (from_frame);
44 6 : n_left_from = from_frame->n_vectors;
45 :
46 6 : next_index = node->cached_next_index;
47 :
48 12 : while (n_left_from > 0)
49 : {
50 : u32 n_left_to_next;
51 :
52 6 : vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
53 :
54 144 : while (n_left_from > 0 && n_left_to_next > 0)
55 : {
56 : bier_hdr_proto_id_t pproto0;
57 : bier_disp_entry_t *bde0;
58 : u32 next0, bi0, bdei0;
59 : const dpo_id_t *dpo0;
60 : vlib_buffer_t * b0;
61 : bier_hdr_t *hdr0;
62 : u32 entropy0;
63 :
64 138 : bi0 = from[0];
65 138 : to_next[0] = bi0;
66 138 : from += 1;
67 138 : to_next += 1;
68 138 : n_left_from -= 1;
69 138 : n_left_to_next -= 1;
70 :
71 138 : b0 = vlib_get_buffer (vm, bi0);
72 138 : bdei0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX];
73 138 : hdr0 = vlib_buffer_get_current(b0);
74 138 : bde0 = bier_disp_entry_get(bdei0);
75 138 : vnet_buffer(b0)->ip.adj_index[VLIB_RX] = BIER_RX_ITF;
76 :
77 : /*
78 : * header is in network order - flip it, we are about to
79 : * consume it anyway
80 : */
81 138 : bier_hdr_ntoh(hdr0);
82 138 : pproto0 = bier_hdr_get_proto_id(hdr0);
83 138 : entropy0 = bier_hdr_get_entropy(hdr0);
84 :
85 : /*
86 : * strip the header and copy the entropy value into
87 : * the packets flow-hash field
88 : * DSCP mumble mumble...
89 : */
90 138 : vlib_buffer_advance(b0, (vnet_buffer(b0)->mpls.bier.n_bytes +
91 : sizeof(*hdr0)));
92 138 : vnet_buffer(b0)->ip.flow_hash = entropy0;
93 :
94 : /*
95 : * use the payload proto to dispatch to the
96 : * correct stacked DPO.
97 : */
98 138 : dpo0 = &bde0->bde_fwd[pproto0].bde_dpo;
99 138 : next0 = dpo0->dpoi_next_node;
100 138 : vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
101 138 : vnet_buffer(b0)->ip.rpf_id = bde0->bde_fwd[pproto0].bde_rpf_id;
102 :
103 138 : if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
104 : {
105 : bier_disp_dispatch_trace_t *tr =
106 138 : vlib_add_trace (vm, node, b0, sizeof (*tr));
107 138 : tr->pproto = pproto0;
108 138 : tr->rpf_id = vnet_buffer(b0)->ip.rpf_id;
109 : }
110 :
111 138 : vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
112 : n_left_to_next, bi0, next0);
113 : }
114 6 : vlib_put_next_frame (vm, node, next_index, n_left_to_next);
115 : }
116 6 : return from_frame->n_vectors;
117 : }
118 :
119 : static u8 *
120 173 : format_bier_disp_dispatch_trace (u8 * s, va_list * args)
121 : {
122 173 : CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
123 173 : CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
124 : bier_disp_dispatch_trace_t * t;
125 :
126 173 : t = va_arg (*args, bier_disp_dispatch_trace_t *);
127 173 : s = format (s, "%U", format_bier_hdr_proto, t->pproto);
128 :
129 173 : return (s);
130 : }
131 :
132 2242 : VLIB_NODE_FN (bier_disp_dispatch_node) (vlib_main_t * vm,
133 : vlib_node_runtime_t * node,
134 : vlib_frame_t * frame)
135 : {
136 6 : return (bier_disp_dispatch_inline(vm, node, frame));
137 : }
138 :
139 178120 : VLIB_REGISTER_NODE (bier_disp_dispatch_node) = {
140 : .name = "bier-disp-dispatch",
141 : .vector_size = sizeof (u32),
142 :
143 : .format_trace = format_bier_disp_dispatch_trace,
144 : .n_next_nodes = 1,
145 : .next_nodes = {
146 : [0] = "bier-drop",
147 : }
148 : };
|