FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
bier_types.h
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 #ifndef __BIER_TYPES_H__
17 #define __BIER_TYPES_H__
18 
19 #include <vlib/vlib.h>
20 #include <vnet/dpo/dpo.h>
21 
22 /**
23  * @brief Flags to control show output
24  */
25 typedef enum bier_show_flags_t_ {
27  BIER_SHOW_DETAIL = (1 << 0),
29 
30 /**
31  * Types of BIER tables
32  */
33 typedef enum bier_table_type_t_ {
34  /**
35  * BIER over MPLS with SPF
36  */
38 
39  /**
40  * BIER over MPLS for TE
41  */
43 } __attribute__((packed)) bier_table_type_t;
44 
45 #define BIER_TABLE_TYPES { \
46  [BIER_TABLE_MPLS_SPF] = "mpls-spf", \
47  [BIER_TABLE_MPLS_TE] = "mpls-te", \
48 }
49 
50 /**
51  * bier_hdr_len_id_t enumerator
52  **/
53 typedef enum bier_hdr_len_id_t_ {
62 } __attribute__((packed)) bier_hdr_len_id_t;
63 
64 #define BIER_HDR_LEN_IDS { \
65  [BIER_HDR_LEN_INVALID] = "invalid",\
66  [BIER_HDR_LEN_64] = "64", \
67  [BIER_HDR_LEN_128] = "128", \
68  [BIER_HDR_LEN_256] = "256", \
69  [BIER_HDR_LEN_512] = "512", \
70  [BIER_HDR_LEN_1024] = "1024", \
71  [BIER_HDR_LEN_2048] = "2048", \
72  [BIER_HDR_LEN_4096] = "4096", \
73 }
74 
75 #define FOR_EACH_BIER_HDR_LEN(_len) \
76  for (_item = BIER_HDR_LEN_64; \
77  _item <= BIER_HDR_LEN_4096; \
78  _item++)
79 
80 /**
81  * Format the header length field
82  */
83 extern u8 *format_bier_hdr_len_id(u8 *s, va_list *ap);
84 
85 /*
86  * convert from prefix len to hdr ID
87  */
88 static inline bier_hdr_len_id_t
90 
91  switch (prfx_len) {
92  case 7:
93  return (BIER_HDR_LEN_64);
94  case 8:
95  return (BIER_HDR_LEN_128);
96  case 9:
97  return (BIER_HDR_LEN_256);
98  case 10:
99  return (BIER_HDR_LEN_512);
100  case 11:
101  return (BIER_HDR_LEN_1024);
102  case 12:
103  return (BIER_HDR_LEN_2048);
104  case 13:
105  return (BIER_HDR_LEN_4096);
106  default:
107  break;
108  }
109 
110  return (BIER_HDR_LEN_INVALID);
111 }
112 
113 static inline bier_hdr_len_id_t
115 {
116  switch (bytes) {
117  case 8:
118  return (BIER_HDR_LEN_64);
119  case 16:
120  return (BIER_HDR_LEN_128);
121  case 32:
122  return (BIER_HDR_LEN_256);
123  case 64:
124  return (BIER_HDR_LEN_512);
125  case 128:
126  return (BIER_HDR_LEN_1024);
127  case 256:
128  return (BIER_HDR_LEN_2048);
129  case 512:
130  return (BIER_HDR_LEN_4096);
131  }
132 
133  return (BIER_HDR_LEN_INVALID);
134 }
135 
136 static inline bier_hdr_len_id_t
138 {
139  switch (bytes) {
140  case 64:
141  return (BIER_HDR_LEN_64);
142  case 128:
143  return (BIER_HDR_LEN_128);
144  case 256:
145  return (BIER_HDR_LEN_256);
146  case 512:
147  return (BIER_HDR_LEN_512);
148  case 1024:
149  return (BIER_HDR_LEN_1024);
150  case 2048:
151  return (BIER_HDR_LEN_2048);
152  case 4096:
153  return (BIER_HDR_LEN_4096);
154  }
155 
156  return (BIER_HDR_LEN_INVALID);
157 }
158 
159 /**
160  * bier_hdr_len_num_buckets_t enumerator
161  **/
171 
172 /**
173  * BIER header protocol payload types
174  **/
175 typedef enum bier_hdr_proto_id_t_ {
185 } __attribute__((packed)) bier_hdr_proto_id_t;
186 
187 #define BIER_HDR_N_PROTO (BIER_HDR_PROTO_OAM + 1)
188 
189 #define BIER_HDR_PROTO_ID_NAMES { \
190  [BIER_HDR_PROTO_INVALID] = "invalid", \
191  [BIER_HDR_PROTO_MPLS_DOWN_STREAM] = "mpls-down-stream", \
192  [BIER_HDR_PROTO_MPLS_UP_STREAM] = "mpls-up-stream", \
193  [BIER_HDR_PROTO_ETHERNET] = "ethernet", \
194  [BIER_HDR_PROTO_IPV4] = "ipv4", \
195  [BIER_HDR_PROTO_IPV6] = "ipv6", \
196  [BIER_HDR_PROTO_VXLAN] = "vxlan", \
197  [BIER_HDR_PROTO_CTRL] = "control-plane", \
198  [BIER_HDR_PROTO_OAM] = "oam", \
199 }
200 
201 #define FOR_EACH_BIER_HDR_PROTO(_proto) \
202  for (_proto = BIER_HDR_PROTO_MPLS_DOWN_STREAM; \
203  _proto <= BIER_HDR_PROTO_OAM; \
204  _proto++)
205 
206 /**
207  * Format the header length field
208  */
209 extern u8 *format_bier_hdr_proto(u8 *s, va_list *ap);
210 
211 /**
212  * Convert from BIER next-hop proto to DPO proto
213  */
214 extern dpo_proto_t bier_hdr_proto_to_dpo(bier_hdr_proto_id_t bproto);
215 
216 /**
217  * BIER header versions
218  **/
219 typedef enum bier_hdr_version_t_ {
221 } __attribute__((packed)) bier_hdr_version_t;
222 
223 /**
224  * bier_hdr_code_t enumerator
225  **/
226 typedef enum bier_hdr_code_t_ {
231 } __attribute__((packed)) bier_hdr_code_t;
232 
233 /**
234  * bier_hdr_oam_sub_code_t enumerator
235  */
239 } __attribute__((packed)) bier_hdr_oam_sub_code_t;
240 
241 /**
242  * bier_hdr_ctrl_sub_code_t enumerator
243  */
247 } __attribute__((packed)) bier_hdr_ctrl_sub_code_t;
248 
249 /**
250  * A bucket is a byte. The byte string is thus always in network byte order.
251  */
253 
254 /**
255  * A BIER Bit-String value of length 64 bits.
256  */
257 typedef struct bier_bit_mask_64_t_ {
258  bier_bit_mask_bucket_t bits[BIER_HDR_BUCKETS_64];
260 
261 /**
262  * A BIER Bit-String value of length 128 bits.
263  */
264 typedef struct bier_bit_mask_128_t_ {
267 
268 /**
269  * A BIER Bit-String value of length 256 bits.
270  */
271 typedef struct bier_bit_mask_256_t_ {
274 
275 /**
276  * A BIER Bit-String value of length 512 bits.
277  */
278 typedef struct bier_bit_mask_512_t_ {
281 
282 /**
283  * A BIER Bit-String value of length 1024 bits.
284  */
285 typedef struct bier_bit_mask_1024_t_ {
288 
289 /**
290  * A BIER Bit-String value of length 2048 bits.
291  */
292 typedef struct bier_bit_mask_2048_t_ {
295 
296 /**
297  * A BIER Bit-String value of length 4096 bits.
298  */
299 typedef struct bier_bit_mask_4096_t_ {
302 
303 
304 /**
305  * 256 bits = 32 bytes
306  */
307 #define BIER_BIT_MASK_NUM_BUCKETS 32
308 #define BIER_BIT_MASK_MAX_BUCKET (BIER_BIT_MASK_NUM_BUCKETS - 1)
309 
310 /**
311  * number of bits in a bucket
312  */
313 #define BIER_BIT_MASK_BITS_PER_BUCKET 8
314 
315 /**
316  * Supported bit-posiotn range
317  */
318 #define BIER_BIT_MASK_MIN_POS (1)
319 
320 /**
321  * A Variable length BitString
322  */
323 typedef struct bier_bit_string_t_ {
324  /**
325  * The length of the string in BYTES
326  */
328 
329  /**
330  * The buckets in the string
331  */
334 
335 /**
336  * A BIER Bit-mask value
337  *
338  * The size of this mask represents this platforms BIER capabilities
339  */
341 
342 /**
343  * A bit positon
344  * as assigned to egress PEs
345  */
346 typedef u32 bier_bp_t;
347 
348 #define BIER_BP_TO_INDEX(bp) (bp - 1)
349 
350 /**
351  * The maximum BP that can be assigned
352  */
353 #define BIER_BP_MAX 0x10000
354 
355 /**
356  * An identifier of the sender of BIER packets
357  * this is the source of the 'tree' - the BFIR
358  */
360 
361 /**
362  * An entropy value in a BIER header
363  */
365 
366 #define BIER_BP_INVALID 0
367 
368 /**
369  * A BIER header of variable length
370  * The encoding follows:
371  * https://tools.ietf.org/html/draft-ietf-bier-mpls-encapsulation-10
372  */
373 typedef struct bier_hdr_t_ {
374  /**
375  * The first nibble is always set to 0101
376  * to ensure that when carried over MPLS, the BIER packet
377  * is not mistaken for IPv[46]:
378  * type: bier_hdr_version_t
379  *
380  * The second nibble is the version - this is 0:
381  * type: bier_hdr_version_t
382  *
383  * The third nibble is header length ID
384  * type: bier_hdr_len_id_t
385  *
386  * The next 20 bits are entropy
387  * An entropy value, calculated by the head end, used
388  * at the head and mid-points for load-balance hash
389  * type: bier_hdr_entropy_t
390  */
392 
393  /**
394  * The second word comprises:
395  * 2 bits of OAM for passive perf measurement
396  * 2 reserved bits;
397  * 6 bits of DSCP
398  * 6 bits for the next-proto field of type;
399  * bier_hdr_proto_id_t
400  */
402 
403  /**
404  * The BFR-ID of the sender
405  */
407 
408  /**
409  * The variable length bit-string
410  */
411  bier_bit_mask_bucket_t bh_bit_string[0];
412 } bier_hdr_t;
413 
414 /**
415  * Format a BIER header
416  */
417 extern u8 *format_bier_hdr(u8 *s, va_list *ap);
418 
419 /**
420  * The BIER Set ID assigned to a BIER table
421  */
423 
424 #define BIER_TABLE_SET_INVALID_ID 0xffffffff
425 
426 /**
427  * The BIER Sub-domain ID assigned to a BIER table
428  */
430 
431 #define BIER_TABLE_SUB_DOMAIN_INVALID_ID 0xffffffff
432 
433 /**
434  * An ID or instance number of a BIER sub-table
435  */
437 
438 /**
439  * Definition of the ID of the BIER main table
440  */
441 #define BIER_ECMP_TABLE_ID_MAIN 0xFFFF
442 
443 /**
444  * The ID of a table
445  */
446 typedef struct bier_table_id_t_ {
447  /**
448  * The SET-ID
449  * The control plane divdies the bit-position space
450  * into sets in the case the max bit-position is greater
451  * than the table's bit-string size
452  */
453  bier_table_set_id_t bti_set;
454 
455  /**
456  * The Sub-Domain-ID
457  * The control plane has the configuration option to specify multiple
458  * domains or topologies.
459  */
460  bier_table_sub_domain_id_t bti_sub_domain;
461 
462  /**
463  * The SUB/ECMP-ID
464  * Constructed by FIB to achieve ECMP between BFR-NBRs
465  */
466  bier_table_ecmp_id_t bti_ecmp;
467 
468  /**
469  * The size of the bit string processed by this table.
470  */
471  bier_hdr_len_id_t bti_hdr_len;
472 
473  /**
474  * The type of the table; SPF or TE, MPLS or IPv6
475  */
476  bier_table_type_t bti_type;
478 
479 /**
480  * Format a BIER table ID
481  */
482 extern u8 *format_bier_table_id(u8 *s, va_list *ap);
483 
484 /**
485  * Compare to BIER table IDs for equality
486  */
487 extern int bier_table_id_cmp(const bier_table_id_t *btid1,
488  const bier_table_id_t *btid2);
489 
490 /**
491  * Conversion functions for the enumerated bit-string length
492  * values, to bit and bytes
493  */
494 extern u32 bier_hdr_len_id_to_num_buckets(bier_hdr_len_id_t id);
495 extern u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id);
496 extern u32 bier_hdr_len_id_to_max_bucket(bier_hdr_len_id_t id);
497 extern u32 bier_hdr_len_id_to_num_bits(bier_hdr_len_id_t id);
498 extern u32 bier_hdr_len_id_to_max_bit(bier_hdr_len_id_t id);
499 extern u32 bier_hdr_len_id_to_prefix_len(bier_hdr_len_id_t id);
500 
501 #define BIER_OK 0
502 #define BIER_ERR_NO_TABLE 1
503 #define BIER_ERR_DUPLICATE_TABLE 2
504 #define BIER_ERR_PANIC 3
505 typedef int bier_rc;
506 
507 /**
508  * The BIER universal 'label'
509  */
511 
512 /**
513  * An invalid value for the BIFT ID
514  * all ones implies a BSL that's invalid.
515  */
516 #define BIER_BIFT_ID_INVALID (~0)
517 
518 extern u16 bier_bfit_id_get_sub_domain(bier_bift_id_t bift_id);
519 extern u16 bier_bfit_id_get_set(bier_bift_id_t bift_id);
520 extern bier_hdr_proto_id_t bier_bift_id_get_bit_string_length(bier_bift_id_t bift_id);
521 
522 /**
523  * Encode a BIFT-ID as per draft-wijnandsxu-bier-non-mpls-bift-encoding-00.txt
524  */
525 extern bier_bift_id_t bier_bift_id_encode(bier_table_set_id_t set,
526  bier_table_sub_domain_id_t sd,
527  bier_hdr_len_id_t bsl);
528 extern void bier_bift_id_decode(bier_bift_id_t id,
529  bier_table_set_id_t *set,
530  bier_table_sub_domain_id_t *sd,
531  bier_hdr_len_id_t *bsl);
532 
533 extern u8* format_bier_bift_id(u8 *s, va_list *ap);
534 
535 #endif /* __BIER_TYPES_H__ */
u32 bier_table_set_id_t
The BIER Set ID assigned to a BIER table.
Definition: bier_types.h:422
enum bier_hdr_oam_sub_code_t_ bier_hdr_oam_sub_code_t
bier_hdr_oam_sub_code_t enumerator
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:391
u32 bier_hdr_len_id_to_max_bit(bier_hdr_len_id_t id)
Definition: bier_types.c:84
struct bier_bit_string_t_ bier_bit_string_t
A Variable length BitString.
enum bier_show_flags_t_ bier_show_flags_t
Flags to control show output.
bier_hdr_proto_id_t_
BIER header protocol payload types.
Definition: bier_types.h:175
u8 * format_bier_table_id(u8 *s, va_list *ap)
Format a BIER table ID.
Definition: bier_types.c:193
A BIER Bit-String value of length 128 bits.
Definition: bier_types.h:264
u32 bier_table_ecmp_id_t
An ID or instance number of a BIER sub-table.
Definition: bier_types.h:436
The ID of a table.
Definition: bier_types.h:446
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
enum bier_hdr_code_t_ bier_hdr_code_t
bier_hdr_code_t enumerator
struct bier_bit_mask_64_t_ bier_bit_mask_64_t
A BIER Bit-String value of length 64 bits.
u16 bbs_len
The length of the string in BYTES.
Definition: bier_types.h:327
A BIER Bit-String value of length 4096 bits.
Definition: bier_types.h:299
A Variable length BitString.
Definition: bier_types.h:323
u16 bier_bfit_id_get_sub_domain(bier_bift_id_t bift_id)
struct bier_bit_mask_128_t_ bier_bit_mask_128_t
A BIER Bit-String value of length 128 bits.
bier_hdr_len_id_t_
bier_hdr_len_id_t enumerator
Definition: bier_types.h:53
bier_table_ecmp_id_t bti_ecmp
The SUB/ECMP-ID Constructed by FIB to achieve ECMP between BFR-NBRs.
Definition: bier_types.h:466
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:453
enum bier_hdr_len_num_buckets_t_ bier_hdr_len_num_buckets_t
bier_hdr_len_num_buckets_t enumerator
static bier_hdr_len_id_t bier_prefix_len_to_hdr_id(u16 prfx_len)
Definition: bier_types.h:89
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
bier_hdr_oam_sub_code_t_
bier_hdr_oam_sub_code_t enumerator
Definition: bier_types.h:236
u32 bier_bp_t
A bit positon as assigned to egress PEs.
Definition: bier_types.h:346
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:401
bier_hdr_len_num_buckets_t_
bier_hdr_len_num_buckets_t enumerator
Definition: bier_types.h:162
u16 bier_bfit_id_get_set(bier_bift_id_t bift_id)
bier_hdr_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:471
struct bier_table_id_t_ bier_table_id_t
The ID of a table.
u16 bier_hdr_src_id_t
An identifier of the sender of BIER packets this is the source of the &#39;tree&#39; - the BFIR...
Definition: bier_types.h:359
u8 * format_bier_hdr_len_id(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:96
u8 * format_bier_hdr_proto(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:104
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
u32 bier_hdr_entropy_t
An entropy value in a BIER header.
Definition: bier_types.h:364
A BIER Bit-String value of length 512 bits.
Definition: bier_types.h:278
struct bier_bit_mask_256_t_ bier_bit_mask_256_t
A BIER Bit-String value of length 256 bits.
bier_bit_mask_bucket_t bits[BIER_HDR_BUCKETS_128]
Definition: bier_types.h:265
struct bier_bit_mask_2048_t_ bier_bit_mask_2048_t
A BIER Bit-String value of length 2048 bits.
bier_hdr_ctrl_sub_code_t_
bier_hdr_ctrl_sub_code_t enumerator
Definition: bier_types.h:244
bier_show_flags_t_
Flags to control show output.
Definition: bier_types.h:25
A BIER Bit-String value of length 64 bits.
Definition: bier_types.h:257
int bier_rc
Definition: bier_types.h:505
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
u32 bier_bift_id_t
The BIER universal &#39;label&#39;.
Definition: bier_types.h:510
struct bier_bit_mask_1024_t_ bier_bit_mask_1024_t
A BIER Bit-String value of length 1024 bits.
struct bier_bit_mask_512_t_ bier_bit_mask_512_t
A BIER Bit-String value of length 512 bits.
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
A BIER Bit-String value of length 2048 bits.
Definition: bier_types.h:292
struct bier_hdr_t_ bier_hdr_t
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
unsigned int u32
Definition: types.h:88
enum bier_hdr_version_t_ bier_hdr_version_t
BIER header versions.
enum bier_hdr_ctrl_sub_code_t_ bier_hdr_ctrl_sub_code_t
bier_hdr_ctrl_sub_code_t enumerator
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
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_bit_mask_bucket_t * bbs_buckets
The buckets in the string.
Definition: bier_types.h:332
bier_hdr_code_t_
bier_hdr_code_t enumerator
Definition: bier_types.h:226
bier_hdr_version_t_
BIER header versions.
Definition: bier_types.h:219
u32 bier_table_sub_domain_id_t
The BIER Sub-domain ID assigned to a BIER table.
Definition: bier_types.h:429
u32 bier_hdr_len_id_to_max_bucket(bier_hdr_len_id_t id)
Definition: bier_types.c:72
struct bier_bit_mask_4096_t_ bier_bit_mask_4096_t
A BIER Bit-String value of length 4096 bits.
unsigned short u16
Definition: types.h:57
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:373
u32 bier_hdr_len_id_to_prefix_len(bier_hdr_len_id_t id)
Definition: bier_types.c:90
bier_table_type_t bti_type
The type of the table; SPF or TE, MPLS or IPv6.
Definition: bier_types.h:476
unsigned char u8
Definition: types.h:56
bier_hdr_proto_id_t bier_bift_id_get_bit_string_length(bier_bift_id_t bift_id)
A BIER Bit-String value of length 1024 bits.
Definition: bier_types.h:285
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:460
u8 * format_bier_hdr(u8 *s, va_list *ap)
Format a BIER header.
Definition: bier_types.c:205
BIER over MPLS for TE.
Definition: bier_types.h:42
static bier_hdr_len_id_t bier_hdr_byte_len_to_id(u32 bytes)
Definition: bier_types.h:114
u8 * format_bier_bift_id(u8 *s, va_list *ap)
Definition: bier_types.c:222
static bier_hdr_len_id_t bier_hdr_bit_len_to_id(u32 bytes)
Definition: bier_types.h:137
u32 bier_hdr_len_id_to_num_bits(bier_hdr_len_id_t id)
Definition: bier_types.c:78
bier_bit_mask_256_t bier_bit_mask_t
A BIER Bit-mask value.
Definition: bier_types.h:340
u8 bier_bit_mask_bucket_t
A bucket is a byte.
Definition: bier_types.h:252
A BIER Bit-String value of length 256 bits.
Definition: bier_types.h:271
BIER over MPLS with SPF.
Definition: bier_types.h:37
u16 bh_bfr_id
The BFR-ID of the sender.
Definition: bier_types.h:406
bier_table_type_t_
Types of BIER tables.
Definition: bier_types.h:33