blob: 97b8d449650463c7fb29bc7a5d4efac12fc333c6 [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( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030
Jeremy Ronquillob6268842017-10-03 13:02:58 -070031# Command line arguments are read.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000032print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070035# ----------------
36# Import Libraries
37# ----------------
38
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000039print( "Importing libraries." )
40library( ggplot2 )
41library( reshape2 )
42library( RPostgreSQL ) # For databases
43
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070044# -------------------
45# Check CLI Arguments
46# -------------------
47
48print( "Verifying CLI args." )
49
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000050if ( is.na( args[ 7 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051
52 print( paste( "Usage: Rscript SCPFswitchLat",
53 "<database-host>",
54 "<database-port>",
55 "<database-user-id>",
56 "<database-password>",
57 "<test-name>",
58 "<branch-name>",
59 "<directory-to-save-graphs>",
60 sep=" ") )
61
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000062 q() # basically exit(), but in R
63}
64
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070065# -----------------
66# Create File Names
67# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000068
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070069print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071errBarOutputFileUp <- paste( args[ 7 ],
72 "SCPFswitchLat_",
73 args[ 6 ],
74 "_UpErrBarWithStack.jpg",
75 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000076
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070077errBarOutputFileDown <- paste( args[ 7 ],
78 "SCPFswitchLat_",
79 args[ 6 ],
80 "_DownErrBarWithStack.jpg",
81 sep="" )
82# ------------------
83# SQL Initialization
84# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000085
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070086print( "Initializing SQL" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000087
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070088con <- dbConnect( dbDriver( "PostgreSQL" ),
89 dbname = "onostest",
90 host = args[ 1 ],
91 port = strtoi( args[ 2 ] ),
92 user = args[ 3 ],
93 password = args[ 4 ] )
94
95# --------------------------
96# Switch Latency SQL Command
97# --------------------------
98
99print( "Generating Switch Latency SQL Command" )
100
101command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '",
102 args[ 6 ],
103 "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='",
104 args[ 6 ],
105 "' )",
106 sep="" )
107
108print( "Sending SQL command:" )
109print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000110
111fileData <- dbGetQuery( con, command )
112
113# **********************************************************
114# STEP 2: Organize data.
115# **********************************************************
116
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700117print( "**********************************************************" )
118print( "STEP 2: Organize Data." )
119print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000120
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700121# -------------------------------
122# Switch Up Averages Data Sorting
123# -------------------------------
124
125print( "Sorting data for Switch Up Averages." )
126
127upAvgs <- c( fileData[ 'up_device_to_graph_avg' ],
128 fileData[ 'role_reply_to_device_avg' ],
129 fileData[ 'role_request_to_role_reply_avg' ],
130 fileData[ 'feature_reply_to_role_request_avg' ],
131 fileData[ 'tcp_to_feature_reply_avg' ] )
132
133# ------------------------------
134# Switch Up Construct Data Frame
135# ------------------------------
136
137print( "Constructing Switch Up data frame." )
138
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000139upAvgsData <- melt( upAvgs )
140upAvgsData$scale <- fileData$scale
141upAvgsData$up_std <- fileData$up_std
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700142upAvgsData <- na.omit( upAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000143
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700144colnames( upAvgsData ) <- c( "ms",
145 "type",
146 "scale",
147 "stds" )
148
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000149upAvgsData$type <- as.character( upAvgsData$type )
150upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
151
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700152sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] +
153 fileData[ 'role_reply_to_device_avg' ] +
154 fileData[ 'role_request_to_role_reply_avg' ] +
155 fileData[ 'feature_reply_to_role_request_avg' ] +
156 fileData[ 'tcp_to_feature_reply_avg' ]
157
158print( "Up Averages Results:" )
159print( upAvgsData )
160
161# ---------------------------------
162# Switch Down Averages Data Sorting
163# ---------------------------------
164
165print( "Sorting data for Switch Down Averages." )
166
167downAvgs <- c( fileData[ 'down_device_to_graph_avg' ],
168 fileData[ 'ack_to_device_avg' ],
169 fileData[ 'fin_ack_to_ack_avg' ] )
170
171# --------------------------------
172# Switch Down Construct Data Frame
173# --------------------------------
174
175print( "Constructing Switch Down data frame." )
176
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000177downAvgsData <- melt( downAvgs )
178downAvgsData$scale <- fileData$scale
179downAvgsData$down_std <- fileData$down_std
180
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700181colnames( downAvgsData ) <- c( "ms",
182 "type",
183 "scale",
184 "stds" )
185
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000186downAvgsData$type <- as.character( downAvgsData$type )
187downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
188
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700189downAvgsData <- na.omit( downAvgsData )
190
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700191sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] +
192 fileData[ 'ack_to_device_avg' ] +
193 fileData[ 'fin_ack_to_ack_avg' ]
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700194
195print( "Down Averages Results:" )
196print( downAvgsData )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197
198# **********************************************************
199# STEP 3: Generate graphs.
200# **********************************************************
201
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700202print( "**********************************************************" )
203print( "STEP 3: Generate Graph." )
204print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000205
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700206# ------------------------------------
207# Initialize Variables For Both Graphs
208# ------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000209
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700210print( "Initializing variables used in both graphs." )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700211
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700212theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs
213xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000214xLabel <- xlab( "Scale" )
215yLabel <- ylab( "Latency (ms)" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700216imageWidth <- 15
217imageHeight <- 10
218imageDPI <- 200
219errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 )
220barWidth <- 1
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000221
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700222theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
223 legend.position = "bottom",
224 legend.text = element_text( size = 22 ),
225 legend.title = element_blank(),
226 legend.key.size = unit( 1.5, 'lines' ) )
227
228# ----------------------------
229# Switch Up Generate Main Plot
230# ----------------------------
231
232print( "Creating main plot (Switch Up Latency)." )
233
234mainPlot <- ggplot( data = upAvgsData, aes( x = scale,
235 y = ms,
236 fill = type,
237 ymin = fileData[ 'up_end_to_end_avg' ],
238 ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
239
240# ----------------------------------------
241# Switch Up Fundamental Variables Assigned
242# ----------------------------------------
243
244print( "Generating fundamental graph data (Switch Up Latency)." )
245
246title <- ggtitle( "Switch Up Latency" )
247
248fundamentalGraphData <- mainPlot +
249 xScaleConfig +
250 xLabel +
251 yLabel +
252 theme +
253 title
254
255# -------------------------------------
256# Switch Up Generating Bar Graph Format
257# -------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000258
259print( "Generating bar graph with error bars (Switch Up Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000260
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700261barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
262errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
263
264barGraphValues <- geom_text( aes( x = upAvgsData$scale,
265 y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ),
266 label = format( sumOfUpAvgs,
267 digits = 3,
268 big.mark = ",",
269 scientific = FALSE ) ),
270 size = 7.0,
271 fontface = "bold" )
272
273wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) )
274
275result <- fundamentalGraphData +
276 barGraphFormat +
277 errorBarFormat +
278 barGraphValues +
279 wrapLegend
280
281# ---------------------------------
282# Switch Up Exporting Graph to File
283# ---------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000284
285print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000286
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700287ggsave( errBarOutputFileUp,
288 width = imageWidth,
289 height = imageHeight,
290 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000291
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700292print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) )
293
294# ------------------------------
295# Switch Down Generate Main Plot
296# ------------------------------
297
298print( "Creating main plot (Switch Down Latency)." )
299
300mainPlot <- ggplot( data = downAvgsData, aes( x = scale,
301 y = ms,
302 fill = type,
303 ymin = fileData[ 'down_end_to_end_avg' ],
304 ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
305
306# ------------------------------------------
307# Switch Down Fundamental Variables Assigned
308# ------------------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000309
310print( "Generating fundamental graph data (Switch Down Latency)." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000311
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700312colors <- scale_fill_manual( values=c( "#F77670", # Red
313 "#619DFA", # Blue
314 "#18BA48" ) ) # Green
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000315
316title <- ggtitle( "Switch Down Latency" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700317
318fundamentalGraphData <- mainPlot +
319 xScaleConfig +
320 xLabel +
321 yLabel +
322 theme +
323 title
324
325# ---------------------------------------
326# Switch Down Generating Bar Graph Format
327# ---------------------------------------
328
329print( "Generating bar graph with error bars (Switch Down Latency)." )
330barGraphFormat <- geom_bar( stat = "identity", width = barWidth )
331errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor )
332
333barGraphValues <- geom_text( aes( x = downAvgsData$scale,
334 y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ),
335 label = format( sumOfDownAvgs,
336 digits = 3,
337 big.mark = ",",
338 scientific = FALSE ) ),
339 size = 7.0,
340 fontface = "bold" )
341
342wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
343
344result <- fundamentalGraphData +
345 barGraphFormat +
346 colors +
347 errorBarFormat +
348 barGraphValues +
349 wrapLegend
350
351# -----------------------------------
352# Switch Down Exporting Graph to File
353# -----------------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000354
355print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000356
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700357ggsave( errBarOutputFileDown,
358 width = imageWidth,
359 height = imageHeight,
360 dpi = imageDPI )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000361
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700362print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) )