NAME
perfSONAR_PS::owdb
DESCRIPTION
TBD
owdb_prep()
owdb_prep: this routine is used to initialize the database connection for fetching owamp data. Pass in a ref to a hash, and it will be filled with values for: START END SENT LOST DUPS MIN MAX ERR ALPHA_%08.6f (with the %08.6f replaced ala sprintf for every alpha value passed in using the 'ALPHAS' arg.) ALPHAS (A sub hash with the keys set from the original alphas passed in and the values set to the delay of that "alpha".)
owdb_fetch()
TDB
owdb_plot_script()
TDB
bwdb_plot_script()
TDB
bwdb_dist_plot_script()
TDB
ntpdb_loop_plot_script()
TDB
ntpdb_peer_plot_script()
TDB
ntpdb_color_per_peer_plot_script()
TDB
trdb_plot_script()
TDB
ts_owptstamppldatetime()
TDB
my $nrecs;
my $sql;
my $sth;
my @row;
my $sql2;
my $sth2;
my @row2;
######################################################################
# Definition of parameters
my $basex = 0; #base for all plots of the traceroute route tree
my $basey = 0;
my $stepx = 500;
my $stepy = 700;
my $radius= 200;
my $offsetTextx = 7000;
my $offsetTexty = 500;
my $outfile = "route_changes.fig";
my $psfile = "route_changes.ps";
my $pngfile = "route_changes.png";
######################################################################
#global vars
my (@arrayOfDates, @arrayOfRoutes, %hashOfRoutes, %hashOfRoutesList, %arrayOfDefectsByDate);
my (@listOfRouters, @stringOfRouters);
my ($maxRoutes, $sumRoutes, $errorInTrace);
my (%edge, %x, %y, %error, %name, %domain); #data about each router [node] and link [edge] in the graph
my (%miniEdge, @miniRouter); #same but for the timed graphs
my ($source, $destination); #source and destination nodes
my $family="hola"; #destination
my $dir; #source
my $indir;
my $maxy;
my ($widthWeigth);
my (%nodeIndex, @routeName);
my @nodeNumbers;
my ($xfigSummaryTreeWithDomains, $xfigSummaryTree, $xfigTimedTree,
$printTableWithAllAnomalies, $nodebug);
$nodebug = 1;
chomp($dir = `/`);
$outfile = $dir "/tmp/traceplots/". $outfile;
$psfile = $dir "/tmp/traceplots/". $psfile;
$pngfile = $dir "/tmp/traceplots/". $pngfile;
print `rm -rf $outfile $psfile $pngfile`;
$indir = $dir . "/tmp/tracedata";
#code to generate the input files by quering the database
#output file
open (OUT,">$outfile");
#go over all families
&goOverAllFamilies();
close OUT;
#Convert fig to ps
#print `fig2dev -L ps -m 0.750 -x -200 -y -1500 -M -e -z Letter $outfile $psfile`;
print `fig2dev -L ps -m 0.75 $outfile $psfile`;
#Convert ps to png
#print `convert $psfile $pngfile`;
print `gs -dNOPAUSE -q -sDEVICE=png256 -sOutputFile=$pngfile $psfile -dBATCH`;
$plfh = $pngfile;
if(!$plfh){
$nrecs++;
} else {
$nrecs = 0;
}
return $nrecs;
}
###################################################################### sub printDebug { if (!$nodebug) { print STDERR "@_"; } }
###################################################################### #go over all families sub goOverAllFamilies() {
&printXFigHeader();
my $key;
my $value;
my @file_list;
my @listOfFiles = `ls $indir`;
# print "\nFile list: @listOfFiles\n";
undef @arrayOfDates;
undef @arrayOfRoutes;
undef %hashOfRoutes;
undef %hashOfRoutesList;
undef %arrayOfDefectsByDate;
$maxRoutes = 0;
$sumRoutes = 0;
$errorInTrace = 0;
my $file;
my $routerNum;
my $router;
my $date;
my @field;
my $fileNumber;
#go over all files
$fileNumber = 0;
foreach $file (@listOfFiles) {
chop($file);
$file = $indir . "/" . $file ;
#print "\nInput file: $file \n";
open(IN, "<$file");
$routerNum = 1;
#if($fileNumber!=0){&SetArrayOfRoutes("$date");}
&ClearListOfRouters();
#$date = $1;
if ($errorInTrace) {printDebug "clearing up the error ($date)\n\n";print "Inside 3.2\n";}
$errorInTrace = 0;
my $lineNum=0;
my $line;
while ($line=<IN>) {
#print "Reading Line $line\n";
if($lineNum==0){
@routeName[$fileNumber]= $line;
$lineNum++;
next;
}
$lineNum++;
if($lineNum > 10000) {last;}
@field = split ' ', $line ;
#&InsertRouter(@field[1], $fileNumber);
&InsertRouter(@field[0], -1);
$nodeIndex{@field[0]}= "@field[1] @field[2]";
}
#This is a new trace
#if (!$errorInTrace && ($stringOfRouters[0] ne "")) {
&SetArrayOfRoutes("$fileNumber");
#print "Inside 3.1\n";
#}
#print "String of Routers: @stringOfRouters \n";
#print "List of Routers: @listOfRouters \n";
$fileNumber++;
}
#&SetArrayOfRoutes("UNDEF");
&calculateEdges($date);
&xfigTimedTree();
}
###################################################################### sub printXFigHeader() { print OUT "#FIG 3.1\n". # "Landscape\n". "Portrait\n". "Center\n". "Inches\n". "1200 2\n"; } ######################################################################
###################################################################### sub SetArrayOfRoutes() { my ($date) =@_; my ($i, $myStringOfRouters, $myStringOfRouters0);
for ($i=0; $i < 3; $i++) {
$myStringOfRouters = $stringOfRouters[$i];
$myStringOfRouters0 = $stringOfRouters[0];
if (($i == 0) || ($myStringOfRouters ne $myStringOfRouters0)) {
$arrayOfDates[$sumRoutes] = "$date";
# print "I am doing something\n";
$arrayOfRoutes[$sumRoutes] = $myStringOfRouters;
$hashOfRoutes{$myStringOfRouters}=5-$date;
#$hashOfRoutes{$date}=$myStringOfRouters;
$sumRoutes++;
$hashOfRoutesList{$myStringOfRouters}= \@{$listOfRouters[$i]};
#if ($maxRoutes < $hashOfRoutes{$myStringOfRouters}) {
# $maxRoutes = $hashOfRoutes{$myStringOfRouters};
#}
# printDebug "router: $myStringOfRouters=> $hashOfRoutes{$myStringOfRouters}\n";
}
}
}
######################################################################
sub GetRouterName() {
my ($router) = @_;
return ($router, $router);
}
######################################################################
sub ClearListOfRouters() {
my $i;
for ($i=0; $i <= 3; $i++) {
@{$listOfRouters[$i]}= ();
$stringOfRouters[$i]="";
}
}
######################################################################
sub InsertRouter() {
my ($router, $listNum) = @_;
my $i;
# printDebug "router: $router\n"; if ($listNum >= 0 ) { push(@{$listOfRouters[$listNum]}, "$router"); if ($stringOfRouters[$listNum] ne "") { $stringOfRouters[$listNum] .= "-"; } $stringOfRouters[$listNum] .= "$router"; } else { for ($i=0; $i <= $#listOfRouters; $i++) { push(@{$listOfRouters[$i]}, "$router"); if ($stringOfRouters[$i] ne "") { $stringOfRouters[$i] .= "-"; } $stringOfRouters[$i] .= "$router"; } } }
###################################################################### sub calculateEdges() { my ($date) = @_;
my ($router, $end, $i);
my ($key);
undef %edge;
undef %x;
undef %y;
undef %error;
undef %name;
undef %domain;
# %edge = %x = %y = ();
my $y=0;
my ($x, $first, $previous);
if ($maxRoutes > 20) {$widthWeigth = 20/$maxRoutes;}
else {$widthWeigth=1;}
$maxy=0;
$destination = "";
my (@routes);
#print "Inside Edge 1.0\n";
#now print the results of all the files
if (%hashOfRoutes !=()) {
#print "Inside Edge 1.1\n";
my $mostCommmonRoute =1;
foreach $key (sort { $hashOfRoutes{$b} <=> $hashOfRoutes{$a} } keys %hashOfRoutes) {
#foreach $key (sort { $hashOfRoutes{$a} <=> $hashOfRoutes{$b} } keys %hashOfRoutes) {
#my(@routelist);
#@routelist = keys %hashOfRoutes;
#print "Route list: @routelist\n";
#foreach $key (@routelist) {
#print "Inside Edge 1.2\n";
printDebug "router: $key=> $hashOfRoutes{$key}\n";
@routes = split(/-/, $key);
if ($mostCommmonRoute) {
$mostCommmonRoute=0;
$source = $routes[0];
$destination = $routes[$#routes];
}
$first =1;
$maxy = ++$y;
$x=0;
foreach $router (@routes) {
$x++;
#printDebug "router: $router ($x, $y)\n";
if ($first) {
$first=0;
$previous = "$router";
if (! defined $x{"$router"}) {
($domain{"$router"}, $name{"$router"})= &GetRouterName($router);
$x{"$router"}=$x;
$y{"$router"}=$y;
printDebug "$router ($x, $y, $name{$router}, $domain{$router})\n";
}
next;
}
${$edge{"$router"}}{"$previous"}+=$hashOfRoutes{"$key"};
if (! defined $x{"$router"}) {
($domain{"$router"}, $name{"$router"})= &GetRouterName($router);
$x{"$router"}=$x;
$y{"$router"}=$y;
printDebug "$router ($x, $y, $name{$router}, $domain{$router})\n";
}
$previous = "$router";
}
if ("$router" ne "$destination") {
$error{"$router"}++;
printDebug "$router error: ".$error{"$router"}."\n";
${$arrayOfDefectsByDate{$date}}{"NotEndingInDestination"}++;
}
# printDebug "$router $destination\n";
}
$maxy = $y;
}
}
######################################################################
###################################################################### sub calculateMiniEdges() { my ($path, $numPaths) = @_; # printDebug "$path=> $numPaths\n";
undef %miniEdge;
undef @miniRouter;
&recalculateMiniEdges($path, $numPaths);
}
######################################################################
sub recalculateMiniEdges() {
my ($path, $numPaths) = @_;
my ($router);
my ($first, $previous);
# printDebug "$path=> $numPaths\n";
#now print the results of all the files
if (%hashOfRoutes !=()) {
$first =1;
foreach $router (split(/-/, $path)) {
# printDebug "router: $router ($x, $y)\n";
push (@miniRouter, "$router");
if ($first) {
$first=0;
$previous = "$router";
next;
}
${$miniEdge{"$router"}}{"$previous"}+=$numPaths;
# printDebug "$router ($x, $y)\n";
$previous = "$router";
}
#print "LIst of miniRouter: @miniRouter\n";
}
} ###################################################################### sub xfigTimedTree() {
my ($centerx, $centery, $borderx, $bordery, $width);
my ($startx, $starty, $endx, $endy);
my ($labelx, $labely, $label, $textx, $texty);
my ($router, $end, $i);
my ($sumEdges, $firstDate);
if (%hashOfRoutes !=()) {
#print "fig 1.0 \n";
my $numPaths=1;
for ($i=0; $i<=$#arrayOfRoutes; $i++) {
#print "fig 1.1 \n";
#printDebug "path=> $arrayOfRoutes[$i] \n****** $arrayOfRoutes[$i+1]\n";
if ($numPaths==1) {
$firstDate=$arrayOfDates[$i];
}
if (((($i+1)<=$#arrayOfRoutes) &&
("$arrayOfRoutes[$i]" eq "$arrayOfRoutes[$i+1]")) &&
((($i+2)<=$#arrayOfRoutes) && ("$arrayOfDates[$i+1]" ne "$arrayOfDates[$i+2]"))) {
#print "fig 1.2 \n";
$numPaths++;
next;
}
if ((($i+1)<=$#arrayOfRoutes) &&
("$arrayOfDates[$i]" eq "$arrayOfDates[$i+1]")) {
#print "fig 1.3 \n";
&calculateMiniEdges($arrayOfRoutes[$i], 1);
&recalculateMiniEdges($arrayOfRoutes[$i+1], 1);
#printDebug "path=> $arrayOfRoutes[$i] \n****** $arrayOfRoutes[$i+1]\n";
$i++;
} elsif ((($i+2)<=$#arrayOfRoutes) &&
("$arrayOfDates[$i]" eq "$arrayOfDates[$i+2]")) {
#print "fig 1.4 \n";
&calculateMiniEdges($arrayOfRoutes[$i], 1);
&recalculateMiniEdges($arrayOfRoutes[$i+1], 1);
&recalculateMiniEdges($arrayOfRoutes[$i+2], 1);
$i++;
$i++;
} else {
#print "fig 1.5 \n";
&calculateMiniEdges($arrayOfRoutes[$i], $numPaths);
}
$maxy=0;
#Print the route Name first
print OUT "4 0 0 2 0 0 18 0.0000 4 135 360 $basex $basey @routeName[$i]\\001\n\n";
$basey+=300;
foreach $router (@miniRouter) {
#print "Router: $router ($x{\"$router\"},$y{\"$router\"})\n";
$centerx=$basex+$x{"$router"}*$stepx;
$centery=$basey+$y{"$router"}*$stepy;
if ($maxy < $y{"$router"}) {$maxy = $y{"$router"};};
#printDebug "router: $router ($centerx, $centery)\n";
$borderx=$centerx-$radius;
$bordery=$centery-$radius;
$width=1;
print OUT "1 3 0 $width -1 7 0 0 -1 0.000 1 0.0000 $centerx $centery ".
"$radius $radius $borderx $bordery $borderx $bordery\n";
$labelx=$centerx-$radius;
$labely=$centery-$radius;
#if ($router =~ /(\w+)\.(\w+)\.(\w+)\.(\w+)/) {
#label="$4";
#}
$label = $router;
print OUT "4 0 0 2 0 0 16 0.0000 4 135 360 $labelx $labely $label\\001\n\n";
#print OUT "4 0 0 2 0 0 12 0.0000 4 135 360 $labelx $labely test\\001\n\n";
$sumEdges=0;
foreach $end ( keys %{$miniEdge{"$router"}}) {
$startx=$centerx;
$starty=$centery;
$endx=$basex+$x{"$end"}*$stepx;
$endy=$basey+$y{"$end"}*$stepy;
$width=int(${$miniEdge{"$router"}}{"$end"}*$widthWeigth);
$width=($width?$width:1);
$sumEdges+=${$miniEdge{"$router"}}{"$end"};
if (($startx == $endx) && ($starty == $endy)) {
#this is looping into itself
$endx=$startx-$radius;
$endy=$starty+$radius*1.5;
}
print OUT "2 1 0 $width -1 7 0 0 -1 0.000 0 0 -1 0 0 2\n".
" $startx $starty $endx $endy\n";
# printDebug "$router $end 2 1 0 $width -1 7 0 0 -1 0.000 0 0 -1 0 0 2\n".
# " $startx $starty $endx (=$basex+".$x{"$end"}."*$stepx) $endy \n";
}
#$labelx=$centerx+$radius*0;
#$labely=$centery+$radius+200;
#$label=(int($sumEdges/$sumRoutes*100))."%";
#if ($label eq "0%") {
#$label=(int($sumEdges/$sumRoutes*1000))."%%";
#}
#if ($label eq "0%%") {
# $label=".".(int($sumEdges/$sumRoutes*10000))."%%";
#}
#print OUT "4 0 1 2 0 0 12 0.0000 4 135 360 $labelx $labely $label \\001\n\n";
}
$basey += ($maxy+1)*$stepy;
$numPaths=1;
}
$texty = $offsetTexty+$basey;
$textx = $offsetTextx+$basex;
my $key;
foreach $key (sort (keys %nodeIndex)){
print OUT "4 0 -1 0 0 0 16 0.0000 4 135 360 $stepx $texty $key => $nodeIndex{$key} \\001\n\n";
#$textx += $basex;
$texty += 250;
}
}
#print "Done leaving Timed Tree\n"; }
SEE ALSO
FindBin, POSIX, Fcntl, FileHandle, perfSONAR_PS::OWP, perfSONAR_PS::OWP::Utils, perfSONAR_PS::CGI::Carp, File::Basename
To join the 'perfSONAR-PS' mailing list, please visit:
https://mail.internet2.edu/wws/info/i2-perfsonar
The perfSONAR-PS subversion repository is located at:
https://svn.internet2.edu/svn/perfSONAR-PS
Questions and comments can be directed to the author, or the mailing list. Bugs, feature requests, and improvements can be directed here:
https://bugs.internet2.edu/jira/browse/PSPS
VERSION
$Id: owdb.pm 1877 2008-03-27 16:33:01Z aaron $
AUTHOR
Jeff Boote, boote@internet2.edu Jason Zurawski, zurawski@internet2.edu
LICENSE
You should have received a copy of the Internet2 Intellectual Property Framework along with this software. If not, see <http://www.internet2.edu/membership/ip.html>
COPYRIGHT
Copyright (c) 2002-2008, Internet2
All rights reserved.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 1892:
=pod directives shouldn't be over one line long! Ignoring all 5 lines of content