blob: 6f67b0d21336885cf62a201105f1bfc5e88d9d6f [file] [log] [blame]
Jeremy Ronquillodae11042018-02-21 09:21:44 -08001# 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: j_ronquillo@u.pacific.edu
22
23# **********************************************************
24# STEP 1: Data management.
25# **********************************************************
26print( "**********************************************************" )
27print( "STEP 1: Data management." )
28print( "**********************************************************" )
29has_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
39
40# Command line arguments are read.
41print( "Reading commmand-line args." )
42args <- commandArgs( trailingOnly=TRUE )
43
44# ----------------
45# Import Libraries
46# ----------------
47
48print( "Importing libraries." )
49library( ggplot2 )
50library( reshape2 )
51library( RPostgreSQL ) # For databases
52
53# -------------------
54# Check CLI Arguments
55# -------------------
56
57print( "Verifying CLI args." )
58
59if ( is.na( args[ save_directory ] ) ){
60
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>",
70 "<using-old-flow>",
71 "<directory-to-save-graphs>",
72 sep=" " ) )
73 quit( status = 1 ) # basically exit(), but in R
74}
75
76# -----------------------------------
77# Create File Name and Title of Graph
78# -----------------------------------
79
80print( "Creating filename and title of graph." )
81
82chartTitle <- "Intent Install, Withdraw, & Reroute Latencies"
83flowObjFileModifier <- ""
84errBarOutputFile <- paste( args[ save_directory ],
85 "SCPFIntentInstallWithdrawRerouteLat_",
86 args[ branch_name ],
87 sep="" )
88
89if ( args[ has_flow_obj ] == "y" ){
90 errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" )
91 flowObjFileModifier <- "fobj_"
92 chartTitle <- paste( chartTitle, "w/ FlowObj" )
93}
94if ( args[ old_flow ] == "y" ){
95 errBarOutputFile <- paste( errBarOutputFile, "_OldFlow", sep="" )
96 chartTitle <- paste( chartTitle,
97 "With Eventually Consistent Flow Rule Store",
98 sep="\n" )
99}
100errBarOutputFile <- paste( errBarOutputFile,
101 "_",
102 args[ batch_size ],
103 "-batchSize_graph.jpg",
104 sep="" )
105
106chartTitle <- paste( chartTitle,
107 "\nBatch Size =",
108 args[ batch_size ],
109 sep=" " )
110
111# ------------------
112# SQL Initialization
113# ------------------
114
115print( "Initializing SQL" )
116
117con <- dbConnect( dbDriver( "PostgreSQL" ),
118 dbname = "onostest",
119 host = args[ database_host ],
120 port = strtoi( args[ database_port ] ),
121 user = args[ database_u_id ],
122 password = args[ database_pw ] )
123
124# ---------------------------------------
125# Intent Install and Withdraw SQL Command
126# ---------------------------------------
127print( "Generating Intent Install and Withdraw SQL Command" )
128
129installWithdrawSQLCommand <- paste( "SELECT * FROM intent_latency_",
130 flowObjFileModifier,
131 "tests WHERE batch_size=",
132 args[ batch_size ],
133 " AND branch = '",
134 args[ branch_name ],
135 "' AND date IN ( SELECT MAX( date ) FROM intent_latency_",
136 flowObjFileModifier,
137 "tests WHERE branch='",
138 args[ branch_name ],
139 "' AND ",
140 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
141 "is_old_flow",
142 ")",
143 sep="" )
144
145print( "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=",
158 args[ batch_size ],
159 " AND branch = '",
160 args[ branch_name ],
161 "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_",
162 flowObjFileModifier,
163 "tests WHERE branch='",
164 args[ branch_name ],
165 "' AND ",
166 ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) ,
167 "is_old_flow",
168 ")",
169 sep="" )
170
171print( "Sending Intent Reroute SQL command:" )
172print( rerouteSQLCommand )
173rerouteData <- dbGetQuery( con, rerouteSQLCommand )
174
175# **********************************************************
176# STEP 2: Organize Data.
177# **********************************************************
178
179print( "**********************************************************" )
180print( "STEP 2: Organize Data." )
181print( "**********************************************************" )
182
183# -------------------------------------------------------
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
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 )
206} else{
207 colnames( rerouteData ) <- c( "date",
208 "name",
209 "date",
210 "branch",
211 "is_old_flow",
212 "commit",
213 "scale",
214 "batch_size",
215 "reroute_avg",
216 "reroute_std" )
217
218 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
233}
234
235# Combine lists into data frames.
236dataFrame <- melt( avgs )
237
238# --------------------
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 )
250} else{
251 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 )
258}
259
260colnames( dataFrame ) <- c( "ms",
261 "type",
262 "scale",
263 "stds" )
264
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
269dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
270
271print( "Data Frame Results:" )
272print( dataFrame )
273
274# **********************************************************
275# STEP 3: Generate graph.
276# **********************************************************
277
278print( "**********************************************************" )
279print( "STEP 3: Generate Graph." )
280print( "**********************************************************" )
281
282# -------------------
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# ------------------------------
297
298print( "Generating fundamental graph data." )
299
300theme_set( theme_grey( base_size = 22 ) )
301barWidth <- 1.3
302xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) )
303xLabel <- xlab( "Scale" )
304yLabel <- ylab( "Latency (ms)" )
305fillLabel <- labs( fill="Type" )
306imageWidth <- 15
307imageHeight <- 10
308imageDPI <- 200
309errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
310
311theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ),
312 legend.position="bottom",
313 legend.text=element_text( size=22 ),
314 legend.title = element_blank(),
315 legend.key.size = unit( 1.5, 'lines' ),
316 plot.subtitle = element_text( size=16, hjust=1.0 ) )
317
318subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
319
320title <- labs( title = chartTitle, subtitle = subtitle )
321
322colors <- scale_fill_manual( values=c( "#F77670",
323 "#619DFA",
324 "#18BA48" ) )
325
326# Store plot configurations as 1 variable
327fundamentalGraphData <- mainPlot +
328 xScaleConfig +
329 xLabel +
330 yLabel +
331 fillLabel +
332 theme +
333 title +
334 colors
335
336# ---------------------------
337# Generating Bar Graph Format
338# ---------------------------
339
340print( "Generating bar graph with error bars." )
341
342barGraphFormat <- geom_bar( stat = "identity",
343 width = barWidth,
344 position = "dodge" )
345
346errorBarFormat <- geom_errorbar( width = barWidth,
347 position = position_dodge( barWidth ),
348 color = errorBarColor )
349
350values <- geom_text( aes( x = dataFrame$scale,
351 y = dataFrame$ms + 0.035 * max( dataFrame$ms ),
352 label = format( dataFrame$ms,
353 digits = 3,
354 big.mark = ",",
355 scientific = FALSE ) ),
356 position = position_dodge( width = barWidth ),
357 size = 5.5,
358 fontface = "bold" )
359
360wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
361
362result <- fundamentalGraphData +
363 barGraphFormat +
364 errorBarFormat +
365 values +
366 wrapLegend
367
368# -----------------------
369# Exporting Graph to File
370# -----------------------
371
372print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
373
374tryCatch( ggsave( errBarOutputFile,
375 width = imageWidth,
376 height = imageHeight,
377 dpi = imageDPI ),
378 error = function( e ){
379 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
380 print( e )
381 quit( status = 1 )
382 }
383 )
384
385print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )
386quit( status = 0 )