blob: 420b44473916bc5e14a2d2f47d876bdbbd40dead [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
29# Command line arguments are read. Args usually include the database filename and the output
30# directory for the graphs to save to.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000031print( "Reading commmand-line args." )
32args <- commandArgs( trailingOnly=TRUE )
33
34# Import libraries to be used for graphing and organizing data, respectively.
35# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
36# reshape2: https://github.com/hadley/reshape
37print( "Importing libraries." )
38library( ggplot2 )
39library( reshape2 )
40library( RPostgreSQL ) # For databases
41
42# Normal usage
43# Check if sufficient args are provided.
44if ( is.na( args[ 9 ] ) ){
45 print( "Usage: Rscript SCPFIntentEventTp.R <has-flow-obj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <has-neighbors> <directory-to-save-graphs>" )
46 q() # basically exit(), but in R
47}
48
Jeremy Ronquillob6268842017-10-03 13:02:58 -070049# paste() is used to concatenate strings.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000050errBarOutputFile <- paste( args[ 9 ], args[ 6 ], sep="" )
51errBarOutputFile <- paste( errBarOutputFile, args[ 7 ], sep="_" )
52if ( args[ 8 ] == 'y' ){
53 errBarOutputFile <- paste( errBarOutputFile, "all-neighbors", sep="_" )
54} else {
55 errBarOutputFile <- paste( errBarOutputFile, "no-neighbors", sep="_" )
56}
57if ( args[ 1 ] == 'y' ){
58 errBarOutputFile <- paste( errBarOutputFile, "flowObj", sep="_")
59}
60errBarOutputFile <- paste( errBarOutputFile, "_graph.jpg", sep="" )
61
62print( "Reading from databases." )
63con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
64
65commandNeighborModifier <- ""
66flowObjModifier <- ""
67if ( args[ 1 ] == 'y' ){
68 flowObjModifier <- "_fobj"
69}
70if ( args[ 8 ] == 'y' ){
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070071 commandNeighborModifier <- "scale=1 OR NOT "
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000072}
73
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070074command <- paste( "SELECT scale, SUM( avg ) as avg FROM intent_tp", flowObjModifier, sep="" )
75command <- paste( command, "_tests WHERE (", sep="" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000076command <- paste( command, commandNeighborModifier, sep="" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -070077command <- paste( command, "neighbors = 0 ) AND branch = '", sep="")
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000078command <- paste( command, args[ 7 ], sep="" )
79command <- paste( command, "' AND date IN ( SELECT max( date ) FROM intent_tp", sep="" )
80command <- paste( command, flowObjModifier, sep="" )
81command <- paste( command, "_tests WHERE branch='", sep="" )
82command <- paste( command, args[ 7 ], sep="" )
83command <- paste( command, "' ) GROUP BY scale ORDER BY scale", sep="" )
84
85print( paste( "Sending SQL command:", command ) )
86
87fileData <- dbGetQuery( con, command )
88
89title <- paste( args[ 6 ], args[ 7 ], sep="_" )
90
91# **********************************************************
92# STEP 2: Organize data.
93# **********************************************************
94
95print( "STEP 2: Organize data." )
96
97# Create lists c() and organize data into their corresponding list.
98print( "Sorting data." )
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.
104
105colnames( dataFrame ) <- c( "throughput", "type", "scale" )
106
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700107dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
108
109print( "Data Frame Results:" )
110print( dataFrame )
111
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.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123#
124# 3. Generate and save the graphs.
125# Graphs are saved to the filename above, in the directory provided in command line args
126
127print( "Generating fundamental graph data." )
128
129# Create the primary plot here.
130# ggplot contains the following arguments:
131# - data: the data frame that the graph will be based off of
132# - aes: the asthetics of the graph which require:
133# - x: x-axis values (usually node scaling)
134# - y: y-axis values (usually time in milliseconds)
135# - fill: the category of the colored side-by-side bars (usually type)
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700136theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
137
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000138mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = throughput, fill = type ) )
139
140# Formatting the plot
141width <- 0.7 # Width of the bars.
142xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale )
143xLabel <- xlab( "Scale" )
144yLabel <- ylab( "Throughput (events/second)" )
145fillLabel <- labs( fill="Type" )
146chartTitle <- "Intent Event Throughput"
147if ( args[ 1 ] == 'y' ){
148 chartTitle <- paste( chartTitle, " With Flow Objectives", sep="" )
149}
150chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" )
151if ( args[ 8 ] == 'y' ){
152 chartTitle <- paste( chartTitle, "all" )
153} else {
154 chartTitle <- paste( chartTitle, "0" )
155}
156
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700157theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700158values <- geom_text( aes( x=dataFrame$scale, y=dataFrame$throughput + 0.04 * max( dataFrame$throughput ), label = format( dataFrame$throughput, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5, fontface = "bold" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159
160# Store plot configurations as 1 variable
Jeremy Ronquillo4363d092017-10-13 13:28:47 -0700161fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme + values
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000162
163
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000164print( "Generating bar graph." )
165barGraphFormat <- geom_bar( stat = "identity", width = width, fill="#169EFF" )
166title <- ggtitle( paste( chartTitle, "" ) )
167result <- fundamentalGraphData + barGraphFormat + title
168
169# Save graph to file
170print( paste( "Saving bar chart to", errBarOutputFile ) )
171ggsave( errBarOutputFile, width = 10, height = 6, dpi = 200 )
172
173print( paste( "Successfully wrote bar chart out to", errBarOutputFile ) )