]> git.proxmox.com Git - mirror_frr.git/blob - bfdd/event.c
Merge pull request #5812 from pguibert6WIND/bgp_stats_all
[mirror_frr.git] / bfdd / event.c
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 void tv_normalize(struct timeval *tv)
32 {
33 /* Remove seconds part from microseconds. */
34 tv->tv_sec = tv->tv_usec / 1000000;
35 tv->tv_usec = tv->tv_usec % 1000000;
36 }
37
38 void bfd_recvtimer_update(struct bfd_session *bs)
39 {
40 struct timeval tv = {.tv_sec = 0, .tv_usec = bs->detect_TO};
41
42 /* Remove previous schedule if any. */
43 bfd_recvtimer_delete(bs);
44
45 /* Don't add event if peer is deactivated. */
46 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
47 bs->sock == -1)
48 return;
49
50 tv_normalize(&tv);
51 #ifdef BFD_EVENT_DEBUG
52 zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
53 tv.tv_usec);
54 #endif /* BFD_EVENT_DEBUG */
55
56 thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
57 &bs->recvtimer_ev);
58 }
59
60 void bfd_echo_recvtimer_update(struct bfd_session *bs)
61 {
62 struct timeval tv = {.tv_sec = 0, .tv_usec = bs->echo_detect_TO};
63
64 /* Remove previous schedule if any. */
65 bfd_echo_recvtimer_delete(bs);
66
67 /* Don't add event if peer is deactivated. */
68 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
69 bs->sock == -1)
70 return;
71
72 tv_normalize(&tv);
73 #ifdef BFD_EVENT_DEBUG
74 zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
75 tv.tv_usec);
76 #endif /* BFD_EVENT_DEBUG */
77
78 thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
79 &bs->echo_recvtimer_ev);
80 }
81
82 void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
83 {
84 struct timeval tv = {.tv_sec = 0, .tv_usec = jitter};
85
86 /* Remove previous schedule if any. */
87 bfd_xmttimer_delete(bs);
88
89 /* Don't add event if peer is deactivated. */
90 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
91 bs->sock == -1)
92 return;
93
94 tv_normalize(&tv);
95 #ifdef BFD_EVENT_DEBUG
96 zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
97 tv.tv_usec);
98 #endif /* BFD_EVENT_DEBUG */
99
100 thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
101 }
102
103 void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter)
104 {
105 struct timeval tv = {.tv_sec = 0, .tv_usec = jitter};
106
107 /* Remove previous schedule if any. */
108 bfd_echo_xmttimer_delete(bs);
109
110 /* Don't add event if peer is deactivated. */
111 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
112 bs->sock == -1)
113 return;
114
115 tv_normalize(&tv);
116 #ifdef BFD_EVENT_DEBUG
117 zlog_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec,
118 tv.tv_usec);
119 #endif /* BFD_EVENT_DEBUG */
120
121 thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
122 &bs->echo_xmttimer_ev);
123 }
124
125 void bfd_recvtimer_delete(struct bfd_session *bs)
126 {
127 THREAD_OFF(bs->recvtimer_ev);
128 }
129
130 void bfd_echo_recvtimer_delete(struct bfd_session *bs)
131 {
132 THREAD_OFF(bs->echo_recvtimer_ev);
133 }
134
135 void bfd_xmttimer_delete(struct bfd_session *bs)
136 {
137 THREAD_OFF(bs->xmttimer_ev);
138 }
139
140 void bfd_echo_xmttimer_delete(struct bfd_session *bs)
141 {
142 THREAD_OFF(bs->echo_xmttimer_ev);
143 }