blob: a68b51683aa55e3a2c51fed1c78873c665122319 [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,
21# please contact Jeremy Ronquillo: jeremyr@opennetworking.org
22
23# **********************************************************
24# STEP 1: File management.
25# **********************************************************
26
27print( "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/
32print( "Reading commmand-line args." )
33args <- 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
38print( "Importing libraries." )
39library( ggplot2 )
40library( reshape2 )
41library( RPostgreSQL ) # For databases
42
43# Check if sufficient args are provided.
44if ( is.na( args[ 7 ] ) ){
45 print( "Usage: Rscript SCPFswitchLat <database-host> <database-port> <database-user-id> <database-password> <test-name> <branch-name> <directory-to-save-graphs>" )
46 q() # basically exit(), but in R
47}
48
49# Filenames for output graphs include the testname and the graph type.
50# See the examples below. paste() is used to concatenate strings.
51errBarOutputFileUp <- paste( args[ 7 ], "SCPFswitchLat_", sep = "" )
52errBarOutputFileUp <- paste( errBarOutputFileUp, args[ 6 ], sep = "" )
53errBarOutputFileUp <- paste( errBarOutputFileUp, "_UpErrBarWithStack.jpg", sep = "" )
54
55errBarOutputFileDown <- paste( args[ 7 ], "SCPFswitchLat_", sep = "" )
56errBarOutputFileDown <- paste( errBarOutputFileDown, args[ 6 ], sep = "" )
57errBarOutputFileDown <- paste( errBarOutputFileDown, "_DownErrBarWithStack.jpg", sep = "" )
58
59print( "Reading from databases." )
60
61con <- dbConnect( dbDriver( "PostgreSQL" ), dbname="onostest", host=args[ 1 ], port=strtoi( args[ 2 ] ), user=args[ 3 ],password=args[ 4 ] )
62
63command <- paste( "SELECT * FROM switch_latency_details WHERE branch = '", args[ 6 ], sep="" )
64command <- paste( command, "' AND date IN ( SELECT MAX( date ) FROM switch_latency_details WHERE branch='", sep = "")
65command <- paste( command, args[ 6 ], sep="" )
66command <- paste( command, "' )", sep="" )
67
68print( paste( "Sending SQL command:", command ) )
69
70fileData <- dbGetQuery( con, command )
71
72# **********************************************************
73# STEP 2: Organize data.
74# **********************************************************
75
76print( "Sorting data." )
77
78upAvgs <- c( fileData[ 'up_device_to_graph_avg' ], fileData[ 'role_reply_to_device_avg' ], fileData[ 'role_request_to_role_reply_avg' ], fileData[ 'feature_reply_to_role_request_avg' ], fileData[ 'tcp_to_feature_reply_avg' ] )
79upAvgsData <- melt( upAvgs )
80upAvgsData$scale <- fileData$scale
81upAvgsData$up_std <- fileData$up_std
82
83colnames( upAvgsData ) <- c( "ms", "type", "scale", "stds" )
84upAvgsData$type <- as.character( upAvgsData$type )
85upAvgsData$type <- factor( upAvgsData$type, levels=unique( upAvgsData$type ) )
86
87downAvgs <- c( fileData[ 'down_device_to_graph_avg' ], fileData[ 'ack_to_device_avg' ], fileData[ 'fin_ack_to_ack_avg' ] )
88downAvgsData <- melt( downAvgs )
89downAvgsData$scale <- fileData$scale
90downAvgsData$down_std <- fileData$down_std
91
92colnames( downAvgsData ) <- c( "ms", "type", "scale", "stds" )
93downAvgsData$type <- as.character( downAvgsData$type )
94downAvgsData$type <- factor( downAvgsData$type, levels=unique( downAvgsData$type ) )
95
96
97# **********************************************************
98# STEP 3: Generate graphs.
99# **********************************************************
100
101
102print( "Generating fundamental graph data (Switch Up Latency)." )
103width <- 1
104 if ( min( fileData[ 'up_end_to_end_avg' ] - upAvgsData$stds ) < 0 ) {
105 yMin <- min( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds ) * 1.05
106 } else {
107 yMin <- 0
108 }
109yMax <- max( fileData[ 'up_end_to_end_avg' ] + upAvgsData$stds )
110
111mainPlot <- ggplot( data = upAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'up_end_to_end_avg' ] - stds, ymax = fileData[ 'up_end_to_end_avg' ] + stds ) )
112xScaleConfig <- scale_x_continuous( breaks=c( 1, 3, 5, 7, 9) )
113yLimit <- ylim( yMin, yMax )
114xLabel <- xlab( "Scale" )
115yLabel <- ylab( "Latency (ms)" )
116fillLabel <- labs( fill="Type" )
117theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
118
119fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
120
121print( "Generating bar graph with error bars (Switch Up Latency)." )
122barGraphFormat <- geom_bar( stat="identity", width = width )
123errorBarFormat <- geom_errorbar( width = width )
124
125title <- ggtitle( "Switch Up Latency" )
126result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
127
128
129print( paste( "Saving bar chart with error bars (Switch Up Latency) to", errBarOutputFileUp ) )
130ggsave( errBarOutputFileUp, width = 10, height = 6, dpi = 200 )
131
132
133print( paste( "Successfully wrote bar chart with error bars (Switch Up Latency) out to", errBarOutputFileUp ) )
134
135
136print( "Generating fundamental graph data (Switch Down Latency)." )
137 if ( min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds ) < 0 ) {
138 yMin <- min( fileData[ 'down_end_to_end_avg' ] - downAvgsData$stds )
139 } else {
140 yMin <- 0
141 }
142 yMax <- max( fileData[ 'down_end_to_end_avg' ] + downAvgsData$stds )
143
144mainPlot <- ggplot( data = downAvgsData, aes( x = scale, y = ms, fill = type, ymin = fileData[ 'down_end_to_end_avg' ] - stds, ymax = fileData[ 'down_end_to_end_avg' ] + stds ) )
145yLimit <- ylim( yMin, yMax )
146theme <- theme( plot.title=element_text( hjust = 0.5, size = 18, face='bold' ) )
147
148fundamentalGraphData <- mainPlot + yLimit + xScaleConfig + xLabel + yLabel + fillLabel + theme
149
150print( "Generating bar graph with error bars (Switch Down Latency)." )
151barGraphFormat <- geom_bar( stat="identity", width = width )
152errorBarFormat <- geom_errorbar( width = width )
153
154title <- ggtitle( "Switch Down Latency" )
155result <- fundamentalGraphData + barGraphFormat + errorBarFormat + title
156
157
158print( paste( "Saving bar chart with error bars (Switch Down Latency) to", errBarOutputFileDown ) )
159ggsave( errBarOutputFileDown, width = 10, height = 6, dpi = 200 )
160
161
162print( paste( "Successfully wrote bar chart with error bars (Switch Down Latency) out to", errBarOutputFileDown ) )