LCOV - code coverage report
Current view: top level - vnet/dpo - replicate_dpo.h (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 8 8 100.0 %
Date: 2023-10-26 01:39:38 Functions: 2 2 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
      17             :  *
      18             :  */
      19             : 
      20             : #ifndef __REPLICATE_DPO_H__
      21             : #define __REPLICATE_DPO_H__
      22             : 
      23             : #include <vlib/vlib.h>
      24             : #include <vnet/ip/lookup.h>
      25             : #include <vnet/dpo/dpo.h>
      26             : #include <vnet/dpo/load_balance.h>
      27             : #include <vnet/fib/fib_types.h>
      28             : #include <vnet/mpls/mpls_types.h>
      29             : 
      30             : /**
      31             :  * replicate main
      32             :  */
      33             : typedef struct replicate_main_t_
      34             : {
      35             :     vlib_combined_counter_main_t repm_counters;
      36             : 
      37             :     /* per-cpu vector of cloned packets */
      38             :     u32 **clones;
      39             : } replicate_main_t;
      40             : 
      41             : extern replicate_main_t replicate_main;
      42             : 
      43             : /**
      44             :  * The number of buckets that a replicate object can have
      45             :  * This must not overflow the rep_n_buckets field
      46             :  */
      47             : #define REP_MAX_BUCKETS 1024
      48             : 
      49             : /**
      50             :  * The number of buckets that a load-balance object can have and still
      51             :  * fit in one cache-line
      52             :  */
      53             : #define REP_NUM_INLINE_BUCKETS 4
      54             : 
      55             : /**
      56             :  * Flags on the replicate DPO
      57             :  */
      58             : typedef enum replicate_flags_t_
      59             : {
      60             :     REPLICATE_FLAGS_NONE,
      61             :     REPLICATE_FLAGS_HAS_LOCAL,
      62             : } __clib_packed replicate_flags_t;
      63             : 
      64             : /**
      65             :  * The FIB DPO provieds;
      66             :  *  - load-balancing over the next DPOs in the chain/graph
      67             :  *  - per-route counters
      68             :  */
      69             : typedef struct replicate_t_ {
      70             :     /**
      71             :      * required for pool_get_aligned.
      72             :      *  memebers used in the switch path come first!
      73             :      */
      74             :     CLIB_CACHE_LINE_ALIGN_MARK(cacheline0);
      75             : 
      76             :     /**
      77             :      * number of buckets in the replicate.
      78             :      */
      79             :     u16 rep_n_buckets;
      80             : 
      81             :    /**
      82             :      * The protocol of packets that traverse this REP.
      83             :      * need in combination with the flow hash config to determine how to hash.
      84             :      * u8.
      85             :      */
      86             :     dpo_proto_t rep_proto;
      87             : 
      88             :     /**
      89             :      * Flags specifying the replicate properties/behaviour
      90             :      */
      91             :     replicate_flags_t rep_flags;
      92             : 
      93             :     /**
      94             :      * The number of locks, which is approximately the number of users,
      95             :      * of this load-balance.
      96             :      * Load-balance objects of via-entries are heavily shared by recursives,
      97             :      * so the lock count is a u32.
      98             :      */
      99             :     u32 rep_locks;
     100             : 
     101             :     /**
     102             :      * Vector of buckets containing the next DPOs, sized as repo_num
     103             :      */
     104             :     dpo_id_t *rep_buckets;
     105             : 
     106             :     /**
     107             :      * The rest of the cache line is used for buckets. In the common case
     108             :      * where there there are less than 4 buckets, then the buckets are
     109             :      * on the same cachlie and we save ourselves a pointer dereferance in 
     110             :      * the data-path.
     111             :      */
     112             :     dpo_id_t rep_buckets_inline[REP_NUM_INLINE_BUCKETS];
     113             : } replicate_t;
     114             : 
     115             : STATIC_ASSERT(sizeof(replicate_t) <= CLIB_CACHE_LINE_BYTES,
     116             :               "A replicate object size exceeds one cacheline");
     117             : STATIC_ASSERT (REP_MAX_BUCKETS <= CLIB_U16_MAX,
     118             :                "Too many buckets for replicate object");
     119             : 
     120             : /**
     121             :  * Flags controlling load-balance formatting/display
     122             :  */
     123             : typedef enum replicate_format_flags_t_ {
     124             :     REPLICATE_FORMAT_NONE,
     125             :     REPLICATE_FORMAT_DETAIL = (1 << 0),
     126             : } replicate_format_flags_t;
     127             : 
     128             : extern index_t replicate_create(u32 num_buckets,
     129             :                                 dpo_proto_t rep_proto);
     130             : extern void replicate_multipath_update(
     131             :     const dpo_id_t *dpo,
     132             :     load_balance_path_t *next_hops);
     133             : 
     134             : extern void replicate_set_bucket(index_t repi,
     135             :                                  u32 bucket,
     136             :                                  const dpo_id_t *next);
     137             : 
     138             : extern u8* format_replicate(u8 * s, va_list * args);
     139             : 
     140             : extern const dpo_id_t *replicate_get_bucket(index_t repi,
     141             :                                             u32 bucket);
     142             : extern int replicate_is_drop(const dpo_id_t *dpo);
     143             : 
     144             : extern u16 replicate_n_buckets(index_t repi);
     145             : 
     146             : extern index_t replicate_dup(replicate_flags_t flags,
     147             :                              index_t repi);
     148             : 
     149             : /**
     150             :  * The encapsulation breakages are for fast DP access
     151             :  */
     152             : extern replicate_t *replicate_pool;
     153             : static inline replicate_t*
     154      127073 : replicate_get (index_t repi)
     155             : {
     156      127073 :     repi &= ~MPLS_IS_REPLICATE;
     157      127073 :     return (pool_elt_at_index(replicate_pool, repi));
     158             : }
     159             : 
     160             : #define REP_HAS_INLINE_BUCKETS(_rep)            \
     161             :     ((_rep)->rep_n_buckets <= REP_NUM_INLINE_BUCKETS)
     162             : 
     163             : static inline const dpo_id_t *
     164       10931 : replicate_get_bucket_i (const replicate_t *rep,
     165             :                            u32 bucket)
     166             : {
     167       10931 :     ASSERT(bucket < rep->rep_n_buckets);
     168             : 
     169       10931 :     if (PREDICT_TRUE(REP_HAS_INLINE_BUCKETS(rep)))
     170             :     {
     171       10294 :         return (&rep->rep_buckets_inline[bucket]);
     172             :     }
     173             :     else
     174             :     {
     175         637 :         return (&rep->rep_buckets[bucket]);
     176             :     }
     177             : }
     178             : 
     179             : extern void replicate_module_init(void);
     180             : 
     181             : #endif

Generated by: LCOV version 1.14