LCOV - code coverage report
Current view: top level - vnet/mfib - mfib_entry_delegate.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 27 39 69.2 %
Date: 2023-10-26 01:39:38 Functions: 5 8 62.5 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 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             : #include <vnet/mfib/mfib_entry_delegate.h>
      17             : #include <vnet/mfib/mfib_entry.h>
      18             : 
      19             : static mfib_entry_delegate_t *
      20      102138 : mfib_entry_delegate_find_i (const mfib_entry_t *mfib_entry,
      21             :                             mfib_entry_delegate_type_t type,
      22             :                             u32 *index)
      23             : {
      24             :     mfib_entry_delegate_t *delegate;
      25             :     int ii;
      26             : 
      27      102138 :     ii = 0;
      28      102138 :     vec_foreach(delegate, mfib_entry->fe_delegates)
      29             :     {
      30          48 :         if (delegate->mfd_type == type)
      31             :         {
      32          48 :             if (NULL != index)
      33           8 :                 *index = ii;
      34             : 
      35          48 :             return (delegate);
      36             :         }
      37             :         else
      38             :         {
      39           0 :             ii++;
      40             :         }
      41             :     }
      42             : 
      43      102090 :     return (NULL);
      44             : }
      45             : 
      46             : mfib_entry_delegate_t *
      47      102130 : mfib_entry_delegate_get (const mfib_entry_t *mfib_entry,
      48             :                          mfib_entry_delegate_type_t type)
      49             : {
      50      102130 :     return (mfib_entry_delegate_find_i(mfib_entry, type, NULL));
      51             : }
      52             : 
      53             : void
      54           8 : mfib_entry_delegate_remove (mfib_entry_t *mfib_entry,
      55             :                             mfib_entry_delegate_type_t type)
      56             : {
      57             :     mfib_entry_delegate_t *fed;
      58           8 :     u32 index = ~0;
      59             : 
      60           8 :     fed = mfib_entry_delegate_find_i(mfib_entry, type, &index);
      61             : 
      62           8 :     ASSERT(NULL != fed);
      63             : 
      64           8 :     vec_del1(mfib_entry->fe_delegates, index);
      65           8 : }
      66             : 
      67             : static int
      68           0 : mfib_entry_delegate_cmp_for_sort (void * v1,
      69             :                                   void * v2)
      70             : {
      71           0 :     mfib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
      72             : 
      73           0 :     return (delegate1->mfd_type - delegate2->mfd_type);
      74             : }
      75             : 
      76             : static void
      77           8 : mfib_entry_delegate_init (mfib_entry_t *mfib_entry,
      78             :                           mfib_entry_delegate_type_t type)
      79             : 
      80             : {
      81          16 :     mfib_entry_delegate_t delegate = {
      82           8 :         .mfd_entry_index = mfib_entry_get_index(mfib_entry),
      83             :         .mfd_type = type,
      84             :     };
      85             : 
      86           8 :     vec_add1(mfib_entry->fe_delegates, delegate);
      87           8 :     vec_sort_with_function(mfib_entry->fe_delegates,
      88             :                            mfib_entry_delegate_cmp_for_sort);
      89           8 : }
      90             : 
      91             : mfib_entry_delegate_t *
      92           8 : mfib_entry_delegate_find_or_add (mfib_entry_t *mfib_entry,
      93             :                                  mfib_entry_delegate_type_t fdt)
      94             : {
      95             :     mfib_entry_delegate_t *delegate;
      96             : 
      97           8 :     delegate = mfib_entry_delegate_get(mfib_entry, fdt);
      98             : 
      99           8 :     if (NULL == delegate)
     100             :     {
     101           8 :         mfib_entry_delegate_init(mfib_entry, fdt);
     102             :     }
     103             : 
     104           8 :     return (mfib_entry_delegate_get(mfib_entry, fdt));
     105             : }
     106             : 
     107             : /**
     108             :  * typedef for printing a delegate
     109             :  */
     110             : typedef u8 * (*mfib_entry_delegate_format_t)(const mfib_entry_delegate_t *fed,
     111             :                                              u8 *s);
     112             : 
     113             : /**
     114             :  * Print a delegate that represents cover tracking
     115             :  */
     116             : static u8 *
     117           0 : mfib_entry_delegate_fmt_covered (const mfib_entry_delegate_t *fed,
     118             :                                  u8 *s)
     119             : {
     120           0 :     s = format(s, "covered:[");
     121           0 :     s = fib_node_children_format(fed->mfd_list, s);
     122           0 :     s = format(s, "]");
     123             : 
     124           0 :     return (s);
     125             : }
     126             : 
     127             : /**
     128             :  * A delegate type to formatter map
     129             :  */
     130             : static mfib_entry_delegate_format_t fed_formatters[] =
     131             : {
     132             :     [MFIB_ENTRY_DELEGATE_COVERED] = mfib_entry_delegate_fmt_covered,
     133             : };
     134             : 
     135             : u8 *
     136           0 : format_mfib_entry_deletegate (u8 * s, va_list * args)
     137             : {
     138             :     mfib_entry_delegate_t *fed;
     139             : 
     140           0 :     fed = va_arg (*args, mfib_entry_delegate_t *);
     141             : 
     142           0 :     return (fed_formatters[fed->mfd_type](fed, s));
     143             : }

Generated by: LCOV version 1.14