Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 1 | # 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 Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 22 | |
| 23 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 24 | # STEP 1: Data management. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 25 | # ********************************************************** |
| 26 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 27 | print( "**********************************************************" ) |
| 28 | print( "STEP 1: Data management." ) |
| 29 | print( "**********************************************************" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 30 | has_flow_obj = 1 |
| 31 | database_host = 2 |
| 32 | database_port = 3 |
| 33 | database_u_id = 4 |
| 34 | database_pw = 5 |
| 35 | test_name = 6 |
| 36 | branch_name = 7 |
| 37 | old_flow = 8 |
| 38 | save_directory = 9 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 40 | print( "Reading commmand-line args." ) |
| 41 | args <- commandArgs( trailingOnly=TRUE ) |
| 42 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 43 | # ---------------- |
| 44 | # Import Libraries |
| 45 | # ---------------- |
| 46 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 47 | print( "Importing libraries." ) |
| 48 | library( ggplot2 ) |
| 49 | library( reshape2 ) |
| 50 | library( RPostgreSQL ) # For databases |
| 51 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 52 | # ------------------- |
| 53 | # Check CLI Arguments |
| 54 | # ------------------- |
| 55 | |
| 56 | print( "Verifying CLI args." ) |
| 57 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 58 | if ( is.na( args[ save_directory ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 59 | print( paste( "Usage: Rscript SCPFInstalledIntentsFlows", |
| 60 | "<has-flowObj>", |
| 61 | "<database-host>", |
| 62 | "<database-port>", |
| 63 | "<database-user-id>", |
| 64 | "<database-password>", |
| 65 | "<test-name>", |
| 66 | "<branch-name>", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 67 | "<using-old-flow>", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 68 | "<directory-to-save-graphs>", |
| 69 | sep=" " ) ) |
| 70 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 71 | q() # basically exit(), but in R |
| 72 | } |
| 73 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 74 | # ----------------- |
| 75 | # Create File Names |
| 76 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 77 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 78 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 80 | fileFlowObjModifier <- "" |
| 81 | sqlFlowObjModifier <- "" |
| 82 | chartTitle <- "Number of Installed Intents & Flows" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 83 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 84 | if ( args[ has_flow_obj ] == "y" ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 85 | fileFlowObjModifier <- "_flowObj" |
| 86 | sqlFlowObjModifier <- "fobj_" |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 87 | chartTitle <- "Number of Installed Intents & Flows\n with Flow Objectives" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 88 | } |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 89 | fileOldFlowModifier <- "" |
| 90 | if ( args[ old_flow ] == 'y' ){ |
| 91 | fileOldFlowModifier <- "_OldFlow" |
Devin Lim | 1bba762 | 2017-11-14 16:31:41 -0800 | [diff] [blame] | 92 | chartTitle <- paste( chartTitle, "With Eventually Consistent Flow Rule Store", sep="\n" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 93 | } |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 94 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 95 | outputFile <- paste( args[ save_directory ], |
| 96 | args[ test_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 97 | fileFlowObjModifier, |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 98 | fileOldFlowModifier, |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 99 | "_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 100 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 101 | "_errGraph.jpg", |
| 102 | sep="" ) |
| 103 | |
| 104 | # ------------------ |
| 105 | # SQL Initialization |
| 106 | # ------------------ |
| 107 | |
| 108 | print( "Initializing SQL" ) |
| 109 | |
| 110 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 111 | dbname = "onostest", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 112 | host = args[ database_host ], |
| 113 | port = strtoi( args[ database_port ] ), |
| 114 | user = args[ database_u_id ], |
| 115 | password = args[ database_pw ] ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 116 | |
| 117 | # ------------------------------- |
| 118 | # Scaling Max Intents SQL Command |
| 119 | # ------------------------------- |
| 120 | |
| 121 | print( "Scaling Max Intents SQL Command" ) |
| 122 | |
| 123 | command <- paste( "SELECT * FROM max_intents_", |
| 124 | sqlFlowObjModifier, |
| 125 | "tests WHERE branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 126 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 127 | "' AND date IN ( SELECT MAX( date ) FROM max_intents_", |
| 128 | sqlFlowObjModifier, |
| 129 | "tests WHERE branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 130 | args[ branch_name ], |
| 131 | "' AND ", |
| 132 | ( if( args[ old_flow ] == 'y' ) "" else "NOT " ), |
| 133 | "is_old_flow", |
| 134 | " ) ", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 135 | sep="" ) |
| 136 | |
| 137 | print( "Sending SQL command:" ) |
| 138 | print( command ) |
| 139 | fileData <- dbGetQuery( con, command ) |
| 140 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 141 | # ********************************************************** |
| 142 | # STEP 2: Organize data. |
| 143 | # ********************************************************** |
| 144 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 145 | print( "**********************************************************" ) |
| 146 | print( "STEP 2: Organize Data." ) |
| 147 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 148 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 149 | # ------------ |
| 150 | # Data Sorting |
| 151 | # ------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 152 | |
| 153 | print( "Sorting data." ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 154 | |
| 155 | avgs <- c( fileData[ 'max_intents_ovs' ], |
| 156 | fileData[ 'max_flows_ovs' ] ) |
| 157 | |
| 158 | # -------------------- |
| 159 | # Construct Data Frame |
| 160 | # -------------------- |
| 161 | |
| 162 | print( "Constructing Data Frame" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 163 | |
| 164 | dataFrame <- melt( avgs ) |
| 165 | dataFrame$scale <- fileData$scale |
| 166 | |
| 167 | colnames( dataFrame ) <- c( "ms", "type", "scale" ) |
| 168 | |
| 169 | dataFrame$type <- as.character( dataFrame$type ) |
| 170 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 171 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 172 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 173 | |
| 174 | print( "Data Frame Results:" ) |
| 175 | print( dataFrame ) |
| 176 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 177 | # ********************************************************** |
| 178 | # STEP 3: Generate graphs. |
| 179 | # ********************************************************** |
| 180 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 181 | print( "**********************************************************" ) |
| 182 | print( "STEP 3: Generate Graph." ) |
| 183 | print( "**********************************************************" ) |
| 184 | |
| 185 | # ------------------ |
| 186 | # Generate Main Plot |
| 187 | # ------------------ |
| 188 | |
| 189 | print( "Creating main plot." ) |
| 190 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 191 | y = ms, |
| 192 | fill = type ) ) |
| 193 | |
| 194 | # ------------------------------ |
| 195 | # Fundamental Variables Assigned |
| 196 | # ------------------------------ |
| 197 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 198 | print( "Generating fundamental graph data." ) |
| 199 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 200 | barWidth <- 1.3 |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 201 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 202 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 203 | xLabel <- xlab( "Scale" ) |
| 204 | yLabel <- ylab( "Max Number of Intents/Flow Rules" ) |
| 205 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 206 | imageWidth <- 15 |
| 207 | imageHeight <- 10 |
| 208 | imageDPI <- 200 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 209 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 210 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 211 | legend.position = "bottom", |
| 212 | legend.text = element_text( size=22 ), |
| 213 | legend.title = element_blank(), |
| 214 | legend.key.size = unit( 1.5, 'lines' ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 215 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 216 | colors <- scale_fill_manual( values = c( "#F77670", |
| 217 | "#619DFA" ) ) |
| 218 | |
| 219 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 220 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 221 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 222 | fundamentalGraphData <- mainPlot + |
| 223 | xScaleConfig + |
| 224 | xLabel + |
| 225 | yLabel + |
| 226 | fillLabel + |
| 227 | theme + |
| 228 | wrapLegend + |
| 229 | title + |
| 230 | colors |
| 231 | |
| 232 | # --------------------------- |
| 233 | # Generating Bar Graph Format |
| 234 | # --------------------------- |
| 235 | |
| 236 | print( "Generating bar graph." ) |
| 237 | |
| 238 | barGraphFormat <- geom_bar( stat = "identity", |
| 239 | position = position_dodge(), |
| 240 | width = barWidth ) |
| 241 | |
| 242 | values <- geom_text( aes( x = dataFrame$scale, |
| 243 | y = dataFrame$ms + 0.015 * max( dataFrame$ms ), |
| 244 | label = format( dataFrame$ms, |
| 245 | digits=3, |
| 246 | big.mark = ",", |
| 247 | scientific = FALSE ) ), |
| 248 | size = 5.2, |
| 249 | fontface = "bold", |
| 250 | position = position_dodge( width = 1.25 ) ) |
| 251 | |
| 252 | result <- fundamentalGraphData + |
| 253 | barGraphFormat + |
| 254 | values |
| 255 | |
| 256 | # ----------------------- |
| 257 | # Exporting Graph to File |
| 258 | # ----------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 259 | |
| 260 | print( paste( "Saving bar chart to", outputFile ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 261 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 262 | ggsave( outputFile, |
| 263 | width = imageWidth, |
| 264 | height = imageHeight, |
| 265 | dpi = imageDPI ) |
| 266 | |
| 267 | print( paste( "[SUCCESS] Successfully wrote bar chart out to", outputFile ) ) |