blob: e5f54e5a76961d325a1f396173f7a0a877979755 [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[ 8 ] ) ){
46 print( "Usage: Rscript SCPFInstalledIntentsFlows <has-flowObj> <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <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
53outputFile <- paste( args[ 8 ], args[ 6 ], sep="" )
54if ( args[ 1 ] == "y" ){
55 outputFile <- paste( outputFile, "flowObj", sep="_" )
56}
57outputFile <- paste( outputFile, args[ 7 ], sep="_" )
58outputFile <- paste( outputFile, "_errGraph.jpg", sep="" )
59
60print( "Reading from databases." )
61
62con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] )
63
64command <- "SELECT * FROM max_intents_"
65if ( args[ 1 ] == "y" ){
66 command <- paste( command, "fobj_", sep="" )
67}
68command <- paste( command, "tests WHERE branch = '", sep = "" )
69command <- paste( command, args[ 7 ], sep="" )
70command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM max_intents_", sep="" )
71if ( args[ 1 ] == "y" ){
72 command <- paste( command, "fobj_", sep="" )
73}
74command <- paste( command, "tests WHERE branch = '", sep = "" )
75command <- paste( command, args[ 7 ], sep = "" )
76command <- paste( command, "' ) ", sep="" )
77
78print( paste( "Sending SQL command:", command ) )
79
80fileData <- dbGetQuery( con, command )
81
82if ( args[ 1 ] == "y" ){
83 chartTitle <- "Number of Installed Intents & Flows with Flow Objectives"
84} else {
85 chartTitle <- "Number of Installed Intents & Flows"
86}
87
88# **********************************************************
89# STEP 2: Organize data.
90# **********************************************************
91
92fileDataNames <- names( fileData )
93
94avgs <- c()
95
96print( "Sorting data." )
97avgs <- c( fileData[ 'max_intents_ovs' ], fileData[ 'max_flows_ovs' ] )
98
99dataFrame <- melt( avgs )
100dataFrame$scale <- fileData$scale
101
102colnames( dataFrame ) <- c( "ms", "type", "scale" )
103
104dataFrame$type <- as.character( dataFrame$type )
105dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
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
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000112# **********************************************************
113# STEP 3: Generate graphs.
114# **********************************************************
115
116print( "Generating fundamental graph data." )
117
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700118theme_set( theme_grey( base_size = 20 ) ) # set the default text size of the graph.
119
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000120mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, fill = type ) )
121xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
122xLabel <- xlab( "Scale" )
123yLabel <- ylab( "Max Number of Intents/Flow Rules" )
124fillLabel <- labs( fill="Type" )
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700125theme <- theme( plot.title=element_text( hjust = 0.5, size = 28, face='bold' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000126
127fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme
128
129
130print( "Generating bar graph bars." )
131width <- 1.3
132barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width )
133title <- ggtitle( chartTitle )
134result <- fundamentalGraphData + barGraphFormat + title
135
136
137print( paste( "Saving bar chart to", outputFile ) )
138ggsave( outputFile, width = 10, height = 6, dpi = 200 )
139
140print( paste( "Successfully wrote bar chart out to", outputFile ) )