]>
Commit | Line | Data |
---|---|---|
e9e2c950 RZ |
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 | ||
744f824a RZ |
42 | /* Remove previous schedule if any. */ |
43 | bfd_recvtimer_delete(bs); | |
44 | ||
e9e2c950 | 45 | /* Don't add event if peer is deactivated. */ |
d245e522 RZ |
46 | if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
47 | bs->sock == -1) | |
e9e2c950 RZ |
48 | return; |
49 | ||
50 | tv_normalize(&tv); | |
51 | #ifdef BFD_EVENT_DEBUG | |
52 | log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); | |
53 | #endif /* BFD_EVENT_DEBUG */ | |
54 | ||
e9e2c950 RZ |
55 | thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv, |
56 | &bs->recvtimer_ev); | |
57 | } | |
58 | ||
59 | void bfd_echo_recvtimer_update(struct bfd_session *bs) | |
60 | { | |
61 | struct timeval tv = {.tv_sec = 0, .tv_usec = bs->echo_detect_TO}; | |
62 | ||
744f824a RZ |
63 | /* Remove previous schedule if any. */ |
64 | bfd_echo_recvtimer_delete(bs); | |
65 | ||
e9e2c950 | 66 | /* Don't add event if peer is deactivated. */ |
d245e522 RZ |
67 | if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
68 | bs->sock == -1) | |
e9e2c950 RZ |
69 | return; |
70 | ||
71 | tv_normalize(&tv); | |
72 | #ifdef BFD_EVENT_DEBUG | |
73 | log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); | |
74 | #endif /* BFD_EVENT_DEBUG */ | |
75 | ||
e9e2c950 RZ |
76 | thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv, |
77 | &bs->echo_recvtimer_ev); | |
78 | } | |
79 | ||
80 | void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter) | |
81 | { | |
82 | struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; | |
83 | ||
744f824a RZ |
84 | /* Remove previous schedule if any. */ |
85 | bfd_xmttimer_delete(bs); | |
86 | ||
e9e2c950 | 87 | /* Don't add event if peer is deactivated. */ |
d245e522 RZ |
88 | if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
89 | bs->sock == -1) | |
e9e2c950 RZ |
90 | return; |
91 | ||
92 | tv_normalize(&tv); | |
93 | #ifdef BFD_EVENT_DEBUG | |
94 | log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); | |
95 | #endif /* BFD_EVENT_DEBUG */ | |
96 | ||
e9e2c950 RZ |
97 | thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev); |
98 | } | |
99 | ||
100 | void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter) | |
101 | { | |
102 | struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; | |
103 | ||
744f824a RZ |
104 | /* Remove previous schedule if any. */ |
105 | bfd_echo_xmttimer_delete(bs); | |
106 | ||
e9e2c950 | 107 | /* Don't add event if peer is deactivated. */ |
d245e522 RZ |
108 | if (BFD_CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
109 | bs->sock == -1) | |
e9e2c950 RZ |
110 | return; |
111 | ||
112 | tv_normalize(&tv); | |
113 | #ifdef BFD_EVENT_DEBUG | |
114 | log_debug("%s: sec = %ld, usec = %ld", __func__, tv.tv_sec, tv.tv_usec); | |
115 | #endif /* BFD_EVENT_DEBUG */ | |
116 | ||
e9e2c950 RZ |
117 | thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv, |
118 | &bs->echo_xmttimer_ev); | |
119 | } | |
120 | ||
121 | void bfd_recvtimer_delete(struct bfd_session *bs) | |
122 | { | |
8529e180 | 123 | THREAD_OFF(bs->recvtimer_ev); |
e9e2c950 RZ |
124 | } |
125 | ||
126 | void bfd_echo_recvtimer_delete(struct bfd_session *bs) | |
127 | { | |
8529e180 | 128 | THREAD_OFF(bs->echo_recvtimer_ev); |
e9e2c950 RZ |
129 | } |
130 | ||
131 | void bfd_xmttimer_delete(struct bfd_session *bs) | |
132 | { | |
8529e180 | 133 | THREAD_OFF(bs->xmttimer_ev); |
e9e2c950 RZ |
134 | } |
135 | ||
136 | void bfd_echo_xmttimer_delete(struct bfd_session *bs) | |
137 | { | |
8529e180 | 138 | THREAD_OFF(bs->echo_xmttimer_ev); |
e9e2c950 | 139 | } |