Stats module and example merged in.
authortjkopena@cs.drexel.edu
Fri Aug 29 13:22:09 2008 -0400 (17 months ago)
changeset 358944b0bc6817c6
parent 3586 728eb3f583b3
child 3590 05f0716c9c36
Stats module and example merged in.
examples/stats/README
examples/stats/data.db
examples/stats/wifi-default.data
examples/stats/wifi-default.eps
examples/stats/wifi-example-apps.cc
examples/stats/wifi-example-apps.h
examples/stats/wifi-example-db.sh
examples/stats/wifi-example-sim.cc
examples/stats/wifi-example.gnuplot
examples/stats/wscript
examples/wscript
src/contrib/stats/basic-data-calculators.h
src/contrib/stats/data-calculator.cc
src/contrib/stats/data-calculator.h
src/contrib/stats/data-collector.cc
src/contrib/stats/data-collector.h
src/contrib/stats/data-output-interface.cc
src/contrib/stats/data-output-interface.h
src/contrib/stats/omnet-data-output.cc
src/contrib/stats/omnet-data-output.h
src/contrib/stats/packet-data-calculators.cc
src/contrib/stats/packet-data-calculators.h
src/contrib/stats/sqlite-data-output.cc
src/contrib/stats/sqlite-data-output.h
src/contrib/stats/time-data-calculators.cc
src/contrib/stats/time-data-calculators.h
src/contrib/stats/wscript
src/contrib/wscript
src/wscript
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/stats/README	Fri Aug 29 13:22:09 2008 -0400
     1.3 @@ -0,0 +1,16 @@
     1.4 +
     1.5 +			  ns-3 stats example
     1.6 +
     1.7 +The example script wifi-example-db.sh in this directly will run
     1.8 +through the entire process of running a simple experiment.  It assumes
     1.9 +sqlite3 is installed as it uses the sqlite3 data output format of the
    1.10 +statistics package.  It also assumes it is being run from the
    1.11 +examples/stats/ subdirectory of the ns-3 package, together with its
    1.12 +gnuplot script.  When the script completes successfully, a graph will
    1.13 +be have been produced in examples/stats/wifi-default.eps demonstrating
    1.14 +output from this example.
    1.15 +
    1.16 +More information on the statistics package and this example is
    1.17 +available online on the ns-3 wiki at:
    1.18 +
    1.19 +http://www.nsnam.org/wiki/index.php/Statistical_Framework_for_Network_Simulation
     2.1 Binary file examples/stats/data.db has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/examples/stats/wifi-default.data	Fri Aug 29 13:22:09 2008 -0400
     3.3 @@ -0,0 +1,20 @@
     3.4 +25   0.0
     3.5 +50   0.0
     3.6 +75   0.0
     3.7 +100   0.0
     3.8 +125   0.0
     3.9 +145   3.6
    3.10 +147   6.8
    3.11 +150   5.0
    3.12 +152   12.6
    3.13 +155   20.4
    3.14 +157   31.6
    3.15 +160   46.4
    3.16 +162   58.8
    3.17 +165   71.6
    3.18 +167   81.0
    3.19 +170   96.4
    3.20 +172   99.4
    3.21 +175   100.0
    3.22 +177   100.0
    3.23 +180   99.4
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/examples/stats/wifi-default.eps	Fri Aug 29 13:22:09 2008 -0400
     4.3 @@ -0,0 +1,643 @@
     4.4 +%!PS-Adobe-2.0
     4.5 +%%Title: wifi-default.eps
     4.6 +%%Creator: gnuplot 4.2 patchlevel 0
     4.7 +%%CreationDate: Fri Aug 29 13:16:08 2008
     4.8 +%%DocumentFonts: (atend)
     4.9 +%%BoundingBox: 50 50 554 525
    4.10 +%%Orientation: Portrait
    4.11 +%%Pages: (atend)
    4.12 +%%EndComments
    4.13 +%%BeginProlog
    4.14 +/gnudict 256 dict def
    4.15 +gnudict begin
    4.16 +%
    4.17 +% The following 6 true/false flags may be edited by hand if required
    4.18 +% The unit line width may also be changed
    4.19 +%
    4.20 +/Color false def
    4.21 +/Blacktext false def
    4.22 +/Solid false def
    4.23 +/Dashlength 1 def
    4.24 +/Landscape false def
    4.25 +/Level1 false def
    4.26 +/Rounded false def
    4.27 +/TransparentPatterns false def
    4.28 +/gnulinewidth 10.000 def
    4.29 +/userlinewidth gnulinewidth def
    4.30 +%
    4.31 +/vshift -46 def
    4.32 +/dl1 {
    4.33 +  10.0 Dashlength mul mul
    4.34 +  Rounded { currentlinewidth 0.75 mul sub dup 0 le { pop 0.01 } if } if
    4.35 +} def
    4.36 +/dl2 {
    4.37 +  10.0 Dashlength mul mul
    4.38 +  Rounded { currentlinewidth 0.75 mul add } if
    4.39 +} def
    4.40 +/hpt_ 31.5 def
    4.41 +/vpt_ 31.5 def
    4.42 +/hpt hpt_ def
    4.43 +/vpt vpt_ def
    4.44 +Level1 {} {
    4.45 +/SDict 10 dict def
    4.46 +systemdict /pdfmark known not {
    4.47 +  userdict /pdfmark systemdict /cleartomark get put
    4.48 +} if
    4.49 +SDict begin [
    4.50 +  /Title (wifi-default.eps)
    4.51 +  /Subject (gnuplot plot)
    4.52 +  /Creator (gnuplot 4.2 patchlevel 0)
    4.53 +  /Author (Joe Kopena,,,,)
    4.54 +%  /Producer (gnuplot)
    4.55 +%  /Keywords ()
    4.56 +  /CreationDate (Fri Aug 29 13:16:08 2008)
    4.57 +  /DOCINFO pdfmark
    4.58 +end
    4.59 +} ifelse
    4.60 +%
    4.61 +% Gnuplot Prolog Version 4.2 (August 2006)
    4.62 +%
    4.63 +/M {moveto} bind def
    4.64 +/L {lineto} bind def
    4.65 +/R {rmoveto} bind def
    4.66 +/V {rlineto} bind def
    4.67 +/N {newpath moveto} bind def
    4.68 +/Z {closepath} bind def
    4.69 +/C {setrgbcolor} bind def
    4.70 +/f {rlineto fill} bind def
    4.71 +/vpt2 vpt 2 mul def
    4.72 +/hpt2 hpt 2 mul def
    4.73 +/Lshow {currentpoint stroke M 0 vshift R 
    4.74 +	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
    4.75 +/Rshow {currentpoint stroke M dup stringwidth pop neg vshift R
    4.76 +	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
    4.77 +/Cshow {currentpoint stroke M dup stringwidth pop -2 div vshift R 
    4.78 +	Blacktext {gsave 0 setgray show grestore} {show} ifelse} def
    4.79 +/UP {dup vpt_ mul /vpt exch def hpt_ mul /hpt exch def
    4.80 +  /hpt2 hpt 2 mul def /vpt2 vpt 2 mul def} def
    4.81 +/DL {Color {setrgbcolor Solid {pop []} if 0 setdash}
    4.82 + {pop pop pop 0 setgray Solid {pop []} if 0 setdash} ifelse} def
    4.83 +/BL {stroke userlinewidth 2 mul setlinewidth
    4.84 +	Rounded {1 setlinejoin 1 setlinecap} if} def
    4.85 +/AL {stroke userlinewidth 2 div setlinewidth
    4.86 +	Rounded {1 setlinejoin 1 setlinecap} if} def
    4.87 +/UL {dup gnulinewidth mul /userlinewidth exch def
    4.88 +	dup 1 lt {pop 1} if 10 mul /udl exch def} def
    4.89 +/PL {stroke userlinewidth setlinewidth
    4.90 +	Rounded {1 setlinejoin 1 setlinecap} if} def
    4.91 +% Default Line colors
    4.92 +/LCw {1 1 1} def
    4.93 +/LCb {0 0 0} def
    4.94 +/LCa {0 0 0} def
    4.95 +/LC0 {1 0 0} def
    4.96 +/LC1 {0 1 0} def
    4.97 +/LC2 {0 0 1} def
    4.98 +/LC3 {1 0 1} def
    4.99 +/LC4 {0 1 1} def
   4.100 +/LC5 {1 1 0} def
   4.101 +/LC6 {0 0 0} def
   4.102 +/LC7 {1 0.3 0} def
   4.103 +/LC8 {0.5 0.5 0.5} def
   4.104 +% Default Line Types
   4.105 +/LTw {PL [] 1 setgray} def
   4.106 +/LTb {BL [] LCb DL} def
   4.107 +/LTa {AL [1 udl mul 2 udl mul] 0 setdash LCa setrgbcolor} def
   4.108 +/LT0 {PL [] LC0 DL} def
   4.109 +/LT1 {PL [4 dl1 2 dl2] LC1 DL} def
   4.110 +/LT2 {PL [2 dl1 3 dl2] LC2 DL} def
   4.111 +/LT3 {PL [1 dl1 1.5 dl2] LC3 DL} def
   4.112 +/LT4 {PL [6 dl1 2 dl2 1 dl1 2 dl2] LC4 DL} def
   4.113 +/LT5 {PL [3 dl1 3 dl2 1 dl1 3 dl2] LC5 DL} def
   4.114 +/LT6 {PL [2 dl1 2 dl2 2 dl1 6 dl2] LC6 DL} def
   4.115 +/LT7 {PL [1 dl1 2 dl2 6 dl1 2 dl2 1 dl1 2 dl2] LC7 DL} def
   4.116 +/LT8 {PL [2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 2 dl2 2 dl1 4 dl2] LC8 DL} def
   4.117 +/Pnt {stroke [] 0 setdash gsave 1 setlinecap M 0 0 V stroke grestore} def
   4.118 +/Dia {stroke [] 0 setdash 2 copy vpt add M
   4.119 +  hpt neg vpt neg V hpt vpt neg V
   4.120 +  hpt vpt V hpt neg vpt V closepath stroke
   4.121 +  Pnt} def
   4.122 +/Pls {stroke [] 0 setdash vpt sub M 0 vpt2 V
   4.123 +  currentpoint stroke M
   4.124 +  hpt neg vpt neg R hpt2 0 V stroke
   4.125 + } def
   4.126 +/Box {stroke [] 0 setdash 2 copy exch hpt sub exch vpt add M
   4.127 +  0 vpt2 neg V hpt2 0 V 0 vpt2 V
   4.128 +  hpt2 neg 0 V closepath stroke
   4.129 +  Pnt} def
   4.130 +/Crs {stroke [] 0 setdash exch hpt sub exch vpt add M
   4.131 +  hpt2 vpt2 neg V currentpoint stroke M
   4.132 +  hpt2 neg 0 R hpt2 vpt2 V stroke} def
   4.133 +/TriU {stroke [] 0 setdash 2 copy vpt 1.12 mul add M
   4.134 +  hpt neg vpt -1.62 mul V
   4.135 +  hpt 2 mul 0 V
   4.136 +  hpt neg vpt 1.62 mul V closepath stroke
   4.137 +  Pnt} def
   4.138 +/Star {2 copy Pls Crs} def
   4.139 +/BoxF {stroke [] 0 setdash exch hpt sub exch vpt add M
   4.140 +  0 vpt2 neg V hpt2 0 V 0 vpt2 V
   4.141 +  hpt2 neg 0 V closepath fill} def
   4.142 +/TriUF {stroke [] 0 setdash vpt 1.12 mul add M
   4.143 +  hpt neg vpt -1.62 mul V
   4.144 +  hpt 2 mul 0 V
   4.145 +  hpt neg vpt 1.62 mul V closepath fill} def
   4.146 +/TriD {stroke [] 0 setdash 2 copy vpt 1.12 mul sub M
   4.147 +  hpt neg vpt 1.62 mul V
   4.148 +  hpt 2 mul 0 V
   4.149 +  hpt neg vpt -1.62 mul V closepath stroke
   4.150 +  Pnt} def
   4.151 +/TriDF {stroke [] 0 setdash vpt 1.12 mul sub M
   4.152 +  hpt neg vpt 1.62 mul V
   4.153 +  hpt 2 mul 0 V
   4.154 +  hpt neg vpt -1.62 mul V closepath fill} def
   4.155 +/DiaF {stroke [] 0 setdash vpt add M
   4.156 +  hpt neg vpt neg V hpt vpt neg V
   4.157 +  hpt vpt V hpt neg vpt V closepath fill} def
   4.158 +/Pent {stroke [] 0 setdash 2 copy gsave
   4.159 +  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
   4.160 +  closepath stroke grestore Pnt} def
   4.161 +/PentF {stroke [] 0 setdash gsave
   4.162 +  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
   4.163 +  closepath fill grestore} def
   4.164 +/Circle {stroke [] 0 setdash 2 copy
   4.165 +  hpt 0 360 arc stroke Pnt} def
   4.166 +/CircleF {stroke [] 0 setdash hpt 0 360 arc fill} def
   4.167 +/C0 {BL [] 0 setdash 2 copy moveto vpt 90 450 arc} bind def
   4.168 +/C1 {BL [] 0 setdash 2 copy moveto
   4.169 +	2 copy vpt 0 90 arc closepath fill
   4.170 +	vpt 0 360 arc closepath} bind def
   4.171 +/C2 {BL [] 0 setdash 2 copy moveto
   4.172 +	2 copy vpt 90 180 arc closepath fill
   4.173 +	vpt 0 360 arc closepath} bind def
   4.174 +/C3 {BL [] 0 setdash 2 copy moveto
   4.175 +	2 copy vpt 0 180 arc closepath fill
   4.176 +	vpt 0 360 arc closepath} bind def
   4.177 +/C4 {BL [] 0 setdash 2 copy moveto
   4.178 +	2 copy vpt 180 270 arc closepath fill
   4.179 +	vpt 0 360 arc closepath} bind def
   4.180 +/C5 {BL [] 0 setdash 2 copy moveto
   4.181 +	2 copy vpt 0 90 arc
   4.182 +	2 copy moveto
   4.183 +	2 copy vpt 180 270 arc closepath fill
   4.184 +	vpt 0 360 arc} bind def
   4.185 +/C6 {BL [] 0 setdash 2 copy moveto
   4.186 +	2 copy vpt 90 270 arc closepath fill
   4.187 +	vpt 0 360 arc closepath} bind def
   4.188 +/C7 {BL [] 0 setdash 2 copy moveto
   4.189 +	2 copy vpt 0 270 arc closepath fill
   4.190 +	vpt 0 360 arc closepath} bind def
   4.191 +/C8 {BL [] 0 setdash 2 copy moveto
   4.192 +	2 copy vpt 270 360 arc closepath fill
   4.193 +	vpt 0 360 arc closepath} bind def
   4.194 +/C9 {BL [] 0 setdash 2 copy moveto
   4.195 +	2 copy vpt 270 450 arc closepath fill
   4.196 +	vpt 0 360 arc closepath} bind def
   4.197 +/C10 {BL [] 0 setdash 2 copy 2 copy moveto vpt 270 360 arc closepath fill
   4.198 +	2 copy moveto
   4.199 +	2 copy vpt 90 180 arc closepath fill
   4.200 +	vpt 0 360 arc closepath} bind def
   4.201 +/C11 {BL [] 0 setdash 2 copy moveto
   4.202 +	2 copy vpt 0 180 arc closepath fill
   4.203 +	2 copy moveto
   4.204 +	2 copy vpt 270 360 arc closepath fill
   4.205 +	vpt 0 360 arc closepath} bind def
   4.206 +/C12 {BL [] 0 setdash 2 copy moveto
   4.207 +	2 copy vpt 180 360 arc closepath fill
   4.208 +	vpt 0 360 arc closepath} bind def
   4.209 +/C13 {BL [] 0 setdash 2 copy moveto
   4.210 +	2 copy vpt 0 90 arc closepath fill
   4.211 +	2 copy moveto
   4.212 +	2 copy vpt 180 360 arc closepath fill
   4.213 +	vpt 0 360 arc closepath} bind def
   4.214 +/C14 {BL [] 0 setdash 2 copy moveto
   4.215 +	2 copy vpt 90 360 arc closepath fill
   4.216 +	vpt 0 360 arc} bind def
   4.217 +/C15 {BL [] 0 setdash 2 copy vpt 0 360 arc closepath fill
   4.218 +	vpt 0 360 arc closepath} bind def
   4.219 +/Rec {newpath 4 2 roll moveto 1 index 0 rlineto 0 exch rlineto
   4.220 +	neg 0 rlineto closepath} bind def
   4.221 +/Square {dup Rec} bind def
   4.222 +/Bsquare {vpt sub exch vpt sub exch vpt2 Square} bind def
   4.223 +/S0 {BL [] 0 setdash 2 copy moveto 0 vpt rlineto BL Bsquare} bind def
   4.224 +/S1 {BL [] 0 setdash 2 copy vpt Square fill Bsquare} bind def
   4.225 +/S2 {BL [] 0 setdash 2 copy exch vpt sub exch vpt Square fill Bsquare} bind def
   4.226 +/S3 {BL [] 0 setdash 2 copy exch vpt sub exch vpt2 vpt Rec fill Bsquare} bind def
   4.227 +/S4 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def
   4.228 +/S5 {BL [] 0 setdash 2 copy 2 copy vpt Square fill
   4.229 +	exch vpt sub exch vpt sub vpt Square fill Bsquare} bind def
   4.230 +/S6 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill Bsquare} bind def
   4.231 +/S7 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt vpt2 Rec fill
   4.232 +	2 copy vpt Square fill Bsquare} bind def
   4.233 +/S8 {BL [] 0 setdash 2 copy vpt sub vpt Square fill Bsquare} bind def
   4.234 +/S9 {BL [] 0 setdash 2 copy vpt sub vpt vpt2 Rec fill Bsquare} bind def
   4.235 +/S10 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt Square fill
   4.236 +	Bsquare} bind def
   4.237 +/S11 {BL [] 0 setdash 2 copy vpt sub vpt Square fill 2 copy exch vpt sub exch vpt2 vpt Rec fill
   4.238 +	Bsquare} bind def
   4.239 +/S12 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill Bsquare} bind def
   4.240 +/S13 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill
   4.241 +	2 copy vpt Square fill Bsquare} bind def
   4.242 +/S14 {BL [] 0 setdash 2 copy exch vpt sub exch vpt sub vpt2 vpt Rec fill
   4.243 +	2 copy exch vpt sub exch vpt Square fill Bsquare} bind def
   4.244 +/S15 {BL [] 0 setdash 2 copy Bsquare fill Bsquare} bind def
   4.245 +/D0 {gsave translate 45 rotate 0 0 S0 stroke grestore} bind def
   4.246 +/D1 {gsave translate 45 rotate 0 0 S1 stroke grestore} bind def
   4.247 +/D2 {gsave translate 45 rotate 0 0 S2 stroke grestore} bind def
   4.248 +/D3 {gsave translate 45 rotate 0 0 S3 stroke grestore} bind def
   4.249 +/D4 {gsave translate 45 rotate 0 0 S4 stroke grestore} bind def
   4.250 +/D5 {gsave translate 45 rotate 0 0 S5 stroke grestore} bind def
   4.251 +/D6 {gsave translate 45 rotate 0 0 S6 stroke grestore} bind def
   4.252 +/D7 {gsave translate 45 rotate 0 0 S7 stroke grestore} bind def
   4.253 +/D8 {gsave translate 45 rotate 0 0 S8 stroke grestore} bind def
   4.254 +/D9 {gsave translate 45 rotate 0 0 S9 stroke grestore} bind def
   4.255 +/D10 {gsave translate 45 rotate 0 0 S10 stroke grestore} bind def
   4.256 +/D11 {gsave translate 45 rotate 0 0 S11 stroke grestore} bind def
   4.257 +/D12 {gsave translate 45 rotate 0 0 S12 stroke grestore} bind def
   4.258 +/D13 {gsave translate 45 rotate 0 0 S13 stroke grestore} bind def
   4.259 +/D14 {gsave translate 45 rotate 0 0 S14 stroke grestore} bind def
   4.260 +/D15 {gsave translate 45 rotate 0 0 S15 stroke grestore} bind def
   4.261 +/DiaE {stroke [] 0 setdash vpt add M
   4.262 +  hpt neg vpt neg V hpt vpt neg V
   4.263 +  hpt vpt V hpt neg vpt V closepath stroke} def
   4.264 +/BoxE {stroke [] 0 setdash exch hpt sub exch vpt add M
   4.265 +  0 vpt2 neg V hpt2 0 V 0 vpt2 V
   4.266 +  hpt2 neg 0 V closepath stroke} def
   4.267 +/TriUE {stroke [] 0 setdash vpt 1.12 mul add M
   4.268 +  hpt neg vpt -1.62 mul V
   4.269 +  hpt 2 mul 0 V
   4.270 +  hpt neg vpt 1.62 mul V closepath stroke} def
   4.271 +/TriDE {stroke [] 0 setdash vpt 1.12 mul sub M
   4.272 +  hpt neg vpt 1.62 mul V
   4.273 +  hpt 2 mul 0 V
   4.274 +  hpt neg vpt -1.62 mul V closepath stroke} def
   4.275 +/PentE {stroke [] 0 setdash gsave
   4.276 +  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
   4.277 +  closepath stroke grestore} def
   4.278 +/CircE {stroke [] 0 setdash 
   4.279 +  hpt 0 360 arc stroke} def
   4.280 +/Opaque {gsave closepath 1 setgray fill grestore 0 setgray closepath} def
   4.281 +/DiaW {stroke [] 0 setdash vpt add M
   4.282 +  hpt neg vpt neg V hpt vpt neg V
   4.283 +  hpt vpt V hpt neg vpt V Opaque stroke} def
   4.284 +/BoxW {stroke [] 0 setdash exch hpt sub exch vpt add M
   4.285 +  0 vpt2 neg V hpt2 0 V 0 vpt2 V
   4.286 +  hpt2 neg 0 V Opaque stroke} def
   4.287 +/TriUW {stroke [] 0 setdash vpt 1.12 mul add M
   4.288 +  hpt neg vpt -1.62 mul V
   4.289 +  hpt 2 mul 0 V
   4.290 +  hpt neg vpt 1.62 mul V Opaque stroke} def
   4.291 +/TriDW {stroke [] 0 setdash vpt 1.12 mul sub M
   4.292 +  hpt neg vpt 1.62 mul V
   4.293 +  hpt 2 mul 0 V
   4.294 +  hpt neg vpt -1.62 mul V Opaque stroke} def
   4.295 +/PentW {stroke [] 0 setdash gsave
   4.296 +  translate 0 hpt M 4 {72 rotate 0 hpt L} repeat
   4.297 +  Opaque stroke grestore} def
   4.298 +/CircW {stroke [] 0 setdash 
   4.299 +  hpt 0 360 arc Opaque stroke} def
   4.300 +/BoxFill {gsave Rec 1 setgray fill grestore} def
   4.301 +/Density {
   4.302 +  /Fillden exch def
   4.303 +  currentrgbcolor
   4.304 +  /ColB exch def /ColG exch def /ColR exch def
   4.305 +  /ColR ColR Fillden mul Fillden sub 1 add def
   4.306 +  /ColG ColG Fillden mul Fillden sub 1 add def
   4.307 +  /ColB ColB Fillden mul Fillden sub 1 add def
   4.308 +  ColR ColG ColB setrgbcolor} def
   4.309 +/BoxColFill {gsave Rec PolyFill} def
   4.310 +/PolyFill {gsave Density fill grestore grestore} def
   4.311 +/h {rlineto rlineto rlineto gsave fill grestore} bind def
   4.312 +%
   4.313 +% PostScript Level 1 Pattern Fill routine for rectangles
   4.314 +% Usage: x y w h s a XX PatternFill
   4.315 +%	x,y = lower left corner of box to be filled
   4.316 +%	w,h = width and height of box
   4.317 +%	  a = angle in degrees between lines and x-axis
   4.318 +%	 XX = 0/1 for no/yes cross-hatch
   4.319 +%
   4.320 +/PatternFill {gsave /PFa [ 9 2 roll ] def
   4.321 +  PFa 0 get PFa 2 get 2 div add PFa 1 get PFa 3 get 2 div add translate
   4.322 +  PFa 2 get -2 div PFa 3 get -2 div PFa 2 get PFa 3 get Rec
   4.323 +  gsave 1 setgray fill grestore clip
   4.324 +  currentlinewidth 0.5 mul setlinewidth
   4.325 +  /PFs PFa 2 get dup mul PFa 3 get dup mul add sqrt def
   4.326 +  0 0 M PFa 5 get rotate PFs -2 div dup translate
   4.327 +  0 1 PFs PFa 4 get div 1 add floor cvi
   4.328 +	{PFa 4 get mul 0 M 0 PFs V} for
   4.329 +  0 PFa 6 get ne {
   4.330 +	0 1 PFs PFa 4 get div 1 add floor cvi
   4.331 +	{PFa 4 get mul 0 2 1 roll M PFs 0 V} for
   4.332 + } if
   4.333 +  stroke grestore} def
   4.334 +%
   4.335 +/languagelevel where
   4.336 + {pop languagelevel} {1} ifelse
   4.337 + 2 lt
   4.338 +	{/InterpretLevel1 true def}
   4.339 +	{/InterpretLevel1 Level1 def}
   4.340 + ifelse
   4.341 +%
   4.342 +% PostScript level 2 pattern fill definitions
   4.343 +%
   4.344 +/Level2PatternFill {
   4.345 +/Tile8x8 {/PaintType 2 /PatternType 1 /TilingType 1 /BBox [0 0 8 8] /XStep 8 /YStep 8}
   4.346 +	bind def
   4.347 +/KeepColor {currentrgbcolor [/Pattern /DeviceRGB] setcolorspace} bind def
   4.348 +<< Tile8x8
   4.349 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke} 
   4.350 +>> matrix makepattern
   4.351 +/Pat1 exch def
   4.352 +<< Tile8x8
   4.353 + /PaintProc {0.5 setlinewidth pop 0 0 M 8 8 L 0 8 M 8 0 L stroke
   4.354 +	0 4 M 4 8 L 8 4 L 4 0 L 0 4 L stroke}
   4.355 +>> matrix makepattern
   4.356 +/Pat2 exch def
   4.357 +<< Tile8x8
   4.358 + /PaintProc {0.5 setlinewidth pop 0 0 M 0 8 L
   4.359 +	8 8 L 8 0 L 0 0 L fill}
   4.360 +>> matrix makepattern
   4.361 +/Pat3 exch def
   4.362 +<< Tile8x8
   4.363 + /PaintProc {0.5 setlinewidth pop -4 8 M 8 -4 L
   4.364 +	0 12 M 12 0 L stroke}
   4.365 +>> matrix makepattern
   4.366 +/Pat4 exch def
   4.367 +<< Tile8x8
   4.368 + /PaintProc {0.5 setlinewidth pop -4 0 M 8 12 L
   4.369 +	0 -4 M 12 8 L stroke}
   4.370 +>> matrix makepattern
   4.371 +/Pat5 exch def
   4.372 +<< Tile8x8
   4.373 + /PaintProc {0.5 setlinewidth pop -2 8 M 4 -4 L
   4.374 +	0 12 M 8 -4 L 4 12 M 10 0 L stroke}
   4.375 +>> matrix makepattern
   4.376 +/Pat6 exch def
   4.377 +<< Tile8x8
   4.378 + /PaintProc {0.5 setlinewidth pop -2 0 M 4 12 L
   4.379 +	0 -4 M 8 12 L 4 -4 M 10 8 L stroke}
   4.380 +>> matrix makepattern
   4.381 +/Pat7 exch def
   4.382 +<< Tile8x8
   4.383 + /PaintProc {0.5 setlinewidth pop 8 -2 M -4 4 L
   4.384 +	12 0 M -4 8 L 12 4 M 0 10 L stroke}
   4.385 +>> matrix makepattern
   4.386 +/Pat8 exch def
   4.387 +<< Tile8x8
   4.388 + /PaintProc {0.5 setlinewidth pop 0 -2 M 12 4 L
   4.389 +	-4 0 M 12 8 L -4 4 M 8 10 L stroke}
   4.390 +>> matrix makepattern
   4.391 +/Pat9 exch def
   4.392 +/Pattern1 {PatternBgnd KeepColor Pat1 setpattern} bind def
   4.393 +/Pattern2 {PatternBgnd KeepColor Pat2 setpattern} bind def
   4.394 +/Pattern3 {PatternBgnd KeepColor Pat3 setpattern} bind def
   4.395 +/Pattern4 {PatternBgnd KeepColor Landscape {Pat5} {Pat4} ifelse setpattern} bind def
   4.396 +/Pattern5 {PatternBgnd KeepColor Landscape {Pat4} {Pat5} ifelse setpattern} bind def
   4.397 +/Pattern6 {PatternBgnd KeepColor Landscape {Pat9} {Pat6} ifelse setpattern} bind def
   4.398 +/Pattern7 {PatternBgnd KeepColor Landscape {Pat8} {Pat7} ifelse setpattern} bind def
   4.399 +} def
   4.400 +%
   4.401 +%
   4.402 +%End of PostScript Level 2 code
   4.403 +%
   4.404 +/PatternBgnd {
   4.405 +  TransparentPatterns {} {gsave 1 setgray fill grestore} ifelse
   4.406 +} def
   4.407 +%
   4.408 +% Substitute for Level 2 pattern fill codes with
   4.409 +% grayscale if Level 2 support is not selected.
   4.410 +%
   4.411 +/Level1PatternFill {
   4.412 +/Pattern1 {0.250 Density} bind def
   4.413 +/Pattern2 {0.500 Density} bind def
   4.414 +/Pattern3 {0.750 Density} bind def
   4.415 +/Pattern4 {0.125 Density} bind def
   4.416 +/Pattern5 {0.375 Density} bind def
   4.417 +/Pattern6 {0.625 Density} bind def
   4.418 +/Pattern7 {0.875 Density} bind def
   4.419 +} def
   4.420 +%
   4.421 +% Now test for support of Level 2 code
   4.422 +%
   4.423 +Level1 {Level1PatternFill} {Level2PatternFill} ifelse
   4.424 +%
   4.425 +/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont
   4.426 +dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall
   4.427 +currentdict end definefont pop
   4.428 +/MFshow {
   4.429 +   { dup 5 get 3 ge
   4.430 +     { 5 get 3 eq {gsave} {grestore} ifelse }
   4.431 +     {dup dup 0 get findfont exch 1 get scalefont setfont
   4.432 +     [ currentpoint ] exch dup 2 get 0 exch R dup 5 get 2 ne {dup dup 6
   4.433 +     get exch 4 get {show} {stringwidth pop 0 R} ifelse }if dup 5 get 0 eq
   4.434 +     {dup 3 get {2 get neg 0 exch R pop} {pop aload pop M} ifelse} {dup 5
   4.435 +     get 1 eq {dup 2 get exch dup 3 get exch 6 get stringwidth pop -2 div
   4.436 +     dup 0 R} {dup 6 get stringwidth pop -2 div 0 R 6 get
   4.437 +     show 2 index {aload pop M neg 3 -1 roll neg R pop pop} {pop pop pop
   4.438 +     pop aload pop M} ifelse }ifelse }ifelse }
   4.439 +     ifelse }
   4.440 +   forall} bind def
   4.441 +/MFwidth {0 exch { dup 5 get 3 ge { 5 get 3 eq { 0 } { pop } ifelse }
   4.442 + {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont
   4.443 +     6 get stringwidth pop add} {pop} ifelse} ifelse} forall} bind def
   4.444 +/MLshow { currentpoint stroke M
   4.445 +  0 exch R
   4.446 +  Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def
   4.447 +/MRshow { currentpoint stroke M
   4.448 +  exch dup MFwidth neg 3 -1 roll R
   4.449 +  Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def
   4.450 +/MCshow { currentpoint stroke M
   4.451 +  exch dup MFwidth -2 div 3 -1 roll R
   4.452 +  Blacktext {gsave 0 setgray MFshow grestore} {MFshow} ifelse } bind def
   4.453 +/XYsave    { [( ) 1 2 true false 3 ()] } bind def
   4.454 +/XYrestore { [( ) 1 2 true false 4 ()] } bind def
   4.455 +end
   4.456 +%%EndProlog
   4.457 +%%Page: 1 1
   4.458 +gnudict begin
   4.459 +gsave
   4.460 +50 50 translate
   4.461 +0.100 0.100 scale
   4.462 +0 setgray
   4.463 +newpath
   4.464 +(Helvetica) findfont 140 scalefont setfont
   4.465 +1.000 UL
   4.466 +LTb
   4.467 +714 420 M
   4.468 +63 0 V
   4.469 +4025 0 R
   4.470 +-63 0 V
   4.471 +stroke
   4.472 +630 420 M
   4.473 +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)]
   4.474 +] -46.7 MRshow
   4.475 +1.000 UL
   4.476 +LTb
   4.477 +714 1177 M
   4.478 +63 0 V
   4.479 +4025 0 R
   4.480 +-63 0 V
   4.481 +stroke
   4.482 +630 1177 M
   4.483 +[ [(Helvetica) 140.0 0.0 true true 0 ( 20)]
   4.484 +] -46.7 MRshow
   4.485 +1.000 UL
   4.486 +LTb
   4.487 +714 1934 M
   4.488 +63 0 V
   4.489 +4025 0 R
   4.490 +-63 0 V
   4.491 +stroke
   4.492 +630 1934 M
   4.493 +[ [(Helvetica) 140.0 0.0 true true 0 ( 40)]
   4.494 +] -46.7 MRshow
   4.495 +1.000 UL
   4.496 +LTb
   4.497 +714 2691 M
   4.498 +63 0 V
   4.499 +4025 0 R
   4.500 +-63 0 V
   4.501 +stroke
   4.502 +630 2691 M
   4.503 +[ [(Helvetica) 140.0 0.0 true true 0 ( 60)]
   4.504 +] -46.7 MRshow
   4.505 +1.000 UL
   4.506 +LTb
   4.507 +714 3448 M
   4.508 +63 0 V
   4.509 +4025 0 R
   4.510 +-63 0 V
   4.511 +stroke
   4.512 +630 3448 M
   4.513 +[ [(Helvetica) 140.0 0.0 true true 0 ( 80)]
   4.514 +] -46.7 MRshow
   4.515 +1.000 UL
   4.516 +LTb
   4.517 +714 4205 M
   4.518 +63 0 V
   4.519 +4025 0 R
   4.520 +-63 0 V
   4.521 +stroke
   4.522 +630 4205 M
   4.523 +[ [(Helvetica) 140.0 0.0 true true 0 ( 100)]
   4.524 +] -46.7 MRshow
   4.525 +1.000 UL
   4.526 +LTb
   4.527 +714 420 M
   4.528 +0 63 V
   4.529 +0 4101 R
   4.530 +0 -63 V
   4.531 +stroke
   4.532 +714 280 M
   4.533 +[ [(Helvetica) 140.0 0.0 true true 0 ( 0)]
   4.534 +] -46.7 MCshow
   4.535 +1.000 UL
   4.536 +LTb
   4.537 +1736 420 M
   4.538 +0 63 V
   4.539 +0 4101 R
   4.540 +0 -63 V
   4.541 +stroke
   4.542 +1736 280 M
   4.543 +[ [(Helvetica) 140.0 0.0 true true 0 ( 50)]
   4.544 +] -46.7 MCshow
   4.545 +1.000 UL
   4.546 +LTb
   4.547 +2758 420 M
   4.548 +0 63 V
   4.549 +0 4101 R
   4.550 +0 -63 V
   4.551 +stroke
   4.552 +2758 280 M
   4.553 +[ [(Helvetica) 140.0 0.0 true true 0 ( 100)]
   4.554 +] -46.7 MCshow
   4.555 +1.000 UL
   4.556 +LTb
   4.557 +3780 420 M
   4.558 +0 63 V
   4.559 +0 4101 R
   4.560 +0 -63 V
   4.561 +stroke
   4.562 +3780 280 M
   4.563 +[ [(Helvetica) 140.0 0.0 true true 0 ( 150)]
   4.564 +] -46.7 MCshow
   4.565 +1.000 UL
   4.566 +LTb
   4.567 +4802 420 M
   4.568 +0 63 V
   4.569 +0 4101 R
   4.570 +0 -63 V
   4.571 +stroke
   4.572 +4802 280 M
   4.573 +[ [(Helvetica) 140.0 0.0 true true 0 ( 200)]
   4.574 +] -46.7 MCshow
   4.575 +1.000 UL
   4.576 +LTb
   4.577 +1.000 UL
   4.578 +LTb
   4.579 +714 4584 N
   4.580 +714 420 L
   4.581 +4088 0 V
   4.582 +0 4164 V
   4.583 +-4088 0 V
   4.584 +Z stroke
   4.585 +LCb setrgbcolor
   4.586 +140 2502 M
   4.587 +currentpoint gsave translate 90 rotate 0 0 moveto
   4.588 +[ [(Helvetica) 140.0 0.0 true true 0 (% Packet Loss --- average of 5 trials per distance)]
   4.589 +] -46.7 MCshow
   4.590 +grestore
   4.591 +LTb
   4.592 +LCb setrgbcolor
   4.593 +2758 70 M
   4.594 +[ [(Helvetica) 140.0 0.0 true true 0 (Distance \(m\))]
   4.595 +] -46.7 MCshow
   4.596 +LTb
   4.597 +1.000 UP
   4.598 +1.000 UL
   4.599 +LTb
   4.600 +1.000 UL
   4.601 +LT0
   4.602 +LTb
   4.603 +4151 4451 M
   4.604 +[ [(Helvetica) 140.0 0.0 true true 0 (WiFi Defaults)]
   4.605 +] -46.7 MRshow
   4.606 +LT0
   4.607 +4235 4451 M
   4.608 +399 0 V
   4.609 +1225 420 M
   4.610 +511 0 V
   4.611 +511 0 V
   4.612 +511 0 V
   4.613 +511 0 V
   4.614 +409 136 V
   4.615 +41 121 V
   4.616 +61 -68 V
   4.617 +41 288 V
   4.618 +61 295 V
   4.619 +41 424 V
   4.620 +61 560 V
   4.621 +41 470 V
   4.622 +62 484 V
   4.623 +40 356 V
   4.624 +62 583 V
   4.625 +41 114 V
   4.626 +61 22 V
   4.627 +41 0 V
   4.628 +61 -22 V
   4.629 +stroke
   4.630 +LTb
   4.631 +714 4584 N
   4.632 +714 420 L
   4.633 +4088 0 V
   4.634 +0 4164 V
   4.635 +-4088 0 V
   4.636 +Z stroke
   4.637 +1.000 UP
   4.638 +1.000 UL
   4.639 +LTb
   4.640 +stroke
   4.641 +grestore
   4.642 +end
   4.643 +showpage
   4.644 +%%Trailer
   4.645 +%%DocumentFonts: Helvetica
   4.646 +%%Pages: 1
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/examples/stats/wifi-example-apps.cc	Fri Aug 29 13:22:09 2008 -0400
     5.3 @@ -0,0 +1,330 @@
     5.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     5.5 +/*
     5.6 + * This program is free software; you can redistribute it and/or modify
     5.7 + * it under the terms of the GNU General Public License version 2 as
     5.8 + * published by the Free Software Foundation;
     5.9 + *
    5.10 + * This program is distributed in the hope that it will be useful,
    5.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.13 + * GNU General Public License for more details.
    5.14 + *
    5.15 + * You should have received a copy of the GNU General Public License
    5.16 + * along with this program; if not, write to the Free Software
    5.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.18 + *
    5.19 + * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
    5.20 + *
    5.21 + * These applications are used in the WiFi Distance Test experiment,
    5.22 + * described and implemented in test02.cc.  That file should be in the
    5.23 + * same place as this file.  The applications have two very simple
    5.24 + * jobs, they just generate and receive packets.  We could use the
    5.25 + * standard Application classes included in the NS-3 distribution.
    5.26 + * These have been written just to change the behavior a little, and
    5.27 + * provide more examples.
    5.28 + *
    5.29 + */
    5.30 +
    5.31 +#include <ostream>
    5.32 +
    5.33 +#include "ns3/core-module.h"
    5.34 +#include "ns3/common-module.h"
    5.35 +#include "ns3/simulator-module.h"
    5.36 +#include "ns3/node-module.h"
    5.37 +#include "ns3/internet-stack-module.h"
    5.38 +
    5.39 +#include "ns3/stats-module.h"
    5.40 +
    5.41 +#include "wifi-example-apps.h"
    5.42 +
    5.43 +using namespace ns3;
    5.44 +
    5.45 +NS_LOG_COMPONENT_DEFINE ("WiFiDistanceApps");
    5.46 +
    5.47 +TypeId
    5.48 +Sender::GetTypeId(void)
    5.49 +{
    5.50 +  static TypeId tid = TypeId ("Sender")
    5.51 +    .SetParent<Application> ()
    5.52 +    .AddConstructor<Sender> ()
    5.53 +    .AddAttribute ("PacketSize", "The size of packets transmitted.",
    5.54 +                   UintegerValue(64),
    5.55 +                   MakeUintegerAccessor(&Sender::m_pktSize),
    5.56 +                   MakeUintegerChecker<uint32_t>(1))
    5.57 +    .AddAttribute("Destination", "Target host address.",
    5.58 +                  Ipv4AddressValue("255.255.255.255"),
    5.59 +                  MakeIpv4AddressAccessor(&Sender::m_destAddr),
    5.60 +                  MakeIpv4AddressChecker())
    5.61 +    .AddAttribute("Port", "Destination app port.",
    5.62 +                  UintegerValue(1603),
    5.63 +                  MakeUintegerAccessor(&Sender::m_destPort),
    5.64 +                  MakeUintegerChecker<uint32_t>())
    5.65 +    .AddAttribute("NumPackets", "Total number of packets to send.",
    5.66 +                  UintegerValue(30),
    5.67 +                  MakeUintegerAccessor(&Sender::m_numPkts),
    5.68 +                  MakeUintegerChecker<uint32_t>(1))
    5.69 +    .AddAttribute ("Interval", "Delay between transmissions.",
    5.70 +                   RandomVariableValue(ConstantVariable(0.5)),
    5.71 +                   MakeRandomVariableAccessor(&Sender::m_interval),
    5.72 +                   MakeRandomVariableChecker())
    5.73 +    .AddTraceSource ("Tx", "A new packet is created and is sent",
    5.74 +                     MakeTraceSourceAccessor (&Sender::m_txTrace))
    5.75 +    ;
    5.76 +  return tid;
    5.77 +}
    5.78 +
    5.79 +
    5.80 +Sender::Sender()
    5.81 +{
    5.82 +  NS_LOG_FUNCTION_NOARGS ();
    5.83 +  m_socket = 0;
    5.84 +}
    5.85 +
    5.86 +Sender::~Sender()
    5.87 +{
    5.88 +  NS_LOG_FUNCTION_NOARGS ();
    5.89 +}
    5.90 +
    5.91 +void
    5.92 +Sender::DoDispose (void)
    5.93 +{
    5.94 +  NS_LOG_FUNCTION_NOARGS ();
    5.95 +
    5.96 +  m_socket = 0;
    5.97 +  // chain up
    5.98 +  Application::DoDispose ();
    5.99 +}
   5.100 +
   5.101 +void Sender::StartApplication()
   5.102 +{
   5.103 +  NS_LOG_FUNCTION_NOARGS ();
   5.104 +
   5.105 +  if (m_socket == 0) {
   5.106 +      Ptr<SocketFactory> socketFactory = GetNode()->GetObject<SocketFactory>
   5.107 +        (UdpSocketFactory::GetTypeId());
   5.108 +      m_socket = socketFactory->CreateSocket ();
   5.109 +      m_socket->Bind ();
   5.110 +  }
   5.111 +
   5.112 +  m_count = 0;
   5.113 +
   5.114 +  Simulator::Cancel(m_sendEvent);
   5.115 +  m_sendEvent = Simulator::ScheduleNow(&Sender::SendPacket, this);
   5.116 +
   5.117 +  // end Sender::StartApplication
   5.118 +}
   5.119 +
   5.120 +void Sender::StopApplication()
   5.121 +{
   5.122 +  NS_LOG_FUNCTION_NOARGS ();
   5.123 +  Simulator::Cancel(m_sendEvent);
   5.124 +  // end Sender::StopApplication
   5.125 +}
   5.126 +  
   5.127 +void Sender::SendPacket()
   5.128 +{
   5.129 +  // NS_LOG_FUNCTION_NOARGS ();
   5.130 +  NS_LOG_INFO("Sending packet at " << Simulator::Now() << " to " <<
   5.131 +              m_destAddr);
   5.132 +
   5.133 +  Ptr<Packet> packet = Create<Packet>(m_pktSize);
   5.134 +
   5.135 +  TimestampTag timestamp;
   5.136 +  timestamp.SetTimestamp(Simulator::Now());
   5.137 +  packet->AddTag(timestamp);
   5.138 +
   5.139 +  // Could connect the socket since the address never changes; using SendTo
   5.140 +  // here simply because all of the standard apps do not.
   5.141 +  m_socket->SendTo(packet, 0, InetSocketAddress(m_destAddr, m_destPort));
   5.142 +
   5.143 +  // Report the event to the trace.
   5.144 +  m_txTrace(packet);
   5.145 +
   5.146 +  if (++m_count < m_numPkts) {
   5.147 +    m_sendEvent = Simulator::Schedule(Seconds(m_interval.GetValue()),
   5.148 +                                      &Sender::SendPacket, this);
   5.149 +  }
   5.150 +
   5.151 +  // end Sender::SendPacket
   5.152 +}
   5.153 +
   5.154 +
   5.155 +
   5.156 +
   5.157 +//----------------------------------------------------------------------
   5.158 +//-- Receiver
   5.159 +//------------------------------------------------------
   5.160 +TypeId
   5.161 +Receiver::GetTypeId(void)
   5.162 +{
   5.163 +  static TypeId tid = TypeId ("Receiver")
   5.164 +    .SetParent<Application> ()
   5.165 +    .AddConstructor<Receiver> ()
   5.166 +    .AddAttribute("Port", "Listening port.",
   5.167 +                  UintegerValue(1603),
   5.168 +                  MakeUintegerAccessor(&Receiver::m_port),
   5.169 +                  MakeUintegerChecker<uint32_t>())
   5.170 +    ;
   5.171 +  return tid;
   5.172 +}
   5.173 +
   5.174 +Receiver::Receiver() :
   5.175 +  m_calc(0),
   5.176 +  m_delay(0)
   5.177 +{
   5.178 +  NS_LOG_FUNCTION_NOARGS ();
   5.179 +  m_socket = 0;
   5.180 +}
   5.181 +
   5.182 +Receiver::~Receiver()
   5.183 +{
   5.184 +  NS_LOG_FUNCTION_NOARGS ();
   5.185 +}
   5.186 +
   5.187 +void
   5.188 +Receiver::DoDispose (void)
   5.189 +{
   5.190 +  NS_LOG_FUNCTION_NOARGS ();
   5.191 +
   5.192 +  m_socket = 0;
   5.193 +  // chain up
   5.194 +  Application::DoDispose ();
   5.195 +}
   5.196 +
   5.197 +void
   5.198 +Receiver::StartApplication()
   5.199 +{
   5.200 +  NS_LOG_FUNCTION_NOARGS ();
   5.201 +
   5.202 +  if (m_socket == 0) {
   5.203 +      Ptr<SocketFactory> socketFactory = GetNode()->GetObject<SocketFactory>
   5.204 +        (UdpSocketFactory::GetTypeId());
   5.205 +      m_socket = socketFactory->CreateSocket();
   5.206 +      InetSocketAddress local = 
   5.207 +        InetSocketAddress(Ipv4Address::GetAny(), m_port);
   5.208 +      m_socket->Bind(local);
   5.209 +  }
   5.210 +
   5.211 +  m_socket->SetRecvCallback(MakeCallback(&Receiver::Receive, this));
   5.212 +
   5.213 +  // end Receiver::StartApplication
   5.214 +}
   5.215 +
   5.216 +void
   5.217 +Receiver::StopApplication()
   5.218 +{
   5.219 +  NS_LOG_FUNCTION_NOARGS ();
   5.220 +
   5.221 +  if (m_socket != 0) {
   5.222 +      m_socket->SetRecvCallback(MakeNullCallback<void, Ptr<Socket> > ());
   5.223 +  }
   5.224 +
   5.225 +  // end Receiver::StopApplication
   5.226 +}
   5.227 +
   5.228 +void
   5.229 +Receiver::SetCounter(Ptr<CounterCalculator<> > calc)
   5.230 +{
   5.231 +  m_calc = calc;
   5.232 +  // end Receiver::SetCounter
   5.233 +}
   5.234 +void
   5.235 +Receiver::SetDelayTracker(Ptr<TimeMinMaxAvgTotalCalculator> delay)
   5.236 +{
   5.237 +  m_delay = delay;
   5.238 +  // end Receiver::SetDelayTracker
   5.239 +}
   5.240 +
   5.241 +void
   5.242 +Receiver::Receive(Ptr<Socket> socket)
   5.243 +{
   5.244 +  // NS_LOG_FUNCTION (this << socket << packet << from);
   5.245 +
   5.246 +  Ptr<Packet> packet;
   5.247 +  Address from;
   5.248 +  while (packet = socket->RecvFrom(from)) {
   5.249 +    if (InetSocketAddress::IsMatchingType (from)) {
   5.250 +      InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
   5.251 +      NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " << 
   5.252 +                   address.GetIpv4());
   5.253 +    }
   5.254 +
   5.255 +    TimestampTag timestamp;
   5.256 +    packet->FindFirstMatchingTag(timestamp);
   5.257 +    Time tx = timestamp.GetTimestamp();
   5.258 +
   5.259 +    if (m_delay != 0) {
   5.260 +      m_delay->Update(Simulator::Now() - tx);
   5.261 +    }
   5.262 +
   5.263 +    if (m_calc != 0) {
   5.264 +      m_calc->Update();
   5.265 +    }
   5.266 +
   5.267 +    // end receiving packets
   5.268 +  }
   5.269 +
   5.270 +  // end Receiver::Receive
   5.271 +}
   5.272 +
   5.273 +
   5.274 +
   5.275 +
   5.276 +//----------------------------------------------------------------------
   5.277 +//-- TimestampTag
   5.278 +//------------------------------------------------------
   5.279 +TypeId 
   5.280 +TimestampTag::GetTypeId(void)
   5.281 +{
   5.282 +  static TypeId tid = TypeId ("TimestampTag")
   5.283 +    .SetParent<Tag> ()
   5.284 +    .AddConstructor<TimestampTag> ()
   5.285 +    .AddAttribute ("Timestamp",
   5.286 +                   "Some momentous point in time!",
   5.287 +                   EmptyAttributeValue(),
   5.288 +                   MakeTimeAccessor(&TimestampTag::GetTimestamp),
   5.289 +                   MakeTimeChecker())
   5.290 +    ;
   5.291 +  return tid;
   5.292 +}
   5.293 +TypeId 
   5.294 +TimestampTag::GetInstanceTypeId(void) const
   5.295 +{
   5.296 +  return GetTypeId ();
   5.297 +}
   5.298 +
   5.299 +uint32_t 
   5.300 +TimestampTag::GetSerializedSize (void) const
   5.301 +{
   5.302 +  return 8;
   5.303 +}
   5.304 +void 
   5.305 +TimestampTag::Serialize (TagBuffer i) const
   5.306 +{
   5.307 +  int64_t t = m_timestamp.GetNanoSeconds();
   5.308 +  i.Write((const uint8_t *)&t, 8);
   5.309 +}
   5.310 +void 
   5.311 +TimestampTag::Deserialize (TagBuffer i)
   5.312 +{
   5.313 +  int64_t t;
   5.314 +  i.Read((uint8_t *)&t, 8);
   5.315 +  m_timestamp = NanoSeconds(t);
   5.316 +}
   5.317 +
   5.318 +void
   5.319 +TimestampTag::SetTimestamp(Time time)
   5.320 +{
   5.321 +  m_timestamp = time;
   5.322 +}
   5.323 +Time
   5.324 +TimestampTag::GetTimestamp(void) const
   5.325 +{
   5.326 +  return m_timestamp;
   5.327 +}
   5.328 +
   5.329 +void 
   5.330 +TimestampTag::Print(std::ostream &os) const
   5.331 +{
   5.332 +  os << "t=" << m_timestamp;
   5.333 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/examples/stats/wifi-example-apps.h	Fri Aug 29 13:22:09 2008 -0400
     6.3 @@ -0,0 +1,126 @@
     6.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     6.5 +/*
     6.6 + * This program is free software; you can redistribute it and/or modify
     6.7 + * it under the terms of the GNU General Public License version 2 as
     6.8 + * published by the Free Software Foundation;
     6.9 + *
    6.10 + * This program is distributed in the hope that it will be useful,
    6.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.13 + * GNU General Public License for more details.
    6.14 + *
    6.15 + * You should have received a copy of the GNU General Public License
    6.16 + * along with this program; if not, write to the Free Software
    6.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.18 + *
    6.19 + * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
    6.20 + *
    6.21 + * These applications are used in the WiFi Distance Test experiment,
    6.22 + * described and implemented in test02.cc.  That file should be in the
    6.23 + * same place as this file.  The applications have two very simple
    6.24 + * jobs, they just generate and receive packets.  We could use the
    6.25 + * standard Application classes included in the NS-3 distribution.
    6.26 + * These have been written just to change the behavior a little, and
    6.27 + * provide more examples.
    6.28 + *
    6.29 + */
    6.30 +
    6.31 +// #define NS3_LOG_ENABLE // Now defined by Makefile
    6.32 +
    6.33 +#include "ns3/core-module.h"
    6.34 +#include "ns3/common-module.h"
    6.35 +#include "ns3/application.h"
    6.36 +
    6.37 +#include "ns3/stats-module.h"
    6.38 +
    6.39 +using namespace ns3;
    6.40 +
    6.41 +//----------------------------------------------------------------------
    6.42 +//------------------------------------------------------
    6.43 +class Sender: public Application {
    6.44 +public:
    6.45 +  static TypeId GetTypeId(void);
    6.46 +  Sender();
    6.47 +  virtual ~Sender();
    6.48 +
    6.49 +protected:
    6.50 +  virtual void DoDispose(void);
    6.51 +
    6.52 +private:
    6.53 +  virtual void StartApplication(void);
    6.54 +  virtual void StopApplication(void);
    6.55 +
    6.56 +  void SendPacket();
    6.57 +
    6.58 +  uint32_t        m_pktSize;
    6.59 +  Ipv4Address     m_destAddr;
    6.60 +  uint32_t        m_destPort;
    6.61 +  RandomVariable  m_interval;
    6.62 +  uint32_t        m_numPkts;
    6.63 +
    6.64 +  Ptr<Socket>     m_socket;
    6.65 +  EventId         m_sendEvent;
    6.66 +
    6.67 +  TracedCallback<Ptr<const Packet> > m_txTrace;
    6.68 +
    6.69 +  uint32_t        m_count;
    6.70 +
    6.71 +  // end class Sender
    6.72 +};
    6.73 +
    6.74 +
    6.75 +
    6.76 +
    6.77 +//------------------------------------------------------
    6.78 +class Receiver: public Application {
    6.79 +public:
    6.80 +  static TypeId GetTypeId(void);
    6.81 +  Receiver();
    6.82 +  virtual ~Receiver();
    6.83 +
    6.84 +  void SetCounter(Ptr<CounterCalculator<> > calc);
    6.85 +  void SetDelayTracker(Ptr<TimeMinMaxAvgTotalCalculator> delay);
    6.86 +
    6.87 +protected:
    6.88 +  virtual void DoDispose(void);
    6.89 +
    6.90 +private:
    6.91 +  virtual void StartApplication(void);
    6.92 +  virtual void StopApplication(void);
    6.93 +
    6.94 +  void Receive(Ptr<Socket> socket);
    6.95 +
    6.96 +  Ptr<Socket>     m_socket;
    6.97 +
    6.98 +  uint32_t        m_port;
    6.99 +
   6.100 +  Ptr<CounterCalculator<> > m_calc;
   6.101 +  Ptr<TimeMinMaxAvgTotalCalculator> m_delay;
   6.102 +
   6.103 +  // end class Receiver
   6.104 +};
   6.105 +
   6.106 +
   6.107 +
   6.108 +
   6.109 +//------------------------------------------------------
   6.110 +class TimestampTag : public Tag {
   6.111 +public:
   6.112 +  static TypeId GetTypeId (void);
   6.113 +  virtual TypeId GetInstanceTypeId (void) const;
   6.114 +
   6.115 +  virtual uint32_t GetSerializedSize (void) const;
   6.116 +  virtual void Serialize (TagBuffer i) const;
   6.117 +  virtual void Deserialize (TagBuffer i);
   6.118 +  
   6.119 +  // these are our accessors to our tag structure
   6.120 +  void SetTimestamp(Time time);
   6.121 +  Time GetTimestamp(void) const;
   6.122 +
   6.123 +  void Print(std::ostream &os) const;
   6.124 +
   6.125 +private:
   6.126 +  Time m_timestamp;
   6.127 +
   6.128 +  // end class TimestampTag
   6.129 +};
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/examples/stats/wifi-example-db.sh	Fri Aug 29 13:22:09 2008 -0400
     7.3 @@ -0,0 +1,76 @@
     7.4 +#!/bin/sh
     7.5 +
     7.6 +DISTANCES="25 50 75 100 125 145 147 150 152 155 157 160 162 165 167 170 172 175 177 180"
     7.7 +TRIALS="1 2 3 4 5"
     7.8 +
     7.9 +echo WiFi Experiment Example
    7.10 +
    7.11 +pCheck=`which sqlite3`
    7.12 +if [ -z "$pCheck" ]
    7.13 +then
    7.14 +  echo "ERROR: This script requires sqlite3 (wifi-example-sim does not)."
    7.15 +  exit 255
    7.16 +fi
    7.17 +
    7.18 +pCheck=`which gnuplot`
    7.19 +if [ -z "$pCheck" ]
    7.20 +then
    7.21 +  echo "ERROR: This script requires gnuplot (wifi-example-sim does not)."
    7.22 +  exit 255
    7.23 +fi
    7.24 +
    7.25 +pCheck=`which sed`
    7.26 +if [ -z "$pCheck" ]
    7.27 +then
    7.28 +  echo "ERROR: This script requires sed (wifi-example-sim does not)."
    7.29 +  exit 255
    7.30 +fi
    7.31 +
    7.32 +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:bin/
    7.33 +
    7.34 +if [ -e ../../data.db ]
    7.35 +then
    7.36 +  echo "Kill data.db? (y/n)"
    7.37 +  read ANS
    7.38 +  if [ "$ANS" = "yes" -o "$ANS" = "y" ]
    7.39 +  then
    7.40 +    echo Deleting database
    7.41 +    rm ../../data.db
    7.42 +  fi
    7.43 +fi
    7.44 +
    7.45 +for trial in $TRIALS
    7.46 +do
    7.47 +  for distance in $DISTANCES
    7.48 +  do
    7.49 +    echo Trial $trial, distance $distance
    7.50 +    ../../waf --run "wifi-example-sim --format=db --distance=$distance --run=run-$distance-$trial"
    7.51 +  done
    7.52 +done
    7.53 +
    7.54 +#
    7.55 +#Another SQL command which just collects raw numbers of frames receved.
    7.56 +#
    7.57 +#CMD="select Experiments.input,avg(Singletons.value) \
    7.58 +#    from Singletons,Experiments \
    7.59 +#    where Singletons.run = Experiments.run AND \
    7.60 +#          Singletons.name='wifi-rx-frames' \
    7.61 +#    group by Experiments.input \
    7.62 +#    order by abs(Experiments.input) ASC;"
    7.63 +
    7.64 +mv ../../data.db .
    7.65 +
    7.66 +CMD="select exp.input,avg(100-((rx.value*100)/tx.value)) \
    7.67 +    from Singletons rx, Singletons tx, Experiments exp \
    7.68 +    where rx.run = tx.run AND \
    7.69 +          rx.run = exp.run AND \
    7.70 +          rx.name='receiver-rx-packets' AND \
    7.71 +          tx.name='sender-tx-packets' \
    7.72 +    group by exp.input \
    7.73 +    order by abs(exp.input) ASC;"
    7.74 +
    7.75 +sqlite3 -noheader data.db "$CMD" > wifi-default.data
    7.76 +sed -i "s/|/   /" wifi-default.data
    7.77 +gnuplot wifi-example.gnuplot
    7.78 +
    7.79 +echo "Done; data in wifi-default.data, plot in wifi-default.eps"
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/examples/stats/wifi-example-sim.cc	Fri Aug 29 13:22:09 2008 -0400
     8.3 @@ -0,0 +1,318 @@
     8.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     8.5 +/*
     8.6 + * This program is free software; you can redistribute it and/or modify
     8.7 + * it under the terms of the GNU General Public License version 2 as
     8.8 + * published by the Free Software Foundation;
     8.9 + *
    8.10 + * This program is distributed in the hope that it will be useful,
    8.11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.13 + * GNU General Public License for more details.
    8.14 + *
    8.15 + * You should have received a copy of the GNU General Public License
    8.16 + * along with this program; if not, write to the Free Software
    8.17 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.18 + *
    8.19 + * Authors: Joe Kopena <tjkopena@cs.drexel.edu>
    8.20 + *
    8.21 + * This program conducts a simple experiment: It places two nodes at a
    8.22 + * parameterized distance apart.  One node generates packets and the
    8.23 + * other node receives.  The stat framework collects data on packet
    8.24 + * loss.  Outside of this program, a control script uses that data to
    8.25 + * produce graphs presenting performance at the varying distances.
    8.26 + * This isn't a typical simulation but is a common "experiment"
    8.27 + * performed in real life and serves as an accessible exemplar for the
    8.28 + * stat framework.  It also gives some intuition on the behavior and
    8.29 + * basic reasonability of the NS-3 WiFi models.
    8.30 + *
    8.31 + * Applications used by this program are in test02-apps.h and
    8.32 + * test02-apps.cc, which should be in the same place as this file.
    8.33 + * 
    8.34 + */
    8.35 +
    8.36 +// #define NS3_LOG_ENABLE // Now defined by Makefile
    8.37 +
    8.38 +#include <sstream>
    8.39 +
    8.40 +#include "ns3/core-module.h"
    8.41 +#include "ns3/common-module.h"
    8.42 +#include "ns3/node-module.h"
    8.43 +#include "ns3/helper-module.h"
    8.44 +#include "ns3/mobility-module.h"
    8.45 +#include "ns3/wifi-module.h"
    8.46 +
    8.47 +#include "ns3/stats-module.h"
    8.48 +
    8.49 +#include "wifi-example-apps.h"
    8.50 +
    8.51 +using namespace ns3;
    8.52 +using namespace std;
    8.53 +
    8.54 +NS_LOG_COMPONENT_DEFINE ("WiFiDistanceExperiment");
    8.55 +
    8.56 +
    8.57 +
    8.58 +
    8.59 +void TxCallback(Ptr<CounterCalculator<uint32_t> > datac,
    8.60 +                std::string path, Ptr<const Packet> packet,
    8.61 +                Mac48Address realto) {
    8.62 +  NS_LOG_INFO("Sent frame to " << realto << "; counted in " <<
    8.63 +              datac->GetKey());
    8.64 +  datac->Update();
    8.65 +  // end TxCallback
    8.66 +}
    8.67 +
    8.68 +
    8.69 +
    8.70 +
    8.71 +//----------------------------------------------------------------------
    8.72 +//-- main
    8.73 +//----------------------------------------------
    8.74 +int main(int argc, char *argv[]) {
    8.75 +
    8.76 +  double distance = 50.0;
    8.77 +  string format("omnet");
    8.78 +
    8.79 +  string experiment("wifi-distance-test");
    8.80 +  string strategy("wifi-default");
    8.81 +  string input;
    8.82 +  string runID;
    8.83 +
    8.84 +  {
    8.85 +    stringstream sstr;
    8.86 +    sstr << "run-" << time(NULL);
    8.87 +    runID = sstr.str();
    8.88 +  }
    8.89 +
    8.90 +  // Set up command line parameters used to control the experiment.
    8.91 +  CommandLine cmd;
    8.92 +  cmd.AddValue("distance", "Distance apart to place nodes (in meters).",
    8.93 +               distance);
    8.94 +  cmd.AddValue("format", "Format to use for data output.",
    8.95 +               format);
    8.96 +  cmd.AddValue("experiment", "Identifier for experiment.",
    8.97 +               experiment);
    8.98 +  cmd.AddValue("strategy", "Identifier for strategy.",
    8.99 +               strategy);
   8.100 +  cmd.AddValue("run", "Identifier for run.",
   8.101 +               runID);
   8.102 +  cmd.Parse (argc, argv);
   8.103 +
   8.104 +  if (format != "omnet" && format != "db") {
   8.105 +    NS_LOG_ERROR("Unknown output format '" << format << "'");
   8.106 +    return -1;
   8.107 +  }
   8.108 +
   8.109 +  #ifndef STATS_HAS_SQLITE3
   8.110 +  if (format == "db") {
   8.111 +      NS_LOG_ERROR("sqlite support not compiled in.");
   8.112 +      return -1;
   8.113 +  }
   8.114 +  #endif
   8.115 +
   8.116 +  {
   8.117 +  stringstream sstr("");
   8.118 +  sstr << distance;
   8.119 +  input = sstr.str();
   8.120 +  }
   8.121 +
   8.122 +
   8.123 +
   8.124 +
   8.125 +  //------------------------------------------------------------
   8.126 +  //-- Create nodes and network stacks
   8.127 +  //--------------------------------------------
   8.128 +  NS_LOG_INFO("Creating nodes.");
   8.129 +  NodeContainer nodes;
   8.130 +  nodes.Create(2);
   8.131 +
   8.132 +  NS_LOG_INFO("Installing WiFi and Internet stack.");
   8.133 +  WifiHelper wifi;
   8.134 +  wifi.SetMac("ns3::AdhocWifiMac");
   8.135 +  wifi.SetPhy("ns3::WifiPhy");
   8.136 +  NetDeviceContainer nodeDevices = wifi.Install(nodes);
   8.137 +
   8.138 +  InternetStackHelper internet;
   8.139 +  internet.Install(nodes);
   8.140 +  Ipv4AddressHelper ipAddrs;
   8.141 +  ipAddrs.SetBase("192.168.0.0", "255.255.255.0");
   8.142 +  ipAddrs.Assign(nodeDevices);
   8.143 +
   8.144 +
   8.145 +
   8.146 +
   8.147 +  //------------------------------------------------------------
   8.148 +  //-- Setup physical layout
   8.149 +  //--------------------------------------------
   8.150 +  NS_LOG_INFO("Installing static mobility; distance " << distance << " .");
   8.151 +  MobilityHelper mobility;
   8.152 +  Ptr<ListPositionAllocator> positionAlloc =
   8.153 +    CreateObject<ListPositionAllocator>();
   8.154 +  positionAlloc->Add(Vector(0.0, 0.0, 0.0));
   8.155 +  positionAlloc->Add(Vector(0.0, distance, 0.0));
   8.156 +  mobility.SetPositionAllocator(positionAlloc);
   8.157 +  mobility.Install(nodes);
   8.158 +
   8.159 +
   8.160 +
   8.161 +
   8.162 +  //------------------------------------------------------------
   8.163 +  //-- Create a custom traffic source and sink
   8.164 +  //--------------------------------------------
   8.165 +  NS_LOG_INFO ("Create traffic source & sink.");
   8.166 +  Ptr<Node> appSource = NodeList::GetNode(0);  
   8.167 +  Ptr<Sender> sender = CreateObject<Sender>();
   8.168 +  appSource->AddApplication(sender);
   8.169 +  sender->Start(Seconds(1));
   8.170 +
   8.171 +  Ptr<Node> appSink = NodeList::GetNode(1);  
   8.172 +  Ptr<Receiver> receiver = CreateObject<Receiver>();
   8.173 +  appSink->AddApplication(receiver);
   8.174 +  receiver->Start(Seconds(0));
   8.175 +
   8.176 +  //  Config::Set("/NodeList/*/ApplicationList/*/$Sender/Destination",
   8.177 +  //              Ipv4AddressValue("192.168.0.2"));
   8.178 +
   8.179 +
   8.180 +
   8.181 +
   8.182 +  //------------------------------------------------------------
   8.183 +  //-- Setup stats and data collection
   8.184 +  //--------------------------------------------
   8.185 +
   8.186 +  // Create a DataCollector object to hold information about this run.
   8.187 +  DataCollector data;
   8.188 +  data.DescribeRun(experiment,
   8.189 +                   strategy,
   8.190 +                   input,
   8.191 +                   runID);
   8.192 +
   8.193 +  // Add any information we wish to record about this run.
   8.194 +  data.AddMetadata("author", "tjkopena");
   8.195 +
   8.196 +
   8.197 +  // Create a counter to track how many frames are generated.  Updates
   8.198 +  // are triggered by the trace signal generated by the WiFi MAC model
   8.199 +  // object.  Here we connect the counter to the signal via the simple
   8.200 +  // TxCallback() glue function defined above.
   8.201 +  Ptr<CounterCalculator<uint32_t> > totalTx =
   8.202 +    CreateObject<CounterCalculator<uint32_t> >();
   8.203 +  totalTx->SetKey("wifi-tx-frames");
   8.204 +  Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Tx",
   8.205 +                  MakeBoundCallback(&TxCallback, totalTx));
   8.206 +  data.AddDataCalculator(totalTx);
   8.207 +
   8.208 +  // This is similar, but creates a counter to track how many frames
   8.209 +  // are received.  Instead of our own glue function, this uses a
   8.210 +  // method of an adapter class to connect a counter directly to the
   8.211 +  // trace signal generated by the WiFi MAC.
   8.212 +  Ptr<PacketCounterCalculator> totalRx =
   8.213 +    CreateObject<PacketCounterCalculator>();
   8.214 +  totalRx->SetKey("wifi-rx-frames");
   8.215 +  Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Rx",
   8.216 +                  MakeCallback(&PacketCounterCalculator::FrameUpdate,
   8.217 +                                    totalRx));
   8.218 +  data.AddDataCalculator(totalRx);
   8.219 +
   8.220 +
   8.221 +
   8.222 +
   8.223 +  // This counter tracks how many packets---as opposed to frames---are
   8.224 +  // generated.  This is connected directly to a trace signal provided
   8.225 +  // by our Sender class.
   8.226 +  Ptr<PacketCounterCalculator> appTx =
   8.227 +    CreateObject<PacketCounterCalculator>();
   8.228 +  appTx->SetKey("sender-tx-packets");
   8.229 +  Config::Connect("/NodeList/0/ApplicationList/*/$Sender/Tx",
   8.230 +                  MakeCallback(&PacketCounterCalculator::PacketUpdate,
   8.231 +                                    appTx));
   8.232 +  data.AddDataCalculator(appTx);
   8.233 +
   8.234 +  // Here a counter for received packets is directly manipulated by
   8.235 +  // one of the custom objects in our simulation, the Receiver
   8.236 +  // Application.  The Receiver object is given a pointer to the
   8.237 +  // counter and calls its Update() method whenever a packet arrives.
   8.238 +  Ptr<CounterCalculator<> > appRx =
   8.239 +    CreateObject<CounterCalculator<> >();
   8.240 +  appRx->SetKey("receiver-rx-packets");
   8.241 +  receiver->SetCounter(appRx);
   8.242 +  data.AddDataCalculator(appRx);
   8.243 +
   8.244 +
   8.245 +
   8.246 +
   8.247 +  /**
   8.248 +   * Just to show this is here...
   8.249 +   Ptr<MinMaxAvgTotalCalculator<uint32_t> > test = 
   8.250 +   CreateObject<MinMaxAvgTotalCalculator<uint32_t> >();
   8.251 +   test->SetKey("test-dc");
   8.252 +   data.AddDataCalculator(test);
   8.253 +
   8.254 +   test->Update(4);
   8.255 +   test->Update(8);
   8.256 +   test->Update(24);
   8.257 +   test->Update(12);
   8.258 +  **/
   8.259 +
   8.260 +  // This DataCalculator connects directly to the transmit trace
   8.261 +  // provided by our Sender Application.  It records some basic
   8.262 +  // statistics about the sizes of the packets received (min, max,
   8.263 +  // avg, total # bytes), although in this scenaro they're fixed.
   8.264 +  Ptr<PacketSizeMinMaxAvgTotalCalculator> appTxPkts =
   8.265 +    CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
   8.266 +  appTxPkts->SetKey("tx-pkt-size");
   8.267 +  Config::Connect("/NodeList/0/ApplicationList/*/$Sender/Tx",
   8.268 +                  MakeCallback
   8.269 +                    (&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate,
   8.270 +                    appTxPkts));
   8.271 +  data.AddDataCalculator(appTxPkts);
   8.272 +
   8.273 +
   8.274 +  // Here we directly manipulate another DataCollector tracking min,
   8.275 +  // max, total, and average propagation delays.  Check out the Sender
   8.276 +  // and Receiver classes to see how packets are tagged with
   8.277 +  // timestamps to do this.
   8.278 +  Ptr<TimeMinMaxAvgTotalCalculator> delayStat =
   8.279 +    CreateObject<TimeMinMaxAvgTotalCalculator>();
   8.280 +  delayStat->SetKey("delay");
   8.281 +  receiver->SetDelayTracker(delayStat);
   8.282 +  data.AddDataCalculator(delayStat);
   8.283 +
   8.284 +
   8.285 +
   8.286 +
   8.287 +  //------------------------------------------------------------
   8.288 +  //-- Run the simulation
   8.289 +  //--------------------------------------------
   8.290 +  NS_LOG_INFO("Run Simulation.");
   8.291 +  Simulator::Run();    
   8.292 +  Simulator::Destroy();
   8.293 +
   8.294 +
   8.295 +
   8.296 +
   8.297 +  //------------------------------------------------------------
   8.298 +  //-- Generate statistics output.
   8.299 +  //--------------------------------------------
   8.300 +
   8.301 +  // Pick an output writer based in the requested format.
   8.302 +  Ptr<DataOutputInterface> output = 0;
   8.303 +  if (format == "omnet") {
   8.304 +    NS_LOG_INFO("Creating omnet formatted data output.");
   8.305 +    output = CreateObject<OmnetDataOutput>();
   8.306 +  } else if (format == "db") {
   8.307 +    #ifdef STATS_HAS_SQLITE3
   8.308 +      NS_LOG_INFO("Creating sqlite formatted data output.");
   8.309 +      output = CreateObject<SqliteDataOutput>();
   8.310 +    #endif
   8.311 +  } else {
   8.312 +    NS_LOG_ERROR("Unknown output format " << format);
   8.313 +  }
   8.314 +
   8.315 +  // Finally, have that writer interrogate the DataCollector and save
   8.316 +  // the results.
   8.317 +  if (output != 0)
   8.318 +    output->Output(data);
   8.319 +
   8.320 +  // end main
   8.321 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/examples/stats/wifi-example.gnuplot	Fri Aug 29 13:22:09 2008 -0400
     9.3 @@ -0,0 +1,13 @@
     9.4 +set terminal postscript portrait enhanced lw 2 "Helvetica" 14
     9.5 +
     9.6 +set size 1.0, 0.66
     9.7 +
     9.8 +#-------------------------------------------------------
     9.9 +set out "wifi-default.eps"
    9.10 +#set title "Packet Loss Over Distance"
    9.11 +set xlabel "Distance (m)"
    9.12 +set xrange [0:200]
    9.13 +set ylabel "% Packet Loss --- average of 5 trials per distance"
    9.14 +set yrange [0:110]
    9.15 +
    9.16 +plot "wifi-default.data" with lines title "WiFi Defaults"
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/examples/stats/wscript	Fri Aug 29 13:22:09 2008 -0400
    10.3 @@ -0,0 +1,6 @@
    10.4 +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
    10.5 +
    10.6 +def build(bld):
    10.7 +    obj = bld.create_ns3_program('wifi-example-sim', ['stats'])
    10.8 +    obj.source = ['wifi-example-sim.cc',
    10.9 +                  'wifi-example-apps.cc']
    11.1 --- a/examples/wscript	Fri Aug 29 14:56:24 2008 +0100
    11.2 +++ b/examples/wscript	Fri Aug 29 13:22:09 2008 -0400
    11.3 @@ -76,4 +76,4 @@
    11.4                                   ['core', 'simulator', 'mobility', 'wifi'])
    11.5      obj.source = 'wifi-ap.cc'
    11.6  
    11.7 -
    11.8 +    bld.add_subdirs('stats')
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/contrib/stats/basic-data-calculators.h	Fri Aug 29 13:22:09 2008 -0400
    12.3 @@ -0,0 +1,189 @@
    12.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    12.5 +/*
    12.6 + * Copyright (c) 2008 Drexel University
    12.7 + *
    12.8 + * This program is free software; you can redistribute it and/or modify
    12.9 + * it under the terms of the GNU General Public License version 2 as
   12.10 + * published by the Free Software Foundation;
   12.11 + *
   12.12 + * This program is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU General Public License
   12.18 + * along with this program; if not, write to the Free Software
   12.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.20 + *
   12.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   12.22 + */
   12.23 +
   12.24 +#ifndef __BASIC_DATA_CALCULATORS_H__
   12.25 +#define __BASIC_DATA_CALCULATORS_H__
   12.26 +
   12.27 +#include "data-calculator.h"
   12.28 +#include "data-output-interface.h"
   12.29 +
   12.30 +namespace ns3 {
   12.31 +
   12.32 +  //------------------------------------------------------------
   12.33 +  //--------------------------------------------
   12.34 +  template <typename T  = uint32_t>
   12.35 +  class MinMaxAvgTotalCalculator : public DataCalculator {
   12.36 +  public:
   12.37 +    MinMaxAvgTotalCalculator();
   12.38 +    virtual ~MinMaxAvgTotalCalculator();
   12.39 +
   12.40 +    void Update(const T i);
   12.41 +
   12.42 +    virtual void Output(DataOutputCallback &callback) const;
   12.43 +
   12.44 +  protected:
   12.45 +    virtual void DoDispose(void);
   12.46 +
   12.47 +    uint32_t m_count;
   12.48 +    T m_total, m_min, m_max;
   12.49 +
   12.50 +    // end MinMaxAvgTotalCalculator
   12.51 +  };
   12.52 +
   12.53 +  //----------------------------------------------
   12.54 +  template <typename T>
   12.55 +  MinMaxAvgTotalCalculator<T>::MinMaxAvgTotalCalculator()
   12.56 +  {
   12.57 +    m_count = 0;
   12.58 +    m_total = 0;
   12.59 +    m_min = ~0;
   12.60 +    m_max = 0;
   12.61 +  }
   12.62 +
   12.63 +  template <typename T>
   12.64 +  MinMaxAvgTotalCalculator<T>::~MinMaxAvgTotalCalculator()
   12.65 +  {
   12.66 +  }
   12.67 +  template <typename T>
   12.68 +  void
   12.69 +  MinMaxAvgTotalCalculator<T>::DoDispose(void)
   12.70 +  {
   12.71 +    DataCalculator::DoDispose();
   12.72 +    // MinMaxAvgTotalCalculator::DoDispose
   12.73 +  }
   12.74 +
   12.75 +  template <typename T>
   12.76 +  void
   12.77 +  MinMaxAvgTotalCalculator<T>::Update(const T i)
   12.78 +  {
   12.79 +    if (m_enabled) {
   12.80 +      m_total += i;
   12.81 +
   12.82 +      if (i < m_min)
   12.83 +        m_min = i;
   12.84 +
   12.85 +      if (i > m_max)
   12.86 +        m_max = i;
   12.87 +
   12.88 +      m_count++;
   12.89 +    }
   12.90 +    // end MinMaxAvgTotalCalculator::Update
   12.91 +  }
   12.92 +  template <typename T>
   12.93 +  void
   12.94 +  MinMaxAvgTotalCalculator<T>::Output(DataOutputCallback &callback) const
   12.95 +  {
   12.96 +    callback.OutputSingleton(m_key, "count", m_count);
   12.97 +    if (m_count > 0) {
   12.98 +      callback.OutputSingleton(m_key, "total", m_total);
   12.99 +      callback.OutputSingleton(m_key, "average", m_total/m_count);
  12.100 +      callback.OutputSingleton(m_key, "max", m_max);
  12.101 +      callback.OutputSingleton(m_key, "min", m_min);
  12.102 +    }
  12.103 +    // end MinMaxAvgTotalCalculator::Output
  12.104 +  }
  12.105 +
  12.106 +
  12.107 +
  12.108 +
  12.109 +  //------------------------------------------------------------
  12.110 +  //--------------------------------------------
  12.111 +  template <typename T  = uint32_t>
  12.112 +  class CounterCalculator : public DataCalculator {
  12.113 +  public:
  12.114 +    CounterCalculator();
  12.115 +    virtual ~CounterCalculator();
  12.116 +
  12.117 +    void Update();
  12.118 +    void Update(const T i);
  12.119 +
  12.120 +    T GetCount() const;
  12.121 +
  12.122 +    virtual void Output(DataOutputCallback &callback) const;
  12.123 +
  12.124 +  protected:
  12.125 +    virtual void DoDispose(void);
  12.126 +
  12.127 +    T m_count;
  12.128 +
  12.129 +    // end CounterCalculator
  12.130 +  };
  12.131 +
  12.132 +
  12.133 +  //--------------------------------------------
  12.134 +  template <typename T>
  12.135 +  CounterCalculator<T>::CounterCalculator() :
  12.136 +    m_count(0)
  12.137 +  {
  12.138 +  }
  12.139 +
  12.140 +  template <typename T>
  12.141 +  CounterCalculator<T>::~CounterCalculator()
  12.142 +  {
  12.143 +  }
  12.144 +  template <typename T>
  12.145 +  void
  12.146 +  CounterCalculator<T>::DoDispose(void)
  12.147 +  {
  12.148 +    DataCalculator::DoDispose();
  12.149 +    // CounterCalculator::DoDispose
  12.150 +  }
  12.151 +
  12.152 +  template <typename T>
  12.153 +  void
  12.154 +  CounterCalculator<T>::Update()
  12.155 +  {
  12.156 +    if (m_enabled) {
  12.157 +      m_count++;
  12.158 +    }
  12.159 +    // end CounterCalculator::Update
  12.160 +  }
  12.161 +
  12.162 +  template <typename T>
  12.163 +  void
  12.164 +  CounterCalculator<T>::Update(const T i)
  12.165 +  {
  12.166 +    if (m_enabled) {
  12.167 +      m_count += i;
  12.168 +    }
  12.169 +    // end CounterCalculator::Update
  12.170 +  }
  12.171 +
  12.172 +  template <typename T>
  12.173 +  T
  12.174 +  CounterCalculator<T>::GetCount() const
  12.175 +  {
  12.176 +    return m_count;
  12.177 +    // end CounterCalculator::GetCount
  12.178 +  }
  12.179 +
  12.180 +  template <typename T>
  12.181 +  void
  12.182 +  CounterCalculator<T>::Output(DataOutputCallback &callback) const
  12.183 +  {
  12.184 +    callback.OutputSingleton(m_key, "count", m_count);
  12.185 +    // end CounterCalculator::Output
  12.186 +  }
  12.187 +
  12.188 +  // end namespace ns3
  12.189 +};
  12.190 +
  12.191 +
  12.192 +#endif // __BASIC_DATA_CALCULATORS_H__
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/contrib/stats/data-calculator.cc	Fri Aug 29 13:22:09 2008 -0400
    13.3 @@ -0,0 +1,110 @@
    13.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    13.5 +/*
    13.6 + * Copyright (c) 2008 Drexel University
    13.7 + *
    13.8 + * This program is free software; you can redistribute it and/or modify
    13.9 + * it under the terms of the GNU General Public License version 2 as
   13.10 + * published by the Free Software Foundation;
   13.11 + *
   13.12 + * This program is distributed in the hope that it will be useful,
   13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 + * GNU General Public License for more details.
   13.16 + *
   13.17 + * You should have received a copy of the GNU General Public License
   13.18 + * along with this program; if not, write to the Free Software
   13.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.20 + *
   13.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   13.22 + */
   13.23 +
   13.24 +#include "ns3/log.h"
   13.25 +#include "ns3/simulator.h"
   13.26 +
   13.27 +#include "data-calculator.h"
   13.28 +
   13.29 +using namespace ns3;
   13.30 +
   13.31 +NS_LOG_COMPONENT_DEFINE("DataCalculator");
   13.32 +
   13.33 +
   13.34 +//--------------------------------------------------------------
   13.35 +//----------------------------------------------
   13.36 +DataCalculator::DataCalculator() :
   13.37 +  m_enabled(true)
   13.38 +{
   13.39 +  NS_LOG_FUNCTION_NOARGS();
   13.40 +}
   13.41 +
   13.42 +DataCalculator::~DataCalculator()
   13.43 +{
   13.44 +  NS_LOG_FUNCTION_NOARGS();
   13.45 +}
   13.46 +
   13.47 +void
   13.48 +DataCalculator::DoDispose(void)
   13.49 +{
   13.50 +  NS_LOG_FUNCTION_NOARGS();
   13.51 +
   13.52 +  Simulator::Cancel(m_startEvent);
   13.53 +  Simulator::Cancel(m_stopEvent);
   13.54 +
   13.55 +  Object::DoDispose();
   13.56 +  // DataCalculator::DoDispose
   13.57 +}
   13.58 +
   13.59 +//----------------------------------------------
   13.60 +void
   13.61 +DataCalculator::SetKey(const std::string key)
   13.62 +{
   13.63 +  m_key = key;
   13.64 +  // end DataCalculator::SetKey
   13.65 +}
   13.66 +
   13.67 +const std::string
   13.68 +DataCalculator::GetKey() const
   13.69 +{
   13.70 +  return m_key;
   13.71 +  // end DataCalculator::GetKey
   13.72 +}
   13.73 +
   13.74 +//----------------------------------------------
   13.75 +void
   13.76 +DataCalculator::Enable()
   13.77 +{
   13.78 +  m_enabled = true;
   13.79 +  // end DataCalculator::Enable
   13.80 +}
   13.81 +
   13.82 +void
   13.83 +DataCalculator::Disable()
   13.84 +{
   13.85 +  m_enabled = false;
   13.86 +  // end DataCalculator::Disable
   13.87 +}
   13.88 +
   13.89 +bool
   13.90 +DataCalculator::GetEnabled() const
   13.91 +{
   13.92 +  return m_enabled;
   13.93 +  // end DataCalculator::GetEnabled
   13.94 +}
   13.95 +
   13.96 +//----------------------------------------------
   13.97 +void
   13.98 +DataCalculator::Start(const Time& startTime)
   13.99 +{
  13.100 +
  13.101 +  m_startEvent = Simulator::Schedule(startTime,
  13.102 +                                     &DataCalculator::Enable, this);
  13.103 +
  13.104 +  // end DataCalculator::Start
  13.105 +}
  13.106 +
  13.107 +void
  13.108 +DataCalculator::Stop(const Time& stopTime)
  13.109 +{
  13.110 +  m_stopEvent = Simulator::Schedule(stopTime,
  13.111 +                                    &DataCalculator::Disable, this);
  13.112 +  // end DataCalculator::Stop
  13.113 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/contrib/stats/data-calculator.h	Fri Aug 29 13:22:09 2008 -0400
    14.3 @@ -0,0 +1,70 @@
    14.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    14.5 +/*
    14.6 + * Copyright (c) 2008 Drexel University
    14.7 + *
    14.8 + * This program is free software; you can redistribute it and/or modify
    14.9 + * it under the terms of the GNU General Public License version 2 as
   14.10 + * published by the Free Software Foundation;
   14.11 + *
   14.12 + * This program is distributed in the hope that it will be useful,
   14.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.15 + * GNU General Public License for more details.
   14.16 + *
   14.17 + * You should have received a copy of the GNU General Public License
   14.18 + * along with this program; if not, write to the Free Software
   14.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.20 + *
   14.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   14.22 + */
   14.23 +
   14.24 +#ifndef __DATA_CALCULATOR_H__
   14.25 +#define __DATA_CALCULATOR_H__
   14.26 +
   14.27 +#include "ns3/object.h"
   14.28 +#include "ns3/nstime.h"
   14.29 +#include "ns3/simulator.h"
   14.30 +
   14.31 +namespace ns3 {
   14.32 +
   14.33 +  class DataOutputCallback;
   14.34 +
   14.35 +  //------------------------------------------------------------
   14.36 +  //--------------------------------------------
   14.37 +  class DataCalculator : public Object {
   14.38 +  public:
   14.39 +    DataCalculator();
   14.40 +    virtual ~DataCalculator();
   14.41 +
   14.42 +    bool GetEnabled() const;
   14.43 +    void Enable();
   14.44 +    void Disable();
   14.45 +
   14.46 +    void SetKey(const std::string key);
   14.47 +    const std::string GetKey() const;
   14.48 +
   14.49 +    virtual void Start(const Time& startTime);
   14.50 +    virtual void Stop(const Time& stopTime);
   14.51 +
   14.52 +    virtual void Output(DataOutputCallback &callback) const = 0;
   14.53 +
   14.54 +  protected:
   14.55 +    bool m_enabled;  // Descendant classes *must* check & respect m_enabled!
   14.56 +
   14.57 +    std::string m_key;
   14.58 +
   14.59 +    virtual void DoDispose(void);
   14.60 +
   14.61 +  private:
   14.62 +    EventId m_startEvent;
   14.63 +    EventId m_stopEvent;
   14.64 +
   14.65 +    // end class DataCalculator
   14.66 +  };
   14.67 +
   14.68 +
   14.69 +  // end namespace ns3
   14.70 +};
   14.71 +
   14.72 +
   14.73 +#endif // __DATA_CALCULATOR_H__
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/contrib/stats/data-collector.cc	Fri Aug 29 13:22:09 2008 -0400
    15.3 @@ -0,0 +1,131 @@
    15.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    15.5 +/*
    15.6 + * Copyright (c) 2008 Drexel University
    15.7 + *
    15.8 + * This program is free software; you can redistribute it and/or modify
    15.9 + * it under the terms of the GNU General Public License version 2 as
   15.10 + * published by the Free Software Foundation;
   15.11 + *
   15.12 + * This program is distributed in the hope that it will be useful,
   15.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 + * GNU General Public License for more details.
   15.16 + *
   15.17 + * You should have received a copy of the GNU General Public License
   15.18 + * along with this program; if not, write to the Free Software
   15.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.20 + *
   15.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   15.22 + */
   15.23 +
   15.24 +#include "ns3/object.h"
   15.25 +#include "ns3/log.h"
   15.26 +
   15.27 +#include "data-collector.h"
   15.28 +#include "data-calculator.h"
   15.29 +
   15.30 +using namespace ns3;
   15.31 +
   15.32 +NS_LOG_COMPONENT_DEFINE("DataCollector");
   15.33 +
   15.34 +//--------------------------------------------------------------
   15.35 +//----------------------------------------------
   15.36 +DataCollector::DataCollector() {
   15.37 +  NS_LOG_FUNCTION_NOARGS();
   15.38 +  // end DataCollector::DataCollector
   15.39 +}
   15.40 +
   15.41 +DataCollector::~DataCollector() {
   15.42 +  NS_LOG_FUNCTION_NOARGS();
   15.43 +  // end DataCollector::~DataCollector
   15.44 +}
   15.45 +
   15.46 +void DataCollector::DoDispose() {
   15.47 +  NS_LOG_FUNCTION_NOARGS();
   15.48 +
   15.49 +  m_calcList.clear();
   15.50 +  m_metadata.clear();
   15.51 +
   15.52 +  Object::DoDispose();
   15.53 +  // end DataCollector::DoDispose
   15.54 +}
   15.55 +
   15.56 +void
   15.57 +DataCollector::DescribeRun(std::string experiment,
   15.58 +                           std::string strategy,
   15.59 +                           std::string input,
   15.60 +                           std::string runID,
   15.61 +                           std::string description)
   15.62 +{
   15.63 +
   15.64 +  m_experimentLabel = experiment;
   15.65 +  m_strategyLabel = strategy;
   15.66 +  m_inputLabel = input;
   15.67 +  m_runLabel = runID;
   15.68 +  m_description = description;
   15.69 +
   15.70 +  // end DataCollector::DescribeRun
   15.71 +}
   15.72 +
   15.73 +void
   15.74 +DataCollector::AddDataCalculator(Ptr<DataCalculator> datac)
   15.75 +{
   15.76 +
   15.77 +  m_calcList.push_back(datac);
   15.78 +
   15.79 +  // end DataCollector::AddDataCalculator
   15.80 +}
   15.81 +
   15.82 +DataCalculatorList::iterator
   15.83 +DataCollector::DataCalculatorBegin()
   15.84 +{
   15.85 +  return m_calcList.begin();
   15.86 +  // end DataCollector::DataCalculatorBegin
   15.87 +}
   15.88 +DataCalculatorList::iterator
   15.89 +DataCollector::DataCalculatorEnd()
   15.90 +{
   15.91 +  return m_calcList.end();
   15.92 +  // end DataCollector::DataCalculatorEnd
   15.93 +}
   15.94 +
   15.95 +void
   15.96 +DataCollector::AddMetadata(std::string key, std::string value)
   15.97 +{
   15.98 +  std::pair<std::string, std::string> blob(key, value);
   15.99 +  m_metadata.push_back(blob);
  15.100 +  // end DataCollector::AddMetadata
  15.101 +}
  15.102 +void
  15.103 +DataCollector::AddMetadata(std::string key, uint32_t value)
  15.104 +{
  15.105 +  std::stringstream st;
  15.106 +  st << value;
  15.107 +
  15.108 +  std::pair<std::string, std::string> blob(key, st.str());
  15.109 +  m_metadata.push_back(blob);
  15.110 +  // end DataCollector::AddMetadata
  15.111 +}
  15.112 +void
  15.113 +DataCollector::AddMetadata(std::string key, double value)
  15.114 +{
  15.115 +  std::stringstream st;
  15.116 +  st << value;
  15.117 +
  15.118 +  std::pair<std::string, std::string> blob(key, st.str());
  15.119 +  m_metadata.push_back(blob);
  15.120 +  // end DataCollector::AddMetadata
  15.121 +}
  15.122 +
  15.123 +MetadataList::iterator
  15.124 +DataCollector::MetadataBegin()
  15.125 +{
  15.126 +  return m_metadata.begin();
  15.127 +  // end DataCollector::MetadataBegin
  15.128 +}
  15.129 +MetadataList::iterator
  15.130 +DataCollector::MetadataEnd()
  15.131 +{
  15.132 +  return m_metadata.end();
  15.133 +  // end DataCollector::MetadataEnd
  15.134 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/contrib/stats/data-collector.h	Fri Aug 29 13:22:09 2008 -0400
    16.3 @@ -0,0 +1,84 @@
    16.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    16.5 +/*
    16.6 + * Copyright (c) 2008 Drexel University
    16.7 + *
    16.8 + * This program is free software; you can redistribute it and/or modify
    16.9 + * it under the terms of the GNU General Public License version 2 as
   16.10 + * published by the Free Software Foundation;
   16.11 + *
   16.12 + * This program is distributed in the hope that it will be useful,
   16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.15 + * GNU General Public License for more details.
   16.16 + *
   16.17 + * You should have received a copy of the GNU General Public License
   16.18 + * along with this program; if not, write to the Free Software
   16.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.20 + *
   16.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   16.22 + */
   16.23 +
   16.24 +#ifndef __DATA_COLLECTOR_H__
   16.25 +#define __DATA_COLLECTOR_H__
   16.26 +
   16.27 +#include <list>
   16.28 +#include <string>
   16.29 +
   16.30 +#include "ns3/object.h"
   16.31 +
   16.32 +namespace ns3 {
   16.33 +
   16.34 +  class DataCalculator;
   16.35 +
   16.36 +  //------------------------------------------------------------
   16.37 +  //--------------------------------------------
   16.38 +  typedef std::list<Ptr<DataCalculator> > DataCalculatorList;
   16.39 +  typedef std::list<std::pair<std::string, std::string> > MetadataList;
   16.40 +
   16.41 +  class DataCollector : public Object {
   16.42 +  public:
   16.43 +    DataCollector();
   16.44 +    virtual ~DataCollector();
   16.45 +
   16.46 +    void DescribeRun(std::string experiment,
   16.47 +                     std::string strategy,
   16.48 +                     std::string input,
   16.49 +                     std::string runID,
   16.50 +                     std::string description = "");
   16.51 +
   16.52 +    std::string GetExperimentLabel() const { return m_experimentLabel; }
   16.53 +    std::string GetStrategyLabel() const { return m_strategyLabel; }
   16.54 +    std::string GetInputLabel() const { return m_inputLabel; }
   16.55 +    std::string GetRunLabel() const { return m_runLabel; }
   16.56 +    std::string GetDescription() const { return m_description; }
   16.57 +
   16.58 +    void AddMetadata(std::string key, std::string value);
   16.59 +    void AddMetadata(std::string key, double value);
   16.60 +    void AddMetadata(std::string key, uint32_t value);
   16.61 +    MetadataList::iterator MetadataBegin();
   16.62 +    MetadataList::iterator MetadataEnd();
   16.63 +
   16.64 +    void AddDataCalculator(Ptr<DataCalculator> datac);
   16.65 +    DataCalculatorList::iterator DataCalculatorBegin();
   16.66 +    DataCalculatorList::iterator DataCalculatorEnd();
   16.67 +
   16.68 +  protected:
   16.69 +    virtual void DoDispose();
   16.70 +
   16.71 +  private:
   16.72 +    std::string m_experimentLabel;
   16.73 +    std::string m_strategyLabel;
   16.74 +    std::string m_inputLabel;
   16.75 +    std::string m_runLabel;
   16.76 +    std::string m_description;
   16.77 +
   16.78 +    MetadataList m_metadata;
   16.79 +    DataCalculatorList m_calcList;
   16.80 +
   16.81 +    // end class DataCollector
   16.82 +  };
   16.83 +
   16.84 +  // end namespace ns3
   16.85 +};
   16.86 +
   16.87 +#endif // __DATA_COLLECTOR_H__
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/src/contrib/stats/data-output-interface.cc	Fri Aug 29 13:22:09 2008 -0400
    17.3 @@ -0,0 +1,47 @@
    17.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    17.5 +/*
    17.6 + * Copyright (c) 2008 Drexel University
    17.7 + *
    17.8 + * This program is free software; you can redistribute it and/or modify
    17.9 + * it under the terms of the GNU General Public License version 2 as
   17.10 + * published by the Free Software Foundation;
   17.11 + *
   17.12 + * This program is distributed in the hope that it will be useful,
   17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.15 + * GNU General Public License for more details.
   17.16 + *
   17.17 + * You should have received a copy of the GNU General Public License
   17.18 + * along with this program; if not, write to the Free Software
   17.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.20 + *
   17.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   17.22 + */
   17.23 +
   17.24 +#include "ns3/log.h"
   17.25 +
   17.26 +#include "data-output-interface.h"
   17.27 +
   17.28 +using namespace ns3;
   17.29 +
   17.30 +NS_LOG_COMPONENT_DEFINE("DataOutputInterface");
   17.31 +
   17.32 +
   17.33 +//--------------------------------------------------------------
   17.34 +//----------------------------------------------
   17.35 +DataOutputInterface::DataOutputInterface()
   17.36 +{
   17.37 +  NS_LOG_FUNCTION_NOARGS();
   17.38 +}
   17.39 +DataOutputInterface::~DataOutputInterface()
   17.40 +{
   17.41 +  NS_LOG_FUNCTION_NOARGS();
   17.42 +}
   17.43 +void
   17.44 +DataOutputInterface::DoDispose()
   17.45 +{
   17.46 +  NS_LOG_FUNCTION_NOARGS();
   17.47 +
   17.48 +  Object::DoDispose();
   17.49 +  // end DataOutputInterface::DoDispose
   17.50 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/contrib/stats/data-output-interface.h	Fri Aug 29 13:22:09 2008 -0400
    18.3 @@ -0,0 +1,76 @@
    18.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    18.5 +/*
    18.6 + * Copyright (c) 2008 Drexel University
    18.7 + *
    18.8 + * This program is free software; you can redistribute it and/or modify
    18.9 + * it under the terms of the GNU General Public License version 2 as
   18.10 + * published by the Free Software Foundation;
   18.11 + *
   18.12 + * This program is distributed in the hope that it will be useful,
   18.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.15 + * GNU General Public License for more details.
   18.16 + *
   18.17 + * You should have received a copy of the GNU General Public License
   18.18 + * along with this program; if not, write to the Free Software
   18.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.20 + *
   18.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   18.22 + */
   18.23 +
   18.24 +#ifndef __DATA_OUTPUT_INTERFACE_H__
   18.25 +#define __DATA_OUTPUT_INTERFACE_H__
   18.26 +
   18.27 +#include "ns3/object.h"
   18.28 +#include "ns3/nstime.h"
   18.29 +
   18.30 +namespace ns3 {
   18.31 +
   18.32 +  class DataCollector;
   18.33 +
   18.34 +  //------------------------------------------------------------
   18.35 +  //--------------------------------------------
   18.36 +  class DataOutputInterface : public Object {
   18.37 +  public:
   18.38 +    DataOutputInterface();
   18.39 +    virtual ~DataOutputInterface();
   18.40 +
   18.41 +    virtual void Output(DataCollector &dc) = 0;
   18.42 +
   18.43 +  protected:
   18.44 +    virtual void DoDispose();
   18.45 +
   18.46 +    // end class DataOutputInterface
   18.47 +  };
   18.48 +
   18.49 +  class DataOutputCallback {
   18.50 +  public:
   18.51 +    virtual ~DataOutputCallback() {}
   18.52 +
   18.53 +    virtual void OutputSingleton(std::string key,
   18.54 +                                 std::string variable,
   18.55 +                                 int val) = 0;
   18.56 +
   18.57 +    virtual void OutputSingleton(std::string key,
   18.58 +                                 std::string variable,
   18.59 +                                 uint32_t val) = 0;
   18.60 +
   18.61 +    virtual void OutputSingleton(std::string key,
   18.62 +                                 std::string variable,
   18.63 +                                 double val) = 0;
   18.64 +
   18.65 +    virtual void OutputSingleton(std::string key,
   18.66 +                                 std::string variable,
   18.67 +                                 std::string val) = 0;
   18.68 +
   18.69 +    virtual void OutputSingleton(std::string key,
   18.70 +                                 std::string variable,
   18.71 +                                 Time val) = 0;
   18.72 +    // end class DataOutputCallback
   18.73 +  };
   18.74 +
   18.75 +  // end namespace ns3
   18.76 +};
   18.77 +
   18.78 +
   18.79 +#endif // __DATA_OUTPUT_INTERFACE_H__
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/contrib/stats/omnet-data-output.cc	Fri Aug 29 13:22:09 2008 -0400
    19.3 @@ -0,0 +1,155 @@
    19.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    19.5 +/*
    19.6 + * Copyright (c) 2008 Drexel University
    19.7 + *
    19.8 + * This program is free software; you can redistribute it and/or modify
    19.9 + * it under the terms of the GNU General Public License version 2 as
   19.10 + * published by the Free Software Foundation;
   19.11 + *
   19.12 + * This program is distributed in the hope that it will be useful,
   19.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.15 + * GNU General Public License for more details.
   19.16 + *
   19.17 + * You should have received a copy of the GNU General Public License
   19.18 + * along with this program; if not, write to the Free Software
   19.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.20 + *
   19.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   19.22 + */
   19.23 +
   19.24 +#include <fstream>
   19.25 +
   19.26 +#include "ns3/log.h"
   19.27 +#include "ns3/nstime.h"
   19.28 +
   19.29 +#include "data-collector.h"
   19.30 +#include "data-calculator.h"
   19.31 +#include "omnet-data-output.h"
   19.32 +
   19.33 +using namespace ns3;
   19.34 +
   19.35 +NS_LOG_COMPONENT_DEFINE("OmnetDataOutput");
   19.36 +
   19.37 +
   19.38 +//--------------------------------------------------------------
   19.39 +//----------------------------------------------
   19.40 +OmnetDataOutput::OmnetDataOutput() :
   19.41 +  m_filePrefix("data")
   19.42 +{
   19.43 +  NS_LOG_FUNCTION_NOARGS();
   19.44 +}
   19.45 +OmnetDataOutput::~OmnetDataOutput()
   19.46 +{
   19.47 +  NS_LOG_FUNCTION_NOARGS();
   19.48 +}
   19.49 +void
   19.50 +OmnetDataOutput::DoDispose()
   19.51 +{
   19.52 +  NS_LOG_FUNCTION_NOARGS();
   19.53 +
   19.54 +  DataOutputInterface::DoDispose();
   19.55 +  // end OmnetDataOutput::DoDispose
   19.56 +}
   19.57 +
   19.58 +void
   19.59 +OmnetDataOutput::SetFilePrefix(const std::string prefix)
   19.60 +{
   19.61 +  m_filePrefix = prefix;
   19.62 +}
   19.63 +std::string
   19.64 +OmnetDataOutput::GetFilePrefix() const
   19.65 +{
   19.66 +  return m_filePrefix;
   19.67 +}
   19.68 +
   19.69 +//----------------------------------------------
   19.70 +void
   19.71 +OmnetDataOutput::Output(DataCollector &dc)
   19.72 +{
   19.73 +
   19.74 +  std::ofstream scalarFile;
   19.75 +  std::string fn = m_filePrefix + ".sca";
   19.76 +  scalarFile.open(fn.c_str(), std::ios_base::app);
   19.77 +
   19.78 +  scalarFile << std::endl;
   19.79 +  scalarFile << "run " << dc.GetRunLabel() << std::endl;
   19.80 +  scalarFile << std::endl;
   19.81 +  scalarFile << "attr experiment \"" << dc.GetExperimentLabel()
   19.82 +            << "\"" << std::endl;
   19.83 +  scalarFile << "attr strategy \"" << dc.GetStrategyLabel()
   19.84 +            << "\"" << std::endl;
   19.85 +  scalarFile << "attr input \"" << dc.GetInputLabel()
   19.86 +            << "\"" << std::endl;
   19.87 +  scalarFile << "attr description \"" << dc.GetDescription()
   19.88 +            << "\"" << std::endl;
   19.89 +  scalarFile << std::endl;
   19.90 +
   19.91 +  for (MetadataList::iterator i = dc.MetadataBegin();
   19.92 +       i != dc.MetadataEnd(); i++) {
   19.93 +    std::pair<std::string, std::string> blob = (*i);
   19.94 +    scalarFile << "attr \"" << blob.first << "\" \"" << blob.second << "\""
   19.95 +               << std::endl;
   19.96 +  }
   19.97 +
   19.98 +  scalarFile << std::endl;
   19.99 +
  19.100 +  OmnetOutputCallback callback(&scalarFile);
  19.101 +
  19.102 +  for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
  19.103 +       i != dc.DataCalculatorEnd(); i++) {
  19.104 +    (*i)->Output(callback);
  19.105 +  }
  19.106 +
  19.107 +  scalarFile << std::endl << std::endl;
  19.108 +  scalarFile.close();
  19.109 +
  19.110 +  // end OmnetDataOutput::Output
  19.111 +}
  19.112 +
  19.113 +OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback
  19.114 +  (std::ostream *scalar) :
  19.115 +  m_scalar(scalar)
  19.116 +{
  19.117 +}
  19.118 +
  19.119 +void
  19.120 +OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key,
  19.121 +                                                      std::string variable,
  19.122 +                                                      int val)
  19.123 +{
  19.124 +  (*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl;
  19.125 +  // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
  19.126 +}
  19.127 +void
  19.128 +OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key,
  19.129 +                                                      std::string variable,
  19.130 +                                                      uint32_t val)
  19.131 +{
  19.132 +  (*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl;
  19.133 +  // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
  19.134 +}
  19.135 +void
  19.136 +OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key,
  19.137 +                                                      std::string variable,
  19.138 +                                                      double val)
  19.139 +{
  19.140 +  (*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl;
  19.141 +  // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
  19.142 +}
  19.143 +void
  19.144 +OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key,
  19.145 +                                                      std::string variable,
  19.146 +                                                      std::string val)
  19.147 +{
  19.148 +  (*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl;
  19.149 +  // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
  19.150 +}
  19.151 +void
  19.152 +OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key,
  19.153 +                                                      std::string variable,
  19.154 +                                                      Time val)
  19.155 +{
  19.156 +  (*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl;
  19.157 +  // end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
  19.158 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/contrib/stats/omnet-data-output.h	Fri Aug 29 13:22:09 2008 -0400
    20.3 @@ -0,0 +1,84 @@
    20.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    20.5 +/*
    20.6 + * Copyright (c) 2008 Drexel University
    20.7 + *
    20.8 + * This program is free software; you can redistribute it and/or modify
    20.9 + * it under the terms of the GNU General Public License version 2 as
   20.10 + * published by the Free Software Foundation;
   20.11 + *
   20.12 + * This program is distributed in the hope that it will be useful,
   20.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.15 + * GNU General Public License for more details.
   20.16 + *
   20.17 + * You should have received a copy of the GNU General Public License
   20.18 + * along with this program; if not, write to the Free Software
   20.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   20.20 + *
   20.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   20.22 + */
   20.23 +
   20.24 +#ifndef __OMNET_DATA_OUTPUT_H__
   20.25 +#define __OMNET_DATA_OUTPUT_H__
   20.26 +
   20.27 +#include "ns3/nstime.h"
   20.28 +
   20.29 +#include "data-output-interface.h"
   20.30 +
   20.31 +namespace ns3 {
   20.32 +
   20.33 +
   20.34 +  //------------------------------------------------------------
   20.35 +  //--------------------------------------------
   20.36 +  class OmnetDataOutput : public DataOutputInterface {
   20.37 +  public:
   20.38 +    OmnetDataOutput();
   20.39 +    virtual ~OmnetDataOutput();
   20.40 +
   20.41 +    virtual void Output(DataCollector &dc);
   20.42 +
   20.43 +    void SetFilePrefix(const std::string prefix);
   20.44 +    std::string GetFilePrefix() const;
   20.45 +
   20.46 +  protected:
   20.47 +    virtual void DoDispose();
   20.48 +
   20.49 +  private:
   20.50 +    class OmnetOutputCallback : public DataOutputCallback {
   20.51 +    public:
   20.52 +      OmnetOutputCallback(std::ostream *scalar);
   20.53 +
   20.54 +      void OutputSingleton(std::string key,
   20.55 +                           std::string variable,
   20.56 +                           int val);
   20.57 +
   20.58 +      void OutputSingleton(std::string key,
   20.59 +                           std::string variable,
   20.60 +                           uint32_t val);
   20.61 +
   20.62 +      void OutputSingleton(std::string key,
   20.63 +                           std::string variable,
   20.64 +                           double val);
   20.65 +
   20.66 +      void OutputSingleton(std::string key,
   20.67 +                           std::string variable,
   20.68 +                           std::string val);
   20.69 +
   20.70 +      void OutputSingleton(std::string key,
   20.71 +                           std::string variable,
   20.72 +                           Time val);
   20.73 +
   20.74 +    private:
   20.75 +      std::ostream *m_scalar;
   20.76 +      // end class OmnetOutputCallback
   20.77 +    };
   20.78 +
   20.79 +    std::string m_filePrefix;
   20.80 +    // end class OmnetDataOutput
   20.81 +  };
   20.82 +
   20.83 +  // end namespace ns3
   20.84 +};
   20.85 +
   20.86 +
   20.87 +#endif // __OMNET_DATA_OUTPUT_H__
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/src/contrib/stats/packet-data-calculators.cc	Fri Aug 29 13:22:09 2008 -0400
    21.3 @@ -0,0 +1,118 @@
    21.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    21.5 +/*
    21.6 + * Copyright (c) 2008 Drexel University
    21.7 + *
    21.8 + * This program is free software; you can redistribute it and/or modify
    21.9 + * it under the terms of the GNU General Public License version 2 as
   21.10 + * published by the Free Software Foundation;
   21.11 + *
   21.12 + * This program is distributed in the hope that it will be useful,
   21.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   21.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21.15 + * GNU General Public License for more details.
   21.16 + *
   21.17 + * You should have received a copy of the GNU General Public License
   21.18 + * along with this program; if not, write to the Free Software
   21.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21.20 + *
   21.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   21.22 + */
   21.23 +
   21.24 +#include "ns3/log.h"
   21.25 +#include "ns3/packet.h"
   21.26 +#include "ns3/mac48-address.h"
   21.27 +
   21.28 +#include "basic-data-calculators.h"
   21.29 +#include "packet-data-calculators.h"
   21.30 +
   21.31 +using namespace ns3;
   21.32 +
   21.33 +NS_LOG_COMPONENT_DEFINE("PacketDataCalculators");
   21.34 +
   21.35 +
   21.36 +//--------------------------------------------------------------
   21.37 +//----------------------------------------------
   21.38 +PacketCounterCalculator::PacketCounterCalculator()
   21.39 +{
   21.40 +  NS_LOG_FUNCTION_NOARGS();
   21.41 +}
   21.42 +
   21.43 +PacketCounterCalculator::~PacketCounterCalculator()
   21.44 +{
   21.45 +  NS_LOG_FUNCTION_NOARGS();
   21.46 +}
   21.47 +void
   21.48 +PacketCounterCalculator::DoDispose(void)
   21.49 +{
   21.50 +  NS_LOG_FUNCTION_NOARGS();
   21.51 +
   21.52 +  CounterCalculator<uint32_t>::DoDispose();
   21.53 +  // PacketCounterCalculator::DoDispose
   21.54 +}
   21.55 +
   21.56 +void
   21.57 +PacketCounterCalculator::PacketUpdate(std::string path,
   21.58 +                                      Ptr<const Packet> packet)
   21.59 +{
   21.60 +  NS_LOG_FUNCTION_NOARGS();
   21.61 +
   21.62 +  CounterCalculator<uint32_t>::Update();
   21.63 +
   21.64 +  // PacketCounterCalculator::Update
   21.65 +}
   21.66 +void
   21.67 +PacketCounterCalculator::FrameUpdate(std::string path,
   21.68 +                                     Ptr<const Packet> packet,
   21.69 +                                     Mac48Address realto)
   21.70 +{
   21.71 +  NS_LOG_FUNCTION_NOARGS();
   21.72 +
   21.73 +  CounterCalculator<uint32_t>::Update();
   21.74 +
   21.75 +  // PacketCounterCalculator::Update
   21.76 +}
   21.77 +
   21.78 +
   21.79 +
   21.80 +
   21.81 +//--------------------------------------------------------------
   21.82 +//----------------------------------------------
   21.83 +PacketSizeMinMaxAvgTotalCalculator::PacketSizeMinMaxAvgTotalCalculator()
   21.84 +{
   21.85 +  NS_LOG_FUNCTION_NOARGS();
   21.86 +}
   21.87 +
   21.88 +PacketSizeMinMaxAvgTotalCalculator::~PacketSizeMinMaxAvgTotalCalculator()
   21.89 +{
   21.90 +  NS_LOG_FUNCTION_NOARGS();
   21.91 +}
   21.92 +void
   21.93 +PacketSizeMinMaxAvgTotalCalculator::DoDispose(void)
   21.94 +{
   21.95 +  NS_LOG_FUNCTION_NOARGS();
   21.96 +
   21.97 +  MinMaxAvgTotalCalculator<uint32_t>::DoDispose();
   21.98 +  // end PacketSizeMinMaxAvgTotalCalculator::DoDispose
   21.99 +}
  21.100 +
  21.101 +void
  21.102 +PacketSizeMinMaxAvgTotalCalculator::PacketUpdate(std::string path,
  21.103 +                                      Ptr<const Packet> packet)
  21.104 +{
  21.105 +  NS_LOG_FUNCTION_NOARGS();
  21.106 +
  21.107 +  MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
  21.108 +
  21.109 +  // end PacketSizeMinMaxAvgTotalCalculator::Update
  21.110 +}
  21.111 +void
  21.112 +PacketSizeMinMaxAvgTotalCalculator::FrameUpdate(std::string path,
  21.113 +                                     Ptr<const Packet> packet,
  21.114 +                                     Mac48Address realto)
  21.115 +{
  21.116 +  NS_LOG_FUNCTION_NOARGS();
  21.117 +
  21.118 +  MinMaxAvgTotalCalculator<uint32_t>::Update(packet->GetSize());
  21.119 +
  21.120 +  // end PacketSizeMinMaxAvgTotalCalculator::Update
  21.121 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/contrib/stats/packet-data-calculators.h	Fri Aug 29 13:22:09 2008 -0400
    22.3 @@ -0,0 +1,68 @@
    22.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    22.5 +/*
    22.6 + * Copyright (c) 2008 Drexel University
    22.7 + *
    22.8 + * This program is free software; you can redistribute it and/or modify
    22.9 + * it under the terms of the GNU General Public License version 2 as
   22.10 + * published by the Free Software Foundation;
   22.11 + *
   22.12 + * This program is distributed in the hope that it will be useful,
   22.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   22.15 + * GNU General Public License for more details.
   22.16 + *
   22.17 + * You should have received a copy of the GNU General Public License
   22.18 + * along with this program; if not, write to the Free Software
   22.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22.20 + *
   22.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   22.22 + */
   22.23 +
   22.24 +#ifndef __PACKET_DATA_CALCULATORS_H__
   22.25 +#define __PACKET_DATA_CALCULATORS_H__
   22.26 +
   22.27 +#include "ns3/packet.h"
   22.28 +#include "ns3/mac48-address.h"
   22.29 +
   22.30 +#include "data-calculator.h"
   22.31 +
   22.32 +namespace ns3 {
   22.33 +
   22.34 +  class PacketCounterCalculator : public CounterCalculator<uint32_t> {
   22.35 +  public:
   22.36 +    PacketCounterCalculator();
   22.37 +    virtual ~PacketCounterCalculator();
   22.38 +
   22.39 +    void PacketUpdate(std::string path, Ptr<const Packet> packet);
   22.40 +    void FrameUpdate(std::string path, Ptr<const Packet> packet,
   22.41 +                     Mac48Address realto);
   22.42 +
   22.43 +  protected:
   22.44 +    virtual void DoDispose(void);
   22.45 +
   22.46 +    // end class PacketCounterCalculator
   22.47 +  };
   22.48 +
   22.49 +
   22.50 +  class PacketSizeMinMaxAvgTotalCalculator :
   22.51 +    public MinMaxAvgTotalCalculator<uint32_t> {
   22.52 +  public:
   22.53 +    PacketSizeMinMaxAvgTotalCalculator();
   22.54 +    virtual ~PacketSizeMinMaxAvgTotalCalculator();
   22.55 +
   22.56 +    void PacketUpdate(std::string path, Ptr<const Packet> packet);
   22.57 +    void FrameUpdate(std::string path, Ptr<const Packet> packet,
   22.58 +                     Mac48Address realto);
   22.59 +
   22.60 +  protected:
   22.61 +    virtual void DoDispose(void);
   22.62 +
   22.63 +    // end class PacketSizeMinMaxAvgTotalCalculator
   22.64 +  };
   22.65 +
   22.66 +
   22.67 +  // end namespace ns3
   22.68 +};
   22.69 +
   22.70 +
   22.71 +#endif // __PACKET_DATA_CALCULATORS_H__
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/contrib/stats/sqlite-data-output.cc	Fri Aug 29 13:22:09 2008 -0400
    23.3 @@ -0,0 +1,238 @@
    23.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    23.5 +/*
    23.6 + * Copyright (c) 2008 Drexel University
    23.7 + *
    23.8 + * This program is free software; you can redistribute it and/or modify
    23.9 + * it under the terms of the GNU General Public License version 2 as
   23.10 + * published by the Free Software Foundation;
   23.11 + *
   23.12 + * This program is distributed in the hope that it will be useful,
   23.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23.15 + * GNU General Public License for more details.
   23.16 + *
   23.17 + * You should have received a copy of the GNU General Public License
   23.18 + * along with this program; if not, write to the Free Software
   23.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.20 + *
   23.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   23.22 + */
   23.23 +
   23.24 +#include <sstream>
   23.25 +
   23.26 +#include <sqlite3.h>
   23.27 +
   23.28 +#include "ns3/log.h"
   23.29 +#include "ns3/nstime.h"
   23.30 +
   23.31 +#include "data-collector.h"
   23.32 +#include "data-calculator.h"
   23.33 +#include "sqlite-data-output.h"
   23.34 +
   23.35 +using namespace ns3;
   23.36 +
   23.37 +NS_LOG_COMPONENT_DEFINE("SqliteDataOutput");
   23.38 +
   23.39 +
   23.40 +//--------------------------------------------------------------
   23.41 +//----------------------------------------------
   23.42 +SqliteDataOutput::SqliteDataOutput() :
   23.43 +  m_dbFile("data.db")
   23.44 +{
   23.45 +  NS_LOG_FUNCTION_NOARGS();
   23.46 +}
   23.47 +SqliteDataOutput::~SqliteDataOutput()
   23.48 +{
   23.49 +  NS_LOG_FUNCTION_NOARGS();
   23.50 +}
   23.51 +void
   23.52 +SqliteDataOutput::DoDispose()
   23.53 +{
   23.54 +  NS_LOG_FUNCTION_NOARGS();
   23.55 +
   23.56 +  DataOutputInterface::DoDispose();
   23.57 +  // end SqliteDataOutput::DoDispose
   23.58 +}
   23.59 +
   23.60 +void
   23.61 +SqliteDataOutput::SetDBFile(const std::string file)
   23.62 +{
   23.63 +  m_dbFile = file;
   23.64 +}
   23.65 +std::string
   23.66 +SqliteDataOutput::GetDBFile() const
   23.67 +{
   23.68 +  return m_dbFile;
   23.69 +}
   23.70 +
   23.71 +int
   23.72 +SqliteDataOutput::Exec(std::string exe) {
   23.73 +  int res;
   23.74 +  char **result;
   23.75 +  int nrows, ncols;
   23.76 +  char *errMsg = 0;
   23.77 +
   23.78 +  NS_LOG_INFO("executing '" << exe << "'");
   23.79 +
   23.80 +  res = sqlite3_get_table(m_db,
   23.81 +                          exe.c_str(),
   23.82 +                          &result, &nrows, &ncols,
   23.83 +                          &errMsg);
   23.84 +
   23.85 +  if (res != SQLITE_OK) {
   23.86 +    NS_LOG_ERROR("sqlite3 error: \"" << errMsg << "\"");
   23.87 +  /*
   23.88 +  } else {
   23.89 +    // std::cout << "nrows " << nrows << " ncols " << ncols << std::endl;
   23.90 +
   23.91 +    if (nrows > 0) {
   23.92 +      for (int i = 0; i < ncols; i++) {
   23.93 +        std::cout << "  " << result[i];
   23.94 +      }
   23.95 +      std::cout << std::endl;
   23.96 +
   23.97 +      for (int r = 1; r <= nrows; r++) {
   23.98 +        for (int c = 0; c < ncols; c++) {
   23.99 +          std::cout << "  " << result[(r*ncols)+c];
  23.100 +        }
  23.101 +        std::cout << std::endl;
  23.102 +      }
  23.103 +      std::cout << std::endl;
  23.104 +    }
  23.105 +  */
  23.106 +  }
  23.107 +
  23.108 +  sqlite3_free_table(result);
  23.109 +  return res;
  23.110 +
  23.111 +  // end SqliteDataOutput::Exec
  23.112 +}
  23.113 +
  23.114 +//----------------------------------------------
  23.115 +void
  23.116 +SqliteDataOutput::Output(DataCollector &dc)
  23.117 +{
  23.118 +
  23.119 +  if (sqlite3_open(m_dbFile.c_str(), &m_db)) {
  23.120 +    NS_LOG_ERROR("Could not open sqlite3 database \"" << m_dbFile << "\"");
  23.121 +    NS_LOG_ERROR("sqlite3 error \"" << sqlite3_errmsg(m_db) << "\"");
  23.122 +    sqlite3_close(m_db);
  23.123 +    // TODO: Better error reporting, management!
  23.124 +    return;
  23.125 +  }
  23.126 +
  23.127 +  std::string run = dc.GetRunLabel();
  23.128 +
  23.129 +  Exec("create table if not exists Experiments (run, experiment, strategy, input, description text)");
  23.130 +  Exec("insert into Experiments (run,experiment,strategy,input,description) values ('" +
  23.131 +       run + "', '" +
  23.132 +       dc.GetExperimentLabel() + "', '" +
  23.133 +       dc.GetStrategyLabel() + "', '" +
  23.134 +       dc.GetInputLabel() + "', '" +
  23.135 +       dc.GetDescription() + "')");
  23.136 +
  23.137 +  Exec("create table if not exists Metadata ( run text, key text, value)");
  23.138 +
  23.139 +  for (MetadataList::iterator i = dc.MetadataBegin();
  23.140 +       i != dc.MetadataEnd(); i++) {
  23.141 +    std::pair<std::string, std::string> blob = (*i);
  23.142 +    Exec("insert into Metadata (run,key,value) values ('" +
  23.143 +         run + "', '" +
  23.144 +         blob.first + "', '" +
  23.145 +         blob.second + "')");
  23.146 +  }
  23.147 +
  23.148 +  SqliteOutputCallback callback(this, run);
  23.149 +  for (DataCalculatorList::iterator i = dc.DataCalculatorBegin();
  23.150 +       i != dc.DataCalculatorEnd(); i++) {
  23.151 +    (*i)->Output(callback);
  23.152 +  }
  23.153 +
  23.154 +  sqlite3_close(m_db);
  23.155 +
  23.156 +  // end SqliteDataOutput::Output
  23.157 +}
  23.158 +
  23.159 +SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
  23.160 +  (Ptr<SqliteDataOutput> owner, std::string run) :
  23.161 +    m_owner(owner),
  23.162 +    m_runLabel(run)
  23.163 +{
  23.164 +
  23.165 +  m_owner->Exec("create table if not exists Singletons ( run text, name text, variable text, value )");
  23.166 +
  23.167 +  // end SqliteDataOutput::SqliteOutputCallback::SqliteOutputCallback
  23.168 +}
  23.169 +
  23.170 +void
  23.171 +SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
  23.172 +                                                        std::string variable,
  23.173 +                                                        int val)
  23.174 +{
  23.175 +
  23.176 +  std::stringstream sstr;
  23.177 +  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
  23.178 +    m_runLabel << "', '" <<
  23.179 +    key << "', '" <<
  23.180 +    variable << "', " <<
  23.181 +    val << ")";
  23.182 +  m_owner->Exec(sstr.str());
  23.183 +
  23.184 +  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
  23.185 +}
  23.186 +void
  23.187 +SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
  23.188 +                                                        std::string variable,
  23.189 +                                                        uint32_t val)
  23.190 +{
  23.191 +  std::stringstream sstr;
  23.192 +  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
  23.193 +    m_runLabel << "', '" <<
  23.194 +    key << "', '" <<
  23.195 +    variable << "', " <<
  23.196 +    val << ")";
  23.197 +  m_owner->Exec(sstr.str());
  23.198 +  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
  23.199 +}
  23.200 +void
  23.201 +SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
  23.202 +                                                        std::string variable,
  23.203 +                                                        double val)
  23.204 +{
  23.205 +  std::stringstream sstr;
  23.206 +  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
  23.207 +    m_runLabel << "', '" <<
  23.208 +    key << "', '" <<
  23.209 +    variable << "', " <<
  23.210 +    val << ")";
  23.211 +  m_owner->Exec(sstr.str());
  23.212 +  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
  23.213 +}
  23.214 +void
  23.215 +SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
  23.216 +                                                        std::string variable,
  23.217 +                                                        std::string val)
  23.218 +{
  23.219 +  std::stringstream sstr;
  23.220 +  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
  23.221 +    m_runLabel << "', '" <<
  23.222 +    key << "', '" <<
  23.223 +    variable << "', '" <<
  23.224 +    val << "')";
  23.225 +  m_owner->Exec(sstr.str());
  23.226 +  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
  23.227 +}
  23.228 +void
  23.229 +SqliteDataOutput::SqliteOutputCallback::OutputSingleton(std::string key,
  23.230 +                                                        std::string variable,
  23.231 +                                                        Time val)
  23.232 +{
  23.233 +  std::stringstream sstr;
  23.234 +  sstr << "insert into Singletons (run,name,variable,value) values ('" <<
  23.235 +    m_runLabel << "', '" <<
  23.236 +    key << "', '" <<
  23.237 +    variable << "', " <<
  23.238 +    val << ")";
  23.239 +  m_owner->Exec(sstr.str());
  23.240 +  // end SqliteDataOutput::SqliteOutputCallback::OutputSingleton
  23.241 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/contrib/stats/sqlite-data-output.h	Fri Aug 29 13:22:09 2008 -0400
    24.3 @@ -0,0 +1,93 @@
    24.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    24.5 +/*
    24.6 + * Copyright (c) 2008 Drexel University
    24.7 + *
    24.8 + * This program is free software; you can redistribute it and/or modify
    24.9 + * it under the terms of the GNU General Public License version 2 as
   24.10 + * published by the Free Software Foundation;
   24.11 + *
   24.12 + * This program is distributed in the hope that it will be useful,
   24.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   24.15 + * GNU General Public License for more details.
   24.16 + *
   24.17 + * You should have received a copy of the GNU General Public License
   24.18 + * along with this program; if not, write to the Free Software
   24.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.20 + *
   24.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   24.22 + */
   24.23 +
   24.24 +#ifndef __SQLITE_DATA_OUTPUT_H__
   24.25 +#define __SQLITE_DATA_OUTPUT_H__
   24.26 +
   24.27 +#include "ns3/nstime.h"
   24.28 +
   24.29 +#include "data-output-interface.h"
   24.30 +
   24.31 +#define STATS_HAS_SQLITE3
   24.32 +
   24.33 +class sqlite3;
   24.34 +
   24.35 +namespace ns3 {
   24.36 +
   24.37 +  //------------------------------------------------------------
   24.38 +  //--------------------------------------------
   24.39 +  class SqliteDataOutput : public DataOutputInterface {
   24.40 +  public:
   24.41 +    SqliteDataOutput();
   24.42 +    virtual ~SqliteDataOutput();
   24.43 +
   24.44 +    virtual void Output(DataCollector &dc);
   24.45 +
   24.46 +    void SetDBFile(const std::string file);
   24.47 +    std::string GetDBFile() const;
   24.48 +
   24.49 +  protected:
   24.50 +    virtual void DoDispose();
   24.51 +
   24.52 +  private:
   24.53 +    class SqliteOutputCallback : public DataOutputCallback {
   24.54 +    public:
   24.55 +      SqliteOutputCallback(Ptr<SqliteDataOutput> owner, std::string run);
   24.56 +
   24.57 +      void OutputSingleton(std::string key,
   24.58 +                           std::string variable,
   24.59 +                           int val);
   24.60 +
   24.61 +      void OutputSingleton(std::string key,
   24.62 +                           std::string variable,
   24.63 +                           uint32_t val);
   24.64 +
   24.65 +      void OutputSingleton(std::string key,
   24.66 +                           std::string variable,
   24.67 +                           double val);
   24.68 +
   24.69 +      void OutputSingleton(std::string key,
   24.70 +                           std::string variable,
   24.71 +                           std::string val);
   24.72 +
   24.73 +      void OutputSingleton(std::string key,
   24.74 +                           std::string variable,
   24.75 +                           Time val);
   24.76 +
   24.77 +    private:
   24.78 +      Ptr<SqliteDataOutput> m_owner;
   24.79 +      std::string m_runLabel;
   24.80 +
   24.81 +      // end class SqliteOutputCallback
   24.82 +    };
   24.83 +
   24.84 +
   24.85 +    sqlite3 *m_db;
   24.86 +    int Exec(std::string exe);
   24.87 +
   24.88 +    std::string m_dbFile;
   24.89 +    // end class SqliteDataOutput
   24.90 +  };
   24.91 +
   24.92 +  // end namespace ns3
   24.93 +};
   24.94 +
   24.95 +
   24.96 +#endif // __SQLITE_DATA_OUTPUT_H__
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/contrib/stats/time-data-calculators.cc	Fri Aug 29 13:22:09 2008 -0400
    25.3 @@ -0,0 +1,81 @@
    25.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    25.5 +/*
    25.6 + * Copyright (c) 2008 Drexel University
    25.7 + *
    25.8 + * This program is free software; you can redistribute it and/or modify
    25.9 + * it under the terms of the GNU General Public License version 2 as
   25.10 + * published by the Free Software Foundation;
   25.11 + *
   25.12 + * This program is distributed in the hope that it will be useful,
   25.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   25.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   25.15 + * GNU General Public License for more details.
   25.16 + *
   25.17 + * You should have received a copy of the GNU General Public License
   25.18 + * along with this program; if not, write to the Free Software
   25.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   25.20 + *
   25.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   25.22 + */
   25.23 +
   25.24 +#include "ns3/log.h"
   25.25 +#include "ns3/nstime.h"
   25.26 +
   25.27 +#include "time-data-calculators.h"
   25.28 +
   25.29 +using namespace ns3;
   25.30 +
   25.31 +NS_LOG_COMPONENT_DEFINE("TimeDataCalculators");
   25.32 +
   25.33 +
   25.34 +//--------------------------------------------------------------
   25.35 +//----------------------------------------------
   25.36 +TimeMinMaxAvgTotalCalculator::TimeMinMaxAvgTotalCalculator()
   25.37 +{
   25.38 +  m_count = 0;
   25.39 +}
   25.40 +TimeMinMaxAvgTotalCalculator::~TimeMinMaxAvgTotalCalculator()
   25.41 +{
   25.42 +}
   25.43 +void
   25.44 +TimeMinMaxAvgTotalCalculator::DoDispose(void)
   25.45 +{
   25.46 +  DataCalculator::DoDispose();
   25.47 +  // TimeMinMaxAvgTotalCalculator::DoDispose
   25.48 +}
   25.49 +
   25.50 +void
   25.51 +TimeMinMaxAvgTotalCalculator::Update(const Time i)
   25.52 +{
   25.53 +  if (m_enabled) {
   25.54 +    if (m_count) {
   25.55 +      m_total += i;
   25.56 +
   25.57 +      if (i < m_min)
   25.58 +        m_min = i;
   25.59 +
   25.60 +      if (i > m_max)
   25.61 +        m_max = i;
   25.62 +
   25.63 +    } else {
   25.64 +      m_min = i;
   25.65 +      m_max = i;
   25.66 +      m_total = i;
   25.67 +    }
   25.68 +    m_count++;
   25.69 +
   25.70 +  }
   25.71 +  // end TimeMinMaxAvgTotalCalculator::Update
   25.72 +}
   25.73 +void
   25.74 +TimeMinMaxAvgTotalCalculator::Output(DataOutputCallback &callback) const
   25.75 +{
   25.76 +  callback.OutputSingleton(m_key, "count", m_count);
   25.77 +  if (m_count > 0) {
   25.78 +    callback.OutputSingleton(m_key, "total", m_total);
   25.79 +    callback.OutputSingleton(m_key, "average", m_total/Scalar(m_count));
   25.80 +    callback.OutputSingleton(m_key, "max", m_max);
   25.81 +    callback.OutputSingleton(m_key, "min", m_min);
   25.82 +  }
   25.83 +  // end TimeMinMaxAvgTotalCalculator::Output
   25.84 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/contrib/stats/time-data-calculators.h	Fri Aug 29 13:22:09 2008 -0400
    26.3 @@ -0,0 +1,62 @@
    26.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    26.5 +/*
    26.6 + * Copyright (c) 2008 Drexel University
    26.7 + *
    26.8 + * This program is free software; you can redistribute it and/or modify
    26.9 + * it under the terms of the GNU General Public License version 2 as
   26.10 + * published by the Free Software Foundation;
   26.11 + *
   26.12 + * This program is distributed in the hope that it will be useful,
   26.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   26.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   26.15 + * GNU General Public License for more details.
   26.16 + *
   26.17 + * You should have received a copy of the GNU General Public License
   26.18 + * along with this program; if not, write to the Free Software
   26.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   26.20 + *
   26.21 + * Author: Joe Kopena (tjkopena@cs.drexel.edu)
   26.22 + */
   26.23 +
   26.24 +#ifndef __TIME_DATA_CALCULATORS_H__
   26.25 +#define __TIME_DATA_CALCULATORS_H__
   26.26 +
   26.27 +#include "ns3/nstime.h"
   26.28 +
   26.29 +#include "data-calculator.h"
   26.30 +#include "data-output-interface.h"
   26.31 +
   26.32 +namespace ns3 {
   26.33 +
   26.34 +  //------------------------------------------------------------
   26.35 +  //--------------------------------------------
   26.36 +  /**
   26.37 +   * Unfortunately, templating the base MinMaxAvgTotalCalculator to
   26.38 +   * operate over Time values isn't straightforward.  The main issues
   26.39 +   * are setting the maximum value, which can be worked around easily
   26.40 +   * as it done here, and dividing to get the average, which is not as
   26.41 +   * easily worked around.
   26.42 +  */
   26.43 +  class TimeMinMaxAvgTotalCalculator : public DataCalculator {
   26.44 +  public:
   26.45 +    TimeMinMaxAvgTotalCalculator();
   26.46 +    virtual ~TimeMinMaxAvgTotalCalculator();
   26.47 +
   26.48 +    void Update(const Time i);
   26.49 +
   26.50 +    virtual void Output(DataOutputCallback &callback) const;
   26.51 +
   26.52 +  protected:
   26.53 +    virtual void DoDispose(void);
   26.54 +
   26.55 +    uint32_t m_count;
   26.56 +    Time m_total, m_min, m_max;
   26.57 +
   26.58 +    // end class TimeMinMaxAvgTotalCalculator
   26.59 +  };
   26.60 +
   26.61 +  // end namespace ns3
   26.62 +};
   26.63 +
   26.64 +
   26.65 +#endif // __TIME_DATA_CALCULATORS_H__
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/src/contrib/stats/wscript	Fri Aug 29 13:22:09 2008 -0400
    27.3 @@ -0,0 +1,36 @@
    27.4 +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
    27.5 +
    27.6 +def configure(conf):
    27.7 +   e = conf.create_library_configurator()
    27.8 +   e.mandatory = False
    27.9 +   e.name = 'sqlite3'
   27.10 +   e.define = 'SQLITE3'
   27.11 +   e.uselib = 'SQLITE3'
   27.12 +   conf.env['SQLITE_STATS'] = e.run()
   27.13 +
   27.14 +def build(bld):
   27.15 +    obj = bld.create_ns3_module('stats', ['node'])
   27.16 +    obj.source = [
   27.17 +        'data-calculator.cc',
   27.18 +        'packet-data-calculators.cc',
   27.19 +        'time-data-calculators.cc',
   27.20 +        'data-output-interface.cc',
   27.21 +        'omnet-data-output.cc',
   27.22 +        'data-collector.cc',
   27.23 +        ]
   27.24 +    headers = bld.create_obj('ns3header')
   27.25 +    headers.module = 'stats'
   27.26 +    headers.source = [
   27.27 +        'data-calculator.h',
   27.28 +        'packet-data-calculators.h',
   27.29 +        'time-data-calculators.h',
   27.30 +        'basic-data-calculators.h',
   27.31 +        'data-output-interface.h',
   27.32 +        'omnet-data-output.h',
   27.33 +        'data-collector.h',
   27.34 +        ]
   27.35 +
   27.36 +    if bld.env()['SQLITE_STATS']:
   27.37 +        headers.source.append('sqlite-data-output.h')
   27.38 +        obj.source.append('sqlite-data-output.cc')
   27.39 +        obj.uselib = 'SQLITE3'
    28.1 --- a/src/contrib/wscript	Fri Aug 29 14:56:24 2008 +0100
    28.2 +++ b/src/contrib/wscript	Fri Aug 29 13:22:09 2008 -0400
    28.3 @@ -6,7 +6,7 @@
    28.4      check.uselib = 'GTK_CONFIG_STORE'
    28.5      check.mandatory = False
    28.6      conf.env['ENABLE_GTK_CONFIG_STORE'] = check.run()
    28.7 -
    28.8 +    conf.sub_config('stats')
    28.9  
   28.10  def build(bld):
   28.11      module = bld.create_ns3_module('contrib', ['simulator'])
    29.1 --- a/src/wscript	Fri Aug 29 14:56:24 2008 +0100
    29.2 +++ b/src/wscript	Fri Aug 29 13:22:09 2008 -0400
    29.3 @@ -28,6 +28,7 @@
    29.4      'devices/wifi',
    29.5      'helper',
    29.6      'devices/bridge',
    29.7 +    'contrib/stats',
    29.8      )
    29.9  
   29.10  def set_options(opt):