blob: 679d205984563a0160de1fe0b9fc146d822c4ee9 [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# Switch Latency Graph (https://jenkins.onosproject.org/view/QA/job/postjob-BM/lastSuccessfulBuild/artifact/SCPFswitchLat_master_UpErrBarWithStack.jpg):
22# Rscript SCPFspecificGraphRScripts/SCPFswitchLat.R <url> <port> <username> <pass> SCPFswitchLat 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( "SCPFswitchLat.R" )
59 quit( status = 1 )
60}
61
62# -----------------
63# Create File Names
64# -----------------
65
66print( "Creating filenames and title of graph." )
67
68errBarOutputFileUp <- paste( args[ save_directory ],
69 "SCPFswitchLat_",
70 args[ branch_name ],
71 "_UpErrBarWithStack.jpg",
72 sep="" )
73
74errBarOutputFileDown <- paste( args[ save_directory ],
75 "SCPFswitchLat_",
76 args[ branch_name ],
77 "_DownErrBarWithStack.jpg",
78 sep="" )
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# Switch Latency SQL Command
92# --------------------------
93
94print( "Generating Switch Latency SQL Command" )
95
96command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '",
97 args[ branch_name ],
98 "' AND date IN ( SELECT MAX( date ) FROM switch_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# Switch Up Averages Data Sorting
117# -------------------------------
118
119print( "Sorting data for Switch Up Averages." )
120
121requiredColumns <- c( "up_device_to_graph_avg",
122 "feature_reply_to_device_avg",
123 "tcp_to_feature_reply_avg" )
124
125tryCatch( upAvgs <- c( fileData[ requiredColumns] ),
126 error = function( e ) {
127 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." )
128 print( "Required columns: " )
129 print( requiredColumns )
130 print( "Actual columns: " )
131 print( names( fileData ) )
132 print( "Error dump:" )
133 print( e )
134 quit( status = 1 )
135 }
136 )
137
138# ------------------------------
139# Switch Up Construct Data Frame
140# ------------------------------
141
142print( "Constructing Switch Up data frame." )
143
144upAvgsData <- melt( upAvgs )
145upAvgsData$scale <- fileData$scale
146upAvgsData$up_std <- fileData$up_std
147upAvgsData <- na.omit( upAvgsData )
148
149colnames( upAvgsData ) <- c( "ms",
150 "type",
151 "scale",
152 "stds" )
153
154upAvgsData$type <- as.character( upAvgsData$type )
155upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
156
157sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] +
158 fileData[ 'feature_reply_to_device_avg' ] +
159 fileData[ 'tcp_to_feature_reply_avg' ]
160
161print( "Up Averages Results:" )
162print( upAvgsData )
163
164# ---------------------------------
165# Switch Down Averages Data Sorting
166# ---------------------------------
167
168print( "Sorting data for Switch Down Averages." )
169
170requiredColumns <- c( "down_device_to_graph_avg",
171 "ack_to_device_avg",
172 "fin_ack_to_ack_avg" )
173
174tryCatch( downAvgs <- c( fileData[ requiredColumns] ),
175 error = function( e ) {
176 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." )
177 print( "Required columns: " )
178 print( requiredColumns )
179 print( "Actual columns: " )
180 print( names( fileData ) )
181 print( "Error dump:" )
182 print( e )
183 quit( status = 1 )
184 }
185 )
186
187# --------------------------------
188# Switch Down Construct Data Frame
189# --------------------------------
190
191print( "Constructing Switch Down data frame." )
192
193downAvgsData <- melt( downAvgs )
194downAvgsData$scale <- fileData$scale
195downAvgsData$down_std <- fileData$down_std
196
197colnames( downAvgsData ) <- c( "ms",
198 "type",
199 "scale",
200 "stds" )
201
202downAvgsData$type <- as.character( downAvgsData$type )
203downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
204
205downAvgsData <- na.omit( downAvgsData )
206
207sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] +
208 fileData[ 'ack_to_device_avg' ] +
209 fileData[ 'fin_ack_to_ack_avg' ]
210
211print( "Down Averages Results:" )
212print( downAvgsData )
213
214# **********************************************************
215# STEP 3: Generate graphs.
216# **********************************************************
217
218print( "**********************************************************" )
219print( "STEP 3: Generate Graph." )
220print( "**********************************************************" )
221
222# ------------------------------------
223# Initialize Variables For Both Graphs
224# ------------------------------------
225
226print( "Initializing variables used in both graphs." )
227
228defaultTextSize()
229xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) )
230
231xLabel <- xlab( "Scale" )
232yLabel <- ylab( "Latency (ms)" )
233
234errorBarColor <- webColor( "darkerGray" )
235barWidth <- 1
236
237theme <- graphTheme()
238
Jeremy Ronquillo76efee42020-01-13 13:27:44 -0800239subtitle <- lastUpdatedLabel( latestBuildDate )
Jeremy Ronquillodae11042018-02-21 09:21:44 -0800240
241colors <- scale_fill_manual( values=c( webColor( "redv2" ),
242 webColor( "light_blue" ),
243 webColor( "green" ) ) )
244
245# ----------------------------
246# Switch Up Generate Main Plot
247# ----------------------------
248
249print( "Creating main plot (Switch Up Latency)." )
250
251mainPlot <- ggplot( data = upAvgsData, aes( x = scale,
252 y = ms,
253 fill = type,
254 ymin = fileData[ 'up_end_to_end_avg' ],
255 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
256
257# ----------------------------------------
258# Switch Up Fundamental Variables Assigned
259# ----------------------------------------
260
261print( "Generating fundamental graph data (Switch Up Latency)." )
262
263title <- labs( title = "Switch Up Latency", subtitle = subtitle )
264
265fundamentalGraphData <- mainPlot +
266 xScaleConfig +
267 xLabel +
268 yLabel +
269 theme +
270 title +
271 colors
272
273# -------------------------------------
274# Switch Up Generating Bar Graph Format
275# -------------------------------------
276
277print( "Generating bar graph with error bars (Switch Up Latency)." )
278
279barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
280errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
281
282barGraphValues <- geom_text( aes( x = upAvgsData$scale,
283 y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ),
284 label = format( sumOfUpAvgs,
285 digits = 3,
286 big.mark = ",",
287 scientific = FALSE ) ),
288 size = 7.0,
289 fontface = "bold" )
290
291wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) )
292
293result <- fundamentalGraphData +
294 barGraphFormat +
295 errorBarFormat +
296 barGraphValues +
297 wrapLegend
298
299# ---------------------------------
300# Switch Up Exporting Graph to File
301# ---------------------------------
302
303saveGraph( errBarOutputFileUp )
304
305# ------------------------------
306# Switch Down Generate Main Plot
307# ------------------------------
308
309print( "Creating main plot (Switch Down Latency)." )
310
311mainPlot <- ggplot( data = downAvgsData, aes( x = scale,
312 y = ms,
313 fill = type,
314 ymin = fileData[ 'down_end_to_end_avg' ],
315 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
316
317# ------------------------------------------
318# Switch Down Fundamental Variables Assigned
319# ------------------------------------------
320
321print( "Generating fundamental graph data (Switch Down Latency)." )
322
323title <- labs( title = "Switch Down Latency", subtitle = subtitle )
324
325fundamentalGraphData <- mainPlot +
326 xScaleConfig +
327 xLabel +
328 yLabel +
329 theme +
330 title +
331 colors
332
333# ---------------------------------------
334# Switch Down Generating Bar Graph Format
335# ---------------------------------------
336
337print( "Generating bar graph with error bars (Switch Down Latency)." )
338barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
339errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
340
341barGraphValues <- geom_text( aes( x = downAvgsData$scale,
342 y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ),
343 label = format( sumOfDownAvgs,
344 digits = 3,
345 big.mark = ",",
346 scientific = FALSE ) ),
347 size = 7.0,
348 fontface = "bold" )
349
350wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
351
352result <- fundamentalGraphData +
353 barGraphFormat +
354 errorBarFormat +
355 barGraphValues +
356 wrapLegend
357
358# -----------------------------------
359# Switch Down Exporting Graph to File
360# -----------------------------------
361
362saveGraph( errBarOutputFileDown )
363quit( status = 0 )