LCOV - code coverage report
Current view: top level - vnet/bier - bier_hdr_inlines.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 68 68 100.0 %
Date: 2023-07-05 22:20:52 Functions: 18 18 100.0 %

          Line data    Source code
       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>
      26             : #include <vnet/bier/bier_bit_string.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
      61        1515 : bier_hdr_get_version (const bier_hdr_t *bier_hdr)
      62             : {
      63        1515 :     return ((bier_hdr->bh_first_word &
      64        1515 :              BIER_HDR_VERSION_FIELD_MASK) >>
      65             :             BIER_HDR_VERSION_FIELD_SHIFT);
      66             : }
      67             : 
      68             : static inline bier_hdr_len_id_t
      69        2752 : bier_hdr_get_len_id (const bier_hdr_t *bier_hdr)
      70             : {
      71        2752 :     return ((bier_hdr->bh_first_word &
      72        2752 :              BIER_HDR_LEN_FIELD_MASK) >>
      73             :             BIER_HDR_LEN_FIELD_SHIFT);
      74             : }
      75             : 
      76             : static inline bier_hdr_entropy_t
      77         480 : bier_hdr_get_entropy (const bier_hdr_t *bier_hdr)
      78             : {
      79         480 :     return ((bier_hdr->bh_first_word &
      80         480 :              BIER_HDR_ENTROPY_FIELD_MASK) >>
      81             :             BIER_HDR_ENTROPY_FIELD_SHIFT);
      82             : }
      83             : 
      84             : static inline void
      85           7 : bier_hdr_1st_nibble (bier_hdr_t *hdr)
      86             : {
      87           7 :     hdr->bh_first_word &= ~(BIER_HDR_1ST_NIBBLE_MASK);
      88           7 :     hdr->bh_first_word |= (BIER_HDR_1ST_NIBBLE_VALUE <<
      89             :                            BIER_HDR_1ST_NIBBLE_SHIFT);
      90           7 : }
      91             : 
      92             : static inline u8
      93         342 : bier_hdr_get_1st_nibble (bier_hdr_t *hdr)
      94             : {
      95         342 :     return ((hdr->bh_first_word & BIER_HDR_1ST_NIBBLE_MASK) >>
      96             :             BIER_HDR_1ST_NIBBLE_SHIFT);
      97             : }
      98             : 
      99             : static inline void
     100           7 : bier_hdr_set_version (bier_hdr_t *hdr,
     101             :                       bier_hdr_version_t version)
     102             : {
     103           7 :     hdr->bh_first_word &= ~(BIER_HDR_VERSION_FIELD_MASK);
     104           7 :     hdr->bh_first_word |= (version << BIER_HDR_VERSION_FIELD_SHIFT);
     105           7 : }
     106             : 
     107             : static inline void
     108           7 : bier_hdr_set_len_id (bier_hdr_t *hdr,
     109             :                      bier_hdr_len_id_t len)
     110             : {
     111           7 :     hdr->bh_first_word &= ~(BIER_HDR_LEN_FIELD_MASK);
     112           7 :     hdr->bh_first_word |= (len << BIER_HDR_LEN_FIELD_SHIFT);
     113           7 : }
     114             : 
     115             : static inline void
     116           7 : bier_hdr_set_entropy (bier_hdr_t *hdr,
     117             :                       bier_hdr_entropy_t entropy)
     118             : {
     119           7 :     entropy = entropy & BIER_HDR_ENTROPY_FIELD_MASK;
     120           7 :     hdr->bh_first_word &= ~(BIER_HDR_ENTROPY_FIELD_MASK);
     121           7 :     hdr->bh_first_word |= (entropy << BIER_HDR_ENTROPY_FIELD_SHIFT);
     122           7 : }
     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
     133        1834 : bier_hdr_ntoh (bier_hdr_t *bier_hdr)
     134             : {
     135        1834 :     bier_hdr->bh_first_word = clib_net_to_host_u32(bier_hdr->bh_first_word);
     136        1834 :     bier_hdr->bh_oam_dscp_proto = clib_net_to_host_u16(bier_hdr->bh_oam_dscp_proto);
     137        1834 :     bier_hdr->bh_bfr_id = clib_net_to_host_u16(bier_hdr->bh_bfr_id);
     138        1834 : }
     139             : 
     140             : static inline void
     141        1049 : bier_hdr_hton (bier_hdr_t *bier_hdr)
     142             : {
     143        1049 :     bier_hdr->bh_first_word = clib_host_to_net_u32(bier_hdr->bh_first_word);
     144        1049 :     bier_hdr->bh_oam_dscp_proto = clib_host_to_net_u16(bier_hdr->bh_oam_dscp_proto);
     145        1049 :     bier_hdr->bh_bfr_id = clib_host_to_net_u16(bier_hdr->bh_bfr_id);
     146        1049 : }
     147             : 
     148             : static inline bier_hdr_src_id_t
     149         632 : bier_hdr_get_src_id (const bier_hdr_t *bier_hdr)
     150             : {
     151         632 :     return (bier_hdr->bh_bfr_id);
     152             : }
     153             : 
     154             : static inline void
     155           7 : bier_hdr_set_src_id (bier_hdr_t *bier_hdr,
     156             :                      bier_hdr_src_id_t src_id)
     157             : {
     158           7 :     bier_hdr->bh_bfr_id = src_id;
     159           7 : }
     160             : static inline void
     161           7 : bier_hdr_set_proto_id (bier_hdr_t *bier_hdr,
     162             :                        bier_hdr_proto_id_t proto)
     163             : {
     164           7 :     bier_hdr->bh_oam_dscp_proto &= ~(BIER_HDR_PROTO_FIELD_MASK);
     165           7 :     bier_hdr->bh_oam_dscp_proto |= (proto << BIER_HDR_PROTO_FIELD_SHIFT);
     166           7 : }
     167             : 
     168             : static inline bier_hdr_proto_id_t
     169         480 : bier_hdr_get_proto_id (const bier_hdr_t *bier_hdr)
     170             : {
     171         480 :     return ((bier_hdr->bh_oam_dscp_proto & BIER_HDR_PROTO_FIELD_MASK) >>
     172             :             BIER_HDR_PROTO_FIELD_SHIFT);
     173             : }
     174             : 
     175             : static inline void
     176           7 : bier_hdr_clear (bier_hdr_t *bier_hdr)
     177             : {
     178           7 :     clib_memset(&bier_hdr->bh_bit_string, 0,
     179             :            bier_hdr_len_id_to_num_buckets(
     180             :                bier_hdr_get_len_id(bier_hdr)));
     181           7 : }
     182             : 
     183             : static inline void
     184           7 : bier_hdr_init (bier_hdr_t *bier_hdr,
     185             :                bier_hdr_version_t version,
     186             :                bier_hdr_proto_id_t proto,
     187             :                bier_hdr_len_id_t len,
     188             :                bier_hdr_entropy_t entropy,
     189             :                bier_bp_t src)
     190             : {
     191           7 :     bier_hdr_1st_nibble(bier_hdr);
     192           7 :     bier_hdr_set_version(bier_hdr, version);
     193           7 :     bier_hdr_set_len_id(bier_hdr, len);
     194           7 :     bier_hdr_set_entropy(bier_hdr, entropy);
     195           7 :     bier_hdr_set_proto_id(bier_hdr, proto);
     196           7 :     bier_hdr_set_src_id(bier_hdr, src);
     197           7 :     bier_hdr_clear(bier_hdr);
     198           7 : }
     199             : 
     200             : static inline size_t
     201        1042 : bier_hdr_str_num_bytes (const bier_hdr_t *bier_hdr)
     202             : {
     203        1042 :     return (bier_hdr_len_id_to_num_bytes(
     204        1042 :                 bier_hdr_get_len_id(bier_hdr)));
     205             : }
     206             : 
     207             : static inline size_t
     208             : bier_hdr_num_bytes (const bier_hdr_t *bier_hdr)
     209             : {
     210             :     return (sizeof(bier_hdr_t) +
     211             :             bier_hdr_str_num_bytes(bier_hdr));
     212             : }
     213             : 
     214             : static inline void
     215        1042 : bier_bit_string_init_from_hdr (bier_hdr_t *bier_hdr,
     216             :                                bier_bit_string_t *bit_string)
     217             : {
     218        1042 :     bit_string->bbs_len = bier_hdr_str_num_bytes(bier_hdr);
     219        1042 :     bit_string->bbs_buckets = bier_hdr->bh_bit_string;
     220        1042 : }
     221             : 
     222             : #endif

Generated by: LCOV version 1.14