forked from sdn-ixp/iSDX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickviz
executable file
·79 lines (64 loc) · 2 KB
/
quickviz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl -w
use strict;
sub usage {
print "Usage: quickviz <config_file> <data_directory>\n";
exit 1;
}
usage() if scalar(@ARGV) != 2;
my ($config,$dir) = @ARGV;
load_config();
my $count = 0;
my (%cookie2cnt, %prev_cnt);
my (%ports,%flows);
printf " %8s%8s%8s%8s%8s%8s%8s%8s\n", 'A','B','C1','C2','Aout','Bout','C1out','C2out';
while (1) {
my $cur_port_file = sprintf("$dir/ports/%03d.ports", $count);
open(PORT_STATS,"<$cur_port_file") or die "Can't open $cur_port_file";
while (<PORT_STATS>) {
if (/dpid: (\d+).*port_no.: (\d+).*rx_packets.: (\d+)/) {
my ($dpid,$cookie,$count) = ($1,$2,$3);
$cookie = "PORT_${dpid}_$cookie";
$cookie2cnt{$cookie} = $count;
$prev_cnt{$cookie} = 0 if !defined($prev_cnt{$cookie});
}
}
close(PORT_STATS);
my $cur_flow_file = sprintf("$dir/flows/%03d.flow", $count);
open(FLOW_STATS,"<$cur_flow_file") or die "Can't open $cur_flow_file";
while (<FLOW_STATS>) {
if (/(\d+).*packet_count\":\s+(\d+)/) {
my ($cookie,$count) = ($1,$2);
next if $cookie == 0;
$cookie2cnt{$cookie} = $count;
$prev_cnt{$cookie} = 0 if !defined($prev_cnt{$cookie});
}
}
close(FLOW_STATS);
printf "%3d:%8d%8d%8d%8d%8d%8d%8d%8d\n", $count+1,
cookie_diff($ports{'A1'}), cookie_diff($ports{'B1'}),
cookie_diff($ports{'C1'}), cookie_diff($ports{'C2'}),
cookie_diff($flows{'VA1'}), cookie_diff($flows{'VB1'}),
cookie_diff($flows{'VC1'}), cookie_diff($flows{'VC2'});
%prev_cnt = %cookie2cnt;
$count += 1;
}
sub cookie_diff {
my($cookie) = (@_);
return 0 if !defined($prev_cnt{$cookie});
return $cookie2cnt{$cookie} - $prev_cnt{$cookie};
}
sub load_config {
open(CONFIG, "<$config") or die "Can't open $config";
while (<CONFIG>) {
s/#.*//;
next if /^\s*$/;
if (/(\S+).*\s+(PORT\S+)/) {
my ($portFlow,$portId) = ($1,$2);
$ports{$portFlow} = $portId;
} else {
my @fields = split(/\s+/);
$flows{$fields[1]} = $fields[3];
}
}
close(CONFIG);
}