blob: 70d6607c2ab360f55b403b017c7839ba9da50a1c [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
46source( "dependencies/saveGraph.R" )
47source( "dependencies/fundamentalGraphData.R" )
48source( "dependencies/initSQL.R" )
49source( "dependencies/cliArgs.R" )
50
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
113# -----------------------------
114# Port Up Averages Data Sorting
115# -----------------------------
116
117print( "Sorting data for Port Up Averages." )
118
119requiredColumns <- c( "up_ofp_to_dev_avg", "up_dev_to_link_avg", "up_link_to_graph_avg" )
120
121tryCatch( upAvgs <- c( fileData[ requiredColumns] ),
122 error = function( e ) {
123 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." )
124 print( "Required columns: " )
125 print( requiredColumns )
126 print( "Actual columns: " )
127 print( names( fileData ) )
128 print( "Error dump:" )
129 print( e )
130 quit( status = 1 )
131 }
132 )
133
134# ----------------------------
135# Port Up Construct Data Frame
136# ----------------------------
137
138print( "Constructing Port Up data frame." )
139
140upAvgsDataFrame <- melt( upAvgs )
141upAvgsDataFrame$scale <- fileData$scale
142upAvgsDataFrame$up_std <- fileData$up_std
143
144colnames( upAvgsDataFrame ) <- c( "ms",
145 "type",
146 "scale",
147 "stds" )
148
149upAvgsDataFrame <- na.omit( upAvgsDataFrame )
150
151upAvgsDataFrame$type <- as.character( upAvgsDataFrame$type )
152upAvgsDataFrame$type <- factor( upAvgsDataFrame$type, levels=unique( upAvgsDataFrame$type ) )
153
154sumOfUpAvgs <- fileData[ 'up_ofp_to_dev_avg' ] +
155 fileData[ 'up_dev_to_link_avg' ] +
156 fileData[ 'up_link_to_graph_avg' ]
157
158print( "Up Averages Results:" )
159print( upAvgsDataFrame )
160
161# -------------------------------
162# Port Down Averages Data Sorting
163# -------------------------------
164
165print( "Sorting data for Port Down Averages." )
166
167requiredColumns <- c( "down_ofp_to_dev_avg", "down_dev_to_link_avg", "down_link_to_graph_avg" )
168
169tryCatch( downAvgs <- c( fileData[ requiredColumns] ),
170 error = function( e ) {
171 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." )
172 print( "Required columns: " )
173 print( requiredColumns )
174 print( "Actual columns: " )
175 print( names( fileData ) )
176 print( "Error dump:" )
177 print( e )
178 quit( status = 1 )
179 }
180 )
181
182# ------------------------------
183# Port Down Construct Data Frame
184# ------------------------------
185
186print( "Constructing Port Down data frame." )
187
188downAvgsDataFrame <- melt( downAvgs )
189downAvgsDataFrame$scale <- fileData$scale
190downAvgsDataFrame$down_std <- fileData$down_std
191
192colnames( downAvgsDataFrame ) <- c( "ms",
193 "type",
194 "scale",
195 "stds" )
196
197downAvgsDataFrame <- na.omit( downAvgsDataFrame )
198
199downAvgsDataFrame$type <- as.character( downAvgsDataFrame$type )
200downAvgsDataFrame$type <- factor( downAvgsDataFrame$type, levels=unique( downAvgsDataFrame$type ) )
201
202sumOfDownAvgs <- fileData[ 'down_ofp_to_dev_avg' ] +
203 fileData[ 'down_dev_to_link_avg' ] +
204 fileData[ 'down_link_to_graph_avg' ]
205
206print( "Down Averages Results:" )
207print( downAvgsDataFrame )
208
209# **********************************************************
210# STEP 3: Generate graphs.
211# **********************************************************
212
213print( "**********************************************************" )
214print( "STEP 3: Generate Graph." )
215print( "**********************************************************" )
216
217# ------------------------------------
218# Initialize Variables For Both Graphs
219# ------------------------------------
220
221print( "Initializing variables used in both graphs." )
222
223defaultTextSize()
224xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
225
226xLabel <- xlab( "Scale" )
227yLabel <- ylab( "Latency (ms)" )
228fillLabel <- labs( fill="Type" )
229
230barWidth <- 1
231
232wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) )
233
234theme <- graphTheme()
235
236subtitle <- lastUpdatedLabel()
237
238colors <- scale_fill_manual( values=c( webColor( "redv2" ),
239 webColor( "light_blue" ),
240 webColor( "green" ) ) )
241
242errorBarColor <- webColor( "darkerGray" )
243
244# --------------------------
245# Port Up Generate Main Plot
246# --------------------------
247
248print( "Generating main plot (Port Up Latency)." )
249
250mainPlot <- ggplot( data = upAvgsDataFrame, aes( x = scale,
251 y = ms,
252 fill = type,
253 ymin = fileData[ 'up_end_to_end_avg' ],
254 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
255
256# --------------------------------------
257# Port Up Fundamental Variables Assigned
258# --------------------------------------
259
260print( "Generating fundamental graph data (Port Up Latency)." )
261
262title <- labs( title = "Port Up Latency", subtitle = lastUpdatedLabel() )
263
264fundamentalGraphData <- mainPlot +
265 xScaleConfig +
266 xLabel +
267 yLabel +
268 fillLabel +
269 theme +
270 wrapLegend +
271 title +
272 colors
273
274# -----------------------------------
275# Port Up Generating Bar Graph Format
276# -----------------------------------
277
278print( "Generating bar graph with error bars (Port Up Latency)." )
279
280barGraphFormat <- geom_bar( stat = "identity",
281 width = barWidth )
282
283errorBarFormat <- geom_errorbar( width = barWidth,
284 color = errorBarColor )
285
286values <- geom_text( aes( x = upAvgsDataFrame$scale,
287 y = sumOfUpAvgs + 0.03 * max( sumOfUpAvgs ),
288 label = format( sumOfUpAvgs,
289 digits=3,
290 big.mark = ",",
291 scientific = FALSE ) ),
292 size = 7.0,
293 fontface = "bold" )
294
295result <- fundamentalGraphData +
296 barGraphFormat +
297 errorBarFormat +
298 values
299
300# -------------------------------
301# Port Up Exporting Graph to File
302# -------------------------------
303
304saveGraph( errBarOutputFileUp )
305
306# ----------------------------
307# Port Down Generate Main Plot
308# ----------------------------
309
310print( "Generating main plot (Port Down Latency)." )
311
312mainPlot <- ggplot( data = downAvgsDataFrame, aes( x = scale,
313 y = ms,
314 fill = type,
315 ymin = fileData[ 'down_end_to_end_avg' ],
316 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
317
318# ----------------------------------------
319# Port Down Fundamental Variables Assigned
320# ----------------------------------------
321
322print( "Generating fundamental graph data (Port Down Latency)." )
323
324title <- labs( title = "Port Down Latency", subtitle = lastUpdatedLabel() )
325
326fundamentalGraphData <- mainPlot +
327 xScaleConfig +
328 xLabel +
329 yLabel +
330 fillLabel +
331 theme +
332 wrapLegend +
333 title +
334 colors
335
336# -------------------------------------
337# Port Down Generating Bar Graph Format
338# -------------------------------------
339
340print( "Generating bar graph with error bars (Port Down Latency)." )
341
342barGraphFormat <- geom_bar( stat = "identity",
343 width = barWidth )
344
345errorBarFormat <- geom_errorbar( width = barWidth,
346 color = errorBarColor )
347
348values <- geom_text( aes( x = downAvgsDataFrame$scale,
349 y = sumOfDownAvgs + 0.03 * max( sumOfDownAvgs ),
350 label = format( sumOfDownAvgs,
351 digits=3,
352 big.mark = ",",
353 scientific = FALSE ) ),
354 size = 7.0,
355 fontface = "bold" )
356
357result <- fundamentalGraphData +
358 barGraphFormat +
359 errorBarFormat +
360 values
361
362# ---------------------------------
363# Port Down Exporting Graph to File
364# ---------------------------------
365
366saveGraph( errBarOutputFileDown )
367quit( status = 0 )