blob: 9eb38a506bce3a8457f8465a9db1924530c401f3 [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,
21# please contact Jeremy Ronquillo: jeremyr@opennetworking.org
22
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
29# Command line arguments are read. Args usually include the database filename and the output
30# directory for the graphs to save to.
31# ie: Rscript SCPFgraphGenerator SCPFsampleDataDB.csv ~/tmp/
32print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
35# Import libraries to be used for graphing and organizing data, respectively.
36# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
37# reshape2: https://github.com/hadley/reshape
38print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
43# Check if sufficient args are provided.
44if ( is.na( args[ 7 ] ) ){
45 print( "Usage: Rscript SCPFportLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
46 q() # basically exit(), but in R
47}
48
49# Filenames for output graphs include the testname and the graph type.
50# See the examples below. paste() is used to concatenate strings.
51errBarOutputFileUp <- paste( args[ 7 ], "SCPFportLat_", sep = "" )
52errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" )
53errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" )
54
55errBarOutputFileDown <- paste( args[ 7 ], "SCPFportLat_", sep = "" )
56errBarOutputFileDown <- paste( errBarOutputFileDown, args[ 6 ], sep = "" )
57errBarOutputFileDown <- paste( errBarOutputFileDown, "_DownErrBarWithStack.jpg", sep = "" )
58
59print( "Reading from databases." )
60
61con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
62
63command <- paste( "SELECT * FROM port_latency_details WHERE branch = '", args[ 6 ], sep = "" )
64command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '", sep = "" )
65command <- paste( command, args[ 6 ], sep = "" )
66command <- paste( command, "' ) ", sep="" )
67
68print( paste( "Sending SQL command:", command ) )
69
70fileData <- dbGetQuery( con, command )
71
72chartTitle <- paste( "Port Latency", args[ 6 ], sep = " - " )
73chartTitle <- paste( chartTitle, "\n" )
74
75
76# **********************************************************
77# STEP 2: Organize data.
78# **********************************************************
79
80print( "Sorting data." )
81
82upAvgs <- c( fileData[ 'up_ofp_to_dev_avg' ], fileData[ 'up_dev_to_link_avg' ], fileData[ 'up_link_to_graph_avg' ] )
83upAvgsData <- melt( upAvgs )
84upAvgsData$scale <- fileData$scale
85upAvgsData$up_std <- fileData$up_std
86
87
88colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" )
89upAvgsData$type <- as.character( upAvgsData$type )
90upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
91
92downAvgs <- c( fileData[ 'down_ofp_to_dev_avg' ], fileData[ 'down_dev_to_link_avg' ], fileData[ 'down_link_to_graph_avg' ] )
93downAvgsData <- melt( downAvgs )
94downAvgsData$scale <- fileData$scale
95downAvgsData$down_std <- fileData$down_std
96
97colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" )
98downAvgsData$type <- as.character( downAvgsData$type )
99downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
100
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700101upAvgsData <- na.omit( upAvgsData ) # Omit any data that doesn't exist
102downAvgsData <- na.omit( downAvgsData ) # Omit any data that doesn't exist
103
104print( "Up Averages Results:" )
105print( upAvgsData )
106
107print( "Down Averages Results:" )
108print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000109
110# **********************************************************
111# STEP 3: Generate graphs.
112# **********************************************************
113
114
115print( "Generating fundamental graph data (Port Up Latency)." )
116width <- 1
117 if ( min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) < 0 ) {
118 yMin <- min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) * 1.05
119 } else {
120 yMin <- 0
121 }
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700122theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
123
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000124yMax <- max( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds )
125
126mainPlot <- 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 ) )
127xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
128yLimit <- ylim( yMin, yMax )
129xLabel <- xlab( "Scale" )
130yLabel <- ylab( "Latency (ms)" )
131fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700132theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000133
134fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
135
136print( "Generating bar graph with error bars (Port Up Latency)." )
137barGraphFormat <- geom_bar( stat="identity", width = width )
138errorBarFormat <- geom_errorbar( width = width )
139
140title <- ggtitle( "Port Up Latency" )
141result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
142
143
144print( paste( "Saving bar chart with error bars (Port Up Latency) to", errBarOutputFileUp ) )
145ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 )
146
147
148print( paste( "Successfully wrote bar chart with error bars (Port Up Latency) out to", errBarOutputFileUp ) )
149
150
151print( "Generating fundamental graph data (Port Down Latency)." )
152 if ( min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) < 0 ) {
153 yMin <- min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds )
154 } else {
155 yMin <- 0
156 }
157 yMax <- max( fileData[ 'down_end_to_end_avg' ] + downAvgsData$stds )
158
159mainPlot <- 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 ) )
160yLimit <- ylim( yMin, yMax )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700161theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000162
163fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
164
165print( "Generating bar graph with error bars (Port Down Latency)." )
166barGraphFormat <- geom_bar( stat="identity", width = width )
167errorBarFormat <- geom_errorbar( width = width )
168
169title <- ggtitle( "Port Down Latency" )
170result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
171
172
173print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) )
174ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 )
175
176
177print( paste( "Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) )