#!/usr/bin/perl

use warnings;
use strict;

my $graph;

my ($max,$min);

foreach my $file ( glob '*/*.np' ) {

	my $direction = $file;
	$direction =~ s/\.np$//;
	my ( $from, $to ) = split(m{/},$direction,2);

	my $line = `tail -1 $file`;
	$line =~ s{^\s+}{};
	$line =~ s{\s+$}{};
	my ( $size, $speed, $rtt ) = split(/\s+/, $line);

	warn "$from -> $to | $size | $speed | $rtt\n";

	my $len = int($speed / 100);

	$graph->{ qq|"$from" -> "$to"| } = {
		size => $size,
		speed => $speed,
		rtt => $rtt,
	};

	$min ||= $speed;
	$min = $speed if $speed < $min;

	$max ||= $speed;
	$max = $speed if $speed > $max;

}

warn "# speed $min ... $max\n";

print qq|
digraph "netpipe" {
|,
join("\n", map {
	my $node = $_;
	my $speed = $graph->{$_}->{speed};
	my $c = 'ff0000';
	$c = '00ff00' if ( $speed /  100 ) > 1.5;
	$c = '0000ff' if ( $speed / 1000 ) > 1;
	$c = '8888ff' if ( $speed / 1000 ) > 2;
	my $label = $speed;
	$label =~ s/\.\d+//;
	qq|$node [ label="$label",color="#$c",len=$speed ]|;
} keys %$graph),
qq|
}
|;

