FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
bier_hdr_inlines.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  * @brief The BIER inline functions acting on the bier header
17  */
18 
19 #ifndef __BIER_HDR_INLINES_H__
20 #define __BIER_HDR_INLINES_H__
21 
22 #include <vppinfra/byte_order.h>
23 #include <vppinfra/string.h>
24 
25 #include <vnet/bier/bier_types.h>
27 #include <vnet/ip/ip6_packet.h>
28 
29 /**
30  * Special Value of the BIER RX interface
31  */
32 #define BIER_RX_ITF (~0 - 1)
33 
34 /**
35  * Mask and shift values for the fields incorporated
36  * into the header's first word
37  */
38 #define BIER_HDR_1ST_NIBBLE_MASK 0xf0000000
39 #define BIER_HDR_VERSION_FIELD_MASK 0x0f000000
40 #define BIER_HDR_LEN_FIELD_MASK 0x00f00000
41 #define BIER_HDR_ENTROPY_FIELD_MASK 0x000fffff
42 
43 #define BIER_HDR_1ST_NIBBLE_SHIFT 28
44 #define BIER_HDR_VERSION_FIELD_SHIFT 24
45 #define BIER_HDR_LEN_FIELD_SHIFT 20
46 #define BIER_HDR_ENTROPY_FIELD_SHIFT 0
47 
48 #define BIER_HDR_1ST_NIBBLE_VALUE 0x5
49 
50 /**
51  * Mask and shift values for fields in the headers trainling word
52  */
53 #define BIER_HDR_PROTO_FIELD_MASK 0x003f
54 #define BIER_HDR_OAM_FIELD_MASK 0xc000
55 #define BIER_HDR_DSCP_FIELD_MASK 0x0fc0
56 #define BIER_HDR_DSCP_FIELD_SHIFT 6
57 #define BIER_HDR_PROTO_FIELD_SHIFT 0
58 #define BIER_HDR_OAM_FIELD_SHIFT 14
59 
60 static inline bier_hdr_version_t
62 {
63  return ((bier_hdr->bh_first_word &
66 }
67 
68 static inline bier_hdr_len_id_t
70 {
71  return ((bier_hdr->bh_first_word &
74 }
75 
76 static inline bier_hdr_entropy_t
78 {
79  return ((bier_hdr->bh_first_word &
82 }
83 
84 static inline void
86 {
90 }
91 
92 static inline u8
94 {
95  return ((hdr->bh_first_word & BIER_HDR_1ST_NIBBLE_MASK) >>
97 }
98 
99 static inline void
102 {
104  hdr->bh_first_word |= (version << BIER_HDR_VERSION_FIELD_SHIFT);
105 }
106 
107 static inline void
110 {
112  hdr->bh_first_word |= (len << BIER_HDR_LEN_FIELD_SHIFT);
113 }
114 
115 static inline void
117  bier_hdr_entropy_t entropy)
118 {
119  entropy = entropy & BIER_HDR_ENTROPY_FIELD_MASK;
121  hdr->bh_first_word |= (entropy << BIER_HDR_ENTROPY_FIELD_SHIFT);
122 }
123 
124 #define BIER_HDR_FIRST_WORD(version, len, entropy) \
125  ((BIER_HDR_1ST_NIBBLE_VALUE << \
126  BIER_HDR_1ST_NIBBLE_SHIFT) | \
127  (version << BIER_HDR_VERSION_FIELD_SHIFT) | \
128  (len << BIER_HDR_LEN_FIELD_SHIFT) | \
129  ((entropy & BIER_HDR_ENTROPY_FIELD_MASK) \
130  << BIER_HDR_ENTROPY_FIELD_SHIFT))
131 
132 static inline void
134 {
135  bier_hdr->bh_first_word = clib_net_to_host_u32(bier_hdr->bh_first_word);
136  bier_hdr->bh_oam_dscp_proto = clib_net_to_host_u16(bier_hdr->bh_oam_dscp_proto);
137  bier_hdr->bh_bfr_id = clib_net_to_host_u16(bier_hdr->bh_bfr_id);
138 }
139 
140 static inline void
142 {
143  bier_hdr->bh_first_word = clib_host_to_net_u32(bier_hdr->bh_first_word);
144  bier_hdr->bh_oam_dscp_proto = clib_host_to_net_u16(bier_hdr->bh_oam_dscp_proto);
145  bier_hdr->bh_bfr_id = clib_host_to_net_u16(bier_hdr->bh_bfr_id);
146 }
147 
148 static inline bier_hdr_src_id_t
150 {
151  return (bier_hdr->bh_bfr_id);
152 }
153 
154 static inline void
156  bier_hdr_src_id_t src_id)
157 {
158  bier_hdr->bh_bfr_id = src_id;
159 }
160 static inline void
162  bier_hdr_proto_id_t proto)
163 {
165  bier_hdr->bh_oam_dscp_proto |= (proto << BIER_HDR_PROTO_FIELD_SHIFT);
166 }
167 
168 static inline bier_hdr_proto_id_t
170 {
171  return ((bier_hdr->bh_oam_dscp_proto & BIER_HDR_PROTO_FIELD_MASK) >>
173 }
174 
175 static inline void
177 {
178  clib_memset(&bier_hdr->bh_bit_string, 0,
180  bier_hdr_get_len_id(bier_hdr)));
181 }
182 
183 static inline void
186  bier_hdr_proto_id_t proto,
188  bier_hdr_entropy_t entropy,
189  bier_bp_t src)
190 {
191  bier_hdr_1st_nibble(bier_hdr);
192  bier_hdr_set_version(bier_hdr, version);
193  bier_hdr_set_len_id(bier_hdr, len);
194  bier_hdr_set_entropy(bier_hdr, entropy);
195  bier_hdr_set_proto_id(bier_hdr, proto);
196  bier_hdr_set_src_id(bier_hdr, src);
197  bier_hdr_clear(bier_hdr);
198 }
199 
200 static inline size_t
202 {
204  bier_hdr_get_len_id(bier_hdr)));
205 }
206 
207 static inline size_t
209 {
210  return (sizeof(bier_hdr_t) +
211  bier_hdr_str_num_bytes(bier_hdr));
212 }
213 
214 static inline void
216  bier_bit_string_t *bit_string)
217 {
218  bit_string->bbs_len = bier_hdr_str_num_bytes(bier_hdr);
219  bit_string->bbs_buckets = bier_hdr->bh_bit_string;
220 }
221 
222 #endif
static void bier_hdr_set_len_id(bier_hdr_t *hdr, bier_hdr_len_id_t len)
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:339
static bier_hdr_len_id_t bier_hdr_get_len_id(const bier_hdr_t *bier_hdr)
Optimized string handling code, including c11-compliant "safe C library" variants.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void bier_hdr_clear(bier_hdr_t *bier_hdr)
u32 bier_hdr_len_id_to_num_bytes(bier_hdr_len_id_t id)
Definition: bier_types.c:66
unsigned char u8
Definition: types.h:56
static void bier_hdr_set_version(bier_hdr_t *hdr, bier_hdr_version_t version)
u16 bbs_len
The length of the string in BYTES.
Definition: bier_types.h:282
#define BIER_HDR_VERSION_FIELD_MASK
A Variable length BitString.
Definition: bier_types.h:278
static void bier_hdr_set_entropy(bier_hdr_t *hdr, bier_hdr_entropy_t entropy)
#define BIER_HDR_ENTROPY_FIELD_MASK
static void bier_hdr_1st_nibble(bier_hdr_t *hdr)
#define BIER_HDR_ENTROPY_FIELD_SHIFT
u32 bier_bp_t
A bit positon as assigned to egress PEs.
Definition: bier_types.h:294
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:349
static void bier_hdr_hton(bier_hdr_t *bier_hdr)
#define BIER_HDR_VERSION_FIELD_SHIFT
static bier_hdr_src_id_t bier_hdr_get_src_id(const bier_hdr_t *bier_hdr)
#define BIER_HDR_LEN_FIELD_MASK
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:307
u32 bier_hdr_entropy_t
An entropy value in a BIER header.
Definition: bier_types.h:312
vl_api_ip4_address_t src
Definition: ipsec_gre.api:38
#define BIER_HDR_1ST_NIBBLE_VALUE
static bier_hdr_entropy_t bier_hdr_get_entropy(const bier_hdr_t *bier_hdr)
static void bier_hdr_set_src_id(bier_hdr_t *bier_hdr, bier_hdr_src_id_t src_id)
u8 len
Definition: ip_types.api:49
#define BIER_HDR_LEN_FIELD_SHIFT
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.
static size_t bier_hdr_str_num_bytes(const bier_hdr_t *bier_hdr)
enum bier_hdr_version_t_ bier_hdr_version_t
BIER header versions.
option version
Definition: memclnt.api:17
bier_bit_mask_bucket_t * bbs_buckets
The buckets in the string.
Definition: bier_types.h:287
static bier_hdr_proto_id_t bier_hdr_get_proto_id(const bier_hdr_t *bier_hdr)
bier_bit_mask_bucket_t bh_bit_string[0]
The variable length bit-string.
Definition: bier_types.h:359
A BIER header of variable length The encoding follows: https://tools.ietf.org/html/draft-ietf-bier-mp...
Definition: bier_types.h:321
#define BIER_HDR_1ST_NIBBLE_SHIFT
static void bier_hdr_set_proto_id(bier_hdr_t *bier_hdr, bier_hdr_proto_id_t proto)
static bier_hdr_version_t bier_hdr_get_version(const bier_hdr_t *bier_hdr)
#define BIER_HDR_1ST_NIBBLE_MASK
Mask and shift values for the fields incorporated into the header&#39;s first word.
static u8 bier_hdr_get_1st_nibble(bier_hdr_t *hdr)
#define BIER_HDR_PROTO_FIELD_SHIFT
#define BIER_HDR_PROTO_FIELD_MASK
Mask and shift values for fields in the headers trainling word.
static size_t bier_hdr_num_bytes(const bier_hdr_t *bier_hdr)
static void bier_bit_string_init_from_hdr(bier_hdr_t *bier_hdr, bier_bit_string_t *bit_string)
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)
static void bier_hdr_init(bier_hdr_t *bier_hdr, bier_hdr_version_t version, bier_hdr_proto_id_t proto, bier_hdr_len_id_t len, bier_hdr_entropy_t entropy, bier_bp_t src)
u16 bh_bfr_id
The BFR-ID of the sender.
Definition: bier_types.h:354