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, |
| 21 | # please contact Jeremy Ronquillo: jeremyr@opennetworking.org |
| 22 | |
| 23 | # ********************************************************** |
| 24 | # STEP 1: File management. |
| 25 | # ********************************************************** |
| 26 | |
| 27 | print( "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/ |
| 32 | print( "Reading commmand-line args." ) |
| 33 | args <- 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 |
| 38 | print( "Importing libraries." ) |
| 39 | library( ggplot2 ) |
| 40 | library( reshape2 ) |
| 41 | library( RPostgreSQL ) # For databases |
| 42 | |
| 43 | # Normal usage |
| 44 | # Check if sufficient args are provided. |
| 45 | if ( 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 | |
| 53 | outputFile <- paste( args[ 8 ], args[ 6 ], sep="" ) |
| 54 | if ( args[ 1 ] == "y" ){ |
| 55 | outputFile <- paste( outputFile, "flowObj", sep="_" ) |
| 56 | } |
| 57 | outputFile <- paste( outputFile, args[ 7 ], sep="_" ) |
| 58 | outputFile <- paste( outputFile, "_errGraph.jpg", sep="" ) |
| 59 | |
| 60 | print( "Reading from databases." ) |
| 61 | |
| 62 | con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 2 ], port=strtoi( args[ 3 ] ), user=args[ 4 ],password=args[ 5 ] ) |
| 63 | |
| 64 | command <- "SELECT * FROM max_intents_" |
| 65 | if ( args[ 1 ] == "y" ){ |
| 66 | command <- paste( command, "fobj_", sep="" ) |
| 67 | } |
| 68 | command <- paste( command, "tests WHERE branch = '", sep = "" ) |
| 69 | command <- paste( command, args[ 7 ], sep="" ) |
| 70 | command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM max_intents_", sep="" ) |
| 71 | if ( args[ 1 ] == "y" ){ |
| 72 | command <- paste( command, "fobj_", sep="" ) |
| 73 | } |
| 74 | command <- paste( command, "tests WHERE branch = '", sep = "" ) |
| 75 | command <- paste( command, args[ 7 ], sep = "" ) |
| 76 | command <- paste( command, "' ) ", sep="" ) |
| 77 | |
| 78 | print( paste( "Sending SQL command:", command ) ) |
| 79 | |
| 80 | fileData <- dbGetQuery( con, command ) |
| 81 | |
| 82 | if ( 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 | |
| 92 | fileDataNames <- names( fileData ) |
| 93 | |
| 94 | avgs <- c() |
| 95 | |
| 96 | print( "Sorting data." ) |
| 97 | avgs <- c( fileData[ 'max_intents_ovs' ], fileData[ 'max_flows_ovs' ] ) |
| 98 | |
| 99 | dataFrame <- melt( avgs ) |
| 100 | dataFrame$scale <- fileData$scale |
| 101 | |
| 102 | colnames( dataFrame ) <- c( "ms", "type", "scale" ) |
| 103 | |
| 104 | dataFrame$type <- as.character( dataFrame$type ) |
| 105 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 106 | |
| 107 | # ********************************************************** |
| 108 | # STEP 3: Generate graphs. |
| 109 | # ********************************************************** |
| 110 | |
| 111 | print( "Generating fundamental graph data." ) |
| 112 | |
| 113 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, y = ms, fill = type ) ) |
| 114 | xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) ) |
| 115 | xLabel <- xlab( "Scale" ) |
| 116 | yLabel <- ylab( "Max Number of Intents/Flow Rules" ) |
| 117 | fillLabel <- labs( fill="Type" ) |
| 118 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) ) |
| 119 | |
| 120 | fundamentalGraphData <- mainPlot + xScaleConfig + xLabel + yLabel + fillLabel + theme |
| 121 | |
| 122 | |
| 123 | print( "Generating bar graph bars." ) |
| 124 | width <- 1.3 |
| 125 | barGraphFormat <- geom_bar( stat="identity", position=position_dodge( ), width = width ) |
| 126 | title <- ggtitle( chartTitle ) |
| 127 | result <- fundamentalGraphData + barGraphFormat + title |
| 128 | |
| 129 | |
| 130 | print( paste( "Saving bar chart to", outputFile ) ) |
| 131 | ggsave( outputFile, width = 10, height = 6, dpi = 200 ) |
| 132 | |
| 133 | print( paste( "Successfully wrote bar chart out to", outputFile ) ) |