]>
git.proxmox.com Git - mirror_frr.git/blob - bfdd/event.c
1 /*********************************************************************
2 * Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
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)
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
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
18 * event.c: implements the BFD loop event handlers.
22 * Rafael Zalamena <rzalamena@opensourcerouting.org>
29 void tv_normalize(struct timeval
*tv
);
31 void tv_normalize(struct timeval
*tv
)
33 /* Remove seconds part from microseconds. */
34 tv
->tv_sec
= tv
->tv_usec
/ 1000000;
35 tv
->tv_usec
= tv
->tv_usec
% 1000000;
38 void bfd_recvtimer_update(struct bfd_session
*bs
)
40 struct timeval tv
= {.tv_sec
= 0, .tv_usec
= bs
->detect_TO
};
42 /* Don't add event if peer is deactivated. */
43 if (BFD_CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_SHUTDOWN
))
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 */
51 /* Remove previous schedule if any. */
53 bfd_recvtimer_delete(bs
);
55 thread_add_timer_tv(master
, bfd_recvtimer_cb
, bs
, &tv
,
59 void bfd_echo_recvtimer_update(struct bfd_session
*bs
)
61 struct timeval tv
= {.tv_sec
= 0, .tv_usec
= bs
->echo_detect_TO
};
63 /* Don't add event if peer is deactivated. */
64 if (BFD_CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_SHUTDOWN
))
68 #ifdef BFD_EVENT_DEBUG
69 log_debug("%s: sec = %ld, usec = %ld", __func__
, tv
.tv_sec
, tv
.tv_usec
);
70 #endif /* BFD_EVENT_DEBUG */
72 /* Remove previous schedule if any. */
73 if (bs
->echo_recvtimer_ev
)
74 bfd_echo_recvtimer_delete(bs
);
76 thread_add_timer_tv(master
, bfd_echo_recvtimer_cb
, bs
, &tv
,
77 &bs
->echo_recvtimer_ev
);
80 void bfd_xmttimer_update(struct bfd_session
*bs
, uint64_t jitter
)
82 struct timeval tv
= {.tv_sec
= 0, .tv_usec
= jitter
};
84 /* Don't add event if peer is deactivated. */
85 if (BFD_CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_SHUTDOWN
))
89 #ifdef BFD_EVENT_DEBUG
90 log_debug("%s: sec = %ld, usec = %ld", __func__
, tv
.tv_sec
, tv
.tv_usec
);
91 #endif /* BFD_EVENT_DEBUG */
93 /* Remove previous schedule if any. */
95 bfd_xmttimer_delete(bs
);
97 thread_add_timer_tv(master
, bfd_xmt_cb
, bs
, &tv
, &bs
->xmttimer_ev
);
100 void bfd_echo_xmttimer_update(struct bfd_session
*bs
, uint64_t jitter
)
102 struct timeval tv
= {.tv_sec
= 0, .tv_usec
= jitter
};
104 /* Don't add event if peer is deactivated. */
105 if (BFD_CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_SHUTDOWN
))
109 #ifdef BFD_EVENT_DEBUG
110 log_debug("%s: sec = %ld, usec = %ld", __func__
, tv
.tv_sec
, tv
.tv_usec
);
111 #endif /* BFD_EVENT_DEBUG */
113 /* Remove previous schedule if any. */
114 if (bs
->echo_xmttimer_ev
)
115 bfd_echo_xmttimer_delete(bs
);
117 thread_add_timer_tv(master
, bfd_echo_xmt_cb
, bs
, &tv
,
118 &bs
->echo_xmttimer_ev
);
121 void bfd_recvtimer_delete(struct bfd_session
*bs
)
123 if (bs
->recvtimer_ev
== NULL
)
126 thread_cancel(bs
->recvtimer_ev
);
127 bs
->recvtimer_ev
= NULL
;
130 void bfd_echo_recvtimer_delete(struct bfd_session
*bs
)
132 if (bs
->echo_recvtimer_ev
== NULL
)
135 thread_cancel(bs
->echo_recvtimer_ev
);
136 bs
->echo_recvtimer_ev
= NULL
;
139 void bfd_xmttimer_delete(struct bfd_session
*bs
)
141 if (bs
->xmttimer_ev
== NULL
)
144 thread_cancel(bs
->xmttimer_ev
);
145 bs
->xmttimer_ev
= NULL
;
148 void bfd_echo_xmttimer_delete(struct bfd_session
*bs
)
150 if (bs
->echo_xmttimer_ev
== NULL
)
153 thread_cancel(bs
->echo_xmttimer_ev
);
154 bs
->echo_xmttimer_ev
= NULL
;