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