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