FD.io VPP  v21.06-3-gbb25fbf28
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 training 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 {
105 }
106 
107 static inline void
110 {
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
163 {
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
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
bier_hdr_hton
static void bier_hdr_hton(bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:141
bier_hdr_t_::bh_oam_dscp_proto
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
bier_hdr_src_id_t
u16 bier_hdr_src_id_t
An identifier of the sender of BIER packets this is the source of the 'tree' - the BFIR.
Definition: bier_types.h:307
string.h
bier_hdr_set_src_id
static void bier_hdr_set_src_id(bier_hdr_t *bier_hdr, bier_hdr_src_id_t src_id)
Definition: bier_hdr_inlines.h:155
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
BIER_HDR_LEN_FIELD_SHIFT
#define BIER_HDR_LEN_FIELD_SHIFT
Definition: bier_hdr_inlines.h:45
byte_order.h
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_bp_t
u32 bier_bp_t
A bit positon as assigned to egress PEs.
Definition: bier_types.h:294
BIER_HDR_1ST_NIBBLE_MASK
#define BIER_HDR_1ST_NIBBLE_MASK
Mask and shift values for the fields incorporated into the header's first word.
Definition: bier_hdr_inlines.h:38
bier_hdr_get_1st_nibble
static u8 bier_hdr_get_1st_nibble(bier_hdr_t *hdr)
Definition: bier_hdr_inlines.h:93
bier_hdr_ntoh
static void bier_hdr_ntoh(bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:133
bier_hdr_str_num_bytes
static size_t bier_hdr_str_num_bytes(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:201
ip6_packet.h
bier_bit_string_t_::bbs_len
u16 bbs_len
The length of the string in BYTES.
Definition: bier_types.h:282
BIER_HDR_PROTO_FIELD_SHIFT
#define BIER_HDR_PROTO_FIELD_SHIFT
Definition: bier_hdr_inlines.h:57
bier_hdr_set_proto_id
static void bier_hdr_set_proto_id(bier_hdr_t *bier_hdr, bier_hdr_proto_id_t proto)
Definition: bier_hdr_inlines.h:161
len
u8 len
Definition: ip_types.api:103
BIER_HDR_PROTO_FIELD_MASK
#define BIER_HDR_PROTO_FIELD_MASK
Mask and shift values for fields in the headers training word.
Definition: bier_hdr_inlines.h:53
BIER_HDR_1ST_NIBBLE_SHIFT
#define BIER_HDR_1ST_NIBBLE_SHIFT
Definition: bier_hdr_inlines.h:43
bier_hdr_set_len_id
static void bier_hdr_set_len_id(bier_hdr_t *hdr, bier_hdr_len_id_t len)
Definition: bier_hdr_inlines.h:108
bier_hdr_num_bytes
static size_t bier_hdr_num_bytes(const bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:208
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_bit_string_init_from_hdr
static void bier_bit_string_init_from_hdr(bier_hdr_t *bier_hdr, bier_bit_string_t *bit_string)
Definition: bier_hdr_inlines.h:215
src
vl_api_address_t src
Definition: gre.api:54
bier_bit_string.h
bier_hdr_proto_id_t
enum bier_hdr_proto_id_t_ bier_hdr_proto_id_t
BIER header protocol payload types.
bier_hdr_len_id_t
enum bier_hdr_len_id_t_ bier_hdr_len_id_t
bier_hdr_len_id_t enumerator
bier_hdr_clear
static void bier_hdr_clear(bier_hdr_t *bier_hdr)
Definition: bier_hdr_inlines.h:176
bier_hdr_init
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)
Definition: bier_hdr_inlines.h:184
BIER_HDR_VERSION_FIELD_MASK
#define BIER_HDR_VERSION_FIELD_MASK
Definition: bier_hdr_inlines.h:39
bier_hdr_version_t
enum bier_hdr_version_t_ bier_hdr_version_t
BIER header versions.
version
option version
Definition: sample.api:19
bier_hdr_entropy_t
u32 bier_hdr_entropy_t
An entropy value in a BIER header.
Definition: bier_types.h:312
bier_types.h
bier_hdr_set_entropy
static void bier_hdr_set_entropy(bier_hdr_t *hdr, bier_hdr_entropy_t entropy)
Definition: bier_hdr_inlines.h:116
bier_bit_string_t_::bbs_buckets
bier_bit_mask_bucket_t * bbs_buckets
The buckets in the string.
Definition: bier_types.h:287
BIER_HDR_ENTROPY_FIELD_MASK
#define BIER_HDR_ENTROPY_FIELD_MASK
Definition: bier_hdr_inlines.h:41
BIER_HDR_VERSION_FIELD_SHIFT
#define BIER_HDR_VERSION_FIELD_SHIFT
Definition: bier_hdr_inlines.h:44
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
BIER_HDR_LEN_FIELD_MASK
#define BIER_HDR_LEN_FIELD_MASK
Definition: bier_hdr_inlines.h:40
u8
unsigned char u8
Definition: types.h:56
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_t_::bh_bit_string
bier_bit_mask_bucket_t bh_bit_string[0]
The variable length bit-string.
Definition: bier_types.h:359
bier_hdr_t_::bh_first_word
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
bier_hdr_set_version
static void bier_hdr_set_version(bier_hdr_t *hdr, bier_hdr_version_t version)
Definition: bier_hdr_inlines.h:100
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
proto
vl_api_ip_proto_t proto
Definition: acl_types.api:51
bier_hdr_t_::bh_bfr_id
u16 bh_bfr_id
The BFR-ID of the sender.
Definition: bier_types.h:354
bier_bit_string_t_
A Variable length BitString.
Definition: bier_types.h:278
BIER_HDR_1ST_NIBBLE_VALUE
#define BIER_HDR_1ST_NIBBLE_VALUE
Definition: bier_hdr_inlines.h:48
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_1st_nibble
static void bier_hdr_1st_nibble(bier_hdr_t *hdr)
Definition: bier_hdr_inlines.h:85
BIER_HDR_ENTROPY_FIELD_SHIFT
#define BIER_HDR_ENTROPY_FIELD_SHIFT
Definition: bier_hdr_inlines.h:46
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