blob: 6311df79225ed8f270ee40e9d1f2a28592cdfe81 [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# Example script:
21# Port Latency Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFportLat_master_UpErrBarWithStack.jpg):
22# Rscript SCPFportLat.R <url> <port> <username> <pass> SCPFmastershipFailoverLat master /path/to/save/directory/
23
24# **********************************************************
25# STEP 1: Data management.
26# **********************************************************
27
28print( "**********************************************************" )
29print( "STEP 1: Data management." )
30print( "**********************************************************" )
31
32save_directory = 7
33
34# Command line arguments are read.
35print( "Reading commmand-line args." )
36args <- commandArgs( trailingOnly=TRUE )
37
38# ----------------
39# Import Libraries
40# ----------------
41
42print( "Importing libraries." )
43library( ggplot2 )
44library( reshape2 )
45library( RPostgreSQL ) # For databases
Devin Lim324806b2018-05-11 15:36:52 -070046source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/saveGraph.R" )
47source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/fundamentalGraphData.R" )
48source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/initSQL.R" )
49source( "~/OnosSystemTest/TestON/JenkinsFile/wikiGraphRScripts/dependencies/cliArgs.R" )
Jeremy Ronquillodae11042018-02-21 09:21:44 -080050
51# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
56
57if ( length( args ) != save_directory ){
58 usage( "SCPFmastershipFailoverLat.R" )
59 quit( status = 1 )
60}
61
62# -----------------
63# Create File Names
64# -----------------
65
66print( "Creating filenames and title of graph." )
67errBarOutputFileUp <- paste( args[ save_directory ],
68 "SCPFportLat_",
69 args[ branch_name ],
70 "_UpErrBarWithStack.jpg",
71 sep = "" )
72
73errBarOutputFileDown <- paste( args[ save_directory ],
74 "SCPFportLat_",
75 args[ branch_name ],
76 "_DownErrBarWithStack.jpg",
77 sep = "" )
78
79# ------------------
80# SQL Initialization
81# ------------------
82
83print( "Initializing SQL" )
84
85con <- initSQL( args[ database_host ],
86 args[ database_port ],
87 args[ database_u_id ],
88 args[ database_pw ] )
89
90# ------------------------
91# Port Latency SQL Command
92# ------------------------
93
94print( "Generating Port Latency SQL Command" )
95
96command <- paste( "SELECT * FROM port_latency_details WHERE branch = '",
97 args[ branch_name ],
98 "' AND date IN ( SELECT MAX( date ) FROM port_latency_details WHERE branch = '",
99 args[ branch_name ],
100 "' ) ",
101 sep = "" )
102
103fileData <- retrieveData( con, command )
104
105# **********************************************************
106# STEP 2: Organize data.
107# **********************************************************
108
109print( "**********************************************************" )
110print( "STEP 2: Organize Data." )
111print( "**********************************************************" )
112
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800113latestBuildDate <- fileData$date[1]
114
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800115# -----------------------------
116# Port Up Averages Data Sorting
117# -----------------------------
118
119print( "Sorting data for Port Up Averages." )
120
121requiredColumns <- c( "up_ofp_to_dev_avg", "up_dev_to_link_avg", "up_link_to_graph_avg" )
122
123tryCatch( upAvgs <- c( fileData[ requiredColumns] ),
124 error = function( e ) {
125 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." )
126 print( "Required columns: " )
127 print( requiredColumns )
128 print( "Actual columns: " )
129 print( names( fileData ) )
130 print( "Error dump:" )
131 print( e )
132 quit( status = 1 )
133 }
134 )
135
136# ----------------------------
137# Port Up Construct Data Frame
138# ----------------------------
139
140print( "Constructing Port Up data frame." )
141
142upAvgsDataFrame <- melt( upAvgs )
143upAvgsDataFrame$scale <- fileData$scale
144upAvgsDataFrame$up_std <- fileData$up_std
145
146colnames( upAvgsDataFrame ) <- c( "ms",
147 "type",
148 "scale",
149 "stds" )
150
151upAvgsDataFrame <- na.omit( upAvgsDataFrame )
152
153upAvgsDataFrame$type <- as.character( upAvgsDataFrame$type )
154upAvgsDataFrame$type <- factor( upAvgsDataFrame$type, levels=unique( upAvgsDataFrame$type ) )
155
156sumOfUpAvgs <- fileData[ 'up_ofp_to_dev_avg' ] +
157 fileData[ 'up_dev_to_link_avg' ] +
158 fileData[ 'up_link_to_graph_avg' ]
159
160print( "Up Averages Results:" )
161print( upAvgsDataFrame )
162
163# -------------------------------
164# Port Down Averages Data Sorting
165# -------------------------------
166
167print( "Sorting data for Port Down Averages." )
168
169requiredColumns <- c( "down_ofp_to_dev_avg", "down_dev_to_link_avg", "down_link_to_graph_avg" )
170
171tryCatch( downAvgs <- c( fileData[ requiredColumns] ),
172 error = function( e ) {
173 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." )
174 print( "Required columns: " )
175 print( requiredColumns )
176 print( "Actual columns: " )
177 print( names( fileData ) )
178 print( "Error dump:" )
179 print( e )
180 quit( status = 1 )
181 }
182 )
183
184# ------------------------------
185# Port Down Construct Data Frame
186# ------------------------------
187
188print( "Constructing Port Down data frame." )
189
190downAvgsDataFrame <- melt( downAvgs )
191downAvgsDataFrame$scale <- fileData$scale
192downAvgsDataFrame$down_std <- fileData$down_std
193
194colnames( downAvgsDataFrame ) <- c( "ms",
195 "type",
196 "scale",
197 "stds" )
198
199downAvgsDataFrame <- na.omit( downAvgsDataFrame )
200
201downAvgsDataFrame$type <- as.character( downAvgsDataFrame$type )
202downAvgsDataFrame$type <- factor( downAvgsDataFrame$type, levels=unique( downAvgsDataFrame$type ) )
203
204sumOfDownAvgs <- fileData[ 'down_ofp_to_dev_avg' ] +
205 fileData[ 'down_dev_to_link_avg' ] +
206 fileData[ 'down_link_to_graph_avg' ]
207
208print( "Down Averages Results:" )
209print( downAvgsDataFrame )
210
211# **********************************************************
212# STEP 3: Generate graphs.
213# **********************************************************
214
215print( "**********************************************************" )
216print( "STEP 3: Generate Graph." )
217print( "**********************************************************" )
218
219# ------------------------------------
220# Initialize Variables For Both Graphs
221# ------------------------------------
222
223print( "Initializing variables used in both graphs." )
224
225defaultTextSize()
226xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
227
228xLabel <- xlab( "Scale" )
229yLabel <- ylab( "Latency (ms)" )
230fillLabel <- labs( fill="Type" )
231
232barWidth <- 1
233
234wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
235
236theme <- graphTheme()
237
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800238subtitle <- lastUpdatedLabel( latestBuildDate )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800239
240colors <- scale_fill_manual( values=c( webColor( "redv2" ),
241 webColor( "light_blue" ),
242 webColor( "green" ) ) )
243
244errorBarColor <- webColor( "darkerGray" )
245
246# --------------------------
247# Port Up Generate Main Plot
248# --------------------------
249
250print( "Generating main plot (Port Up Latency)." )
251
252mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale,
253 y = ms,
254 fill = type,
255 ymin = fileData[ 'up_end_to_end_avg' ],
256 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
257
258# --------------------------------------
259# Port Up Fundamental Variables Assigned
260# --------------------------------------
261
262print( "Generating fundamental graph data (Port Up Latency)." )
263
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800264title <- labs( title = "Port Up Latency", subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800265
266fundamentalGraphData <- mainPlot +
267 xScaleConfig +
268 xLabel +
269 yLabel +
270 fillLabel +
271 theme +
272 wrapLegend +
273 title +
274 colors
275
276# -----------------------------------
277# Port Up Generating Bar Graph Format
278# -----------------------------------
279
280print( "Generating bar graph with error bars (Port Up Latency)." )
281
282barGraphFormat <- geom_bar( stat = "identity",
283 width = barWidth )
284
285errorBarFormat <- geom_errorbar( width = barWidth,
286 color = errorBarColor )
287
288values <- geom_text( aes( x = upAvgsDataFrame$scale,
289 y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ),
290 label = format( sumOfUpAvgs,
291 digits=3,
292 big.mark = ",",
293 scientific = FALSE ) ),
294 size = 7.0,
295 fontface = "bold" )
296
297result <- fundamentalGraphData +
298 barGraphFormat +
299 errorBarFormat +
300 values
301
302# -------------------------------
303# Port Up Exporting Graph to File
304# -------------------------------
305
306saveGraph( errBarOutputFileUp )
307
308# ----------------------------
309# Port Down Generate Main Plot
310# ----------------------------
311
312print( "Generating main plot (Port Down Latency)." )
313
314mainPlot <- ggplot( data = downAvgsDataFrame, aes( x = scale,
315 y = ms,
316 fill = type,
317 ymin = fileData[ 'down_end_to_end_avg' ],
318 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
319
320# ----------------------------------------
321# Port Down Fundamental Variables Assigned
322# ----------------------------------------
323
324print( "Generating fundamental graph data (Port Down Latency)." )
325
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800326title <- labs( title = "Port Down Latency", subtitle = lastUpdatedLabel( latestBuildDate ) )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800327
328fundamentalGraphData <- mainPlot +
329 xScaleConfig +
330 xLabel +
331 yLabel +
332 fillLabel +
333 theme +
334 wrapLegend +
335 title +
336 colors
337
338# -------------------------------------
339# Port Down Generating Bar Graph Format
340# -------------------------------------
341
342print( "Generating bar graph with error bars (Port Down Latency)." )
343
344barGraphFormat <- geom_bar( stat = "identity",
345 width = barWidth )
346
347errorBarFormat <- geom_errorbar( width = barWidth,
348 color = errorBarColor )
349
350values <- geom_text( aes( x = downAvgsDataFrame$scale,
351 y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ),
352 label = format( sumOfDownAvgs,
353 digits=3,
354 big.mark = ",",
355 scientific = FALSE ) ),
356 size = 7.0,
357 fontface = "bold" )
358
359result <- fundamentalGraphData +
360 barGraphFormat +
361 errorBarFormat +
362 values
363
364# ---------------------------------
365# Port Down Exporting Graph to File
366# ---------------------------------
367
368saveGraph( errBarOutputFileDown )
369quit( status = 0 )