blob: 9131be92b5dbada915e35c0e94cdf3ec2a3ed03b [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 SCPFswitchLat <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 ], "SCPFswitchLat_", sep = "" )
52errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" )
53errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" )
54
55errBarOutputFileDown <- paste( args[ 7 ], "SCPFswitchLat_", 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 switch_latency_details WHERE branch = '", args[ 6 ], sep="" )
64command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM switch_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
72# **********************************************************
73# STEP 2: Organize data.
74# **********************************************************
75
76print( "Sorting data." )
77
78upAvgs <- c( fileData[ 'up_device_to_graph_avg' ], fileData[ 'role_reply_to_device_avg' ], fileData[ 'role_request_to_role_reply_avg' ], fileData[ 'feature_reply_to_role_request_avg' ], fileData[ 'tcp_to_feature_reply_avg' ] )
79upAvgsData <- melt( upAvgs )
80upAvgsData$scale <- fileData$scale
81upAvgsData$up_std <- fileData$up_std
82
83colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" )
84upAvgsData$type <- as.character( upAvgsData$type )
85upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
86
87downAvgs <- c( fileData[ 'down_device_to_graph_avg' ], fileData[ 'ack_to_device_avg' ], fileData[ 'fin_ack_to_ack_avg' ] )
88downAvgsData <- melt( downAvgs )
89downAvgsData$scale <- fileData$scale
90downAvgsData$down_std <- fileData$down_std
91
92colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" )
93downAvgsData$type <- as.character( downAvgsData$type )
94downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
95
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070096upAvgsData <- na.omit( upAvgsData ) # Omit any data that doesn't exist
97downAvgsData <- na.omit( downAvgsData )
98
99print( "Up Averages Results:" )
100print( upAvgsData )
101
102print( "Down Averages Results:" )
103print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000104
105# **********************************************************
106# STEP 3: Generate graphs.
107# **********************************************************
108
109
110print( "Generating fundamental graph data (Switch Up Latency)." )
111width <- 1
112 if ( min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) < 0 ) {
113 yMin <- min( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds ) * 1.05
114 } else {
115 yMin <- 0
116 }
117yMax <- max( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds )
118
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700119theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
120
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000121mainPlot <- 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 ) )
122xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
123yLimit <- ylim( yMin, yMax )
124xLabel <- xlab( "Scale" )
125yLabel <- ylab( "Latency (ms)" )
126fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700127theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000128
129fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
130
131print( "Generating bar graph with error bars (Switch Up Latency)." )
132barGraphFormat <- geom_bar( stat="identity", width = width )
133errorBarFormat <- geom_errorbar( width = width )
134
135title <- ggtitle( "Switch Up Latency" )
136result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
137
138
139print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) )
140ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 )
141
142
143print( paste( "Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) )
144
145
146print( "Generating fundamental graph data (Switch Down Latency)." )
147 if ( min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) < 0 ) {
148 yMin <- min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds )
149 } else {
150 yMin <- 0
151 }
152 yMax <- max( fileData[ 'down_end_to_end_avg' ] + downAvgsData$stds )
153
154mainPlot <- 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 ) )
155yLimit <- ylim( yMin, yMax )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700156theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000157
158fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
159
160print( "Generating bar graph with error bars (Switch Down Latency)." )
161barGraphFormat <- geom_bar( stat="identity", width = width )
162errorBarFormat <- geom_errorbar( width = width )
163
164title <- ggtitle( "Switch Down Latency" )
165result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
166
167
168print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) )
169ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 )
170
171
172print( paste( "Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) )