Experiment5.R 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #
  2. # Copyright (C) 2012 Opensim Ltd.
  3. # Author: Tamas Borbely
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. #
  18. require(omnetpp)
  19. require(ggplot2)
  20. dataset <- loadDataset(c("results/Exp5*-*.sca", "results/Exp5*-*.vec"))
  21. configs <- with(subset(dataset$runattrs, attrname=="configname"),
  22. data.frame(runid=runid,
  23. config=as.character(attrvalue),
  24. stringsAsFactors=FALSE))
  25. scalars <- merge(dataset$scalars, configs, by="runid")
  26. vectors <- merge(dataset$vectors, configs, by="runid")
  27. medianOfVector <- function(vectorkey) {
  28. d <- loadVectors(dataset, vectorkey)
  29. median(d$vectordata$y)
  30. }
  31. averageReplications <- function(data, formula, value) {
  32. as.data.frame(rename(cast(data, formula, mean, value=value), c('(all)' = value)))
  33. }
  34. moduleToHost <- function(module) {
  35. if (grepl("\\.H1\\.", module) || grepl("\\.H5\\.", module))
  36. "Host 1"
  37. else if (grepl("\\.H2\\.", module) || grepl("\\.H6\\.", module))
  38. "Host 2"
  39. else if (grepl("\\.H3\\.", module) || grepl("\\.H7\\.", module))
  40. "Host 3"
  41. else if (grepl("\\.H4\\.", module) || grepl("\\.H8\\.", module))
  42. "Host 4"
  43. else
  44. NA_character_
  45. }
  46. moduleToApp <- function(module) {
  47. if (grepl("\\.H.\\.udpApp\\[0\\]", module))
  48. "voice"
  49. else if (grepl("\\.H.\\.udpApp\\[1\\]", module))
  50. "video"
  51. else
  52. NA_character_
  53. }
  54. scalars <- transform(scalars, host=sapply(module, moduleToHost), app=sapply(module, moduleToApp))
  55. vectors <- transform(vectors, host=sapply(module, moduleToHost), app=sapply(module, moduleToApp))
  56. # loss average
  57. pkLoss <- cast(scalars, runid+config+app+host~name, value='value',
  58. subset= ((grepl('H[1-4].*udpApp', module) & name=='sentPk:count') |
  59. (grepl('H[5-8].*udpApp', module) & name=='rcvdPk:count')))
  60. pkLoss <- transform(pkLoss, loss=(`sentPk:count`-`rcvdPk:count`)/`sentPk:count`, configapp=paste(config,app))
  61. pkLoss <- averageReplications(pkLoss, configapp+host~., value='loss')
  62. pkLoss.plot <- ggplot(pkLoss, aes(x=configapp, y=loss, fill=host)) +
  63. geom_bar(position='dodge') +
  64. opts(title='Exp 5 Loss Average (voice and video)')
  65. # delay 50th percentile
  66. endToEndDelay <- subset(vectors, grepl('H[5-8].*udpApp\\[.\\]', module) & name=='endToEndDelay:vector')
  67. endToEndDelay <- transform(endToEndDelay, delay=sapply(resultkey, medianOfVector), configapp=paste(config,app))
  68. endToEndDelay <- averageReplications(endToEndDelay, configapp+host~., value='delay')
  69. endToEndDelay.plot <- ggplot(endToEndDelay, aes(x=configapp, y=delay, fill=host)) +
  70. geom_bar(position='dodge') +
  71. opts(title='Exp 5 Median Delay (voice and video)')
  72. #
  73. # R2 queue statistics
  74. #
  75. modulesToDscps <- function(modules) {
  76. sub('.*\\.(.*?)x?Queue', '\\U\\1', modules, perl=TRUE)
  77. }
  78. queueScalars <- subset(scalars, grepl('R2.*ppp\\[2\\].*(af1x|af2x|ef)Queue', module) & config=='Exp51')
  79. queueScalars <- transform(queueScalars, dscp=modulesToDscps(module))
  80. queueVectors <- subset(vectors, grepl('R2.*ppp\\[2\\].*(af1x|af2x|ef)Queue', module) & config=='Exp51')
  81. queueVectors <- transform(queueVectors, dscp=modulesToDscps(module))
  82. # R2.ppp[2] queue packet loss
  83. queuePkLoss <- cast(queueScalars, runid+config+dscp~name, value='value',
  84. subset=(name=='rcvdPk:count' | name=='dropPk:count'))
  85. queuePkLoss <- transform(queuePkLoss, loss=`dropPk:count`/`rcvdPk:count`)
  86. queuePkLoss <- averageReplications(queuePkLoss, config+dscp~., value='loss')
  87. queuePkLoss.plot <- ggplot(queuePkLoss, aes(x=dscp, y=loss, fill=config)) +
  88. geom_bar(position='dodge') +
  89. opts(title='Exp5.1 R2 Queue - Packet Loss')
  90. # R2.ppp[2] queue delay
  91. queueDelay <- subset(queueVectors, name=='queueingTime:vector')
  92. queueDelay <- transform(queueDelay, delay=sapply(resultkey, medianOfVector))
  93. queueDelay <- averageReplications(queueDelay, config+dscp~., value='delay')
  94. queueDelay.plot <- ggplot(queueDelay, aes(x=dscp, y=delay, fill=config)) +
  95. geom_bar(position='dodge') +
  96. opts(title='Exp5.1 R2 Queue - Median Queueing Delay')
  97. # R2.ppp[2] queue length
  98. queueLength <- subset(queueScalars,
  99. name=='queueLength:timeavg',
  100. c('config', 'dscp', 'value'))
  101. queueLength <- rename(averageReplications(queueLength, config+dscp~., value='value'), c('value'='queue length'))
  102. queueLength.plot <- ggplot(queueLength, aes(x=dscp, y=`queue length`, fill=config)) +
  103. geom_bar(position='dodge') +
  104. opts(title='Exp5.1 R2 Queue - Average Queue Length')
  105. plotAll <- function() {
  106. plot <- function(p) {
  107. if (names(dev.cur())!='RStudioGD')
  108. dev.new()
  109. print(p)
  110. }
  111. plot(pkLoss.plot)
  112. plot(endToEndDelay.plot)
  113. plot(queuePkLoss.plot)
  114. plot(queueDelay.plot)
  115. plot(queueLength.plot)
  116. }