blob: 2ca06271b543ce6c7541d424ee524ac8f9d13ada [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# **********************************************************
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070024# STEP 1: Data management.
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000025# **********************************************************
26
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070027print( "**********************************************************" )
28print( "STEP 1: Data management." )
29print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000030
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000031print( "Reading commmand-line args." )
32args <- commandArgs( trailingOnly=TRUE )
33
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070034# ----------------
35# Import Libraries
36# ----------------
37
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000038print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070043# -------------------
44# Check CLI Arguments
45# -------------------
46
47print( "Verifying CLI args." )
48
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000049if ( is.na( args[ 8 ] ) ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070050
51 print( paste( "Usage: Rscript SCPFInstalledIntentsFlows",
52 "<has-flowObj>",
53 "<database-host>",
54 "<database-port>",
55 "<database-user-id>",
56 "<database-password>",
57 "<test-name>",
58 "<branch-name>",
59 "<directory-to-save-graphs>",
60 sep=" " ) )
61
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000062 q() # basically exit(), but in R
63}
64
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070065# -----------------
66# Create File Names
67# -----------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000068
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070069print( "Creating filenames and title of graph." )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000070
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070071fileFlowObjModifier <- ""
72sqlFlowObjModifier <- ""
73chartTitle <- "Number of Installed Intents & Flows"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000074
75if ( args[ 1 ] == "y" ){
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070076 fileFlowObjModifier <- "_flowObj"
77 sqlFlowObjModifier <- "fobj_"
Jeremy Ronquillo4363d092017-10-13 13:28:47 -070078 chartTitle <- "Number of Installed Intents & Flows\n with Flow Objectives"
Jeremy Ronquillo6df87812017-08-28 16:17:36 +000079}
80
Jeremy Ronquillo7673f802017-10-30 09:42:44 -070081outputFile <- paste( args[ 8 ],
82 args[ 6 ],
83 fileFlowObjModifier,
84 "_",
85 args[ 7 ],
86 "_errGraph.jpg",
87 sep="" )
88
89# ------------------
90# SQL Initialization
91# ------------------
92
93print( "Initializing SQL" )
94
95con <- dbConnect( dbDriver( "PostgreSQL" ),
96 dbname = "onostest",
97 host = args[ 2 ],
98 port = strtoi( args[ 3 ] ),
99 user = args[ 4 ],
100 password = args[ 5 ] )
101
102# -------------------------------
103# Scaling Max Intents SQL Command
104# -------------------------------
105
106print( "Scaling Max Intents SQL Command" )
107
108command <- paste( "SELECT * FROM max_intents_",
109 sqlFlowObjModifier,
110 "tests WHERE branch = '",
111 args[ 7 ],
112 "' AND date IN ( SELECT MAX( date ) FROM max_intents_",
113 sqlFlowObjModifier,
114 "tests WHERE branch = '",
115 args[ 7 ],
116 "' ) ",
117 sep="" )
118
119print( "Sending SQL command:" )
120print( command )
121fileData <- dbGetQuery( con, command )
122
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000123# **********************************************************
124# STEP 2: Organize data.
125# **********************************************************
126
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700127print( "**********************************************************" )
128print( "STEP 2: Organize Data." )
129print( "**********************************************************" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000130
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700131# ------------
132# Data Sorting
133# ------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000134
135print( "Sorting data." )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700136
137avgs <- c( fileData[ 'max_intents_ovs' ],
138 fileData[ 'max_flows_ovs' ] )
139
140# --------------------
141# Construct Data Frame
142# --------------------
143
144print( "Constructing Data Frame" )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000145
146dataFrame <- melt( avgs )
147dataFrame$scale <- fileData$scale
148
149colnames( dataFrame ) <- c( "ms", "type", "scale" )
150
151dataFrame$type <- as.character( dataFrame$type )
152dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) )
153
Jeremy Ronquillo2d2649d2017-09-14 12:53:06 -0700154dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist
155
156print( "Data Frame Results:" )
157print( dataFrame )
158
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000159# **********************************************************
160# STEP 3: Generate graphs.
161# **********************************************************
162
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700163print( "**********************************************************" )
164print( "STEP 3: Generate Graph." )
165print( "**********************************************************" )
166
167# ------------------
168# Generate Main Plot
169# ------------------
170
171print( "Creating main plot." )
172mainPlot <- ggplot( data = dataFrame, aes( x = scale,
173 y = ms,
174 fill = type ) )
175
176# ------------------------------
177# Fundamental Variables Assigned
178# ------------------------------
179
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000180print( "Generating fundamental graph data." )
181
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700182barWidth <- 1.3
Jeremy Ronquillo0e27b912017-10-21 14:34:24 -0700183theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph.
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700184xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000185xLabel <- xlab( "Scale" )
186yLabel <- ylab( "Max Number of Intents/Flow Rules" )
187fillLabel <- labs( fill="Type" )
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700188imageWidth <- 15
189imageHeight <- 10
190imageDPI <- 200
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000191
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700192theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ),
193 legend.position = "bottom",
194 legend.text = element_text( size=22 ),
195 legend.title = element_blank(),
196 legend.key.size = unit( 1.5, 'lines' ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000197
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700198colors <- scale_fill_manual( values = c( "#F77670",
199 "#619DFA" ) )
200
201wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000202title <- ggtitle( chartTitle )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000203
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700204fundamentalGraphData <- mainPlot +
205 xScaleConfig +
206 xLabel +
207 yLabel +
208 fillLabel +
209 theme +
210 wrapLegend +
211 title +
212 colors
213
214# ---------------------------
215# Generating Bar Graph Format
216# ---------------------------
217
218print( "Generating bar graph." )
219
220barGraphFormat <- geom_bar( stat = "identity",
221 position = position_dodge(),
222 width = barWidth )
223
224values <- geom_text( aes( x = dataFrame$scale,
225 y = dataFrame$ms + 0.015 * max( dataFrame$ms ),
226 label = format( dataFrame$ms,
227 digits=3,
228 big.mark = ",",
229 scientific = FALSE ) ),
230 size = 5.2,
231 fontface = "bold",
232 position = position_dodge( width = 1.25 ) )
233
234result <- fundamentalGraphData +
235 barGraphFormat +
236 values
237
238# -----------------------
239# Exporting Graph to File
240# -----------------------
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000241
242print( paste( "Saving bar chart to", outputFile ) )
Jeremy Ronquillo6df87812017-08-28 16:17:36 +0000243
Jeremy Ronquillo7673f802017-10-30 09:42:44 -0700244ggsave( outputFile,
245 width = imageWidth,
246 height = imageHeight,
247 dpi = imageDPI )
248
249print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) )