Skip to content

Commit

Permalink
Update timer
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqiangz committed Dec 13, 2024
1 parent 786bfa1 commit 6df25dc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,13 @@ void loop_relay(std::unordered_map<std::string, relay_config> &vlans) {
timer_event = event_new(base, -1, EV_PERSIST, lla_check_callback, timer_args);
std::get<7>(*timer_args) = timer_event;
evutil_timerclear(&tv);
tv.tv_sec = 5;
tv.tv_sec = 60;
event_add(timer_event, &tv);

// We set check timer to be executed every 60s, it would case that its first excution be delayed 60s,
// hence manually invoke it here to immediate execute it
lla_check_callback(-1, 0, timer_args);

if(signal_init() == 0 && signal_start() == 0) {
shutdown_relay();
for(std::size_t i = 0; i < sockets.size(); i++) {
Expand Down Expand Up @@ -1351,9 +1355,8 @@ void clear_counter(std::shared_ptr<swss::DBConnector> state_db) {
* @return none
*/
void lla_check_callback(evutil_socket_t fd, short event, void *arg) {
syslog(LOG_WARNING, "Timer event");
auto args = reinterpret_cast<std::tuple<
std::unordered_map<std::string, struct relay_config> &,
std::unordered_map<std::string, struct relay_config> *,
std::shared_ptr<swss::DBConnector>,
std::shared_ptr<swss::DBConnector>,
std::shared_ptr<swss::Table>,
Expand All @@ -1371,12 +1374,14 @@ void lla_check_callback(evutil_socket_t fd, short event, void *arg) {
auto filter = std::get<6>(*args);
auto timer_event = std::get<7>(*args);

for(auto &vlan : vlans) {
bool all_llas_are_ready = true;
for(auto &vlan : *vlans) {
if (vlan.second.is_lla_ready) {
continue;
}
if (!check_is_lla_ready(vlan.first)) {
syslog(LOG_WARNING, "Link local address for %s is not ready\n", vlan.first.c_str());
all_llas_are_ready = false;
continue;
}
vlan.second.is_lla_ready = true;
Expand Down Expand Up @@ -1413,4 +1418,8 @@ void lla_check_callback(evutil_socket_t fd, short event, void *arg) {
exit(EXIT_FAILURE);
}
}
if (all_llas_are_ready) {
syslog(LOG_INFO, "All Vlans' lla are ready, terminate check timer");
event_del(timer_event);
}
}

0 comments on commit 6df25dc

Please sign in to comment.