blob: e4b9d4fba365426183ab2deff0b7528d713a6058 [file] [log] [blame]
Jeremy Ronquillo6df87812017-08-28 16:17:36 +00001# Copyright 2017 Open Networking Foundation (ONF)
2#
3# Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
4# the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
5# or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
6#
7# TestON is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 2 of the License, or
10# (at your option) any later version.
11#
12# TestON is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with TestON. If not, see <http://www.gnu.org/licenses/>.
19#
20# If you have any questions, or if you don't understand R,
Jeremy Ronquillob6268842017-10-03 13:02:58 -070021# please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000022
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
Jeremy Ronquillob6268842017-10-03 13:02:58 -070029# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030print( "Reading commmand-line args." )
31args <- commandArgs( trailingOnly=TRUE )
32
33# Import libraries to be used for graphing and organizing data, respectively.
34# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
35# reshape2: https://github.com/hadley/reshape
36print( "Importing libraries." )
37library( ggplot2 )
38library( reshape2 )
39library( RPostgreSQL ) # For databases
40
41# Check if sufficient args are provided.
42if ( is.na( args[ 7 ] ) ){
43 print( "Usage: Rscript SCPFportLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
44 q() # basically exit(), but in R
45}
46
Jeremy Ronquillob6268842017-10-03 13:02:58 -070047# paste() is used to concatenate strings.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000048errBarOutputFileUp <- paste( args[ 7 ], "SCPFportLat_", sep = "" )
49errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" )
50errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" )
51
52errBarOutputFileDown <- paste( args[ 7 ], "SCPFportLat_", sep = "" )
53errBarOutputFileDown <- paste( errBarOutputFileDown, args[ 6 ], sep = "" )
54errBarOutputFileDown <- paste( errBarOutputFileDown, "_DownErrBarWithStack.jpg", sep = "" )
55
56print( "Reading from databases." )
57
58con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
59
60command <- paste( "SELECT * FROM port_latency_details WHERE branch = '", args[ 6 ], sep = "" )
61command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '", sep = "" )
62command <- paste( command, args[ 6 ], sep = "" )
63command <- paste( command, "' ) ", sep="" )
64
65print( paste( "Sending SQL command:", command ) )
66
67fileData <- dbGetQuery( con, command )
68
69chartTitle <- paste( "Port Latency", args[ 6 ], sep = " - " )
70chartTitle <- paste( chartTitle, "\n" )
71
72
73# **********************************************************
74# STEP 2: Organize data.
75# **********************************************************
76
77print( "Sorting data." )
78
79upAvgs <- c( fileData[ 'up_ofp_to_dev_avg' ], fileData[ 'up_dev_to_link_avg' ], fileData[ 'up_link_to_graph_avg' ] )
80upAvgsData <- melt( upAvgs )
81upAvgsData$scale <- fileData$scale
82upAvgsData$up_std <- fileData$up_std
83
84
85colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" )
86upAvgsData$type <- as.character( upAvgsData$type )
87upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
88
89downAvgs <- c( fileData[ 'down_ofp_to_dev_avg' ], fileData[ 'down_dev_to_link_avg' ], fileData[ 'down_link_to_graph_avg' ] )
90downAvgsData <- melt( downAvgs )
91downAvgsData$scale <- fileData$scale
92downAvgsData$down_std <- fileData$down_std
93
94colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" )
95downAvgsData$type <- as.character( downAvgsData$type )
96downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
97
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070098upAvgsData <- na.omit( upAvgsData ) # Omit any data that doesn't exist
99downAvgsData <- na.omit( downAvgsData ) # Omit any data that doesn't exist
100
101print( "Up Averages Results:" )
102print( upAvgsData )
103
104print( "Down Averages Results:" )
105print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000106
107# **********************************************************
108# STEP 3: Generate graphs.
109# **********************************************************
110
111
112print( "Generating fundamental graph data (Port Up Latency)." )
113width <- 1
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700114theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
115
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116mainPlot <- ggplot( data = upAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'up_end_to_end_avg' ] - stds, ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
117xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000118xLabel <- xlab( "Scale" )
119yLabel <- ylab( "Latency (ms)" )
120fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700121theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000122
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700123fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000124
125print( "Generating bar graph with error bars (Port Up Latency)." )
126barGraphFormat <- geom_bar( stat="identity", width = width )
127errorBarFormat <- geom_errorbar( width = width )
128
129title <- ggtitle( "Port Up Latency" )
130result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
131
132
133print( paste( "Saving bar chart with error bars (Port Up Latency) to", errBarOutputFileUp ) )
134ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 )
135
136
137print( paste( "Successfully wrote bar chart with error bars (Port Up Latency) out to", errBarOutputFileUp ) )
138
139
140print( "Generating fundamental graph data (Port Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000141
142mainPlot <- ggplot( data = downAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'down_end_to_end_avg' ] - stds, ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700143theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000144
Jeremy Ronquillob6268842017-10-03 13:02:58 -0700145fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000146
147print( "Generating bar graph with error bars (Port Down Latency)." )
148barGraphFormat <- geom_bar( stat="identity", width = width )
149errorBarFormat <- geom_errorbar( width = width )
150
151title <- ggtitle( "Port Down Latency" )
152result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
153
154
155print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) )
156ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 )
157
158
159print( paste( "Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) )