back to topotato report
topotato coverage report
Current view: top level - lib - routing_nb_config.c (source / functions) Hit Total Coverage
Test: aggregated run ( view descriptions ) Lines: 24 33 72.7 %
Date: 2023-02-24 19:38:44 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2018        Vmware
       3             :  *                           Vishal Dhingra
       4             :  *
       5             :  * This program is free software; you can redistribute it and/or modify it
       6             :  * under the terms of the GNU General Public License as published by the Free
       7             :  * Software Foundation; either version 2 of the License, or (at your option)
       8             :  * any later version.
       9             :  *
      10             :  * This program is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             :  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      13             :  * more details.
      14             :  *
      15             :  * You should have received a copy of the GNU General Public License along
      16             :  * with this program; see the file COPYING; if not, write to the Free Software
      17             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      18             :  */
      19             : 
      20             : #include <zebra.h>
      21             : 
      22             : #include "northbound.h"
      23             : #include "libfrr.h"
      24             : #include "vrf.h"
      25             : #include "lib_errors.h"
      26             : #include "routing_nb.h"
      27             : 
      28             : 
      29          40 : DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args));
      30             : 
      31             : /*
      32             :  * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
      33             :  */
      34             : 
      35          60 : int routing_control_plane_protocols_control_plane_protocol_create(
      36             :         struct nb_cb_create_args *args)
      37             : {
      38          60 :         struct vrf *vrf;
      39          60 :         const char *vrfname;
      40             : 
      41          60 :         switch (args->event) {
      42          20 :         case NB_EV_VALIDATE:
      43          20 :                 if (hook_call(routing_conf_event, args))
      44             :                         return NB_ERR_VALIDATION;
      45             :                 break;
      46             :         case NB_EV_PREPARE:
      47             :         case NB_EV_ABORT:
      48             :                 break;
      49          20 :         case NB_EV_APPLY:
      50             :                 /*
      51             :                  * If the daemon relies on the VRF pointer stored in this
      52             :                  * dnode, then it should register the dependency between this
      53             :                  * module and the VRF module using
      54             :                  * routing_control_plane_protocols_register_vrf_dependency.
      55             :                  * If such dependency is not registered, then nothing is
      56             :                  * stored in the dnode. If the dependency is registered,
      57             :                  * find the vrf and store the pointer.
      58             :                  */
      59          20 :                 if (nb_node_has_dependency(args->dnode->schema->priv)) {
      60          20 :                         vrfname = yang_dnode_get_string(args->dnode, "./vrf");
      61          20 :                         vrf = vrf_lookup_by_name(vrfname);
      62          20 :                         assert(vrf);
      63          20 :                         nb_running_set_entry(args->dnode, vrf);
      64             :                 }
      65             :                 break;
      66             :         };
      67             : 
      68             :         return NB_OK;
      69             : }
      70             : 
      71           0 : int routing_control_plane_protocols_control_plane_protocol_destroy(
      72             :         struct nb_cb_destroy_args *args)
      73             : {
      74           0 :         if (args->event != NB_EV_APPLY)
      75             :                 return NB_OK;
      76             : 
      77             :         /*
      78             :          * If dependency on VRF module is registered, then VRF
      79             :          * pointer was stored and must be cleared.
      80             :          */
      81           0 :         if (nb_node_has_dependency(args->dnode->schema->priv))
      82           0 :                 nb_running_unset_entry(args->dnode);
      83             : 
      84             :         return NB_OK;
      85             : }
      86             : 
      87           0 : static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
      88             :                                           char *xpath)
      89             : {
      90           0 :         const char *vrf;
      91             : 
      92           0 :         vrf = yang_dnode_get_string(dnode, "./name");
      93             : 
      94           0 :         snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH_VRF, vrf);
      95           0 : }
      96             : 
      97          20 : static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
      98             :                                           char *xpath)
      99             : {
     100          20 :         const char *vrf;
     101             : 
     102          20 :         vrf = yang_dnode_get_string(dnode, "./vrf");
     103             : 
     104          20 :         snprintf(xpath, XPATH_MAXLEN, FRR_VRF_KEY_XPATH, vrf);
     105          20 : }
     106             : 
     107          43 : void routing_control_plane_protocols_register_vrf_dependency(void)
     108             : {
     109          43 :         struct nb_dependency_callbacks cbs;
     110             : 
     111          43 :         cbs.get_dependant_xpath = vrf_to_control_plane_protocol;
     112          43 :         cbs.get_dependency_xpath = control_plane_protocol_to_vrf;
     113             : 
     114          43 :         nb_node_set_dependency_cbs(FRR_VRF_XPATH, FRR_ROUTING_XPATH, &cbs);
     115          43 : }

Generated by: LCOV version v1.16-topotato