blob: e7818d1f403928a3bd0aa1b4fbc0d6c70d04fcb4 [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 SCPFIntentEventTp.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' ){
74 commandNeighborModifier <- "NOT "
75}
76
77command <- paste( "SELECT scale, avg( avg ) FROM intent_tp", flowObjModifier, sep="" )
78command <- paste( command, "_tests WHERE ", sep="" )
79command <- paste( command, commandNeighborModifier, sep="" )
80command <- paste( command, "neighbors = 0 AND branch = '", sep="")
81command <- paste( command, args[ 7 ], sep="" )
82command <- paste( command, "' AND date IN ( SELECT max( date ) FROM intent_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." )
102avgs <- c( fileData[ 'avg' ] )
103
104# Parse lists into data frames.
105dataFrame <- melt( avgs ) # This is where reshape2 comes in. Avgs list is converted to data frame
106dataFrame$scale <- fileData$scale # Add node scaling to the data frame.
107
108colnames( dataFrame ) <- c( "throughput", "type", "scale" )
109
110# **********************************************************
111# STEP 3: Generate graphs.
112# **********************************************************
113
114print( "STEP 3: Generate graphs." )
115
116# 1. Graph fundamental data is generated first.
117# These are variables that apply to all of the graphs being generated, regardless of type.
118#
119# 2. Type specific graph data is generated.
120# Data specific for the error bar and stacked bar graphs are generated.
121#
122# 3. Generate and save the graphs.
123# Graphs are saved to the filename above, in the directory provided in command line args
124
125print( "Generating fundamental graph data." )
126
127# Create the primary plot here.
128# ggplot contains the following arguments:
129# - data: the data frame that the graph will be based off of
130# - aes: the asthetics of the graph which require:
131# - x: x-axis values (usually node scaling)
132# - y: y-axis values (usually time in milliseconds)
133# - fill: the category of the colored side-by-side bars (usually type)
134mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = throughput, fill = type ) )
135
136# Formatting the plot
137width <- 0.7 # Width of the bars.
138xScaleConfig <- scale_x_continuous( breaks = dataFrame$scale, label = dataFrame$scale )
139xLabel <- xlab( "Scale" )
140yLabel <- ylab( "Throughput (events/second)" )
141fillLabel <- labs( fill="Type" )
142chartTitle <- "Intent Event Throughput"
143if ( args[ 1 ] == 'y' ){
144 chartTitle <- paste( chartTitle, " With Flow Objectives", sep="" )
145}
146chartTitle <- paste( chartTitle, "\nevents/second with Neighbors =", sep="" )
147if ( args[ 8 ] == 'y' ){
148 chartTitle <- paste( chartTitle, "all" )
149} else {
150 chartTitle <- paste( chartTitle, "0" )
151}
152
153theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
154
155# Store plot configurations as 1 variable
156fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
157
158
159# Create the stacked bar graph with error bars.
160# geom_bar contains:
161# - stat: data formatting (usually "identity")
162# - width: the width of the bar types (declared above)
163# geom_errorbar contains similar arguments as geom_bar.
164print( "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 ) )