blob: 2116035cd8989017fb02fc6502702e22070dc064 [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,
21# please contact Jeremy Ronquillo: jeremyr@opennetworking.org
22
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "STEP 1: File management." )
28
29# Command line arguments are read. Args usually include the database filename and the output
30# directory for the graphs to save to.
31# ie: Rscript SCPFgraphGenerator SCPFsampleDataDB.csv ~/tmp/
32print( "Reading commmand-line args." )
33args <- commandArgs( trailingOnly=TRUE )
34
35# Import libraries to be used for graphing and organizing data, respectively.
36# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
37# reshape2: https://github.com/hadley/reshape
38print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
43# Normal usage
44# Check if sufficient args are provided.
45if ( is.na( args[ 9 ] ) ){
46 print( "Usage: Rscript SCPFflowTp1g.R <has-flow-obj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <has-neighbors> <directory-to-save-graphs>" )
47 q() # basically exit(), but in R
48}
49
50# Filenames for output graphs include the testname and the graph type.
51# See the examples below. paste() is used to concatenate strings.
52
53errBarOutputFile <- paste( args[ 9 ], args[ 6 ], sep="" )
54errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" )
55if ( args[ 8 ] == 'y' ){
56 errBarOutputFile <- paste( errBarOutputFile, "all-neighbors", sep="_" )
57} else {
58 errBarOutputFile <- paste( errBarOutputFile, "no-neighbors", sep="_" )
59}
60if ( args[ 1 ] == 'y' ){
61 errBarOutputFile <- paste( errBarOutputFile, "flowObj", sep="_")
62}
63errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" )
64
65print( "Reading from databases." )
66con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
67
68commandNeighborModifier <- ""
69flowObjModifier <- ""
70if ( args[ 1 ] == 'y' ){
71 flowObjModifier <- "_fobj"
72}
73if ( args[ 8 ] == 'y' ){
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070074 commandNeighborModifier <- "scale=1 OR NOT "
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000075}
76
77command <- paste( "SELECT scale, avg( avg ), avg( std ) FROM flow_tp", flowObjModifier, sep="" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070078command <- paste( command, "_tests WHERE (", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079command <- paste( command, commandNeighborModifier, sep="" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070080command <- paste( command, "neighbors = 0 ) AND branch = '", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000081command <- paste( command, args[ 7 ], sep="" )
82command <- paste( command, "' AND date IN ( SELECT max( date ) FROM flow_tp", sep="" )
83command <- paste( command, flowObjModifier, sep="" )
84command <- paste( command, "_tests WHERE branch='", sep="" )
85command <- paste( command, args[ 7 ], sep="" )
86command <- paste( command, "' ) GROUP BY scale ORDER BY scale", sep="" )
87
88print( paste( "Sending SQL command:", command ) )
89
90fileData <- dbGetQuery( con, command )
91
92title <- paste( args[ 6 ], args[ 7 ], sep="_" )
93
94# **********************************************************
95# STEP 2: Organize data.
96# **********************************************************
97
98print( "STEP 2: Organize data." )
99
100# Create lists c() and organize data into their corresponding list.
101print( "Sorting data." )
102colnames( fileData ) <- c( "scale", "avg", "std" )
103avgs <- c( fileData[ 'avg' ] )
104
105# Parse lists into data frames.
106dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
107dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
108dataFrame$std <- fileData$std
109
110colnames( dataFrame ) <- c( "throughput", "type", "scale", "std" )
111
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700112dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
113
114print( "Data Frame Results:" )
115print( dataFrame )
116
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000117# **********************************************************
118# STEP 3: Generate graphs.
119# **********************************************************
120
121print( "STEP 3: Generate graphs." )
122
123# 1. Graph fundamental data is generated first.
124# These are variables that apply to all of the graphs being generated, regardless of type.
125#
126# 2. Type specific graph data is generated.
127# Data specific for the error bar and stacked bar graphs are generated.
128#
129# 3. Generate and save the graphs.
130# Graphs are saved to the filename above, in the directory provided in command line args
131
132print( "Generating fundamental graph data." )
133
134# Create the primary plot here.
135# ggplot contains the following arguments:
136# - data: the data frame that the graph will be based off of
137# - aes: the asthetics of the graph which require:
138# - x: x-axis values (usually node scaling)
139# - y: y-axis values (usually time in milliseconds)
140# - fill: the category of the colored side-by-side bars (usually type)
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700141
142theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
143
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000144mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = throughput, ymin = throughput - std, ymax = throughput + std, fill = type ) )
145
146# Formatting the plot
147width <- 0.7 # Width of the bars.
148xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale )
149xLabel <- xlab( "Scale" )
150yLabel <- ylab( "Throughput (events/second)" )
151fillLabel <- labs( fill="Type" )
152chartTitle <- "Flow Throughput Test"
153if ( args[ 1 ] == 'y' ){
154 chartTitle <- paste( chartTitle, " with Flow Objectives", sep="" )
155}
156chartTitle <- paste( chartTitle, "\nNeighbors =", sep="" )
157if ( args[ 8 ] == 'y' ){
158 chartTitle <- paste( chartTitle, "Cluster Size - 1" )
159} else {
160 chartTitle <- paste( chartTitle, "0" )
161}
162
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700163theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000164
165# Store plot configurations as 1 variable
166fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
167
168
169# Create the stacked bar graph with error bars.
170# geom_bar contains:
171# - stat: data formatting (usually "identity")
172# - width: the width of the bar types (declared above)
173# geom_errorbar contains similar arguments as geom_bar.
174print( "Generating bar graph with error bars." )
175barGraphFormat <- geom_bar( stat = "identity", width = width, fill="#FFA94F" )
176errorBarFormat <- geom_errorbar( position=position_dodge( ), width = width )
177title <- ggtitle( paste( chartTitle, "" ) )
178result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
179
180# Save graph to file
181print( paste( "Saving bar chart with error bars to", errBarOutputFile ) )
182ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
183print( paste( "Successfully wrote bar chart with error bars out to", errBarOutputFile ) )