FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
bier_types.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 <vppinfra/types.h>
17 #include <vnet/bier/bier_types.h>
19 
20 /*
21  * enum to string conversions
22  */
23 const static char* const bier_hdr_len_id_names[] = BIER_HDR_LEN_IDS;
24 const static char* const bier_hdr_proto_names[] = BIER_HDR_PROTO_ID_NAMES;
25 
26 const static u16 bier_hdr_len_num_buckets[] = {
28  [BIER_HDR_LEN_64] = 8,
29  [BIER_HDR_LEN_128] = 16,
30  [BIER_HDR_LEN_256] = 32,
31  [BIER_HDR_LEN_512] = 64,
32  [BIER_HDR_LEN_1024] = 128,
33  [BIER_HDR_LEN_2048] = 256,
34  [BIER_HDR_LEN_4096] = 512,
35 };
36 
37 const static u16 bier_hdr_len_num_bits[] = {
39  [BIER_HDR_LEN_64] = 64,
40  [BIER_HDR_LEN_128] = 128,
41  [BIER_HDR_LEN_256] = 256,
42  [BIER_HDR_LEN_512] = 512,
43  [BIER_HDR_LEN_1024] = 1024,
44  [BIER_HDR_LEN_2048] = 2048,
45  [BIER_HDR_LEN_4096] = 4096,
46 };
47 
48 const static u16 bier_hdr_len_prefix_len[] = {
50  [BIER_HDR_LEN_64] = 7,
51  [BIER_HDR_LEN_128] = 8,
52  [BIER_HDR_LEN_256] = 9,
53  [BIER_HDR_LEN_512] = 10,
54  [BIER_HDR_LEN_1024] = 11,
55  [BIER_HDR_LEN_2048] = 12,
56  [BIER_HDR_LEN_4096] = 13,
57 };
58 
59 u32
61 {
62  return (bier_hdr_len_num_buckets[id]);
63 }
64 
65 u32
67 {
68  return (bier_hdr_len_id_to_num_buckets(id));
69 }
70 
71 u32
73 {
74  return (bier_hdr_len_id_to_num_buckets(id) - 1);
75 }
76 
77 u32
79 {
80  return (bier_hdr_len_num_bits[id]);
81 }
82 
83 u32
85 {
86  return (bier_hdr_len_id_to_num_bits(id));
87 }
88 
89 u32
91 {
92  return (bier_hdr_len_prefix_len[id]);
93 }
94 
95 u8 *
96 format_bier_hdr_len_id (u8 *s, va_list *ap)
97 {
98  bier_hdr_len_id_t hli = va_arg(*ap, int); // int promotion of bier_hdr_len_id_t
99 
100  return (format(s, "%s", bier_hdr_len_id_names[hli]));
101 }
102 
103 u8 *
104 format_bier_hdr_proto (u8 *s, va_list *ap)
105 {
106  bier_hdr_proto_id_t pi = va_arg(*ap, int);
107 
108  return (format(s, "%s", bier_hdr_proto_names[pi]));
109 }
110 
111 int
113  const bier_table_id_t *btid2)
114 {
115  int res;
116 
117  res = (btid1->bti_set - btid2->bti_set);
118 
119  if (0 == res)
120  {
121  res = (btid1->bti_sub_domain - btid2->bti_sub_domain);
122  }
123  if (0 == res)
124  {
125  res = (btid1->bti_ecmp - btid2->bti_ecmp);
126  }
127  if (0 == res)
128  {
129  res = (btid1->bti_hdr_len - btid2->bti_hdr_len);
130  }
131  if (0 == res)
132  {
133  res = (btid1->bti_type - btid2->bti_type);
134  }
135  return (res);
136 }
137 
140 {
141  switch (bproto)
142  {
144  case BIER_HDR_PROTO_CTRL:
145  case BIER_HDR_PROTO_OAM:
146  ASSERT(0);
147  break;
150  return (DPO_PROTO_MPLS);
153  return (DPO_PROTO_ETHERNET);
154  case BIER_HDR_PROTO_IPV4:
155  return (DPO_PROTO_IP4);
156  case BIER_HDR_PROTO_IPV6:
157  return (DPO_PROTO_IP4);
158  }
159 
160  return (DPO_PROTO_NUM);
161 }
162 
166  bier_hdr_len_id_t bsl)
167 {
169 
170  id = bsl;
171  id = id << 8;
172  id |= sd;
173  id = id << 8;
174  id |= set;
175 
176  return (id);
177 }
178 
179 void
183  bier_hdr_len_id_t *bsl)
184 {
185  *set = id & 0xff;
186  id = id >> 8;
187  *sd = id & 0xff;
188  id = id >> 8;
189  *bsl = id;
190 }
191 
192 u8 *
193 format_bier_table_id (u8 *s, va_list *ap)
194 {
195  bier_table_id_t *btid = va_arg(*ap, bier_table_id_t *);
196 
197  return (format(s, "sub-domain:%d set:%d ecmp:%d bsl:%U",
198  btid->bti_sub_domain,
199  btid->bti_set,
200  btid->bti_ecmp,
202 }
203 
204 u8 *
205 format_bier_hdr (u8 *s, va_list *ap)
206 {
207  bier_hdr_t *bh = va_arg(*ap, bier_hdr_t *);
208  bier_hdr_t copy = *bh;
209 
210  bier_hdr_ntoh(&copy);
211 
212  return (format(s, "nibble:%d version:%d hdr-len:%U entropy:%d proto:%U src:%d",
214  bier_hdr_get_version(&copy),
216  bier_hdr_get_entropy(&copy),
218  bier_hdr_get_src_id(&copy)));
219 }
220 
221  u8*
222  format_bier_bift_id(u8 *s, va_list *ap)
223  {
224  bier_bift_id_t id = va_arg(*ap, bier_bift_id_t);
227  bier_hdr_len_id_t bsl;
228 
229  bier_bift_id_decode(id, &set, &sd, &bsl);
230 
231  return (format(s, "0x%x -> set:%d sd:%d hdr-len:%U",
232  id, set, sd, format_bier_hdr_len_id, bsl));
233  }
BIER_HDR_PROTO_MPLS_UP_STREAM
@ BIER_HDR_PROTO_MPLS_UP_STREAM
Definition: bier_types.h:183
BIER_HDR_LEN_4096
@ BIER_HDR_LEN_4096
Definition: bier_types.h:65
bier_table_id_cmp
int bier_table_id_cmp(const bier_table_id_t *btid1, const bier_table_id_t *btid2)
Compare to BIER table IDs for equality.
Definition: bier_types.c:112
bier_bift_id_encode
bier_bift_id_t bier_bift_id_encode(bier_table_set_id_t set, bier_table_sub_domain_id_t sd, bier_hdr_len_id_t bsl)
Encode a BIFT-ID as per draft-wijnandsxu-bier-non-mpls-bift-encoding-00.txt.
Definition: bier_types.c:164
BIER_HDR_PROTO_VXLAN
@ BIER_HDR_PROTO_VXLAN
Definition: bier_types.h:187
bier_hdr_len_id_to_prefix_len
u32 bier_hdr_len_id_to_prefix_len(bier_hdr_len_id_t id)
Definition: bier_types.c:90
BIER_HDR_PROTO_IPV4
@ BIER_HDR_PROTO_IPV4
Definition: bier_types.h:185
types.h
dpo_proto_t
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
bier_table_id_t_
The ID of a table.
Definition: bier_types.h:394
bier_hdr_len_id_to_num_buckets
u32 bier_hdr_len_id_to_num_buckets(bier_hdr_len_id_t id)
Conversion functions for the enumerated bit-string length values, to bit and bytes.
Definition: bier_types.c:60
bier_hdr_get_proto_id
static bier_hdr_proto_id_t bier_hdr_get_proto_id(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:169
u16
unsigned short u16
Definition: types.h:57
BIER_HDR_PROTO_MPLS_DOWN_STREAM
@ BIER_HDR_PROTO_MPLS_DOWN_STREAM
Definition: bier_types.h:182
bier_hdr_proto_names
const static char *const bier_hdr_proto_names[]
Definition: bier_types.c:24
bier_hdr_inlines.h
format_bier_hdr_proto
u8 * format_bier_hdr_proto(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:104
bier_hdr_get_version
static bier_hdr_version_t bier_hdr_get_version(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:61
BIER_HDR_PROTO_ID_NAMES
#define BIER_HDR_PROTO_ID_NAMES
Definition: bier_types.h:194
bier_hdr_len_prefix_len
const static u16 bier_hdr_len_prefix_len[]
Definition: bier_types.c:48
bier_hdr_get_1st_nibble
static u8 bier_hdr_get_1st_nibble(bier_hdr_t *hdr)
Definition: bier_hdr_inlines.h:93
format_bier_bift_id
u8 * format_bier_bift_id(u8 *s, va_list *ap)
Definition: bier_types.c:222
bier_hdr_ntoh
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:133
bier_table_id_t_::bti_type
bier_table_type_t bti_type
The type of the table; SPF or TE, MPLS or IPv6.
Definition: bier_types.h:424
set
description can t DF set
Definition: map.api:451
BIER_HDR_LEN_256
@ BIER_HDR_LEN_256
Definition: bier_types.h:56
BIER_HDR_PROTO_OAM
@ BIER_HDR_PROTO_OAM
Definition: bier_types.h:189
bier_table_id_t_::bti_sub_domain
bier_table_sub_domain_id_t bti_sub_domain
The Sub-Domain-ID The control plane has the configuration option to specify multiple domains or topol...
Definition: bier_types.h:408
BIER_HDR_LEN_512
@ BIER_HDR_LEN_512
Definition: bier_types.h:57
bier_bift_id_decode
void bier_bift_id_decode(bier_bift_id_t id, bier_table_set_id_t *set, bier_table_sub_domain_id_t *sd, bier_hdr_len_id_t *bsl)
Definition: bier_types.c:180
bier_table_sub_domain_id_t
u32 bier_table_sub_domain_id_t
The BIER Sub-domain ID assigned to a BIER table.
Definition: bier_types.h:377
BIER_HDR_PROTO_INVALID
@ BIER_HDR_PROTO_INVALID
Definition: bier_types.h:181
bier_hdr_len_num_bits
const static u16 bier_hdr_len_num_bits[]
Definition: bier_types.c:37
bier_hdr_get_len_id
static bier_hdr_len_id_t bier_hdr_get_len_id(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:69
BIER_HDR_PROTO_ETHERNET
@ BIER_HDR_PROTO_ETHERNET
Definition: bier_types.h:184
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
bier_hdr_proto_id_t
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
format_bier_hdr
u8 * format_bier_hdr(u8 *s, va_list *ap)
Format a BIER header.
Definition: bier_types.c:205
bier_hdr_len_id_t
enum bier_hdr_len_id_t_ bier_hdr_len_id_t
bier_hdr_len_id_t enumerator
id
u8 id[64]
Definition: dhcp.api:160
format_bier_hdr_len_id
u8 * format_bier_hdr_len_id(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:96
BIER_HDR_LEN_2048
@ BIER_HDR_LEN_2048
Bit-string lengths greater than 1024 are not supported due to the limited about pf space available in...
Definition: bier_types.h:64
BIER_HDR_PROTO_IPV6
@ BIER_HDR_PROTO_IPV6
Definition: bier_types.h:186
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
BIER_HDR_LEN_1024
@ BIER_HDR_LEN_1024
Definition: bier_types.h:58
DPO_PROTO_MPLS
@ DPO_PROTO_MPLS
Definition: dpo.h:66
u32
unsigned int u32
Definition: types.h:88
bier_hdr_len_id_to_num_bits
u32 bier_hdr_len_id_to_num_bits(bier_hdr_len_id_t id)
Definition: bier_types.c:78
bier_table_id_t_::bti_ecmp
bier_table_ecmp_id_t bti_ecmp
The SUB/ECMP-ID Constructed by FIB to achieve ECMP between BFR-NBRs.
Definition: bier_types.h:414
BIER_HDR_LEN_IDS
#define BIER_HDR_LEN_IDS
Definition: bier_types.h:69
bier_types.h
bier_hdr_len_id_names
const static char *const bier_hdr_len_id_names[]
Definition: bier_types.c:23
bier_bift_id_t
u32 bier_bift_id_t
The BIER universal 'label'.
Definition: bier_types.h:458
u8
unsigned char u8
Definition: types.h:56
format_bier_table_id
u8 * format_bier_table_id(u8 *s, va_list *ap)
Format a BIER table ID.
Definition: bier_types.c:193
DPO_PROTO_IP4
@ DPO_PROTO_IP4
Definition: dpo.h:64
bier_hdr_len_num_buckets
const static u16 bier_hdr_len_num_buckets[]
Definition: bier_types.c:26
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_hdr_len_id_to_max_bit
u32 bier_hdr_len_id_to_max_bit(bier_hdr_len_id_t id)
Definition: bier_types.c:84
bier_table_set_id_t
u32 bier_table_set_id_t
The BIER Set ID assigned to a BIER table.
Definition: bier_types.h:370
DPO_PROTO_ETHERNET
@ DPO_PROTO_ETHERNET
Definition: dpo.h:67
BIER_HDR_LEN_INVALID
@ BIER_HDR_LEN_INVALID
Definition: bier_types.h:66
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
bier_table_id_t_::bti_set
bier_table_set_id_t bti_set
The SET-ID The control plane divdies the bit-position space into sets in the case the max bit-positio...
Definition: bier_types.h:401
BIER_HDR_LEN_128
@ BIER_HDR_LEN_128
Definition: bier_types.h:55
BIER_HDR_PROTO_CTRL
@ BIER_HDR_PROTO_CTRL
Definition: bier_types.h:188
DPO_PROTO_NUM
#define DPO_PROTO_NUM
Definition: dpo.h:72
BIER_HDR_LEN_64
@ BIER_HDR_LEN_64
Definition: bier_types.h:54
bier_hdr_proto_to_dpo
dpo_proto_t bier_hdr_proto_to_dpo(bier_hdr_proto_id_t bproto)
Convert from BIER next-hop proto to DPO proto.
Definition: bier_types.c:139
bier_hdr_get_entropy
static bier_hdr_entropy_t bier_hdr_get_entropy(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:77
bier_hdr_get_src_id
static bier_hdr_src_id_t bier_hdr_get_src_id(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:149
bier_hdr_len_id_to_max_bucket
u32 bier_hdr_len_id_to_max_bucket(bier_hdr_len_id_t id)
Definition: bier_types.c:72