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