back to topotato report
topotato coverage report
Current view: top level - bfdd - event.c (source / functions) Hit Total Coverage
Test: test_pim_bfd.py::PIMBFDTest Lines: 29 48 60.4 %
Date: 2023-02-24 18:39:40 Functions: 6 9 66.7 %

          Line data    Source code
       1             : /*********************************************************************
       2             :  * Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
       3             :  *
       4             :  * This program is free software; you can redistribute it and/or modify it
       5             :  * under the terms of the GNU General Public License as published by the Free
       6             :  * Software Foundation; either version 2 of the License, or (at your option)
       7             :  * any later version.
       8             :  *
       9             :  * This program is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      11             :  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      12             :  * more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License along
      15             :  * with this program; see the file COPYING; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  *
      18             :  * event.c: implements the BFD loop event handlers.
      19             :  *
      20             :  * Authors
      21             :  * -------
      22             :  * Rafael Zalamena <rzalamena@opensourcerouting.org>
      23             :  */
      24             : 
      25             : #include <zebra.h>
      26             : 
      27             : #include "bfd.h"
      28             : 
      29             : void tv_normalize(struct timeval *tv);
      30             : 
      31          91 : void tv_normalize(struct timeval *tv)
      32             : {
      33             :         /* Remove seconds part from microseconds. */
      34          91 :         tv->tv_sec = tv->tv_usec / 1000000;
      35          91 :         tv->tv_usec = tv->tv_usec % 1000000;
      36           0 : }
      37             : 
      38          45 : void bfd_recvtimer_update(struct bfd_session *bs)
      39             : {
      40          45 :         struct timeval tv = {.tv_sec = 0, .tv_usec = bs->detect_TO};
      41             : 
      42             :         /* Remove previous schedule if any. */
      43          90 :         bfd_recvtimer_delete(bs);
      44             : 
      45             :         /* Don't add event if peer is deactivated. */
      46          90 :         if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
      47          45 :             bs->sock == -1)
      48           0 :                 return;
      49             : 
      50          45 :         tv_normalize(&tv);
      51             : 
      52          45 :         thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
      53             :                             &bs->recvtimer_ev);
      54             : }
      55             : 
      56           0 : void bfd_echo_recvtimer_update(struct bfd_session *bs)
      57             : {
      58           0 :         struct timeval tv = {.tv_sec = 0, .tv_usec = bs->echo_detect_TO};
      59             : 
      60             :         /* Remove previous schedule if any. */
      61           0 :         bfd_echo_recvtimer_delete(bs);
      62             : 
      63             :         /* Don't add event if peer is deactivated. */
      64           0 :         if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
      65           0 :             bs->sock == -1)
      66           0 :                 return;
      67             : 
      68           0 :         tv_normalize(&tv);
      69             : 
      70           0 :         thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
      71             :                             &bs->echo_recvtimer_ev);
      72             : }
      73             : 
      74          46 : void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
      75             : {
      76          46 :         struct timeval tv = {.tv_sec = 0, .tv_usec = jitter};
      77             : 
      78             :         /* Remove previous schedule if any. */
      79          92 :         bfd_xmttimer_delete(bs);
      80             : 
      81             :         /* Don't add event if peer is deactivated. */
      82          92 :         if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
      83          46 :             bs->sock == -1)
      84           0 :                 return;
      85             : 
      86          46 :         tv_normalize(&tv);
      87             : 
      88          46 :         thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
      89             : }
      90             : 
      91           0 : void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
      92             : {
      93           0 :         struct timeval tv = {.tv_sec = 0, .tv_usec = jitter};
      94             : 
      95             :         /* Remove previous schedule if any. */
      96           0 :         bfd_echo_xmttimer_delete(bs);
      97             : 
      98             :         /* Don't add event if peer is deactivated. */
      99           0 :         if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
     100           0 :             bs->sock == -1)
     101           0 :                 return;
     102             : 
     103           0 :         tv_normalize(&tv);
     104             : 
     105           0 :         thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
     106             :                             &bs->echo_xmttimer_ev);
     107             : }
     108             : 
     109          53 : void bfd_recvtimer_delete(struct bfd_session *bs)
     110             : {
     111          53 :         THREAD_OFF(bs->recvtimer_ev);
     112           8 : }
     113             : 
     114           8 : void bfd_echo_recvtimer_delete(struct bfd_session *bs)
     115             : {
     116           8 :         THREAD_OFF(bs->echo_recvtimer_ev);
     117           8 : }
     118             : 
     119          54 : void bfd_xmttimer_delete(struct bfd_session *bs)
     120             : {
     121          54 :         THREAD_OFF(bs->xmttimer_ev);
     122           8 : }
     123             : 
     124           8 : void bfd_echo_xmttimer_delete(struct bfd_session *bs)
     125             : {
     126           8 :         THREAD_OFF(bs->echo_xmttimer_ev);
     127           8 : }

Generated by: LCOV version v1.16-topotato