WPI Worcester Polytechnic Institue

Computer Science Department
-----------------------------------------

NS@WPI FAQ


  1. Is there an NS tutorial somplace?

    Try: http://www.isi.edu/nsnam/ns/tutorial/


  2. How do setup to use NS on nile?

    Add /users/ns/bin is in your path:

       set path=(/users/ns/bin $path) # for csh/tcsh
    

    Make a working directory for your scripts:

       cd /users/claypool
       mkdir my-sim
    

    Then, make sims and run normally.


  3. How do setup to modify NS (edit the simulator) on nile?

    Check that you are part of the "ns" group:

       groups (if you don't see "ns" send email to claypool@cs)
    

    Set your CVSROOT variable (for tcsh):

       setenv CVSROOT /users/cvsroot (put in your .tcshrc)
    

    Make a working directory:

       cd /users/claypool
       mkdir my-ns
    

    Check out ns-2:

       cd /users/claypool/my-ns
       cvs co ns-2
    

    Link in supporting directories:

       cd /users/claypool/my-ns
       ln -s /users/ns/* .
       (will give error for ns-2 link, but that's ok)
    

    Compile ns:

    	
       cd /users/claypool/my-ns/ns-2
       make
    

    Make sure your scripts now use your NEW ns under /users/claypool/my-ns/ns-2/ns! Then, make sims and run normally.

    To edit a file:

    	
       cd /users/claypool/my-ns/ns-2
       (edit file)
       (compile, debug, test, compile, debug test...)
       (MAKE SURE YOUR CODE COMPILES AND WORKS BEFORE SUBMITTING)
       cvs commit
    

    To add a file:

    	
       cd /users/claypool/my-ns/ns-2
       (edit new file)
       (compile, debug, test, compile, debug test...)
       (MAKE SURE YOUR CODE COMPILES AND WORKS BEFORE SUBMITTING)
       cvs add
       cvs commit
    


  4. Where are some sample scripts I can start from?

    Many sample scripts can be found in the NS distribution in /users/ns-2/ns-2/tcl/ex and /users/ns/ns-2/tcl/test. You might also try /users/ns/ns-2/tcl/ns-tutorial/.


  5. Entering flows by hand is a pain. How do you "generate", say, 200 flows automatically?

    You can do so with a for loop. Here is an example:

      #######################
      # Creat Network Topology #
      #######################
    
      #Set number of TCP connections
      set tcp_num 50
    
      #Making two network nodes
      set n(1) [$ns node]
      set n(2) [$ns node]
    
      #Making edge nodes
      for {set i 1} {$i <= $tcp_num} {incr i} {
          set s($i) [$ns node]
          set r($i) [$ns node]
      }
    
      #Creating the network link
      $ns duplex-link $n(1) $n(2) 20Mb 20ms DropTail
    
      #Creating edge links
      for {set i 1} {$i <= $tcp_num} {incr i} {
          $ns duplex-link $s($i) $n(1) 20Mb 5ms DropTail
          $ns duplex-link $n(2) $r($i) 20Mb 5ms DropTail
      }
    
    
      #########################
      # Setup FTP-TCP connections #
      #########################
    
      #Setup TCP
      for {set i 1} {$i <= $tcp_num} {incr i} {
          set tcp($i) [new Agent/TCP/Reno]
          set sink($i) [new Agent/TCPSink]
          $ns attach-agent $s($i) $tcp($i)
          $ns attach-agent $r($i) $sink($i)
          $ns connect $tcp($i) $sink($i)
    
          $tcp($i) set ecn_ true
          $tcp($i) set fid_ $i
          $tcp($i) set window_ 20
          $tcp($i) set packetSize_ 1000
      }
    
      #Setup FTP Applications
      for {set i 1} {$i <= $tcp_num} {incr i} {
          set ftp($i) [new Application/FTP]
          $ftp($i) attach-agent $tcp($i)
          $ftp($i) set type_ FTP
      }
    
      ##########################
      # Start FTP Applications #
      ##########################
      for {set i 1} {$i <= $tcp_num} {incr i} {
          $ns at 0 "$ftp($i) start"
          $ns at 80 "$ftp($i) stop"
      }
    
      $ns run
    


  6. How do I measure things like packet loss, throughput, etc?

    You pull data you need from the trace file NS produces. That file is in text format, so you can parse it by whatever tools you would like. For example, to calculate throughput you'd look for how many packets arrived per second at a node coming from another node maybe with the protocol TCP.


  7. Where are the defaults kept for the NS objects?

    /users/ns/ns-2/tcl/lib


  8. Are there some tools somewhere that do some things I would like?

    Not as many as we'd like. But there is a start in: /users/ns/tools


  9. Does NS simulate the 3-way TCP handshake?

    Yes. You set the syn_ variable to TRUE in Agent/TCP in order to simulate the 3-way handshake. In ns-2.1b7a, syn_ is set to FALSE by default. However since ns-2.1b8, the default setting for syn_ has been changed to TRUE.


  10. I get the exact same drops every time with my RED router. Is there a way to "seed" the NS random number generator?

    You do it with the RNG class from OTcl. For example, a new RNG is created and seeded with:

      set rng [new RNG]
      $rng seed 0 # seeds the RNG heuristically;
      $rng seed n # seeds the RNG with value n;
    

    Other uses could be:

      $rng next-random #  return the next random number;
      $rng uniform a b # return a number uniformly distributed on [a, b];
      $rng integer k   # return an integer uniformly distributed on [0, (k-1)];
      $rng exponential # return a number from an exponential distribution
    		   # with average 1.;
    

    Currently there is no way to select predefined seeds from OTcl.