blob: 8a68e08e555be45b3dbf913e09e5ad460e042ce7 [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# **********************************************************
26
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070027print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
Devin Lim0e967162017-11-03 15:59:53 -070030database_host = 1
31database_port = 2
32database_u_id = 3
33database_pw = 4
34test_name = 5
35branch_name = 6
36save_directory = 7
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000037
Jeremy Ronquillob6268842017-10-03 13:02:58 -070038# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Reading commmand-line args." )
40args <- commandArgs( trailingOnly=TRUE )
41
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070042# ----------------
43# Import Libraries
44# ----------------
45
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000046print( "Importing libraries." )
47library( ggplot2 )
48library( reshape2 )
49library( RPostgreSQL ) # For databases
50
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051# -------------------
52# Check CLI Arguments
53# -------------------
54
55print( "Verifying CLI args." )
56
Devin Lim0e967162017-11-03 15:59:53 -070057if ( is.na( args[ save_directory ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070058
59 print( paste( "Usage: Rscript SCPFswitchLat",
60 "<database-host>",
61 "<database-port>",
62 "<database-user-id>",
63 "<database-password>",
64 "<test-name>",
65 "<branch-name>",
66 "<directory-to-save-graphs>",
67 sep=" ") )
68
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000069 q() # basically exit(), but in R
70}
71
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070072# -----------------
73# Create File Names
74# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000077
Devin Lim0e967162017-11-03 15:59:53 -070078errBarOutputFileUp <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070079 "SCPFswitchLat_",
Devin Lim0e967162017-11-03 15:59:53 -070080 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070081 "_UpErrBarWithStack.jpg",
82 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083
Devin Lim0e967162017-11-03 15:59:53 -070084errBarOutputFileDown <- paste( args[ save_directory ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070085 "SCPFswitchLat_",
Devin Lim0e967162017-11-03 15:59:53 -070086 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070087 "_DownErrBarWithStack.jpg",
88 sep="" )
89# ------------------
90# SQL Initialization
91# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000092
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070093print( "Initializing SQL" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000094
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070095con <- dbConnect( dbDriver( "PostgreSQL" ),
96 dbname = "onostest",
Devin Lim0e967162017-11-03 15:59:53 -070097 host = args[ database_host ],
98 port = strtoi( args[ database_port ] ),
99 user = args[ database_u_id ],
100 password = args[ database_pw ] )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700101
102# --------------------------
103# Switch Latency SQL Command
104# --------------------------
105
106print( "Generating Switch Latency SQL Command" )
107
108command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '",
Devin Lim0e967162017-11-03 15:59:53 -0700109 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700110 "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='",
Devin Lim0e967162017-11-03 15:59:53 -0700111 args[ branch_name ],
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700112 "' )",
113 sep="" )
114
115print( "Sending SQL command:" )
116print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117
118fileData <- dbGetQuery( con, command )
119
120# **********************************************************
121# STEP 2: Organize data.
122# **********************************************************
123
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700124print( "**********************************************************" )
125print( "STEP 2: Organize Data." )
126print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000127
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700128# -------------------------------
129# Switch Up Averages Data Sorting
130# -------------------------------
131
132print( "Sorting data for Switch Up Averages." )
133
134upAvgs <- c( fileData[ 'up_device_to_graph_avg' ],
135 fileData[ 'role_reply_to_device_avg' ],
136 fileData[ 'role_request_to_role_reply_avg' ],
137 fileData[ 'feature_reply_to_role_request_avg' ],
138 fileData[ 'tcp_to_feature_reply_avg' ] )
139
140# ------------------------------
141# Switch Up Construct Data Frame
142# ------------------------------
143
144print( "Constructing Switch Up data frame." )
145
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000146upAvgsData <- melt( upAvgs )
147upAvgsData$scale <- fileData$scale
148upAvgsData$up_std <- fileData$up_std
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700149upAvgsData <- na.omit( upAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000150
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700151colnames( upAvgsData ) <- c( "ms",
152 "type",
153 "scale",
154 "stds" )
155
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000156upAvgsData$type <- as.character( upAvgsData$type )
157upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
158
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700159sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] +
160 fileData[ 'role_reply_to_device_avg' ] +
161 fileData[ 'role_request_to_role_reply_avg' ] +
162 fileData[ 'feature_reply_to_role_request_avg' ] +
163 fileData[ 'tcp_to_feature_reply_avg' ]
164
165print( "Up Averages Results:" )
166print( upAvgsData )
167
168# ---------------------------------
169# Switch Down Averages Data Sorting
170# ---------------------------------
171
172print( "Sorting data for Switch Down Averages." )
173
174downAvgs <- c( fileData[ 'down_device_to_graph_avg' ],
175 fileData[ 'ack_to_device_avg' ],
176 fileData[ 'fin_ack_to_ack_avg' ] )
177
178# --------------------------------
179# Switch Down Construct Data Frame
180# --------------------------------
181
182print( "Constructing Switch Down data frame." )
183
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000184downAvgsData <- melt( downAvgs )
185downAvgsData$scale <- fileData$scale
186downAvgsData$down_std <- fileData$down_std
187
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700188colnames( downAvgsData ) <- c( "ms",
189 "type",
190 "scale",
191 "stds" )
192
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000193downAvgsData$type <- as.character( downAvgsData$type )
194downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
195
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700196downAvgsData <- na.omit( downAvgsData )
197
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] +
199 fileData[ 'ack_to_device_avg' ] +
200 fileData[ 'fin_ack_to_ack_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700201
202print( "Down Averages Results:" )
203print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000204
205# **********************************************************
206# STEP 3: Generate graphs.
207# **********************************************************
208
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700209print( "**********************************************************" )
210print( "STEP 3: Generate Graph." )
211print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000212
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700213# ------------------------------------
214# Initialize Variables For Both Graphs
215# ------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000216
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700217print( "Initializing variables used in both graphs." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700218
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700219theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs
220xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000221xLabel <- xlab( "Scale" )
222yLabel <- ylab( "Latency (ms)" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700223imageWidth <- 15
224imageHeight <- 10
225imageDPI <- 200
226errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
227barWidth <- 1
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000228
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700229theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
230 legend.position = "bottom",
231 legend.text = element_text( size = 22 ),
232 legend.title = element_blank(),
233 legend.key.size = unit( 1.5, 'lines' ) )
234
235# ----------------------------
236# Switch Up Generate Main Plot
237# ----------------------------
238
239print( "Creating main plot (Switch Up Latency)." )
240
241mainPlot <- ggplot( data = upAvgsData, aes( x = scale,
242 y = ms,
243 fill = type,
244 ymin = fileData[ 'up_end_to_end_avg' ],
245 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
246
247# ----------------------------------------
248# Switch Up Fundamental Variables Assigned
249# ----------------------------------------
250
251print( "Generating fundamental graph data (Switch Up Latency)." )
252
253title <- ggtitle( "Switch Up Latency" )
254
255fundamentalGraphData <- mainPlot +
256 xScaleConfig +
257 xLabel +
258 yLabel +
259 theme +
260 title
261
262# -------------------------------------
263# Switch Up Generating Bar Graph Format
264# -------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000265
266print( "Generating bar graph with error bars (Switch Up Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000267
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700268barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
269errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
270
271barGraphValues <- geom_text( aes( x = upAvgsData$scale,
272 y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ),
273 label = format( sumOfUpAvgs,
274 digits = 3,
275 big.mark = ",",
276 scientific = FALSE ) ),
277 size = 7.0,
278 fontface = "bold" )
279
280wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) )
281
282result <- fundamentalGraphData +
283 barGraphFormat +
284 errorBarFormat +
285 barGraphValues +
286 wrapLegend
287
288# ---------------------------------
289# Switch Up Exporting Graph to File
290# ---------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000291
292print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000293
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700294ggsave( errBarOutputFileUp,
295 width = imageWidth,
296 height = imageHeight,
297 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000298
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700299print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) )
300
301# ------------------------------
302# Switch Down Generate Main Plot
303# ------------------------------
304
305print( "Creating main plot (Switch Down Latency)." )
306
307mainPlot <- ggplot( data = downAvgsData, aes( x = scale,
308 y = ms,
309 fill = type,
310 ymin = fileData[ 'down_end_to_end_avg' ],
311 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
312
313# ------------------------------------------
314# Switch Down Fundamental Variables Assigned
315# ------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000316
317print( "Generating fundamental graph data (Switch Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000318
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700319colors <- scale_fill_manual( values=c( "#F77670", # Red
320 "#619DFA", # Blue
321 "#18BA48" ) ) # Green
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000322
323title <- ggtitle( "Switch Down Latency" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700324
325fundamentalGraphData <- mainPlot +
326 xScaleConfig +
327 xLabel +
328 yLabel +
329 theme +
330 title
331
332# ---------------------------------------
333# Switch Down Generating Bar Graph Format
334# ---------------------------------------
335
336print( "Generating bar graph with error bars (Switch Down Latency)." )
337barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
338errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
339
340barGraphValues <- geom_text( aes( x = downAvgsData$scale,
341 y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ),
342 label = format( sumOfDownAvgs,
343 digits = 3,
344 big.mark = ",",
345 scientific = FALSE ) ),
346 size = 7.0,
347 fontface = "bold" )
348
349wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
350
351result <- fundamentalGraphData +
352 barGraphFormat +
353 colors +
354 errorBarFormat +
355 barGraphValues +
356 wrapLegend
357
358# -----------------------------------
359# Switch Down Exporting Graph to File
360# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000361
362print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000363
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700364ggsave( errBarOutputFileDown,
365 width = imageWidth,
366 height = imageHeight,
367 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000368
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700369print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) )