Experiment1.R 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/Exp1*-0.sca", "results/Exp1*-0.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. moduleToSLA <- function(module) {
  32. if (grepl("\\.H1\\.", module) || grepl("\\.H5\\.", module))
  33. "SLA1"
  34. else if (grepl("\\.H2\\.", module) || grepl("\\.H6\\.", module))
  35. "SLA2"
  36. else if (grepl("\\.H3\\.", module) || grepl("\\.H7\\.", module))
  37. "SLA3"
  38. else if (grepl("\\.H4\\.", module) || grepl("\\.H8\\.", module))
  39. "SLA4"
  40. else
  41. NA_character_
  42. }
  43. scalars <- transform(scalars, SLA=sapply(module, moduleToSLA))
  44. vectors <- transform(vectors, SLA=sapply(module, moduleToSLA))
  45. computePkLoss <- function(appType) { # 0 = voice, 1 = video
  46. senderModules <- paste('H[1-4].*udpApp\\[',appType,'\\]', sep='')
  47. receiverModules <- paste('H[5-8].*udpApp\\[',appType,'\\]', sep='')
  48. d <- cast(scalars, config+SLA~name, value='value',
  49. subset= ((grepl(senderModules, module) & name=='sentPk:count') |
  50. (grepl(receiverModules, module) & name=='rcvdPk:count')))
  51. transform(d, loss=(`sentPk:count`-`rcvdPk:count`)/`sentPk:count`)
  52. }
  53. # voice loss
  54. voicePkLoss <- computePkLoss(0)
  55. voicePkLoss.plot <- ggplot(voicePkLoss, aes(x=config, y=loss, fill=SLA)) +
  56. geom_bar(position='dodge') +
  57. opts(title='Exp 1 Loss Average (voice)')
  58. # video loss
  59. videoPkLoss <- computePkLoss(1)
  60. videoPkLoss.plot <- ggplot(videoPkLoss, aes(x=config, y=loss, fill=SLA)) +
  61. geom_bar(position='dodge') +
  62. opts(title='Exp 1 Loss Average (video)')
  63. # voice delay
  64. voiceDelay <- subset(vectors, grepl('H[5-8].*udpApp\\[0\\]', module) & name=='endToEndDelay:vector')
  65. voiceDelay <- transform(voiceDelay, medianDelay=sapply(resultkey, medianOfVector))
  66. voiceDelay.plot <- ggplot(voiceDelay, aes(x=config, y=medianDelay, fill=SLA)) +
  67. geom_bar(position='dodge') +
  68. opts(title="Exp 1 Delay Median (voice)")
  69. # video delay
  70. videoDelay <- subset(vectors, grepl('H[5-8].*udpApp\\[1\\]', module) & name=='endToEndDelay:vector')
  71. videoDelay <- transform(videoDelay, medianDelay=sapply(resultkey, medianOfVector))
  72. videoDelay.plot <- ggplot(videoDelay, aes(x=config, y=medianDelay, fill=SLA)) +
  73. geom_bar(position='dodge') +
  74. opts(title="Exp 1 Delay Median (video)")
  75. #
  76. # Part 2: displaying R2 queue statistics
  77. #
  78. modulesToDscps <- function(modules) {
  79. sub('.*\\.(.*?)x?Queue', '\\U\\1', modules, perl=TRUE)
  80. }
  81. queueScalars <- subset(scalars, grepl('R2.*ppp\\[2\\].*Queue', module) & config!='Exp17')
  82. queueScalars <- transform(queueScalars, dscp=modulesToDscps(module))
  83. queueScalars <- subset(queueScalars, dscp!='BE')
  84. queueVectors <- subset(vectors, grepl('R2.*ppp\\[2\\].*Queue', module) & config!='Exp17')
  85. queueVectors <- transform(queueVectors, dscp=modulesToDscps(module))
  86. queueVectors <- subset(queueVectors, dscp!='BE')
  87. # R2.ppp[2] queue packet loss
  88. queuePkLoss <- cast(queueScalars, config+dscp~name, value='value',
  89. subset=(name=='rcvdPk:count' | name=='dropPk:count'))
  90. queuePkLoss <- transform(queuePkLoss, loss=`dropPk:count`/`rcvdPk:count`)
  91. queuePkLoss.plot <- ggplot(queuePkLoss, aes(x=config, y=loss, fill=dscp)) +
  92. geom_bar(position='dodge') +
  93. opts(title='Exp 1 R2 Queue Packet Loss')
  94. # R2.ppp[2] queue delay
  95. queueDelay <- subset(queueVectors, name=='queueingTime:vector')
  96. queueDelay <- transform(queueDelay, delay=sapply(resultkey, medianOfVector))
  97. queueDelay.plot <- ggplot(queueDelay, aes(x=config, y=delay, fill=dscp)) +
  98. geom_bar(position='dodge') +
  99. opts(title='Exp 1 R2 Queue Delay')
  100. # R2.ppp[2] queue length
  101. queueLength <- subset(queueScalars,
  102. name=='queueLength:timeavg',
  103. c('config', 'dscp', 'value'))
  104. queueLength.plot <- ggplot(queueLength, aes(x=config, y=value, fill=dscp)) +
  105. geom_bar(position='dodge') +
  106. opts(title='Exp 1 R2 - Average Queue Length')
  107. plotAll <- function() {
  108. plot <- function(p) {
  109. if (names(dev.cur())!='RStudioGD')
  110. dev.new()
  111. print(p)
  112. }
  113. plot(voicePkLoss.plot)
  114. plot(videoPkLoss.plot)
  115. plot(voiceDelay.plot)
  116. plot(videoDelay.plot)
  117. plot(queuePkLoss.plot)
  118. plot(queueDelay.plot)
  119. plot(queueLength.plot)
  120. }