blob: 6c1a2204081a951bf1e5df59b553da9266dd1bc7 [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 Ronquillo6df87812017-08-28 16:17:36 +000073 q() # basically exit(), but in R
74}
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
190 avgs <- c( installWithdrawData[ 'install_avg' ],
191 installWithdrawData[ 'withdraw_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000192} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700193 colnames( rerouteData ) <- c( "date",
194 "name",
195 "date",
196 "branch",
Devin Lim0e967162017-11-03 15:59:53 -0700197 "is_old_flow",
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198 "commit",
199 "scale",
200 "batch_size",
201 "reroute_avg",
202 "reroute_std" )
203
204 avgs <- c( installWithdrawData[ 'install_avg' ],
205 installWithdrawData[ 'withdraw_avg' ],
206 rerouteData[ 'reroute_avg' ] )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000207}
208
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700209# Combine lists into data frames.
210dataFrame <- melt( avgs )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000211
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700212# --------------------
213# Construct Data Frame
214# --------------------
215
216print( "Constructing data frame." )
217
218if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists (due to batch size) for the dataFrame this time
219 dataFrame$scale <- c( installWithdrawData$scale,
220 installWithdrawData$scale )
221
222 dataFrame$stds <- c( installWithdrawData$install_std,
223 installWithdrawData$withdraw_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000224} else{
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700225 dataFrame$scale <- c( installWithdrawData$scale,
226 installWithdrawData$scale,
227 rerouteData$scale )
228
229 dataFrame$stds <- c( installWithdrawData$install_std,
230 installWithdrawData$withdraw_std,
231 rerouteData$reroute_std )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000232}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700233
234colnames( dataFrame ) <- c( "ms",
235 "type",
236 "scale",
237 "stds" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000238
239# Format data frame so that the data is in the same order as it appeared in the file.
240dataFrame$type <- as.character( dataFrame$type )
241dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
242
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700243dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700244
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700245print( "Data Frame Results:" )
246print( dataFrame )
247
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000248# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700249# STEP 3: Generate graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000250# **********************************************************
251
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700252print( "**********************************************************" )
253print( "STEP 3: Generate Graph." )
254print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000255
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700256# -------------------
257# Main Plot Generated
258# -------------------
259
260print( "Creating the main plot." )
261
262mainPlot <- ggplot( data = dataFrame, aes( x = scale,
263 y = ms,
264 ymin = ms,
265 ymax = ms + stds,
266 fill = type ) )
267
268# ------------------------------
269# Fundamental Variables Assigned
270# ------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000271
272print( "Generating fundamental graph data." )
273
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700274theme_set( theme_grey( base_size = 22 ) )
275barWidth <- 1.3
276xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000277xLabel <- xlab( "Scale" )
278yLabel <- ylab( "Latency (ms)" )
279fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700280title <- ggtitle( chartTitle )
281imageWidth <- 15
282imageHeight <- 10
283imageDPI <- 200
284errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000285
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700286theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ),
287 legend.position="bottom",
288 legend.text=element_text( size=22 ),
289 legend.title = element_blank(),
290 legend.key.size = unit( 1.5, 'lines' ) )
291
292colors <- scale_fill_manual( values=c( "#F77670",
293 "#619DFA",
294 "#18BA48" ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700295
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000296# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700297fundamentalGraphData <- mainPlot +
298 xScaleConfig +
299 xLabel +
300 yLabel +
301 fillLabel +
302 theme +
303 title +
304 colors
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000305
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700306# ---------------------------
307# Generating Bar Graph Format
308# ---------------------------
309
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000310print( "Generating bar graph with error bars." )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700311
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700312barGraphFormat <- geom_bar( stat = "identity",
313 width = barWidth,
314 position = "dodge" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000315
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700316errorBarFormat <- geom_errorbar( width = barWidth,
317 position = position_dodge( barWidth ),
318 color = errorBarColor )
319
320values <- geom_text( aes( x = dataFrame$scale,
321 y = dataFrame$ms + 0.035 * max( dataFrame$ms ),
322 label = format( dataFrame$ms,
323 digits = 3,
324 big.mark = ",",
325 scientific = FALSE ) ),
326 position = position_dodge( width = barWidth ),
327 size = 5.5,
328 fontface = "bold" )
329
330wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
331
332result <- fundamentalGraphData +
333 barGraphFormat +
334 errorBarFormat +
335 values +
336 wrapLegend
337
338# -----------------------
339# Exporting Graph to File
340# -----------------------
341
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000342print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700343
344ggsave( errBarOutputFile,
345 width = imageWidth,
346 height = imageHeight,
347 dpi = imageDPI )
348
349print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )