blob: 10af8a970cd2e4fd0c76c9ef79cce8bd493125d1 [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
101
102# **********************************************************
103# STEP 3: Generate graphs.
104# **********************************************************
105
106
107print( "Generating fundamental graph data (Port Up Latency)." )
108width <- 1
109 if ( min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) < 0 ) {
110 yMin <- min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) * 1.05
111 } else {
112 yMin <- 0
113 }
114yMax <- max( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds )
115
116mainPlot <- 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) )
118yLimit <- ylim( yMin, yMax )
119xLabel <- xlab( "Scale" )
120yLabel <- ylab( "Latency (ms)" )
121fillLabel <- labs( fill="Type" )
122theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
123
124fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
125
126print( "Generating bar graph with error bars (Port Up Latency)." )
127barGraphFormat <- geom_bar( stat="identity", width = width )
128errorBarFormat <- geom_errorbar( width = width )
129
130title <- ggtitle( "Port Up Latency" )
131result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
132
133
134print( paste( "Saving bar chart with error bars (Port Up Latency) to", errBarOutputFileUp ) )
135ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 )
136
137
138print( paste( "Successfully wrote bar chart with error bars (Port Up Latency) out to", errBarOutputFileUp ) )
139
140
141print( "Generating fundamental graph data (Port Down Latency)." )
142 if ( min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) < 0 ) {
143 yMin <- min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds )
144 } else {
145 yMin <- 0
146 }
147 yMax <- max( fileData[ 'down_end_to_end_avg' ] + downAvgsData$stds )
148
149mainPlot <- 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 ) )
150yLimit <- ylim( yMin, yMax )
151theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
152
153fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
154
155print( "Generating bar graph with error bars (Port Down Latency)." )
156barGraphFormat <- geom_bar( stat="identity", width = width )
157errorBarFormat <- geom_errorbar( width = width )
158
159title <- ggtitle( "Port Down Latency" )
160result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
161
162
163print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) )
164ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 )
165
166
167print( paste( "Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) )