blob: bc90806deb498be856520b322b8b3bcddf644017 [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 Ronquillo6df87812017-08-28 16:17:36 +000029print( "Reading commmand-line args." )
30args <- commandArgs( trailingOnly=TRUE )
31
32# Import libraries to be used for graphing and organizing data, respectively.
33# Find out more about ggplot2: https://github.com/tidyverse/ggplot2
34# reshape2: https://github.com/hadley/reshape
35print( "Importing libraries." )
36library( ggplot2 )
37library( reshape2 )
38library( RPostgreSQL ) # For databases
39
40# Normal usage
41# Check if sufficient args are provided.
42if ( is.na( args[ 8 ] ) ){
43 print( "Usage: Rscript SCPFInstalledIntentsFlows <has-flowObj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
44 q() # basically exit(), but in R
45}
46
Jeremy Ronquillob6268842017-10-03 13:02:58 -070047# paste() is used to concatenate strings.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000048outputFile <- paste( args[ 8 ], args[ 6 ], sep="" )
49if ( args[ 1 ] == "y" ){
50 outputFile <- paste( outputFile, "flowObj", sep="_" )
51}
52outputFile <- paste( outputFile, args[ 7 ], sep="_" )
53outputFile <- paste( outputFile, "_errGraph.jpg", sep="" )
54
55print( "Reading from databases." )
56
57con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
58
59command <- "SELECT * FROM max_intents_"
60if ( args[ 1 ] == "y" ){
61 command <- paste( command, "fobj_", sep="" )
62}
63command <- paste( command, "tests WHERE branch = '", sep = "" )
64command <- paste( command, args[ 7 ], sep="" )
65command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM max_intents_", sep="" )
66if ( args[ 1 ] == "y" ){
67 command <- paste( command, "fobj_", sep="" )
68}
69command <- paste( command, "tests WHERE branch = '", sep = "" )
70command <- paste( command, args[ 7 ], sep = "" )
71command <- paste( command, "' ) ", sep="" )
72
73print( paste( "Sending SQL command:", command ) )
74
75fileData <- dbGetQuery( con, command )
76
77if ( args[ 1 ] == "y" ){
Jeremy Ronquillob6268842017-10-03 13:02:58 -070078 chartTitle <- "Number of Installed Intents & Flows w/ FlowObj"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079} else {
80 chartTitle <- "Number of Installed Intents & Flows"
81}
82
83# **********************************************************
84# STEP 2: Organize data.
85# **********************************************************
86
87fileDataNames <- names( fileData )
88
89avgs <- c()
90
91print( "Sorting data." )
92avgs <- c( fileData[ 'max_intents_ovs' ], fileData[ 'max_flows_ovs' ] )
93
94dataFrame <- melt( avgs )
95dataFrame$scale <- fileData$scale
96
97colnames( dataFrame ) <- c( "ms", "type", "scale" )
98
99dataFrame$type <- as.character( dataFrame$type )
100dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
101
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700102dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
103
104print( "Data Frame Results:" )
105print( dataFrame )
106
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000107# **********************************************************
108# STEP 3: Generate graphs.
109# **********************************************************
110
111print( "Generating fundamental graph data." )
112
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700113theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
114
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000115mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, fill = type ) )
116xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
117xLabel <- xlab( "Scale" )
118yLabel <- ylab( "Max Number of Intents/Flow Rules" )
119fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700120theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000121
122fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
123
124
125print( "Generating bar graph bars." )
126width <- 1.3
127barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width )
128title <- ggtitle( chartTitle )
129result <- fundamentalGraphData + barGraphFormat + title
130
131
132print( paste( "Saving bar chart to", outputFile ) )
133ggsave( outputFile, width = 10, height = 6, dpi = 200 )
134
135print( paste( "Successfully wrote bar chart out to", outputFile ) )