blob: 9c79ac874bb1f03afdb9e8b17ca34f95d0c78333 [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[ 9 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070051
52 print( paste( "Usage: Rscript SCPFflowTp1g.R",
53 "<has-flow-obj>",
54 "<database-host>",
55 "<database-port>",
56 "<database-user-id>",
57 "<database-password>",
58 "<test-name>",
59 "<branch-name>",
60 "<has-neighbors>",
61 "<directory-to-save-graphs>",
62 sep=" " ) )
63
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000064 q() # basically exit(), but in R
65}
66
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070067# -----------------
68# Create File Names
69# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000072
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070073chartTitle <- "Flow Throughput Test"
74fileNeighborsModifier <- "no"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075commandNeighborModifier <- ""
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076fileFlowObjModifier <- ""
77sqlFlowObjModifier <- ""
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000078if ( args[ 1 ] == 'y' ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070079 fileFlowObjModifier <- "_flowObj"
80 sqlFlowObjModifier <- "_fobj"
81 chartTitle <- paste( chartTitle, " with Flow Objectives", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000082}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070083
84chartTitle <- paste( chartTitle, "\nNeighbors =", sep="" )
85
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000086if ( args[ 8 ] == 'y' ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070087 fileNeighborsModifier <- "all"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070088 commandNeighborModifier <- "scale=1 OR NOT "
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070089 chartTitle <- paste( chartTitle, "Cluster Size - 1" )
90} else {
91 chartTitle <- paste( chartTitle, "0" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000092}
93
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070094errBarOutputFile <- paste( args[ 9 ],
95 args[ 6 ],
96 "_",
97 args[ 7 ],
98 "_",
99 fileNeighborsModifier,
100 "-neighbors",
101 fileFlowObjModifier,
102 "_graph.jpg",
103 sep="" )
104# ------------------
105# SQL Initialization
106# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000107
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700108print( "Initializing SQL" )
109
110con <- dbConnect( dbDriver( "PostgreSQL" ),
111 dbname = "onostest",
112 host = args[ 2 ],
113 port = strtoi( args[ 3 ] ),
114 user = args[ 4 ],
115 password = args[ 5 ] )
116
117# ---------------------------
118# Flow Throughput SQL Command
119# ---------------------------
120
121print( "Generating Flow Throughput SQL command." )
122
123command <- paste( "SELECT scale, avg( avg ), avg( std ) FROM flow_tp",
124 sqlFlowObjModifier,
125 "_tests WHERE (",
126 commandNeighborModifier,
127 "neighbors = 0 ) AND branch = '",
128 args[ 7 ],
129 "' AND date IN ( SELECT max( date ) FROM flow_tp",
130 sqlFlowObjModifier,
131 "_tests WHERE branch='",
132 args[ 7 ],
133 "' ) GROUP BY scale ORDER BY scale",
134 sep="" )
135
136print( "Sending SQL command:" )
137print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000138
139fileData <- dbGetQuery( con, command )
140
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000141# **********************************************************
142# STEP 2: Organize data.
143# **********************************************************
144
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700145print( "**********************************************************" )
146print( "STEP 2: Organize Data." )
147print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000148
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700149# ------------
150# Data Sorting
151# ------------
152
153print( "Sorting data for Flow Throughput." )
154
155colnames( fileData ) <- c( "scale",
156 "avg",
157 "std" )
158
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159avgs <- c( fileData[ 'avg' ] )
160
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700161
162# ----------------------------
163# Flow TP Construct Data Frame
164# ----------------------------
165
166print( "Constructing Flow TP data frame." )
167
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000168dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700169dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000170dataFrame$std <- fileData$std
171
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700172colnames( dataFrame ) <- c( "throughput",
173 "type",
174 "scale",
175 "std" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700177dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
178
179print( "Data Frame Results:" )
180print( dataFrame )
181
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000182# **********************************************************
183# STEP 3: Generate graphs.
184# **********************************************************
185
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700186print( "**********************************************************" )
187print( "STEP 3: Generate Graph." )
188print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000189
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700190# ------------------
191# Generate Main Plot
192# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000193
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700194print( "Generating main plot." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000195# Create the primary plot here.
196# ggplot contains the following arguments:
197# - data: the data frame that the graph will be based off of
198# - aes: the asthetics of the graph which require:
199# - x: x-axis values (usually node scaling)
200# - y: y-axis values (usually time in milliseconds)
201# - fill: the category of the colored side-by-side bars (usually type)
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700202
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700203mainPlot <- ggplot( data = dataFrame, aes( x = scale,
204 y = throughput,
205 ymin = throughput,
206 ymax = throughput + std,
207 fill = type ) )
208# ------------------------------
209# Fundamental Variables Assigned
210# ------------------------------
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700211
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700212print( "Generating fundamental graph data." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000213
214# Formatting the plot
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700215theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000216width <- 0.7 # Width of the bars.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700217xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale,
218 label = dataFrame$scale )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000219xLabel <- xlab( "Scale" )
Jeremy Ronquillo1bdaae52017-09-22 11:39:48 -0700220yLabel <- ylab( "Throughput (,000 Flows/sec)" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000221fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700222imageWidth <- 15
223imageHeight <- 10
224imageDPI <- 200
225errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000226
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700227theme <- theme( plot.title = element_text( hjust = 0.5,
228 size = 32,
229 face = 'bold' ) )
230title <- ggtitle( chartTitle )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700231
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000232# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700233fundamentalGraphData <- mainPlot +
234 xScaleConfig +
235 xLabel +
236 yLabel +
237 fillLabel +
238 theme +
239 title
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000240
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700241# ---------------------------
242# Generating Bar Graph Format
243# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000244
245# Create the stacked bar graph with error bars.
246# geom_bar contains:
247# - stat: data formatting (usually "identity")
248# - width: the width of the bar types (declared above)
249# geom_errorbar contains similar arguments as geom_bar.
250print( "Generating bar graph with error bars." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700251barGraphFormat <- geom_bar( stat = "identity",
252 width = width,
253 fill = "#FFAA3C" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000254
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700255errorBarFormat <- geom_errorbar( width = width,
256 position = position_dodge(),
257 color = errorBarColor )
258
259values <- geom_text( aes( x = dataFrame$scale,
260 y = dataFrame$throughput + 0.03 * max( dataFrame$throughput ),
261 label = format( dataFrame$throughput,
262 digits=3,
263 big.mark = ",",
264 scientific = FALSE ) ),
265 size = 7.0,
266 fontface = "bold" )
267
268result <- fundamentalGraphData +
269 barGraphFormat +
270 errorBarFormat +
271 values
272
273# -----------------------
274# Exporting Graph to File
275# -----------------------
276
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000277print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700278
279ggsave( errBarOutputFile,
280 width = imageWidth,
281 height = imageHeight,
282 dpi = imageDPI )
283
284print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) )