blob: 3535a5ac08a9bb4420dac30293b428a6acfb9803 [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# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070024# STEP 1: Data management.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000025# **********************************************************
26
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070027print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
Devin Lim0e967162017-11-03 15:59:53 -070030database_host = 1
31database_port = 2
32database_u_id = 3
33database_pw = 4
34test_name = 5
35branch_name = 6
36save_directory = 7
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000037
Jeremy Ronquillob6268842017-10-03 13:02:58 -070038# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Reading commmand-line args." )
40args <- commandArgs( trailingOnly=TRUE )
41
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070042# ----------------
43# Import Libraries
44# ----------------
45
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000046print( "Importing libraries." )
47library( ggplot2 )
48library( reshape2 )
49library( RPostgreSQL ) # For databases
50
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
56
Devin Lim0e967162017-11-03 15:59:53 -070057if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070058
59 print( paste( "Usage: Rscript SCPFswitchLat",
60 "<database-host>",
61 "<database-port>",
62 "<database-user-id>",
63 "<database-password>",
64 "<test-name>",
65 "<branch-name>",
66 "<directory-to-save-graphs>",
67 sep=" ") )
68
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080069 quit( status = 1 ) # basically exit(), but in R
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070}
71
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070072# -----------------
73# Create File Names
74# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
Devin Lim0e967162017-11-03 15:59:53 -070078errBarOutputFileUp <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070079 "SCPFswitchLat_",
Devin Lim0e967162017-11-03 15:59:53 -070080 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070081 "_UpErrBarWithStack.jpg",
82 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083
Devin Lim0e967162017-11-03 15:59:53 -070084errBarOutputFileDown <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085 "SCPFswitchLat_",
Devin Lim0e967162017-11-03 15:59:53 -070086 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070087 "_DownErrBarWithStack.jpg",
88 sep="" )
89# ------------------
90# SQL Initialization
91# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000092
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070093print( "Initializing SQL" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000094
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070095con <- dbConnect( dbDriver( "PostgreSQL" ),
96 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -070097 host = args[ database_host ],
98 port = strtoi( args[ database_port ] ),
99 user = args[ database_u_id ],
100 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700101
102# --------------------------
103# Switch Latency SQL Command
104# --------------------------
105
106print( "Generating Switch Latency SQL Command" )
107
108command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700109 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700110 "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700111 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700112 "' )",
113 sep="" )
114
115print( "Sending SQL command:" )
116print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117
118fileData <- dbGetQuery( con, command )
119
120# **********************************************************
121# STEP 2: Organize data.
122# **********************************************************
123
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700124print( "**********************************************************" )
125print( "STEP 2: Organize Data." )
126print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000127
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128# -------------------------------
129# Switch Up Averages Data Sorting
130# -------------------------------
131
132print( "Sorting data for Switch Up Averages." )
133
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800134requiredColumns <- c( "up_device_to_graph_avg",
135 "role_reply_to_device_avg",
136 "role_request_to_role_reply_avg",
137 "feature_reply_to_role_request_avg",
138 "tcp_to_feature_reply_avg" )
139
140tryCatch( upAvgs <- c( fileData[ requiredColumns] ),
141 error = function( e ) {
142 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
143 print( "Required columns: " )
144 print( requiredColumns )
145 print( "Actual columns: " )
146 print( names( fileData ) )
147 print( "Error dump:" )
148 print( e )
149 quit( status = 1 )
150 }
151 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700152
153# ------------------------------
154# Switch Up Construct Data Frame
155# ------------------------------
156
157print( "Constructing Switch Up data frame." )
158
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159upAvgsData <- melt( upAvgs )
160upAvgsData$scale <- fileData$scale
161upAvgsData$up_std <- fileData$up_std
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700162upAvgsData <- na.omit( upAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000163
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700164colnames( upAvgsData ) <- c( "ms",
165 "type",
166 "scale",
167 "stds" )
168
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000169upAvgsData$type <- as.character( upAvgsData$type )
170upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
171
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700172sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] +
173 fileData[ 'role_reply_to_device_avg' ] +
174 fileData[ 'role_request_to_role_reply_avg' ] +
175 fileData[ 'feature_reply_to_role_request_avg' ] +
176 fileData[ 'tcp_to_feature_reply_avg' ]
177
178print( "Up Averages Results:" )
179print( upAvgsData )
180
181# ---------------------------------
182# Switch Down Averages Data Sorting
183# ---------------------------------
184
185print( "Sorting data for Switch Down Averages." )
186
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800187requiredColumns <- c( "down_device_to_graph_avg",
188 "ack_to_device_avg",
189 "fin_ack_to_ack_avg" )
190
191tryCatch( downAvgs <- c( fileData[ requiredColumns] ),
192 error = function( e ) {
193 print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." )
194 print( "Required columns: " )
195 print( requiredColumns )
196 print( "Actual columns: " )
197 print( names( fileData ) )
198 print( "Error dump:" )
199 print( e )
200 quit( status = 1 )
201 }
202 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700203
204# --------------------------------
205# Switch Down Construct Data Frame
206# --------------------------------
207
208print( "Constructing Switch Down data frame." )
209
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000210downAvgsData <- melt( downAvgs )
211downAvgsData$scale <- fileData$scale
212downAvgsData$down_std <- fileData$down_std
213
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700214colnames( downAvgsData ) <- c( "ms",
215 "type",
216 "scale",
217 "stds" )
218
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000219downAvgsData$type <- as.character( downAvgsData$type )
220downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
221
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700222downAvgsData <- na.omit( downAvgsData )
223
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700224sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] +
225 fileData[ 'ack_to_device_avg' ] +
226 fileData[ 'fin_ack_to_ack_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700227
228print( "Down Averages Results:" )
229print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000230
231# **********************************************************
232# STEP 3: Generate graphs.
233# **********************************************************
234
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700235print( "**********************************************************" )
236print( "STEP 3: Generate Graph." )
237print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000238
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700239# ------------------------------------
240# Initialize Variables For Both Graphs
241# ------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000242
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700243print( "Initializing variables used in both graphs." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700244
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700245theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs
246xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000247xLabel <- xlab( "Scale" )
248yLabel <- ylab( "Latency (ms)" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700249imageWidth <- 15
250imageHeight <- 10
251imageDPI <- 200
252errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
253barWidth <- 1
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000254
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700255theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
256 legend.position = "bottom",
257 legend.text = element_text( size = 22 ),
258 legend.title = element_blank(),
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800259 legend.key.size = unit( 1.5, 'lines' ),
260 plot.subtitle = element_text( size=16, hjust=1.0 ) )
261
262subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700263
264# ----------------------------
265# Switch Up Generate Main Plot
266# ----------------------------
267
268print( "Creating main plot (Switch Up Latency)." )
269
270mainPlot <- ggplot( data = upAvgsData, aes( x = scale,
271 y = ms,
272 fill = type,
273 ymin = fileData[ 'up_end_to_end_avg' ],
274 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
275
276# ----------------------------------------
277# Switch Up Fundamental Variables Assigned
278# ----------------------------------------
279
280print( "Generating fundamental graph data (Switch Up Latency)." )
281
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800282title <- labs( title = "Switch Up Latency", subtitle = subtitle )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700283
284fundamentalGraphData <- mainPlot +
285 xScaleConfig +
286 xLabel +
287 yLabel +
288 theme +
289 title
290
291# -------------------------------------
292# Switch Up Generating Bar Graph Format
293# -------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000294
295print( "Generating bar graph with error bars (Switch Up Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000296
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700297barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
298errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
299
300barGraphValues <- geom_text( aes( x = upAvgsData$scale,
301 y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ),
302 label = format( sumOfUpAvgs,
303 digits = 3,
304 big.mark = ",",
305 scientific = FALSE ) ),
306 size = 7.0,
307 fontface = "bold" )
308
309wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) )
310
311result <- fundamentalGraphData +
312 barGraphFormat +
313 errorBarFormat +
314 barGraphValues +
315 wrapLegend
316
317# ---------------------------------
318# Switch Up Exporting Graph to File
319# ---------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000320
321print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800323tryCatch( ggsave( errBarOutputFileUp,
324 width = imageWidth,
325 height = imageHeight,
326 dpi = imageDPI ),
327 error = function( e ){
328 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
329 print( e )
330 quit( status = 1 )
331 }
332 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000333
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700334print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) )
335
336# ------------------------------
337# Switch Down Generate Main Plot
338# ------------------------------
339
340print( "Creating main plot (Switch Down Latency)." )
341
342mainPlot <- ggplot( data = downAvgsData, aes( x = scale,
343 y = ms,
344 fill = type,
345 ymin = fileData[ 'down_end_to_end_avg' ],
346 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
347
348# ------------------------------------------
349# Switch Down Fundamental Variables Assigned
350# ------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000351
352print( "Generating fundamental graph data (Switch Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000353
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700354colors <- scale_fill_manual( values=c( "#F77670", # Red
355 "#619DFA", # Blue
356 "#18BA48" ) ) # Green
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000357
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800358title <- labs( title = "Switch Down Latency", subtitle = subtitle )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700359
360fundamentalGraphData <- mainPlot +
361 xScaleConfig +
362 xLabel +
363 yLabel +
364 theme +
365 title
366
367# ---------------------------------------
368# Switch Down Generating Bar Graph Format
369# ---------------------------------------
370
371print( "Generating bar graph with error bars (Switch Down Latency)." )
372barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
373errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
374
375barGraphValues <- geom_text( aes( x = downAvgsData$scale,
376 y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ),
377 label = format( sumOfDownAvgs,
378 digits = 3,
379 big.mark = ",",
380 scientific = FALSE ) ),
381 size = 7.0,
382 fontface = "bold" )
383
384wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
385
386result <- fundamentalGraphData +
387 barGraphFormat +
388 colors +
389 errorBarFormat +
390 barGraphValues +
391 wrapLegend
392
393# -----------------------------------
394# Switch Down Exporting Graph to File
395# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000396
397print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000398
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800399tryCatch( ggsave( errBarOutputFileDown,
400 width = imageWidth,
401 height = imageHeight,
402 dpi = imageDPI ),
403 error = function( e ){
404 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
405 print( e )
406 quit( status = 1 )
407 }
408 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000409
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700410print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800411quit( status = 0 )