blob: 037b6d43f418f7239a52c20bbde9d57b13523b86 [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# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070026print( "**********************************************************" )
27print( "STEP 1: Data management." )
28print( "**********************************************************" )
Devin Lim0e967162017-11-03 15:59:53 -070029has_flow_obj = 1
30database_host = 2
31database_port = 3
32database_u_id = 4
33database_pw = 5
34test_name = 6
35branch_name = 7
36batch_size = 8
37old_flow = 9
38save_directory = 10
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039
Jeremy Ronquillob6268842017-10-03 13:02:58 -070040# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000041print( "Reading commmand-line args." )
42args <- commandArgs( trailingOnly=TRUE )
43
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070044# ----------------
45# Import Libraries
46# ----------------
47
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000048print( "Importing libraries." )
49library( ggplot2 )
50library( reshape2 )
51library( RPostgreSQL ) # For databases
52
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070053# -------------------
54# Check CLI Arguments
55# -------------------
56
57print( "Verifying CLI args." )
58
Devin Lim0e967162017-11-03 15:59:53 -070059if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070060
61 print( paste( "Usage: Rscript SCPFIntentInstallWithdrawRerouteLat.R",
62 "<isFlowObj>" ,
63 "<database-host>",
64 "<database-port>",
65 "<database-user-id>",
66 "<database-password>",
67 "<test-name>",
68 "<branch-name>",
69 "<batch-size>",
Devin Lim0e967162017-11-03 15:59:53 -070070 "<using-old-flow>",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071 "<directory-to-save-graphs>",
72 sep=" " ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080073 quit( status = 1 ) # basically exit(), but in R
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000074}
75
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076# -----------------------------------
77# Create File Name and Title of Graph
78# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070080print( "Creating filename and title of graph." )
81
82chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
83flowObjFileModifier <- ""
Devin Lim0e967162017-11-03 15:59:53 -070084errBarOutputFile <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085 "SCPFIntentInstallWithdrawRerouteLat_",
Devin Lim0e967162017-11-03 15:59:53 -070086 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070087 sep="" )
88
Devin Lim0e967162017-11-03 15:59:53 -070089if ( args[ has_flow_obj ] == "y" ){
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000090 errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070091 flowObjFileModifier <- "fobj_"
92 chartTitle <- paste( chartTitle, "w/ FlowObj" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000093}
Devin Lim0e967162017-11-03 15:59:53 -070094if ( args[ old_flow ] == "y" ){
95 errBarOutputFile <- paste( errBarOutputFile, "_OldFlow", sep="" )
96 chartTitle <- paste( chartTitle,
Devin Lim1bba7622017-11-14 16:31:41 -080097 "With Eventually Consistent Flow Rule Store",
Devin Lim0e967162017-11-03 15:59:53 -070098 sep="\n" )
99}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700100errBarOutputFile <- paste( errBarOutputFile,
101 "_",
Devin Lim0e967162017-11-03 15:59:53 -0700102 args[ batch_size ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700103 "-batchSize_graph.jpg",
104 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000105
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700106chartTitle <- paste( chartTitle,
107 "\nBatch Size =",
Devin Lim0e967162017-11-03 15:59:53 -0700108 args[ batch_size ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700109 sep=" " )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000110
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700111# ------------------
112# SQL Initialization
113# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000114
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700115print( "Initializing SQL" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000116
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700117con <- dbConnect( dbDriver( "PostgreSQL" ),
118 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -0700119 host = args[ database_host ],
120 port = strtoi( args[ database_port ] ),
121 user = args[ database_u_id ],
122 password = args[ database_pw ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700124# ---------------------------------------
125# Intent Install and Withdraw SQL Command
126# ---------------------------------------
127print( "Generating Intent Install and Withdraw SQL Command" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000128
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700129installWithdrawSQLCommand <- paste( "SELECT * FROM intent_latency_",
130 flowObjFileModifier,
131 "tests WHERE batch_size=",
Devin Lim0e967162017-11-03 15:59:53 -0700132 args[ batch_size ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700133 " AND branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700134 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700135 "' AND date IN ( SELECT MAX( date ) FROM intent_latency_",
136 flowObjFileModifier,
137 "tests WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700138 args[ branch_name ],
139 "' AND ",
140 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
141 "is_old_flow",
142 ")",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700143 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000144
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700145print( "Sending Intent Install and Withdraw SQL command:" )
146print( installWithdrawSQLCommand )
147installWithdrawData <- dbGetQuery( con, installWithdrawSQLCommand )
148
149# --------------------------
150# Intent Reroute SQL Command
151# --------------------------
152
153print( "Generating Intent Reroute SQL Command" )
154
155rerouteSQLCommand <- paste( "SELECT * FROM intent_reroute_latency_",
156 flowObjFileModifier,
157 "tests WHERE batch_size=",
Devin Lim0e967162017-11-03 15:59:53 -0700158 args[ batch_size ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700159 " AND branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700160 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700161 "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_",
162 flowObjFileModifier,
163 "tests WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700164 args[ branch_name ],
165 "' AND ",
166 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
167 "is_old_flow",
168 ")",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700169 sep="" )
170
171print( "Sending Intent Reroute SQL command:" )
172print( rerouteSQLCommand )
173rerouteData <- dbGetQuery( con, rerouteSQLCommand )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000174
175# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700176# STEP 2: Organize Data.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000177# **********************************************************
178
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700179print( "**********************************************************" )
180print( "STEP 2: Organize Data." )
181print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000182
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700183# -------------------------------------------------------
184# Combining Install, Withdraw, and Reroute Latencies Data
185# -------------------------------------------------------
186
187print( "Combining Install, Withdraw, and Reroute Latencies Data" )
188
189if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists, so we can exclude it if necessary
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800190
191 requiredColumns <- c( "install_avg",
192 "withdraw_avg" )
193
194 tryCatch( avgs <- c( installWithdrawData[ requiredColumns] ),
195 error = function( e ) {
196 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." )
197 print( "Required columns: " )
198 print( requiredColumns )
199 print( "Actual columns: " )
200 print( names( fileData ) )
201 print( "Error dump:" )
202 print( e )
203 quit( status = 1 )
204 }
205 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000206} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700207 colnames( rerouteData ) <- c( "date",
208 "name",
209 "date",
210 "branch",
Devin Lim0e967162017-11-03 15:59:53 -0700211 "is_old_flow",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700212 "commit",
213 "scale",
214 "batch_size",
215 "reroute_avg",
216 "reroute_std" )
217
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800218 tryCatch( avgs <- c( installWithdrawData[ 'install_avg' ],
219 installWithdrawData[ 'withdraw_avg' ],
220 rerouteData[ 'reroute_avg' ] ),
221 error = function( e ) {
222 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." )
223 print( "Required columns: " )
224 print( requiredColumns )
225 print( "Actual columns: " )
226 print( names( fileData ) )
227 print( "Error dump:" )
228 print( e )
229 quit( status = 1 )
230 }
231 )
232
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000233}
234
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700235# Combine lists into data frames.
236dataFrame <- melt( avgs )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000237
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700238# --------------------
239# Construct Data Frame
240# --------------------
241
242print( "Constructing data frame." )
243
244if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists (due to batch size) for the dataFrame this time
245 dataFrame$scale <- c( installWithdrawData$scale,
246 installWithdrawData$scale )
247
248 dataFrame$stds <- c( installWithdrawData$install_std,
249 installWithdrawData$withdraw_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000250} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700251 dataFrame$scale <- c( installWithdrawData$scale,
252 installWithdrawData$scale,
253 rerouteData$scale )
254
255 dataFrame$stds <- c( installWithdrawData$install_std,
256 installWithdrawData$withdraw_std,
257 rerouteData$reroute_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000258}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700259
260colnames( dataFrame ) <- c( "ms",
261 "type",
262 "scale",
263 "stds" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000264
265# Format data frame so that the data is in the same order as it appeared in the file.
266dataFrame$type <- as.character( dataFrame$type )
267dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
268
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700269dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700270
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700271print( "Data Frame Results:" )
272print( dataFrame )
273
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000274# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700275# STEP 3: Generate graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000276# **********************************************************
277
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700278print( "**********************************************************" )
279print( "STEP 3: Generate Graph." )
280print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000281
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700282# -------------------
283# Main Plot Generated
284# -------------------
285
286print( "Creating the main plot." )
287
288mainPlot <- ggplot( data = dataFrame, aes( x = scale,
289 y = ms,
290 ymin = ms,
291 ymax = ms + stds,
292 fill = type ) )
293
294# ------------------------------
295# Fundamental Variables Assigned
296# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000297
298print( "Generating fundamental graph data." )
299
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700300theme_set( theme_grey( base_size = 22 ) )
301barWidth <- 1.3
302xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000303xLabel <- xlab( "Scale" )
304yLabel <- ylab( "Latency (ms)" )
305fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700306title <- ggtitle( chartTitle )
307imageWidth <- 15
308imageHeight <- 10
309imageDPI <- 200
310errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000311
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700312theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ),
313 legend.position="bottom",
314 legend.text=element_text( size=22 ),
315 legend.title = element_blank(),
316 legend.key.size = unit( 1.5, 'lines' ) )
317
318colors <- scale_fill_manual( values=c( "#F77670",
319 "#619DFA",
320 "#18BA48" ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700321
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700323fundamentalGraphData <- mainPlot +
324 xScaleConfig +
325 xLabel +
326 yLabel +
327 fillLabel +
328 theme +
329 title +
330 colors
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000331
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700332# ---------------------------
333# Generating Bar Graph Format
334# ---------------------------
335
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000336print( "Generating bar graph with error bars." )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700337
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700338barGraphFormat <- geom_bar( stat = "identity",
339 width = barWidth,
340 position = "dodge" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000341
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700342errorBarFormat <- geom_errorbar( width = barWidth,
343 position = position_dodge( barWidth ),
344 color = errorBarColor )
345
346values <- geom_text( aes( x = dataFrame$scale,
347 y = dataFrame$ms + 0.035 * max( dataFrame$ms ),
348 label = format( dataFrame$ms,
349 digits = 3,
350 big.mark = ",",
351 scientific = FALSE ) ),
352 position = position_dodge( width = barWidth ),
353 size = 5.5,
354 fontface = "bold" )
355
356wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
357
358result <- fundamentalGraphData +
359 barGraphFormat +
360 errorBarFormat +
361 values +
362 wrapLegend
363
364# -----------------------
365# Exporting Graph to File
366# -----------------------
367
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000368print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700369
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800370tryCatch( ggsave( errBarOutputFile,
371 width = imageWidth,
372 height = imageHeight,
373 dpi = imageDPI ),
374 error = function( e ){
375 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
376 print( e )
377 quit( status = 1 )
378 }
379 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700380
381print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800382quit( status = 0 )