Experiment2.R 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/Exp2*-*.sca", "results/Exp2*-*.vec"))
  21. configs <- with(subset(dataset$runattrs, attrname=="configname"),
  22. data.frame(runid=runid,
  23. config=as.character(attrvalue),
  24. stringsAsFactors=FALSE))
  25. iaTime <- cast(dataset$scalars, runid~name, value='value', subset=name=='iaTime')
  26. iaTime <- transform(iaTime, load=4000/iaTime)
  27. runattrs <- merge(configs, iaTime)
  28. scalars <- merge(dataset$scalars, runattrs, by="runid")
  29. vectors <- merge(dataset$vectors, runattrs, by="runid")
  30. moduleToSLA <- function(module) {
  31. if (grepl("\\.H1\\.", module) || grepl("\\.H5\\.", module))
  32. "SLA1"
  33. else if (grepl("\\.H2\\.", module) || grepl("\\.H6\\.", module))
  34. "SLA2"
  35. else if (grepl("\\.H3\\.", module) || grepl("\\.H7\\.", module))
  36. "SLA3"
  37. else
  38. NA_character_
  39. }
  40. scalars <- transform(scalars, SLA=sapply(module, moduleToSLA))
  41. vectors <- transform(vectors, SLA=sapply(module, moduleToSLA))
  42. # voice loss
  43. voicePkLoss = cast(scalars, config+load+SLA~name, value='value',
  44. subset= ((grepl('H[1-3].*udpApp\\[0\\]', module) & name=='sentPk:count') |
  45. (grepl('H[5-7].*udpApp\\[0\\]', module) & name=='rcvdPk:count')))
  46. voicePkLoss <- transform(voicePkLoss,
  47. loss=(`sentPk:count`-`rcvdPk:count`)/`sentPk:count`)
  48. pkLossPlot <- function(data, title) {
  49. ggplot(data, aes(x=load, y=loss, colour=SLA)) +
  50. geom_line() +
  51. scale_colour_manual(values=c('SLA1'='green','SLA2'='yellow','SLA3'='red')) +
  52. facet_wrap(~config) +
  53. opts(title=title)
  54. }
  55. voicePkLoss.plot <- pkLossPlot(voicePkLoss, 'Exp 2 Increasing Traffic Load (voice)')
  56. # video loss
  57. videoPkLoss <- cast(scalars, config+load+SLA~name, value='value',
  58. subset= ((grepl('H[1-3].*udpApp\\[1\\]', module) & name=='sentPk:count') |
  59. (grepl('H[5-7].*udpApp\\[1\\]', module) & name=='rcvdPk:count')))
  60. videoPkLoss <- transform(videoPkLoss,
  61. loss=(`sentPk:count`-`rcvdPk:count`)/`sentPk:count`)
  62. videoPkLoss.plot <- pkLossPlot(videoPkLoss, 'Exp 2 Increasing Traffic Load (video)')
  63. # voice loss per color
  64. voicePkLossPerColor.plot <- ggplot(subset(voicePkLoss, config!='Exp24'), aes(x=load,y=loss,colour=config)) +
  65. geom_line() +
  66. scale_colour_manual(values=c('Exp21'='green','Exp22'='yellow','Exp23'='red')) +
  67. facet_wrap(~SLA) +
  68. opts(title='Comparison of green/yellow/red traffic (voice)')
  69. # average length of R2.ppp[2] queue
  70. queueLength <- cast(scalars, config+load~name, value='value',
  71. subset= (grepl('R2\\.ppp\\[2\\]', module) & name=='queueLength:timeavg'))
  72. queueLength.plot <- ggplot(queueLength,
  73. aes(x=load, y=`queueLength:timeavg`, colour=config)) +
  74. geom_line() +
  75. scale_colour_manual(values=c('Exp21'='green','Exp22'='yellow','Exp23'='red')) +
  76. opts(title='Exp 2 R2 Queue - Average Queue Length') +
  77. ylab('Average queue length')
  78. plotAll <- function() {
  79. plot <- function(p) {
  80. if (names(dev.cur())!='RStudioGD')
  81. dev.new()
  82. print(p)
  83. }
  84. plot(voicePkLoss.plot)
  85. plot(videoPkLoss.plot)
  86. plot(voicePkLossPerColor.plot)
  87. plot(queueLength.plot)
  88. }