blob: 53fe2d4d071ba751c3ee2a7d4aa411657f8f2628 [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 Ronquillo7673f802017-10-30 09:42:44 -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 SCPFIntentEventTp.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 <- "Intent Event Throughput"
74fileNeighborsModifier <- "no"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075commandNeighborModifier <- ""
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076fileFlowObjModifier <- ""
77sqlFlowObjModifier <- ""
78
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079if ( args[ 1 ] == 'y' ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070080 fileFlowObjModifier <- "_flowObj"
81 sqlFlowObjModifier <- "_fobj"
82 chartTitle <- paste( chartTitle, " with Flow Objectives", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000083}
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070084
85chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" )
86
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000087if ( args[ 8 ] == 'y' ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070088 fileNeighborsModifier <- "all"
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070089 commandNeighborModifier <- "scale=1 OR NOT "
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070090 chartTitle <- paste( chartTitle, "all" )
91} else {
92 chartTitle <- paste( chartTitle, "0" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000093}
94
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070095errBarOutputFile <- paste( args[ 9 ],
96 args[ 6 ],
97 "_",
98 args[ 7 ],
99 "_",
100 fileNeighborsModifier,
101 "-neighbors",
102 fileFlowObjModifier,
103 "_graph.jpg",
104 sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000105
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700106# ------------------
107# SQL Initialization
108# ------------------
109
110print( "Initializing SQL" )
111
112con <- dbConnect( dbDriver( "PostgreSQL" ),
113 dbname = "onostest",
114 host = args[ 2 ],
115 port = strtoi( args[ 3 ] ),
116 user = args[ 4 ],
117 password = args[ 5 ] )
118
119# -----------------------------------
120# Intent Event Throughput SQL Command
121# -----------------------------------
122
123print( "Generating Intent Event Throughput SQL command." )
124
125command <- paste( "SELECT scale, SUM( avg ) as avg FROM intent_tp",
126 sqlFlowObjModifier,
127 "_tests WHERE (",
128 commandNeighborModifier,
129 "neighbors = 0 ) AND branch = '",
130 args[ 7 ],
131 "' AND date IN ( SELECT max( date ) FROM intent_tp",
132 sqlFlowObjModifier,
133 "_tests WHERE branch='",
134 args[ 7 ],
135 "' ) GROUP BY scale ORDER BY scale",
136 sep="" )
137
138print( "Sending SQL command:" )
139print( command )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000140
141fileData <- dbGetQuery( con, command )
142
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000143# **********************************************************
144# STEP 2: Organize data.
145# **********************************************************
146
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700147print( "**********************************************************" )
148print( "STEP 2: Organize Data." )
149print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000150
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700151# ------------
152# Data Sorting
153# ------------
154
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000155print( "Sorting data." )
156avgs <- c( fileData[ 'avg' ] )
157
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700158# --------------------
159# Construct Data Frame
160# --------------------
161
162print( "Constructing data frame." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000163dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
164dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
165
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700166colnames( dataFrame ) <- c( "throughput",
167 "type",
168 "scale" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000169
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700170dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
171
172print( "Data Frame Results:" )
173print( dataFrame )
174
175
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000176# **********************************************************
177# STEP 3: Generate graphs.
178# **********************************************************
179
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700180print( "**********************************************************" )
181print( "STEP 3: Generate Graph." )
182print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000183
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700184# ------------------
185# Generate Main Plot
186# ------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000187
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700188print( "Generating main plot." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000189# Create the primary plot here.
190# ggplot contains the following arguments:
191# - data: the data frame that the graph will be based off of
192# - aes: the asthetics of the graph which require:
193# - x: x-axis values (usually node scaling)
194# - y: y-axis values (usually time in milliseconds)
195# - fill: the category of the colored side-by-side bars (usually type)
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700196
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700197mainPlot <- ggplot( data = dataFrame, aes( x = scale,
198 y = throughput,
199 fill = type ) )
200# ------------------------------
201# Fundamental Variables Assigned
202# ------------------------------
203
204print( "Generating fundamental graph data." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000205
206# Formatting the plot
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700207theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000208width <- 0.7 # Width of the bars.
209xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale )
210xLabel <- xlab( "Scale" )
211yLabel <- ylab( "Throughput (events/second)" )
212fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700213imageWidth <- 15
214imageHeight <- 10
215imageDPI <- 200
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000216
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700217theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
218 legend.position = "bottom",
219 legend.text = element_text( size = 18, face = "bold" ),
220 legend.title = element_blank() )
221
222values <- geom_text( aes( x = dataFrame$scale,
223 y = dataFrame$throughput + 0.03 * max( dataFrame$throughput ),
224 label = format( dataFrame$throughput,
225 digits=3,
226 big.mark = ",",
227 scientific = FALSE ) ),
228 size = 7,
229 fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000230
231# Store plot configurations as 1 variable
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700232fundamentalGraphData <- mainPlot +
233 xScaleConfig +
234 xLabel +
235 yLabel +
236 fillLabel +
237 theme +
238 values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000239
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700240# ---------------------------
241# Generating Bar Graph Format
242# ---------------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000243
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000244print( "Generating bar graph." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700245barGraphFormat <- geom_bar( stat = "identity",
246 width = width,
247 fill = "#169EFF" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000248
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700249title <- ggtitle( chartTitle )
250
251result <- fundamentalGraphData +
252 barGraphFormat +
253 title
254
255# -----------------------
256# Exporting Graph to File
257# -----------------------
258
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000259print( paste( "Saving bar chart to", errBarOutputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000260
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700261ggsave( errBarOutputFile,
262 width = imageWidth,
263 height = imageHeight,
264 dpi = imageDPI )
265
266print( paste( "[SUCCESS] Successfully wrote bar chart out to", errBarOutputFile ) )