2 * mpls_lookup.c: MPLS lookup
4 * Copyright (c) 2012-2014 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlib/vlib.h>
19 #include <vnet/pg/pg.h>
20 #include <vnet/mpls/mpls.h>
21 #include <vnet/fib/mpls_fib.h>
22 #include <vnet/dpo/load_balance_map.h>
23 #include <vnet/dpo/replicate_dpo.h>
26 * Static MPLS VLIB forwarding node
28 static vlib_node_registration_t mpls_lookup_node;
31 * The arc/edge from the MPLS lookup node to the MPLS replicate node
33 static u32 mpls_lookup_to_replicate_edge;
39 u32 label_net_byte_order;
41 } mpls_lookup_trace_t;
44 format_mpls_lookup_trace (u8 * s, va_list * args)
46 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
47 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
48 mpls_lookup_trace_t * t = va_arg (*args, mpls_lookup_trace_t *);
50 s = format (s, "MPLS: next [%d], lookup fib index %d, LB index %d hash %x "
52 t->next_index, t->lfib_index, t->lb_index, t->hash,
53 vnet_mpls_uc_get_label(
54 clib_net_to_host_u32(t->label_net_byte_order)),
55 vnet_mpls_uc_get_s(t->label_net_byte_order));
61 * We'll use it to select which adjacency to use for this flow. And other things.
64 mpls_compute_flow_hash (const mpls_unicast_header_t * hdr,
65 flow_hash_config_t flow_hash_config)
68 * We need to byte swap so we use the numerical value. i.e. an odd label
69 * leads to an odd bucket. as opposed to a label above and below value X.
71 u8 next_label_is_entropy;
72 mpls_label_t ho_label;
75 ho_label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
76 hash = vnet_mpls_uc_get_label(ho_label);
77 next_label_is_entropy = 0;
79 while (MPLS_EOS != vnet_mpls_uc_get_s(ho_label))
82 ho_label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
83 value = vnet_mpls_uc_get_label(ho_label);
85 if (1 == next_label_is_entropy)
88 * The label is an entropy value, use it alone as the hash
92 if (MPLS_IETF_ENTROPY_LABEL == value)
95 * we've met a label in the stack indicating that tha next
96 * label is an entropy value
98 next_label_is_entropy = 1;
103 * XOR the label values in the stack together to
104 * build up the hash value
111 * check the top nibble for v4 and v6
115 switch (((u8*)hdr)[0] >> 4)
118 /* incorporate the v4 flow-hash */
119 hash ^= ip4_compute_flow_hash ((const ip4_header_t *)hdr,
120 IP_FLOW_HASH_DEFAULT);
123 /* incorporate the v6 flow-hash */
124 hash ^= ip6_compute_flow_hash ((const ip6_header_t *)hdr,
125 IP_FLOW_HASH_DEFAULT);
135 mpls_lookup (vlib_main_t * vm,
136 vlib_node_runtime_t * node,
137 vlib_frame_t * from_frame)
139 vlib_combined_counter_main_t * cm = &load_balance_main.lbm_to_counters;
140 u32 n_left_from, next_index, * from, * to_next;
141 mpls_main_t * mm = &mpls_main;
142 u32 thread_index = vlib_get_thread_index();
144 from = vlib_frame_vector_args (from_frame);
145 n_left_from = from_frame->n_vectors;
146 next_index = node->cached_next_index;
148 while (n_left_from > 0)
152 vlib_get_next_frame (vm, node, next_index,
153 to_next, n_left_to_next);
155 while (n_left_from >= 8 && n_left_to_next >= 4)
157 u32 lbi0, next0, lfib_index0, bi0, hash_c0;
158 const mpls_unicast_header_t * h0;
159 const load_balance_t *lb0;
160 const dpo_id_t *dpo0;
162 u32 lbi1, next1, lfib_index1, bi1, hash_c1;
163 const mpls_unicast_header_t * h1;
164 const load_balance_t *lb1;
165 const dpo_id_t *dpo1;
167 u32 lbi2, next2, lfib_index2, bi2, hash_c2;
168 const mpls_unicast_header_t * h2;
169 const load_balance_t *lb2;
170 const dpo_id_t *dpo2;
172 u32 lbi3, next3, lfib_index3, bi3, hash_c3;
173 const mpls_unicast_header_t * h3;
174 const load_balance_t *lb3;
175 const dpo_id_t *dpo3;
178 /* Prefetch next iteration. */
180 vlib_buffer_t * p2, * p3, *p4, *p5;
182 p2 = vlib_get_buffer (vm, from[2]);
183 p3 = vlib_get_buffer (vm, from[3]);
184 p4 = vlib_get_buffer (vm, from[4]);
185 p5 = vlib_get_buffer (vm, from[5]);
187 vlib_prefetch_buffer_header (p2, STORE);
188 vlib_prefetch_buffer_header (p3, STORE);
189 vlib_prefetch_buffer_header (p4, STORE);
190 vlib_prefetch_buffer_header (p5, STORE);
192 CLIB_PREFETCH (p2->data, sizeof (h0[0]), STORE);
193 CLIB_PREFETCH (p3->data, sizeof (h0[0]), STORE);
194 CLIB_PREFETCH (p4->data, sizeof (h0[0]), STORE);
195 CLIB_PREFETCH (p5->data, sizeof (h0[0]), STORE);
198 bi0 = to_next[0] = from[0];
199 bi1 = to_next[1] = from[1];
200 bi2 = to_next[2] = from[2];
201 bi3 = to_next[3] = from[3];
208 b0 = vlib_get_buffer (vm, bi0);
209 b1 = vlib_get_buffer (vm, bi1);
210 b2 = vlib_get_buffer (vm, bi2);
211 b3 = vlib_get_buffer (vm, bi3);
212 h0 = vlib_buffer_get_current (b0);
213 h1 = vlib_buffer_get_current (b1);
214 h2 = vlib_buffer_get_current (b2);
215 h3 = vlib_buffer_get_current (b3);
217 lfib_index0 = vec_elt(mm->fib_index_by_sw_if_index,
218 vnet_buffer(b0)->sw_if_index[VLIB_RX]);
219 lfib_index1 = vec_elt(mm->fib_index_by_sw_if_index,
220 vnet_buffer(b1)->sw_if_index[VLIB_RX]);
221 lfib_index2 = vec_elt(mm->fib_index_by_sw_if_index,
222 vnet_buffer(b2)->sw_if_index[VLIB_RX]);
223 lfib_index3 = vec_elt(mm->fib_index_by_sw_if_index,
224 vnet_buffer(b3)->sw_if_index[VLIB_RX]);
226 lbi0 = mpls_fib_table_forwarding_lookup (lfib_index0, h0);
227 lbi1 = mpls_fib_table_forwarding_lookup (lfib_index1, h1);
228 lbi2 = mpls_fib_table_forwarding_lookup (lfib_index2, h2);
229 lbi3 = mpls_fib_table_forwarding_lookup (lfib_index3, h3);
231 hash_c0 = vnet_buffer(b0)->ip.flow_hash = 0;
232 hash_c1 = vnet_buffer(b1)->ip.flow_hash = 0;
233 hash_c2 = vnet_buffer(b2)->ip.flow_hash = 0;
234 hash_c3 = vnet_buffer(b3)->ip.flow_hash = 0;
236 if (MPLS_IS_REPLICATE & lbi0)
238 next0 = mpls_lookup_to_replicate_edge;
239 vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
240 (lbi0 & ~MPLS_IS_REPLICATE);
244 lb0 = load_balance_get(lbi0);
245 ASSERT (lb0->lb_n_buckets > 0);
246 ASSERT (is_pow2 (lb0->lb_n_buckets));
248 if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
250 hash_c0 = vnet_buffer (b0)->ip.flow_hash =
251 mpls_compute_flow_hash(h0, lb0->lb_hash_config);
252 dpo0 = load_balance_get_fwd_bucket
254 (hash_c0 & (lb0->lb_n_buckets_minus_1)));
258 dpo0 = load_balance_get_bucket_i (lb0, 0);
260 next0 = dpo0->dpoi_next_node;
262 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
264 vlib_increment_combined_counter
265 (cm, thread_index, lbi0, 1,
266 vlib_buffer_length_in_chain (vm, b0));
268 if (MPLS_IS_REPLICATE & lbi1)
270 next1 = mpls_lookup_to_replicate_edge;
271 vnet_buffer (b1)->ip.adj_index[VLIB_TX] =
272 (lbi1 & ~MPLS_IS_REPLICATE);
276 lb1 = load_balance_get(lbi1);
277 ASSERT (lb1->lb_n_buckets > 0);
278 ASSERT (is_pow2 (lb1->lb_n_buckets));
280 if (PREDICT_FALSE(lb1->lb_n_buckets > 1))
282 hash_c1 = vnet_buffer (b1)->ip.flow_hash =
283 mpls_compute_flow_hash(h1, lb1->lb_hash_config);
284 dpo1 = load_balance_get_fwd_bucket
286 (hash_c1 & (lb1->lb_n_buckets_minus_1)));
290 dpo1 = load_balance_get_bucket_i (lb1, 0);
292 next1 = dpo1->dpoi_next_node;
294 vnet_buffer (b1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
296 vlib_increment_combined_counter
297 (cm, thread_index, lbi1, 1,
298 vlib_buffer_length_in_chain (vm, b1));
300 if (MPLS_IS_REPLICATE & lbi2)
302 next2 = mpls_lookup_to_replicate_edge;
303 vnet_buffer (b2)->ip.adj_index[VLIB_TX] =
304 (lbi2 & ~MPLS_IS_REPLICATE);
308 lb2 = load_balance_get(lbi2);
309 ASSERT (lb2->lb_n_buckets > 0);
310 ASSERT (is_pow2 (lb2->lb_n_buckets));
312 if (PREDICT_FALSE(lb2->lb_n_buckets > 1))
314 hash_c2 = vnet_buffer (b2)->ip.flow_hash =
315 mpls_compute_flow_hash(h2, lb2->lb_hash_config);
316 dpo2 = load_balance_get_fwd_bucket
318 (hash_c2 & (lb2->lb_n_buckets_minus_1)));
322 dpo2 = load_balance_get_bucket_i (lb2, 0);
324 next2 = dpo2->dpoi_next_node;
326 vnet_buffer (b2)->ip.adj_index[VLIB_TX] = dpo2->dpoi_index;
328 vlib_increment_combined_counter
329 (cm, thread_index, lbi2, 1,
330 vlib_buffer_length_in_chain (vm, b2));
332 if (MPLS_IS_REPLICATE & lbi3)
334 next3 = mpls_lookup_to_replicate_edge;
335 vnet_buffer (b3)->ip.adj_index[VLIB_TX] =
336 (lbi3 & ~MPLS_IS_REPLICATE);
340 lb3 = load_balance_get(lbi3);
341 ASSERT (lb3->lb_n_buckets > 0);
342 ASSERT (is_pow2 (lb3->lb_n_buckets));
344 if (PREDICT_FALSE(lb3->lb_n_buckets > 1))
346 hash_c3 = vnet_buffer (b3)->ip.flow_hash =
347 mpls_compute_flow_hash(h3, lb3->lb_hash_config);
348 dpo3 = load_balance_get_fwd_bucket
350 (hash_c3 & (lb3->lb_n_buckets_minus_1)));
354 dpo3 = load_balance_get_bucket_i (lb3, 0);
356 next3 = dpo3->dpoi_next_node;
358 vnet_buffer (b3)->ip.adj_index[VLIB_TX] = dpo3->dpoi_index;
360 vlib_increment_combined_counter
361 (cm, thread_index, lbi3, 1,
362 vlib_buffer_length_in_chain (vm, b3));
366 * before we pop the label copy th values we need to maintain.
367 * The label header is in network byte order.
368 * last byte is the TTL.
369 * bits 2 to 4 inclusive are the EXP bits
371 vnet_buffer (b0)->mpls.ttl = ((char*)h0)[3];
372 vnet_buffer (b0)->mpls.exp = (((char*)h0)[2] & 0xe) >> 1;
373 vnet_buffer (b0)->mpls.first = 1;
374 vnet_buffer (b1)->mpls.ttl = ((char*)h1)[3];
375 vnet_buffer (b1)->mpls.exp = (((char*)h1)[2] & 0xe) >> 1;
376 vnet_buffer (b1)->mpls.first = 1;
377 vnet_buffer (b2)->mpls.ttl = ((char*)h2)[3];
378 vnet_buffer (b2)->mpls.exp = (((char*)h2)[2] & 0xe) >> 1;
379 vnet_buffer (b2)->mpls.first = 1;
380 vnet_buffer (b3)->mpls.ttl = ((char*)h3)[3];
381 vnet_buffer (b3)->mpls.exp = (((char*)h3)[2] & 0xe) >> 1;
382 vnet_buffer (b3)->mpls.first = 1;
385 * pop the label that was just used in the lookup
387 vlib_buffer_advance(b0, sizeof(*h0));
388 vlib_buffer_advance(b1, sizeof(*h1));
389 vlib_buffer_advance(b2, sizeof(*h2));
390 vlib_buffer_advance(b3, sizeof(*h3));
392 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
394 mpls_lookup_trace_t *tr = vlib_add_trace (vm, node,
396 tr->next_index = next0;
398 tr->lfib_index = lfib_index0;
400 tr->label_net_byte_order = h0->label_exp_s_ttl;
403 if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED))
405 mpls_lookup_trace_t *tr = vlib_add_trace (vm, node,
407 tr->next_index = next1;
409 tr->lfib_index = lfib_index1;
411 tr->label_net_byte_order = h1->label_exp_s_ttl;
414 if (PREDICT_FALSE(b2->flags & VLIB_BUFFER_IS_TRACED))
416 mpls_lookup_trace_t *tr = vlib_add_trace (vm, node,
418 tr->next_index = next2;
420 tr->lfib_index = lfib_index2;
422 tr->label_net_byte_order = h2->label_exp_s_ttl;
425 if (PREDICT_FALSE(b3->flags & VLIB_BUFFER_IS_TRACED))
427 mpls_lookup_trace_t *tr = vlib_add_trace (vm, node,
429 tr->next_index = next3;
431 tr->lfib_index = lfib_index3;
433 tr->label_net_byte_order = h3->label_exp_s_ttl;
436 vlib_validate_buffer_enqueue_x4 (vm, node, next_index,
437 to_next, n_left_to_next,
439 next0, next1, next2, next3);
442 while (n_left_from > 0 && n_left_to_next > 0)
444 u32 lbi0, next0, lfib_index0, bi0, hash_c0;
445 const mpls_unicast_header_t * h0;
446 const load_balance_t *lb0;
447 const dpo_id_t *dpo0;
457 b0 = vlib_get_buffer (vm, bi0);
458 h0 = vlib_buffer_get_current (b0);
460 lfib_index0 = vec_elt(mm->fib_index_by_sw_if_index,
461 vnet_buffer(b0)->sw_if_index[VLIB_RX]);
463 lbi0 = mpls_fib_table_forwarding_lookup(lfib_index0, h0);
464 hash_c0 = vnet_buffer(b0)->ip.flow_hash = 0;
466 if (MPLS_IS_REPLICATE & lbi0)
468 next0 = mpls_lookup_to_replicate_edge;
469 vnet_buffer (b0)->ip.adj_index[VLIB_TX] =
470 (lbi0 & ~MPLS_IS_REPLICATE);
474 lb0 = load_balance_get(lbi0);
475 ASSERT (lb0->lb_n_buckets > 0);
476 ASSERT (is_pow2 (lb0->lb_n_buckets));
478 if (PREDICT_FALSE(lb0->lb_n_buckets > 1))
480 hash_c0 = vnet_buffer (b0)->ip.flow_hash =
481 mpls_compute_flow_hash(h0, lb0->lb_hash_config);
482 dpo0 = load_balance_get_fwd_bucket
484 (hash_c0 & (lb0->lb_n_buckets_minus_1)));
488 dpo0 = load_balance_get_bucket_i (lb0, 0);
490 next0 = dpo0->dpoi_next_node;
491 vnet_buffer (b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
493 vlib_increment_combined_counter
494 (cm, thread_index, lbi0, 1,
495 vlib_buffer_length_in_chain (vm, b0));
499 * before we pop the label copy, values we need to maintain.
500 * The label header is in network byte order.
501 * last byte is the TTL.
502 * bits 2 to 4 inclusive are the EXP bits
504 vnet_buffer (b0)->mpls.ttl = ((char*)h0)[3];
505 vnet_buffer (b0)->mpls.exp = (((char*)h0)[2] & 0xe) >> 1;
506 vnet_buffer (b0)->mpls.first = 1;
509 * pop the label that was just used in the lookup
511 vlib_buffer_advance(b0, sizeof(*h0));
513 if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED))
515 mpls_lookup_trace_t *tr = vlib_add_trace (vm, node,
517 tr->next_index = next0;
519 tr->lfib_index = lfib_index0;
521 tr->label_net_byte_order = h0->label_exp_s_ttl;
524 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
525 to_next, n_left_to_next,
529 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
531 vlib_node_increment_counter (vm, mpls_lookup_node.index,
532 MPLS_ERROR_PKTS_DECAP, from_frame->n_vectors);
533 return from_frame->n_vectors;
536 static char * mpls_error_strings[] = {
537 #define mpls_error(n,s) s,
542 VLIB_REGISTER_NODE (mpls_lookup_node, static) = {
543 .function = mpls_lookup,
544 .name = "mpls-lookup",
545 /* Takes a vector of packets. */
546 .vector_size = sizeof (u32),
547 .n_errors = MPLS_N_ERROR,
548 .error_strings = mpls_error_strings,
550 .sibling_of = "mpls-load-balance",
552 .format_buffer = format_mpls_header,
553 .format_trace = format_mpls_lookup_trace,
554 .unformat_buffer = unformat_mpls_header,
557 VLIB_NODE_FUNCTION_MULTIARCH (mpls_lookup_node, mpls_lookup)
563 } mpls_load_balance_trace_t;
566 format_mpls_load_balance_trace (u8 * s, va_list * args)
568 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
569 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
570 mpls_load_balance_trace_t * t = va_arg (*args, mpls_load_balance_trace_t *);
572 s = format (s, "MPLS: next [%d], LB index %d hash %d",
573 t->next_index, t->lb_index, t->hash);
578 mpls_load_balance (vlib_main_t * vm,
579 vlib_node_runtime_t * node,
580 vlib_frame_t * frame)
582 vlib_combined_counter_main_t * cm = &load_balance_main.lbm_via_counters;
583 u32 n_left_from, n_left_to_next, * from, * to_next;
584 u32 thread_index = vlib_get_thread_index();
587 from = vlib_frame_vector_args (frame);
588 n_left_from = frame->n_vectors;
589 next = node->cached_next_index;
591 while (n_left_from > 0)
593 vlib_get_next_frame (vm, node, next,
594 to_next, n_left_to_next);
597 while (n_left_from >= 4 && n_left_to_next >= 2)
599 const load_balance_t *lb0, *lb1;
600 vlib_buffer_t * p0, *p1;
601 u32 pi0, lbi0, hc0, pi1, lbi1, hc1, next0, next1;
602 const mpls_unicast_header_t *mpls0, *mpls1;
603 const dpo_id_t *dpo0, *dpo1;
605 /* Prefetch next iteration. */
607 vlib_buffer_t * p2, * p3;
609 p2 = vlib_get_buffer (vm, from[2]);
610 p3 = vlib_get_buffer (vm, from[3]);
612 vlib_prefetch_buffer_header (p2, STORE);
613 vlib_prefetch_buffer_header (p3, STORE);
615 CLIB_PREFETCH (p2->data, sizeof (mpls0[0]), STORE);
616 CLIB_PREFETCH (p3->data, sizeof (mpls0[0]), STORE);
619 pi0 = to_next[0] = from[0];
620 pi1 = to_next[1] = from[1];
627 p0 = vlib_get_buffer (vm, pi0);
628 p1 = vlib_get_buffer (vm, pi1);
630 mpls0 = vlib_buffer_get_current (p0);
631 mpls1 = vlib_buffer_get_current (p1);
632 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
633 lbi1 = vnet_buffer (p1)->ip.adj_index[VLIB_TX];
635 lb0 = load_balance_get(lbi0);
636 lb1 = load_balance_get(lbi1);
639 * this node is for via FIBs we can re-use the hash value from the
640 * to node if present.
641 * We don't want to use the same hash value at each level in the recursion
642 * graph as that would lead to polarisation
644 hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
645 hc1 = vnet_buffer (p1)->ip.flow_hash = 0;
647 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
649 if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
651 hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
655 hc0 = vnet_buffer(p0)->ip.flow_hash = mpls_compute_flow_hash(mpls0, hc0);
657 dpo0 = load_balance_get_fwd_bucket(lb0, (hc0 & lb0->lb_n_buckets_minus_1));
661 dpo0 = load_balance_get_bucket_i (lb0, 0);
663 if (PREDICT_FALSE (lb1->lb_n_buckets > 1))
665 if (PREDICT_TRUE (vnet_buffer(p1)->ip.flow_hash))
667 hc1 = vnet_buffer(p1)->ip.flow_hash = vnet_buffer(p1)->ip.flow_hash >> 1;
671 hc1 = vnet_buffer(p1)->ip.flow_hash = mpls_compute_flow_hash(mpls1, hc1);
673 dpo1 = load_balance_get_fwd_bucket(lb1, (hc1 & lb1->lb_n_buckets_minus_1));
677 dpo1 = load_balance_get_bucket_i (lb1, 0);
680 next0 = dpo0->dpoi_next_node;
681 next1 = dpo1->dpoi_next_node;
683 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
684 vnet_buffer (p1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index;
686 vlib_increment_combined_counter
687 (cm, thread_index, lbi0, 1,
688 vlib_buffer_length_in_chain (vm, p0));
689 vlib_increment_combined_counter
690 (cm, thread_index, lbi1, 1,
691 vlib_buffer_length_in_chain (vm, p1));
693 if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
695 mpls_load_balance_trace_t *tr = vlib_add_trace (vm, node,
697 tr->next_index = next0;
702 vlib_validate_buffer_enqueue_x2 (vm, node, next,
703 to_next, n_left_to_next,
704 pi0, pi1, next0, next1);
707 while (n_left_from > 0 && n_left_to_next > 0)
709 const load_balance_t *lb0;
711 u32 pi0, lbi0, hc0, next0;
712 const mpls_unicast_header_t *mpls0;
713 const dpo_id_t *dpo0;
722 p0 = vlib_get_buffer (vm, pi0);
724 mpls0 = vlib_buffer_get_current (p0);
725 lbi0 = vnet_buffer (p0)->ip.adj_index[VLIB_TX];
727 lb0 = load_balance_get(lbi0);
729 hc0 = vnet_buffer (p0)->ip.flow_hash = 0;
730 if (PREDICT_FALSE (lb0->lb_n_buckets > 1))
732 if (PREDICT_TRUE (vnet_buffer(p0)->ip.flow_hash))
734 hc0 = vnet_buffer(p0)->ip.flow_hash = vnet_buffer(p0)->ip.flow_hash >> 1;
738 hc0 = vnet_buffer(p0)->ip.flow_hash = mpls_compute_flow_hash(mpls0, hc0);
740 dpo0 = load_balance_get_fwd_bucket(lb0, (hc0 & lb0->lb_n_buckets_minus_1));
744 dpo0 = load_balance_get_bucket_i (lb0, 0);
747 next0 = dpo0->dpoi_next_node;
748 vnet_buffer (p0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index;
750 vlib_increment_combined_counter
751 (cm, thread_index, lbi0, 1,
752 vlib_buffer_length_in_chain (vm, p0));
754 vlib_validate_buffer_enqueue_x1 (vm, node, next,
755 to_next, n_left_to_next,
759 vlib_put_next_frame (vm, node, next, n_left_to_next);
762 return frame->n_vectors;
765 VLIB_REGISTER_NODE (mpls_load_balance_node) = {
766 .function = mpls_load_balance,
767 .name = "mpls-load-balance",
768 .vector_size = sizeof (u32),
769 .format_trace = format_mpls_load_balance_trace,
778 VLIB_NODE_FUNCTION_MULTIARCH (mpls_load_balance_node, mpls_load_balance)
781 static clib_error_t *
782 mpls_lookup_init (vlib_main_t * vm)
784 clib_error_t * error;
786 if ((error = vlib_call_init_function (vm, mpls_init)))
789 mpls_lookup_to_replicate_edge =
790 vlib_node_add_named_next(vm,
791 mpls_lookup_node.index,
797 VLIB_INIT_FUNCTION (mpls_lookup_init);