FD.io VPP  v19.01.3-6-g70449b9b9
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
181  bier_table_set_id_t *set,
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  }
u32 bier_table_set_id_t
The BIER Set ID assigned to a BIER table.
Definition: bier_types.h:370
#define BIER_HDR_LEN_IDS
Definition: bier_types.h:69
static bier_hdr_len_id_t bier_hdr_get_len_id(const bier_hdr_t *bier_hdr)
u8 * format_bier_table_id(u8 *s, va_list *ap)
Format a BIER table ID.
Definition: bier_types.c:193
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
static const u16 bier_hdr_len_num_buckets[]
Definition: bier_types.c:26
u8 * format_bier_bift_id(u8 *s, va_list *ap)
Definition: bier_types.c:222
u32 bier_hdr_len_id_to_max_bit(bier_hdr_len_id_t id)
Definition: bier_types.c:84
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
The ID of a table.
Definition: bier_types.h:394
unsigned char u8
Definition: types.h:56
u32 bier_hdr_len_id_to_max_bucket(bier_hdr_len_id_t id)
Definition: bier_types.c:72
u32 bier_hdr_len_id_to_prefix_len(bier_hdr_len_id_t id)
Definition: bier_types.c:90
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
static const char *const bier_hdr_len_id_names[]
Definition: bier_types.c:23
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_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
unsigned int u32
Definition: types.h:88
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u32 bier_hdr_len_id_to_num_bits(bier_hdr_len_id_t id)
Definition: bier_types.c:78
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_len_id_t bti_hdr_len
The size of the bit string processed by this table.
Definition: bier_types.h:419
static bier_hdr_src_id_t bier_hdr_get_src_id(const bier_hdr_t *bier_hdr)
unsigned short u16
Definition: types.h:57
static bier_hdr_entropy_t bier_hdr_get_entropy(const bier_hdr_t *bier_hdr)
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
#define BIER_HDR_PROTO_ID_NAMES
Definition: bier_types.h:194
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
enum bier_hdr_len_id_t_ bier_hdr_len_id_t
bier_hdr_len_id_t enumerator
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
u32 bier_bift_id_t
The BIER universal &#39;label&#39;.
Definition: bier_types.h:458
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
#define ASSERT(truth)
static bier_hdr_proto_id_t bier_hdr_get_proto_id(const bier_hdr_t *bier_hdr)
u32 bier_table_sub_domain_id_t
The BIER Sub-domain ID assigned to a BIER table.
Definition: bier_types.h:377
u8 * format_bier_hdr_len_id(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:96
#define DPO_PROTO_NUM
Definition: dpo.h:70
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
bier_table_type_t bti_type
The type of the table; SPF or TE, MPLS or IPv6.
Definition: bier_types.h:424
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
u8 * format_bier_hdr(u8 *s, va_list *ap)
Format a BIER header.
Definition: bier_types.c:205
static const u16 bier_hdr_len_num_bits[]
Definition: bier_types.c:37
static bier_hdr_version_t bier_hdr_get_version(const bier_hdr_t *bier_hdr)
u32 id
Definition: udp.api:45
static const u16 bier_hdr_len_prefix_len[]
Definition: bier_types.c:48
static u8 bier_hdr_get_1st_nibble(bier_hdr_t *hdr)
static const char *const bier_hdr_proto_names[]
Definition: bier_types.c:24
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)
u8 * format_bier_hdr_proto(u8 *s, va_list *ap)
Format the header length field.
Definition: bier_types.c:104