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 | # ********************************************************** |
| 24 | # STEP 1: File management. |
| 25 | # ********************************************************** |
| 26 | |
| 27 | print( "STEP 1: File management." ) |
| 28 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 29 | print( "Reading commmand-line args." ) |
| 30 | args <- 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 |
| 35 | print( "Importing libraries." ) |
| 36 | library( ggplot2 ) |
| 37 | library( reshape2 ) |
| 38 | library( RPostgreSQL ) # For databases |
| 39 | |
| 40 | # Normal usage |
| 41 | # Check if sufficient args are provided. |
| 42 | if ( 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 Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 47 | # paste() is used to concatenate strings. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 48 | outputFile <- paste( args[ 8 ], args[ 6 ], sep="" ) |
| 49 | if ( args[ 1 ] == "y" ){ |
| 50 | outputFile <- paste( outputFile, "flowObj", sep="_" ) |
| 51 | } |
| 52 | outputFile <- paste( outputFile, args[ 7 ], sep="_" ) |
| 53 | outputFile <- paste( outputFile, "_errGraph.jpg", sep="" ) |
| 54 | |
| 55 | print( "Reading from databases." ) |
| 56 | |
| 57 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] ) |
| 58 | |
| 59 | command <- "SELECT * FROM max_intents_" |
| 60 | if ( args[ 1 ] == "y" ){ |
| 61 | command <- paste( command, "fobj_", sep="" ) |
| 62 | } |
| 63 | command <- paste( command, "tests WHERE branch = '", sep = "" ) |
| 64 | command <- paste( command, args[ 7 ], sep="" ) |
| 65 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM max_intents_", sep="" ) |
| 66 | if ( args[ 1 ] == "y" ){ |
| 67 | command <- paste( command, "fobj_", sep="" ) |
| 68 | } |
| 69 | command <- paste( command, "tests WHERE branch = '", sep = "" ) |
| 70 | command <- paste( command, args[ 7 ], sep = "" ) |
| 71 | command <- paste( command, "' ) ", sep="" ) |
| 72 | |
| 73 | print( paste( "Sending SQL command:", command ) ) |
| 74 | |
| 75 | fileData <- dbGetQuery( con, command ) |
| 76 | |
| 77 | if ( args[ 1 ] == "y" ){ |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 78 | chartTitle <- "Number of Installed Intents & Flows\n with Flow Objectives" |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | } else { |
| 80 | chartTitle <- "Number of Installed Intents & Flows" |
| 81 | } |
| 82 | |
| 83 | # ********************************************************** |
| 84 | # STEP 2: Organize data. |
| 85 | # ********************************************************** |
| 86 | |
| 87 | fileDataNames <- names( fileData ) |
| 88 | |
| 89 | avgs <- c() |
| 90 | |
| 91 | print( "Sorting data." ) |
| 92 | avgs <- c( fileData[ 'max_intents_ovs' ], fileData[ 'max_flows_ovs' ] ) |
| 93 | |
| 94 | dataFrame <- melt( avgs ) |
| 95 | dataFrame$scale <- fileData$scale |
| 96 | |
| 97 | colnames( dataFrame ) <- c( "ms", "type", "scale" ) |
| 98 | |
| 99 | dataFrame$type <- as.character( dataFrame$type ) |
| 100 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 101 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 102 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
| 103 | |
| 104 | print( "Data Frame Results:" ) |
| 105 | print( dataFrame ) |
| 106 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 107 | # ********************************************************** |
| 108 | # STEP 3: Generate graphs. |
| 109 | # ********************************************************** |
| 110 | |
| 111 | print( "Generating fundamental graph data." ) |
| 112 | |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 113 | theme_set( theme_grey( base_size = 22 ) ) # set the default text size of the graph. |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 114 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 115 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, fill = type ) ) |
| 116 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
| 117 | xLabel <- xlab( "Scale" ) |
| 118 | yLabel <- ylab( "Max Number of Intents/Flow Rules" ) |
| 119 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 120 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), legend.position="bottom", legend.text=element_text( size=22 ), legend.title = element_blank(), legend.key.size = unit( 1.5, 'lines' ) ) |
| 121 | colors <- scale_fill_manual( values=c( "#F77670", "#619DFA" ) ) |
| 122 | wrapLegend <- guides( fill=guide_legend( nrow=1, byrow=TRUE ) ) |
| 123 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme + wrapLegend |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 124 | |
| 125 | |
| 126 | print( "Generating bar graph bars." ) |
| 127 | width <- 1.3 |
| 128 | barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 129 | values <- geom_text( aes( x=dataFrame$scale, y=dataFrame$ms + 0.015 * max( dataFrame$ms ), label = format( dataFrame$ms, digits=3, big.mark = ",", scientific = FALSE ) ), size = 5.2, fontface = "bold", position=position_dodge( width=1.25 ) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 130 | title <- ggtitle( chartTitle ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 131 | result <- fundamentalGraphData + barGraphFormat + colors + title + values |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 132 | |
| 133 | |
| 134 | print( paste( "Saving bar chart to", outputFile ) ) |
Jeremy Ronquillo | 0e27b91 | 2017-10-21 14:34:24 -0700 | [diff] [blame] | 135 | ggsave( outputFile, width = 15, height = 10, dpi = 200 ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 136 | |
| 137 | print( paste( "Successfully wrote bar chart out to", outputFile ) ) |