Skip to content

Commit

Permalink
Allow sweep to be disabled dynamically
Browse files Browse the repository at this point in the history
 * Allow sweep period (sweep_sec) to be set to 0, disabling sweeping.
 * Make sure that next_sweep is properly adjusted, especially for
   "0 to non-0" and "non-0 to 0" transitions.
 * Make sure that sweep_age is set when sweep_sec is non-zero (set it
   to sweep_sec if necessary)
  • Loading branch information
sbakker committed Dec 9, 2020
1 parent a55b35d commit de4c2cb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions lib/M6/ARP/Control/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,33 @@ sub _cmd_set_arp_update_flags {
sub _cmd_set_sweep_sec {
my ($self, $sponge, $cmd, @args) = @_;

my $sec = is_valid_int($args[0], -min=>1);
my $sec = is_valid_int($args[0], -min=>0);
if (!defined $sec) {
return $self->send_error("$cmd <POSITIVE-INT>");
return $self->send_error("$cmd <NON-NEGATIVE-INT>");
}
$self->_log_ctl("[client %d] %s %d", $self->fileno, $cmd, $sec);
my $old = $sponge->user('sweep_sec');
$sponge->user('sweep_sec', $sec);
my $new = $sponge->user('sweep_sec');

# See if we need to sweep right now.
my $next = $sponge->user('next_sweep') - $old + $new;
$sponge->user('next_sweep', $next);
my $next_sweep = 0;
if ($new >= 1) {
# Fix sweep age (threshold) if not previously set.
if (!$sponge->user('sweep_age')) {
$sponge->user('sweep_age', $new);
}
# Determine new "next sweep" time.
my $old_next = $sponge->user('next_sweep') // 0;
if ($old_next > $old) {
# Adjust existing setting.
$next_sweep = $old_next - $old + $new;
}
else {
# No previous setting; make a brand new one.
$next_sweep = time + $new;
}
}
$sponge->user('next_sweep', $next_sweep);
return $self->send_ok(sprintf("old=%d\nnew=%d", $old, $new));
}

Expand Down
2 changes: 1 addition & 1 deletion sbin/asctl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ END
'$secs' => { type=>'int', min=>1 }, },
'set sweep_period $secs' => {
'?' => 'Set sweep/probe parameters.',
'$secs' => { type=>'int', min=>1 }, },
'$secs' => { type=>'int', min=>0 }, },
'set sweep_skip_alive $bool' => {
'?' => 'Enable/disable sweeping of ALIVE addresses.',
'$bool' => { type=>'bool' }, },
Expand Down

0 comments on commit de4c2cb

Please sign in to comment.