blob: 46370721da6b4c5f5093de641af92e611d13a6dd [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 -070029database_host = 1
30database_port = 2
31database_u_id = 3
32database_pw = 4
33test_name = 5
34branch_name = 6
35save_directory = 7
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000036
Jeremy Ronquillob6268842017-10-03 13:02:58 -070037# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000038print( "Reading commmand-line args." )
39args <- commandArgs( trailingOnly=TRUE )
40
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070041# ----------------
42# Import Libraries
43# ----------------
44
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000045print( "Importing libraries." )
46library( ggplot2 )
47library( reshape2 )
48library( RPostgreSQL ) # For databases
49
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070050# -------------------
51# Check CLI Arguments
52# -------------------
53
54print( "Verifying CLI args." )
55
Devin Lim0e967162017-11-03 15:59:53 -070056if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070057
58 print( paste( "Usage: Rscript SCPFportLat",
59 "<database-host>",
60 "<database-port>",
61 "<database-user-id>",
62 "<database-password>",
63 "<test-name>",
64 "<branch-name>",
65 "<directory-to-save-graphs>",
66 sep=" " ) )
67
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -080068 quit( status = 1 ) # basically exit(), but in R
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000069}
70
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071# -----------------
72# Create File Names
73# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000074
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070075print( "Creating filenames and title of graph." )
Devin Lim0e967162017-11-03 15:59:53 -070076errBarOutputFileUp <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070077 "SCPFportLat_",
Devin Lim0e967162017-11-03 15:59:53 -070078 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070079 "_UpErrBarWithStack.jpg",
80 sep = "" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000081
Devin Lim0e967162017-11-03 15:59:53 -070082errBarOutputFileDown <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070083 "SCPFportLat_",
Devin Lim0e967162017-11-03 15:59:53 -070084 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085 "_DownErrBarWithStack.jpg",
86 sep = "" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000087
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070088# ------------------
89# SQL Initialization
90# ------------------
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070091print( "Initializing SQL" )
92
93con <- dbConnect( dbDriver( "PostgreSQL" ),
94 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -070095 host = args[ database_host ],
96 port = strtoi( args[ database_port ] ),
97 user = args[ database_u_id ],
98 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070099
100# ------------------------
101# Port Latency SQL Command
102# ------------------------
103
104print( "Generating Port Latency SQL Command" )
105
106command <- paste( "SELECT * FROM port_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700107 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700108 "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700109 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700110 "' ) ",
111 sep = "" )
112
113print( "Sending SQL command:" )
114print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000115
116fileData <- dbGetQuery( con, command )
117
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000118# **********************************************************
119# STEP 2: Organize data.
120# **********************************************************
121
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700122print( "**********************************************************" )
123print( "STEP 2: Organize Data." )
124print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000125
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700126# -----------------------------
127# Port Up Averages Data Sorting
128# -----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000129
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700130print( "Sorting data for Port Up Averages." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000131
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800132requiredColumns <- c( "up_ofp_to_dev_avg", "up_dev_to_link_avg", "up_link_to_graph_avg" )
133
134tryCatch( upAvgs <- c( fileData[ requiredColumns] ),
135 error = function( e ) {
136 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." )
137 print( "Required columns: " )
138 print( requiredColumns )
139 print( "Actual columns: " )
140 print( names( fileData ) )
141 print( "Error dump:" )
142 print( e )
143 quit( status = 1 )
144 }
145 )
146
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000147
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700148# ----------------------------
149# Port Up Construct Data Frame
150# ----------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000151
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700152print( "Constructing Port Up data frame." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000153
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700154upAvgsDataFrame <- melt( upAvgs )
155upAvgsDataFrame$scale <- fileData$scale
156upAvgsDataFrame$up_std <- fileData$up_std
157
158colnames( upAvgsDataFrame ) <- c( "ms",
159 "type",
160 "scale",
161 "stds" )
162
163upAvgsDataFrame <- na.omit( upAvgsDataFrame )
164
165upAvgsDataFrame$type <- as.character( upAvgsDataFrame$type )
166upAvgsDataFrame$type <- factor( upAvgsDataFrame$type, levels=unique( upAvgsDataFrame$type ) )
167
168sumOfUpAvgs <- fileData[ 'up_ofp_to_dev_avg' ] +
169 fileData[ 'up_dev_to_link_avg' ] +
170 fileData[ 'up_link_to_graph_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700171
172print( "Up Averages Results:" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700173print( upAvgsDataFrame )
174
175# -------------------------------
176# Port Down Averages Data Sorting
177# -------------------------------
178
179print( "Sorting data for Port Down Averages." )
180
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800181requiredColumns <- c( "down_ofp_to_dev_avg", "down_dev_to_link_avg", "down_link_to_graph_avg" )
182
183tryCatch( downAvgs <- c( fileData[ requiredColumns] ),
184 error = function( e ) {
185 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." )
186 print( "Required columns: " )
187 print( requiredColumns )
188 print( "Actual columns: " )
189 print( names( fileData ) )
190 print( "Error dump:" )
191 print( e )
192 quit( status = 1 )
193 }
194 )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700195
196# ------------------------------
197# Port Down Construct Data Frame
198# ------------------------------
199
200print( "Constructing Port Down data frame." )
201
202downAvgsDataFrame <- melt( downAvgs )
203downAvgsDataFrame$scale <- fileData$scale
204downAvgsDataFrame$down_std <- fileData$down_std
205
206colnames( downAvgsDataFrame ) <- c( "ms",
207 "type",
208 "scale",
209 "stds" )
210
211downAvgsDataFrame <- na.omit( downAvgsDataFrame )
212
213downAvgsDataFrame$type <- as.character( downAvgsDataFrame$type )
214downAvgsDataFrame$type <- factor( downAvgsDataFrame$type, levels=unique( downAvgsDataFrame$type ) )
215
216sumOfDownAvgs <- fileData[ 'down_ofp_to_dev_avg' ] +
217 fileData[ 'down_dev_to_link_avg' ] +
218 fileData[ 'down_link_to_graph_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700219
220print( "Down Averages Results:" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700221print( downAvgsDataFrame )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000222
223# **********************************************************
224# STEP 3: Generate graphs.
225# **********************************************************
226
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700227print( "**********************************************************" )
228print( "STEP 3: Generate Graph." )
229print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000230
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700231# ------------------------------------
232# Initialize Variables For Both Graphs
233# ------------------------------------
234
235print( "Initializing variables used in both graphs." )
236
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700237theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700238barWidth <- 1
239xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000240xLabel <- xlab( "Scale" )
241yLabel <- ylab( "Latency (ms)" )
242fillLabel <- labs( fill="Type" )
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700243wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700244imageWidth <- 15
245imageHeight <- 10
246imageDPI <- 200
247errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000248
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700249theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ),
250 legend.position="bottom",
251 legend.text=element_text( size=22 ),
252 legend.title = element_blank(),
253 legend.key.size = unit( 1.5, 'lines' ) )
254
255colors <- scale_fill_manual( values=c( "#F77670",
256 "#619DFA",
257 "#18BA48" ) )
258
259# --------------------------
260# Port Up Generate Main Plot
261# --------------------------
262
263print( "Generating main plot (Port Up Latency)." )
264
265mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale,
266 y = ms,
267 fill = type,
268 ymin = fileData[ 'up_end_to_end_avg' ],
269 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
270
271# --------------------------------------
272# Port Up Fundamental Variables Assigned
273# --------------------------------------
274
275print( "Generating fundamental graph data (Port Up Latency)." )
276
277title <- ggtitle( "Port Up Latency" )
278
279fundamentalGraphData <- mainPlot +
280 xScaleConfig +
281 xLabel +
282 yLabel +
283 fillLabel +
284 theme +
285 wrapLegend +
286 title +
287 colors
288
289# -----------------------------------
290# Port Up Generating Bar Graph Format
291# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000292
293print( "Generating bar graph with error bars (Port Up Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000294
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700295barGraphFormat <- geom_bar( stat = "identity",
296 width = barWidth )
297errorBarFormat <- geom_errorbar( width = barWidth,
298 color = errorBarColor )
299
300values <- geom_text( aes( x = upAvgsDataFrame$scale,
301 y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ),
302 label = format( sumOfUpAvgs,
303 digits=3,
304 big.mark = ",",
305 scientific = FALSE ) ),
306 size = 7.0,
307 fontface = "bold" )
308
309result <- fundamentalGraphData +
310 barGraphFormat +
311 errorBarFormat +
312 values
313
314# -------------------------------
315# Port Up Exporting Graph to File
316# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000317
318print( paste( "Saving bar chart with error bars (Port Up Latency) to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000319
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800320tryCatch( ggsave( errBarOutputFileUp,
321 width = imageWidth,
322 height = imageHeight,
323 dpi = imageDPI ),
324 error = function( e ){
325 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
326 print( e )
327 quit( status = 1 )
328 }
329 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000330
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700331print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Port Up Latency) out to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000332
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700333# ----------------------------
334# Port Down Generate Main Plot
335# ----------------------------
336
337print( "Generating main plot (Port Down Latency)." )
338
339mainPlot <- ggplot( data = downAvgsDataFrame, aes( x = scale,
340 y = ms,
341 fill = type,
342 ymin = fileData[ 'down_end_to_end_avg' ],
343 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
344
345# ----------------------------------------
346# Port Down Fundamental Variables Assigned
347# ----------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000348
349print( "Generating fundamental graph data (Port Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000350
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700351title <- ggtitle( "Port Down Latency" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000352
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700353fundamentalGraphData <- mainPlot +
354 xScaleConfig +
355 xLabel +
356 yLabel +
357 fillLabel +
358 theme +
359 wrapLegend +
360 title +
361 colors
362
363# -------------------------------------
364# Port Down Generating Bar Graph Format
365# -------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000366
367print( "Generating bar graph with error bars (Port Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000368
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700369barGraphFormat <- geom_bar( stat = "identity",
370 width = barWidth )
371errorBarFormat <- geom_errorbar( width = barWidth,
372 color = errorBarColor )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000373
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700374values <- geom_text( aes( x = downAvgsDataFrame$scale,
375 y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ),
376 label = format( sumOfDownAvgs,
377 digits=3,
378 big.mark = ",",
379 scientific = FALSE ) ),
380 size = 7.0,
381 fontface = "bold" )
382
383result <- fundamentalGraphData +
384 barGraphFormat +
385 errorBarFormat +
386 values
387
388# ---------------------------------
389# Port Down Exporting Graph to File
390# ---------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000391
392print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000393
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800394tryCatch( ggsave( errBarOutputFileDown,
395 width = imageWidth,
396 height = imageHeight,
397 dpi = imageDPI ),
398 error = function( e ){
399 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
400 print( e )
401 quit( status = 1 )
402 }
403 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000404
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700405print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800406quit( status = 0 )