Skip to content

Commit

Permalink
#589 only show link with highest agg speed if map links between two d…
Browse files Browse the repository at this point in the history
…evices are asymmetric
  • Loading branch information
ollyg committed May 27, 2019
1 parent 087ca8e commit 8878853
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
( SELECT dp.ip AS left_ip,
ld.dns AS left_dns,
ld.name AS left_name,
array_agg(dp.port) AS left_port,
array_agg(dp.name) AS left_descr,
array_agg(dp.port ORDER BY dp.port) AS left_port,
array_agg(dp.name ORDER BY dp.name) AS left_descr,
count(dpp.*) AS aggports,
sum(COALESCE(dpp.raw_speed, 0)) AS aggspeed,
di.ip AS right_ip,
rd.dns AS right_dns,
rd.name AS right_name,
array_agg(dp.remote_port) AS right_port,
array_agg(dp2.name) AS right_descr
array_agg(dp.remote_port ORDER BY dp.remote_port) AS right_port,
array_agg(dp2.name ORDER BY dp2.name) AS right_descr
FROM device_port dp
Expand Down Expand Up @@ -68,8 +68,7 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
WHERE b2.right_ip = b.left_ip
AND b2.right_port = b.left_port
AND b2.left_ip < b.left_ip )
ORDER BY 1,
2
ORDER BY aggspeed DESC, 1, 2
ENDSQL
);

Expand Down
7 changes: 7 additions & 0 deletions lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {

# LINKS

my %seen_link = ();
my $links = schema('netdisco')->resultset('Virtual::DeviceLinks')->search({
($mapshow eq 'neighbors' ? ( -or => [
{ left_ip => $qdev->ip },
Expand All @@ -175,6 +176,11 @@ ajax '/ajax/data/device/netmap' => require_login sub {
}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });

while (my $link = $links->next) {
# query is ordered by aggregate speed desc so we see highest speed
# first, which is hopefully the "best" if links are not symmetric
next if exists $seen_link{$link->{left_ip} ."\0". $link->{right_ip}}
or exists $seen_link{$link->{right_ip} ."\0". $link->{left_ip}};

push @{$data{'links'}}, {
FROMID => $link->{left_ip},
TOID => $link->{right_ip},
Expand All @@ -184,6 +190,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {

++$ok_dev{$link->{left_ip}};
++$ok_dev{$link->{right_ip}};
++$seen_link{$link->{left_ip} ."\0". $link->{right_ip}};
}

# DEVICES (NODES)
Expand Down

0 comments on commit 8878853

Please sign in to comment.