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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
18 #include <vnet/bier/bier_types.h>
19 #include <vnet/bier/bier_bit_string.h>
22 * the first bit in the first byte is bit position 1.
23 * bit position 0 is not valid
25 #define BIER_GET_STRING_POS(_bp, _byte, _bit, _str) \
28 _byte = ((BIER_BBS_LEN_TO_BUCKETS((_str)->bbs_len) - 1 ) - \
29 (_bp / BIER_BIT_MASK_BITS_PER_BUCKET)); \
30 _bit = _bp % BIER_BIT_MASK_BITS_PER_BUCKET; \
34 bier_bit_pos_is_valid (bier_bp_t bp, const bier_bit_string_t *bbs)
36 if (!((bp <= BIER_BBS_LEN_TO_BITS((bbs)->bbs_len)) &&
44 * Validate a bit poistion
46 #define BIER_BIT_POS_IS_VALID(_bp, _str) \
48 if (!bier_bit_pos_is_valid(_bp, _str)) return; \
52 bier_bit_string_set_bit (bier_bit_string_t *bit_string,
55 bier_bit_mask_bucket_t bmask;
56 u16 byte_pos, bit_pos;
58 BIER_BIT_POS_IS_VALID(bp, bit_string);
59 BIER_GET_STRING_POS(bp, byte_pos, bit_pos, bit_string);
61 bmask = ((bier_bit_mask_bucket_t)1 << bit_pos);
62 bit_string->bbs_buckets[byte_pos] |= bmask;
66 bier_bit_string_clear_bit (bier_bit_string_t *bit_string,
69 u16 byte_pos, bit_pos;
71 BIER_BIT_POS_IS_VALID(bp, bit_string);
72 BIER_GET_STRING_POS(bp, byte_pos, bit_pos, bit_string);
74 bit_string->bbs_buckets[byte_pos] &= ~(1 << bit_pos);
78 format_bier_bit_string (u8 * string,
81 bier_bit_string_t *bs = va_arg(*args, bier_bit_string_t *);
82 int leading_marker = 0;
83 int suppress_zero = 0;
87 ptr = (u32 *)bs->bbs_buckets;
89 string = format(string, "%d#", (8 * bs->bbs_len));
91 for (index = 0; index < (bs->bbs_len/4); index++) {
93 if (!leading_marker) {
96 string = format(string, ":");
99 if (suppress_zero) continue;
104 string = format(string, "%s%X", index ? ":" : "",
105 clib_net_to_host_u32(ptr[index]));