back to topotato report
topotato coverage report
Current view: top level - lib - agg_table.h (source / functions) Hit Total Coverage
Test: test_bgp_aspath_zero.py::BGPAggregatorZero Lines: 7 42 16.7 %
Date: 2023-02-24 18:36:48 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * agg_table - Aggregate Table Header
       3             :  * Copyright (C) 2018 Cumulus Networks, Inc.
       4             :  *               Donald Sharp
       5             :  *
       6             :  * FRR is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by the
       8             :  * Free Software Foundation; either version 2, or (at your option) any
       9             :  * later version.
      10             :  *
      11             :  * FRR is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with this program; see the file COPYING; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : #ifndef __AGG_TABLE_H__
      21             : #define __AGG_TABLE_H__
      22             : 
      23             : #include "prefix.h"
      24             : #include "table.h"
      25             : 
      26             : #ifdef __cplusplus
      27             : extern "C" {
      28             : #endif
      29             : 
      30             : struct agg_table {
      31             :         struct route_table *route_table;
      32             : 
      33             :         void *info;
      34             : };
      35             : 
      36             : struct agg_node {
      37             :         /*
      38             :          * Caution these must be the very first fields
      39             :          * @see agg_node_to_rnode
      40             :          * @see agg_node_from_rnode
      41             :          */
      42             :         ROUTE_NODE_FIELDS
      43             : 
      44             :         /* Aggregation. */
      45             :         void *aggregate;
      46             : };
      47             : 
      48             : static inline struct route_node *agg_node_to_rnode(struct agg_node *node)
      49             : {
      50             :         return (struct route_node *)node;
      51             : }
      52             : 
      53             : static inline struct agg_node *agg_node_from_rnode(struct route_node *node)
      54             : {
      55             :         return (struct agg_node *)node;
      56             : }
      57             : 
      58           0 : static inline struct agg_node *agg_lock_node(struct agg_node *node)
      59             : {
      60           0 :         return (struct agg_node *)route_lock_node(agg_node_to_rnode(node));
      61             : }
      62             : 
      63           0 : static inline void agg_unlock_node(struct agg_node *node)
      64             : {
      65           0 :         route_unlock_node(agg_node_to_rnode(node));
      66           0 : }
      67             : 
      68           0 : static inline void agg_set_table_info(struct agg_table *atable, void *data)
      69             : {
      70           0 :         atable->info = data;
      71           0 : }
      72             : 
      73           0 : static inline void *agg_get_table_info(struct agg_table *atable)
      74             : {
      75           0 :         return atable->info;
      76             : }
      77             : 
      78           6 : static inline struct agg_node *agg_route_top(struct agg_table *table)
      79             : {
      80           6 :         return agg_node_from_rnode(route_top(table->route_table));
      81             : }
      82             : 
      83           0 : static inline struct agg_node *agg_route_next(struct agg_node *node)
      84             : {
      85           0 :         return agg_node_from_rnode(route_next(agg_node_to_rnode(node)));
      86             : }
      87             : 
      88           0 : static inline struct agg_node *agg_node_get(struct agg_table *table,
      89             :                                             const struct prefix *p)
      90             : {
      91           0 :         return agg_node_from_rnode(route_node_get(table->route_table, p));
      92             : }
      93             : 
      94             : static inline struct agg_node *
      95           0 : agg_node_lookup(const struct agg_table *const table, const struct prefix *p)
      96             : {
      97           0 :         return agg_node_from_rnode(route_node_lookup(table->route_table, p));
      98             : }
      99             : 
     100             : static inline struct agg_node *agg_route_next_until(struct agg_node *node,
     101             :                                                     struct agg_node *limit)
     102             : {
     103             :         struct route_node *rnode;
     104             : 
     105             :         rnode = route_next_until(agg_node_to_rnode(node),
     106             :                                 agg_node_to_rnode(limit));
     107             : 
     108             :         return agg_node_from_rnode(rnode);
     109             : }
     110             : 
     111           0 : static inline struct agg_node *agg_node_match(struct agg_table *table,
     112             :                                               const struct prefix *p)
     113             : {
     114           0 :         return agg_node_from_rnode(route_node_match(table->route_table, p));
     115             : }
     116             : 
     117           0 : static inline struct agg_node *agg_node_parent(struct agg_node *node)
     118             : {
     119           0 :         struct route_node *rn = agg_node_to_rnode(node);
     120             : 
     121           0 :         return agg_node_from_rnode(rn->parent);
     122             : }
     123             : 
     124           0 : static inline struct agg_node *agg_node_left(struct agg_node *node)
     125             : {
     126           0 :         struct route_node *rn = agg_node_to_rnode(node);
     127             : 
     128           0 :         return agg_node_from_rnode(rn->l_left);
     129             : }
     130             : 
     131           0 : static inline struct agg_node *agg_node_right(struct agg_node *node)
     132             : {
     133           0 :         struct route_node *rn = agg_node_to_rnode(node);
     134             : 
     135           0 :         return agg_node_from_rnode(rn->l_right);
     136             : }
     137             : 
     138             : extern struct agg_table *agg_table_init(void);
     139             : 
     140          13 : static inline void agg_table_finish(struct agg_table *atable)
     141             : {
     142          13 :         route_table_finish(atable->route_table);
     143          13 :         atable->route_table = NULL;
     144             : 
     145          13 :         XFREE(MTYPE_TMP, atable);
     146          13 : }
     147             : 
     148           0 : static inline struct agg_node *agg_route_table_top(struct agg_node *node)
     149             : {
     150           0 :         return (struct agg_node *)route_top(node->table);
     151             : }
     152             : 
     153           0 : static inline struct agg_table *agg_get_table(struct agg_node *node)
     154             : {
     155           0 :         return (struct agg_table *)route_table_get_info(node->table);
     156             : }
     157             : 
     158             : static inline const struct prefix *
     159           0 : agg_node_get_prefix(const struct agg_node *node)
     160             : {
     161           0 :         return &node->p;
     162             : }
     163             : 
     164           0 : static inline unsigned int agg_node_get_lock_count(const struct agg_node *node)
     165             : {
     166           0 :         return node->lock;
     167             : }
     168             : 
     169             : #ifdef _FRR_ATTRIBUTE_PRINTFRR
     170             : #pragma FRR printfrr_ext "%pRN"  (struct agg_node *)
     171             : #endif
     172             : 
     173             : #ifdef __cplusplus
     174             : }
     175             : #endif
     176             : 
     177             : #endif

Generated by: LCOV version v1.16-topotato