The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...
The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ... The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...
24.5.1 OTclOTcl, especially TclCL, provides a way to allocate new objects. However, it does not accordingly provide a garbage collectionmechanism for these allocated objects. This can easily lead to unintentional memory leaks. Important: tools such as dmallocand purify are unable to detect this kind of memory leaks. For example, consider this simple piece of OTcl script:set ns [new Simulator]for set i 0 $i < 500 incr iset a [new RandomVariable/Constant]One would expect that the memory usage should stay the same after the first RandomVariable is allocated. However, becauseOTcl does not have garbage collection, when the second RandomVariable is allocated, the previous one is not freed andhence results in memory leak. Unfortunately, there is no easy fix for this, because garbage collection of allocated objects isessentially incompatible with the spirit of Tcl. The only way to fix this now is to always explicitly free every allocated OTclobject in your script, in the same way that you take care of malloc-ed object in C/C++.24.5.2 C/C++Another source of memory leak is in C/C++. This is much easier to track given tools that are specifically designed for thistask, e.g., dmalloc and purify. nshas a special target ns-pure to build purified ns executable. First make sure that the macroPURIFY in the ns Makefile contains the right -collector for your linker (check purify man page if you don’t know what thisis). Then simply type make ns-pure. See earlier sections in this chapter on how to use ns with libdmalloc.219
Chapter 25Mathematical SupportThe simulator includes a small collection of mathematical functions used to implement random variate generation and integration.This area of the simulator is currently undergoing some changes.The procedures and functions described in this chapter can be found in ~ns/tools/rng.{cc, h}, ~ns/tools/random.{cc, h},~ns/tools/ranvar.{cc, h}, ~ns/tools/pareto.{cc, h}, ~ns/tools/expoo.{cc, h}, ~ns/tools/integrator.{cc, h}, and ~ns/tcl/lib/nsrandom.tcl.25.1 Random Number GenerationThe RNG class contains an implementation of the combined multiple recursive generator MRG32k3a proposed by L’Ecuyer[16]. The C++ code was adapted from [18]. This replaces the previous implementation of RNG, which used the minimalstandard multiplicative linear congruential generator of Park and Miller [27]. The newer (MRG32k3a) RNG is used in nsversions 2.1b9 and later.The MRG32k3a generator provides 1.8x10 19 independent streams of random numbers, each of which consists of 2.3x10 15substreams. Each substream has a period (i.e., the number of random numbers before overlap) of 7.6x10 22 . The period of theentire generator is 3.1x10 57 . Figure 25.1 provides a graphical idea of how the streams and substreams fit together.A default RNG (defaultRNG), created at simulator initialization time, is provided. If multiple random variables are used ina simulation, each random variable should use a separate RNG object. When a new RNG object is created, it is automaticallyseeded to the beginning of the next independent stream of random numbers. Used in this manner, the implementation allowsfor a maximum of 1.8x10 19 random variables.Often, multiple independent replications of a simulation are needed (i.e., to perform statistical analysis given multiple runswith fixed parameters). For each replication, a different substream should be used to ensure that the random number streamsare independent. (This process is given as an OTcl example later.) This implementation allows for a maximum of 2.3x10 15independent replications. Each random variable in a single replication can produce up to 7.6x10 22 random numbers beforeoverlapping.Note: Only the most common functions are described here. For more information, see [18] and the source code found intools/rng.h and tools/rng.cc. For a comparison of this RNG to the more common LCG16807 RNG (and whyLCG16807 is not a good RNG), see [17].220
- Page 169 and 170: This command is used to create a Go
- Page 171 and 172: Chapter 17Satellite Networking in n
- Page 173 and 174: in counter-rotating planes (where t
- Page 175 and 176: • Position/Sat/Geo A geostationar
- Page 177 and 178: $ns add-isl $ltype $node1 $node2 $b
- Page 179 and 180: $satrouteobject_ compute_routeswher
- Page 181 and 182: This will add an error model to the
- Page 183 and 184: lh_firstnameobj‘‘name’’ is
- Page 185 and 186: from routing agentto Node->entrySat
- Page 187 and 188: $satnode add-isl This method c
- Page 189 and 190: set prop [new Propagation/FreeSpace
- Page 191 and 192: 18.3.2 Using shadowing modelBefore
- Page 193 and 194: Chapter 19Energy Model in nsEnergy
- Page 195 and 196: Chapter 20Directed DiffusionThe dir
- Page 197 and 198: However if we have a large and dens
- Page 199 and 200: yr application in the ns context. T
- Page 201 and 202: value of opt(pre-stop) is usually t
- Page 203 and 204: 21.2 Implementation of XCP in NSIn
- Page 205 and 206: the persistent queue length in the
- Page 207 and 208: Thruput2 0.054024 60000residue_pos_
- Page 209 and 210: Chapter 22DelayBox: Per-Flow Delay
- Page 211 and 212: $ns attach-agent $n_sink $sink# mak
- Page 213 and 214: Chapter 23Changes made to the IEEE
- Page 215 and 216: Part IIISupport214
- Page 217 and 218: endenddocument pargvcPrint out argc
- Page 219: 24.4.2 Memory Conservation TipsSome
- Page 223 and 224: set run [lindex $argv 0]}if {$run <
- Page 225 and 226: }$sizeRNG next-substream# print the
- Page 227 and 228: protected:RNG* rng_;};Classes deriv
- Page 229 and 230: ns-random is implemented in ~ns/mis
- Page 231 and 232: Chapter 26Trace and Monitoring Supp
- Page 233 and 234: The monitor-queue function is const
- Page 235 and 236: also used to accumulate packet drop
- Page 237 and 238: }name,th->size(),flags,iph->flowid(
- Page 239 and 240: PT_TORA,PT_DSR,PT_AODV,// insert ne
- Page 241 and 242: The QueueMonitor class is not deriv
- Page 243 and 244: $ns_ trace-all This is the command
- Page 245 and 246: Chapter 27Test Suite SupportThe ns
- Page 247 and 248: ... ...}$ns_ at $opt(stop).1 "$self
- Page 249 and 250: Example: To enable debugging in Que
- Page 251 and 252: Chapter 29Unicast RoutingThis secti
- Page 253 and 254: Asymmetric Routing Asymmetric routi
- Page 255 and 256: class RouteLogic This class defines
- Page 257 and 258: — The procedure init-all{} is a g
- Page 259 and 260: Global Actions Once the detailed ac
- Page 261 and 262: This dumps next hop information in
- Page 263 and 264: $ns mrtproto ST;# specify shared tr
- Page 265 and 266: Dense Mode The Dense Mode protocol
- Page 267 and 268: and unique label (id). Thus, “inc
- Page 269 and 270: add-iif{ifid link},add-oif{link if}
24.5.1 OTclOTcl, especially TclCL, provides a way to alloc<strong>at</strong>e new objects. However, it does not accordingly provide a garbage collectionmechanism for these alloc<strong>at</strong>ed objects. This can easily lead to unintentional memory leaks. Important: tools such as dmalloc<strong>and</strong> purify are unable to detect this kind of memory leaks. For example, co<strong>ns</strong>ider this simple piece of OTcl script:set <strong>ns</strong> [new Simul<strong>at</strong>or]for set i 0 $i < 500 incr iset a [new R<strong>and</strong>omVariable/Co<strong>ns</strong>tant]One would expect th<strong>at</strong> the memory usage should stay the same after the first R<strong>and</strong>omVariable is alloc<strong>at</strong>ed. However, becauseOTcl does not have garbage collection, when the second R<strong>and</strong>omVariable is alloc<strong>at</strong>ed, the previous one is not freed <strong>and</strong>hence results in memory leak. Unfortun<strong>at</strong>ely, there is no easy fix for this, because garbage collection of alloc<strong>at</strong>ed objects isessentially incomp<strong>at</strong>ible with the spirit of Tcl. <strong>The</strong> only way to fix this now is to always explicitly free every alloc<strong>at</strong>ed OTclobject in your script, in the same way th<strong>at</strong> you take care of malloc-ed object in C/C++.24.5.2 C/C++Another source of memory leak is in C/C++. This is much easier to track given tools th<strong>at</strong> are specifically designed for thistask, e.g., dmalloc <strong>and</strong> purify. <strong>ns</strong>has a special target <strong>ns</strong>-pure to build purified <strong>ns</strong> executable. First make sure th<strong>at</strong> the macroPURIFY in the <strong>ns</strong> Makefile contai<strong>ns</strong> the right -collector for your linker (check purify man page if you don’t know wh<strong>at</strong> thisis). <strong>The</strong>n simply type make <strong>ns</strong>-pure. See earlier sectio<strong>ns</strong> in this chapter on how to use <strong>ns</strong> with libdmalloc.219