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( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 30 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 31 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 32 | print( "Reading commmand-line args." ) |
| 33 | args <- commandArgs( trailingOnly=TRUE ) |
| 34 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 35 | # ---------------- |
| 36 | # Import Libraries |
| 37 | # ---------------- |
| 38 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | print( "Importing libraries." ) |
| 40 | library( ggplot2 ) |
| 41 | library( reshape2 ) |
| 42 | library( RPostgreSQL ) # For databases |
| 43 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 44 | # ------------------- |
| 45 | # Check CLI Arguments |
| 46 | # ------------------- |
| 47 | |
| 48 | print( "Verifying CLI args." ) |
| 49 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 50 | if ( is.na( args[ 7 ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 51 | |
| 52 | print( paste( "Usage: Rscript SCPFswitchLat", |
| 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 Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 62 | q() # basically exit(), but in R |
| 63 | } |
| 64 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 65 | # ----------------- |
| 66 | # Create File Names |
| 67 | # ----------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 68 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 69 | print( "Creating filenames and title of graph." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 70 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 71 | errBarOutputFileUp <- paste( args[ 7 ], |
| 72 | "SCPFswitchLat_", |
| 73 | args[ 6 ], |
| 74 | "_UpErrBarWithStack.jpg", |
| 75 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 76 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 77 | errBarOutputFileDown <- paste( args[ 7 ], |
| 78 | "SCPFswitchLat_", |
| 79 | args[ 6 ], |
| 80 | "_DownErrBarWithStack.jpg", |
| 81 | sep="" ) |
| 82 | # ------------------ |
| 83 | # SQL Initialization |
| 84 | # ------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 85 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 86 | print( "Initializing SQL" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 87 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 88 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 89 | dbname = "onostest", |
| 90 | host = args[ 1 ], |
| 91 | port = strtoi( args[ 2 ] ), |
| 92 | user = args[ 3 ], |
| 93 | password = args[ 4 ] ) |
| 94 | |
| 95 | # -------------------------- |
| 96 | # Switch Latency SQL Command |
| 97 | # -------------------------- |
| 98 | |
| 99 | print( "Generating Switch Latency SQL Command" ) |
| 100 | |
| 101 | command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '", |
| 102 | args[ 6 ], |
| 103 | "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='", |
| 104 | args[ 6 ], |
| 105 | "' )", |
| 106 | sep="" ) |
| 107 | |
| 108 | print( "Sending SQL command:" ) |
| 109 | print( command ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 110 | |
| 111 | fileData <- dbGetQuery( con, command ) |
| 112 | |
| 113 | # ********************************************************** |
| 114 | # STEP 2: Organize data. |
| 115 | # ********************************************************** |
| 116 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 117 | print( "**********************************************************" ) |
| 118 | print( "STEP 2: Organize Data." ) |
| 119 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 120 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 121 | # ------------------------------- |
| 122 | # Switch Up Averages Data Sorting |
| 123 | # ------------------------------- |
| 124 | |
| 125 | print( "Sorting data for Switch Up Averages." ) |
| 126 | |
| 127 | upAvgs <- c( fileData[ 'up_device_to_graph_avg' ], |
| 128 | fileData[ 'role_reply_to_device_avg' ], |
| 129 | fileData[ 'role_request_to_role_reply_avg' ], |
| 130 | fileData[ 'feature_reply_to_role_request_avg' ], |
| 131 | fileData[ 'tcp_to_feature_reply_avg' ] ) |
| 132 | |
| 133 | # ------------------------------ |
| 134 | # Switch Up Construct Data Frame |
| 135 | # ------------------------------ |
| 136 | |
| 137 | print( "Constructing Switch Up data frame." ) |
| 138 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 139 | upAvgsData <- melt( upAvgs ) |
| 140 | upAvgsData$scale <- fileData$scale |
| 141 | upAvgsData$up_std <- fileData$up_std |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 142 | upAvgsData <- na.omit( upAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 143 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 144 | colnames( upAvgsData ) <- c( "ms", |
| 145 | "type", |
| 146 | "scale", |
| 147 | "stds" ) |
| 148 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 149 | upAvgsData$type <- as.character( upAvgsData$type ) |
| 150 | upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) ) |
| 151 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 152 | sumOfUpAvgs <- fileData[ 'up_device_to_graph_avg' ] + |
| 153 | fileData[ 'role_reply_to_device_avg' ] + |
| 154 | fileData[ 'role_request_to_role_reply_avg' ] + |
| 155 | fileData[ 'feature_reply_to_role_request_avg' ] + |
| 156 | fileData[ 'tcp_to_feature_reply_avg' ] |
| 157 | |
| 158 | print( "Up Averages Results:" ) |
| 159 | print( upAvgsData ) |
| 160 | |
| 161 | # --------------------------------- |
| 162 | # Switch Down Averages Data Sorting |
| 163 | # --------------------------------- |
| 164 | |
| 165 | print( "Sorting data for Switch Down Averages." ) |
| 166 | |
| 167 | downAvgs <- c( fileData[ 'down_device_to_graph_avg' ], |
| 168 | fileData[ 'ack_to_device_avg' ], |
| 169 | fileData[ 'fin_ack_to_ack_avg' ] ) |
| 170 | |
| 171 | # -------------------------------- |
| 172 | # Switch Down Construct Data Frame |
| 173 | # -------------------------------- |
| 174 | |
| 175 | print( "Constructing Switch Down data frame." ) |
| 176 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 177 | downAvgsData <- melt( downAvgs ) |
| 178 | downAvgsData$scale <- fileData$scale |
| 179 | downAvgsData$down_std <- fileData$down_std |
| 180 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 181 | colnames( downAvgsData ) <- c( "ms", |
| 182 | "type", |
| 183 | "scale", |
| 184 | "stds" ) |
| 185 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 186 | downAvgsData$type <- as.character( downAvgsData$type ) |
| 187 | downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) ) |
| 188 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 189 | downAvgsData <- na.omit( downAvgsData ) |
| 190 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 191 | sumOfDownAvgs <- fileData[ 'down_device_to_graph_avg' ] + |
| 192 | fileData[ 'ack_to_device_avg' ] + |
| 193 | fileData[ 'fin_ack_to_ack_avg' ] |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 194 | |
| 195 | print( "Down Averages Results:" ) |
| 196 | print( downAvgsData ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 197 | |
| 198 | # ********************************************************** |
| 199 | # STEP 3: Generate graphs. |
| 200 | # ********************************************************** |
| 201 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 202 | print( "**********************************************************" ) |
| 203 | print( "STEP 3: Generate Graph." ) |
| 204 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 205 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 206 | # ------------------------------------ |
| 207 | # Initialize Variables For Both Graphs |
| 208 | # ------------------------------------ |
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 | print( "Initializing variables used in both graphs." ) |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 211 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 212 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graphs |
| 213 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 214 | xLabel <- xlab( "Scale" ) |
| 215 | yLabel <- ylab( "Latency (ms)" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 216 | imageWidth <- 15 |
| 217 | imageHeight <- 10 |
| 218 | imageDPI <- 200 |
| 219 | errorBarColor <- rgb( 140, 140, 140, maxColorValue = 255 ) |
| 220 | barWidth <- 1 |
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 | theme <- theme( plot.title = element_text( hjust = 0.5, size = 32, face = 'bold' ), |
| 223 | legend.position = "bottom", |
| 224 | legend.text = element_text( size = 22 ), |
| 225 | legend.title = element_blank(), |
| 226 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 227 | |
| 228 | # ---------------------------- |
| 229 | # Switch Up Generate Main Plot |
| 230 | # ---------------------------- |
| 231 | |
| 232 | print( "Creating main plot (Switch Up Latency)." ) |
| 233 | |
| 234 | mainPlot <- ggplot( data = upAvgsData, aes( x = scale, |
| 235 | y = ms, |
| 236 | fill = type, |
| 237 | ymin = fileData[ 'up_end_to_end_avg' ], |
| 238 | ymax = fileData[ 'up_end_to_end_avg' ] + stds ) ) |
| 239 | |
| 240 | # ---------------------------------------- |
| 241 | # Switch Up Fundamental Variables Assigned |
| 242 | # ---------------------------------------- |
| 243 | |
| 244 | print( "Generating fundamental graph data (Switch Up Latency)." ) |
| 245 | |
| 246 | title <- ggtitle( "Switch Up Latency" ) |
| 247 | |
| 248 | fundamentalGraphData <- mainPlot + |
| 249 | xScaleConfig + |
| 250 | xLabel + |
| 251 | yLabel + |
| 252 | theme + |
| 253 | title |
| 254 | |
| 255 | # ------------------------------------- |
| 256 | # Switch Up Generating Bar Graph Format |
| 257 | # ------------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 258 | |
| 259 | print( "Generating bar graph with error bars (Switch Up Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 260 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 261 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 262 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 263 | |
| 264 | barGraphValues <- geom_text( aes( x = upAvgsData$scale, |
| 265 | y = sumOfUpAvgs + 0.04 * max( sumOfUpAvgs ), |
| 266 | label = format( sumOfUpAvgs, |
| 267 | digits = 3, |
| 268 | big.mark = ",", |
| 269 | scientific = FALSE ) ), |
| 270 | size = 7.0, |
| 271 | fontface = "bold" ) |
| 272 | |
| 273 | wrapLegend <- guides( fill = guide_legend( nrow = 2, byrow = TRUE ) ) |
| 274 | |
| 275 | result <- fundamentalGraphData + |
| 276 | barGraphFormat + |
| 277 | errorBarFormat + |
| 278 | barGraphValues + |
| 279 | wrapLegend |
| 280 | |
| 281 | # --------------------------------- |
| 282 | # Switch Up Exporting Graph to File |
| 283 | # --------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 284 | |
| 285 | print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 286 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 287 | ggsave( errBarOutputFileUp, |
| 288 | width = imageWidth, |
| 289 | height = imageHeight, |
| 290 | dpi = imageDPI ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 291 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 292 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) ) |
| 293 | |
| 294 | # ------------------------------ |
| 295 | # Switch Down Generate Main Plot |
| 296 | # ------------------------------ |
| 297 | |
| 298 | print( "Creating main plot (Switch Down Latency)." ) |
| 299 | |
| 300 | mainPlot <- ggplot( data = downAvgsData, aes( x = scale, |
| 301 | y = ms, |
| 302 | fill = type, |
| 303 | ymin = fileData[ 'down_end_to_end_avg' ], |
| 304 | ymax = fileData[ 'down_end_to_end_avg' ] + stds ) ) |
| 305 | |
| 306 | # ------------------------------------------ |
| 307 | # Switch Down Fundamental Variables Assigned |
| 308 | # ------------------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 309 | |
| 310 | print( "Generating fundamental graph data (Switch Down Latency)." ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 311 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 312 | colors <- scale_fill_manual( values=c( "#F77670", # Red |
| 313 | "#619DFA", # Blue |
| 314 | "#18BA48" ) ) # Green |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 315 | |
| 316 | title <- ggtitle( "Switch Down Latency" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 317 | |
| 318 | fundamentalGraphData <- mainPlot + |
| 319 | xScaleConfig + |
| 320 | xLabel + |
| 321 | yLabel + |
| 322 | theme + |
| 323 | title |
| 324 | |
| 325 | # --------------------------------------- |
| 326 | # Switch Down Generating Bar Graph Format |
| 327 | # --------------------------------------- |
| 328 | |
| 329 | print( "Generating bar graph with error bars (Switch Down Latency)." ) |
| 330 | barGraphFormat <- geom_bar( stat = "identity", width = barWidth ) |
| 331 | errorBarFormat <- geom_errorbar( width = barWidth, color = errorBarColor ) |
| 332 | |
| 333 | barGraphValues <- geom_text( aes( x = downAvgsData$scale, |
| 334 | y = sumOfDownAvgs + 0.04 * max( sumOfDownAvgs ), |
| 335 | label = format( sumOfDownAvgs, |
| 336 | digits = 3, |
| 337 | big.mark = ",", |
| 338 | scientific = FALSE ) ), |
| 339 | size = 7.0, |
| 340 | fontface = "bold" ) |
| 341 | |
| 342 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
| 343 | |
| 344 | result <- fundamentalGraphData + |
| 345 | barGraphFormat + |
| 346 | colors + |
| 347 | errorBarFormat + |
| 348 | barGraphValues + |
| 349 | wrapLegend |
| 350 | |
| 351 | # ----------------------------------- |
| 352 | # Switch Down Exporting Graph to File |
| 353 | # ----------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 354 | |
| 355 | print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 356 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 357 | ggsave( errBarOutputFileDown, |
| 358 | width = imageWidth, |
| 359 | height = imageHeight, |
| 360 | dpi = imageDPI ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 361 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 362 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) ) |