FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
mpls_lookup.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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 #ifndef __MPLS_LOOKUP_H__
17 #define __MPLS_LOOKUP_H__
18 
19 #include <vnet/mpls/mpls.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/bier/bier_fwd.h>
22 
23 /**
24  * The arc/edge from the MPLS lookup node to the MPLS replicate node
25  */
27 
28 /**
29  * Enum of statically configred MPLS lookup next nodes
30  */
31 typedef enum mpls_lookup_next_t_
32 {
35 
36 /*
37  * Compute flow hash.
38  * We'll use it to select which adjacency to use for this flow. And other things.
39  */
42  flow_hash_config_t flow_hash_config)
43 {
44  /*
45  * We need to byte swap so we use the numerical value. i.e. an odd label
46  * leads to an odd bucket. as opposed to a label above and below value X.
47  */
48  u8 next_label_is_entropy;
49  mpls_label_t ho_label;
50  u32 hash, value;
51 
52  ho_label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
53  hash = vnet_mpls_uc_get_label(ho_label);
54  next_label_is_entropy = 0;
55 
56  while (MPLS_EOS != vnet_mpls_uc_get_s(ho_label))
57  {
58  hdr++;
59  ho_label = clib_net_to_host_u32(hdr->label_exp_s_ttl);
60  value = vnet_mpls_uc_get_label(ho_label);
61 
62  if (1 == next_label_is_entropy)
63  {
64  /*
65  * The label is an entropy value, use it alone as the hash
66  */
67  return (ho_label);
68  }
69  if (MPLS_IETF_ENTROPY_LABEL == value)
70  {
71  /*
72  * we've met a label in the stack indicating that tha next
73  * label is an entropy value
74  */
75  next_label_is_entropy = 1;
76  }
77  else
78  {
79  /*
80  * XOR the label values in the stack together to
81  * build up the hash value
82  */
83  hash ^= value;
84  }
85  }
86 
87  /*
88  * check the top nibble for v4 and v6
89  */
90  hdr++;
91 
92  switch (((u8*)hdr)[0] >> 4)
93  {
94  case 4:
95  /* incorporate the v4 flow-hash */
96  hash ^= ip4_compute_flow_hash ((const ip4_header_t *)hdr,
98  break;
99  case 6:
100  /* incorporate the v6 flow-hash */
101  hash ^= ip6_compute_flow_hash ((const ip6_header_t *)hdr,
103  break;
104  case 5:
105  /* incorporate the bier flow-hash */
106  hash ^= bier_compute_flow_hash ((const bier_hdr_t *)hdr);
107  break;
108  default:
109  break;
110  }
111 
112  return (hash);
113 }
114 
115 #endif /* __MPLS_LOOKUP_H__ */
u32 mpls_lookup_to_replicate_edge
The arc/edge from the MPLS lookup node to the MPLS replicate node.
Definition: mpls_lookup.c:29
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip4.h:304
u32 mpls_label_t
A label value only, i.e.
Definition: packet.h:26
#define MPLS_IETF_ENTROPY_LABEL
Definition: mpls_types.h:33
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
enum mpls_lookup_next_t_ mpls_lookup_next_t
Enum of statically configred MPLS lookup next nodes.
static u32 mpls_compute_flow_hash(const mpls_unicast_header_t *hdr, flow_hash_config_t flow_hash_config)
Definition: mpls_lookup.h:41
static_always_inline u32 bier_compute_flow_hash(const bier_hdr_t *hdr)
Definition: bier_fwd.h:23
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6.h:380
static u32 vnet_mpls_uc_get_label(mpls_label_t label_exp_s_ttl)
Definition: packet.h:105
#define always_inline
Definition: ipsec.h:28
mpls_lookup_next_t_
Enum of statically configred MPLS lookup next nodes.
Definition: mpls_lookup.h:31
u8 value
Definition: qos.api:54
mpls_label_t label_exp_s_ttl
Definition: packet.h:33
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
Definition: lookup.h:70
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:84
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
static u32 vnet_mpls_uc_get_s(mpls_label_t label_exp_s_ttl)
Definition: packet.h:115