blob: 3398b0ba36bf2c908de1bcf07c2eecf1336e7b68 [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(),
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800253 legend.key.size = unit( 1.5, 'lines' ),
254 plot.subtitle = element_text( size=16, hjust=1.0 ) )
255
256subtitle <- paste( "Last Updated: ", format( Sys.time(), format = "%b %d, %Y at %I:%M %p %Z" ), sep="" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700257
258colors <- scale_fill_manual( values=c( "#F77670",
259 "#619DFA",
260 "#18BA48" ) )
261
262# --------------------------
263# Port Up Generate Main Plot
264# --------------------------
265
266print( "Generating main plot (Port Up Latency)." )
267
268mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale,
269 y = ms,
270 fill = type,
271 ymin = fileData[ 'up_end_to_end_avg' ],
272 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
273
274# --------------------------------------
275# Port Up Fundamental Variables Assigned
276# --------------------------------------
277
278print( "Generating fundamental graph data (Port Up Latency)." )
279
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800280title <- labs( title = "Port Up Latency", subtitle = subtitle )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700281
282fundamentalGraphData <- mainPlot +
283 xScaleConfig +
284 xLabel +
285 yLabel +
286 fillLabel +
287 theme +
288 wrapLegend +
289 title +
290 colors
291
292# -----------------------------------
293# Port Up Generating Bar Graph Format
294# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000295
296print( "Generating bar graph with error bars (Port Up Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000297
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700298barGraphFormat <- geom_bar( stat = "identity",
299 width = barWidth )
300errorBarFormat <- geom_errorbar( width = barWidth,
301 color = errorBarColor )
302
303values <- geom_text( aes( x = upAvgsDataFrame$scale,
304 y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ),
305 label = format( sumOfUpAvgs,
306 digits=3,
307 big.mark = ",",
308 scientific = FALSE ) ),
309 size = 7.0,
310 fontface = "bold" )
311
312result <- fundamentalGraphData +
313 barGraphFormat +
314 errorBarFormat +
315 values
316
317# -------------------------------
318# Port Up Exporting Graph to File
319# -------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000320
321print( paste( "Saving bar chart with error bars (Port 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 (Port Up Latency) out to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000335
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700336# ----------------------------
337# Port Down Generate Main Plot
338# ----------------------------
339
340print( "Generating main plot (Port Down Latency)." )
341
342mainPlot <- ggplot( data = downAvgsDataFrame, 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# Port Down Fundamental Variables Assigned
350# ----------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000351
352print( "Generating fundamental graph data (Port Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000353
Jeremy Ronquillo94f99dd2018-01-05 11:11:27 -0800354title <- labs( title = "Port Down Latency", subtitle = subtitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000355
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700356fundamentalGraphData <- mainPlot +
357 xScaleConfig +
358 xLabel +
359 yLabel +
360 fillLabel +
361 theme +
362 wrapLegend +
363 title +
364 colors
365
366# -------------------------------------
367# Port Down Generating Bar Graph Format
368# -------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000369
370print( "Generating bar graph with error bars (Port Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000371
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700372barGraphFormat <- geom_bar( stat = "identity",
373 width = barWidth )
374errorBarFormat <- geom_errorbar( width = barWidth,
375 color = errorBarColor )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000376
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700377values <- geom_text( aes( x = downAvgsDataFrame$scale,
378 y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ),
379 label = format( sumOfDownAvgs,
380 digits=3,
381 big.mark = ",",
382 scientific = FALSE ) ),
383 size = 7.0,
384 fontface = "bold" )
385
386result <- fundamentalGraphData +
387 barGraphFormat +
388 errorBarFormat +
389 values
390
391# ---------------------------------
392# Port Down Exporting Graph to File
393# ---------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000394
395print( paste( "Saving bar chart with error bars (Port Down Latency) to", errBarOutputFileDown ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000396
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800397tryCatch( ggsave( errBarOutputFileDown,
398 width = imageWidth,
399 height = imageHeight,
400 dpi = imageDPI ),
401 error = function( e ){
402 print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" )
403 print( e )
404 quit( status = 1 )
405 }
406 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000407
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700408print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Port Down Latency) out to", errBarOutputFileDown ) )
Jeremy Ronquillo9ea85d02017-11-27 10:21:03 -0800409quit( status = 0 )