Skip to main content

CONGESTION WINDOW "cwnd" IN NS2

 In TCP Networks, the most important factor that determines behavior is its congestion window size. In NS2, we can handle it with using cwnd command. In NS, every TCP type classes have a variable named "cwnd" that contains the congestion window size of the TCP Module. In here we can use 'set' command to return a value. 


We can write it as;
set  tcp1  [new  Agent/TCP/Reno]
set  cwnd1  [ $tcp1  set  cwnd_ ]

To obtain TCP's CWND value frquently;

  • We can easily make the NS simulation system repeatedly read the value (say, after every 0.1 sec of simulation time).
  • Schedule a read operation repeatedly

Proc plotWindow {tcpSource outfile} {
     global ns

     set now [$ns now]
     set cwnd [$tcpSource set cwnd_]

  #  Print TIME CWND   for  gnuplot to plot progressing on CWND   
     puts  $outfile  "$now $cwnd"

     $ns at [expr $now+0.1] "plotWindow  $tcpSource  $outfile"
  }

  • The procedure plotWindow takes a paramter tcpSource which is a TCP agent.So you can use the procedure to plot the CWND from any number of TCP flows.


  • The procedure plotWindow takes an output file ID outfile.You should first open an output file (or use "stdout") in the main program.

Examining progressing of CWND in TCP (Reno)

#Make a NS simulator   
  set ns [new Simulator]

  # Define a 'finish' procedure
  proc finish {} {
     exit 0
  }

  # Create the nodes:
  set n0 [$ns node]
  set n1 [$ns node]
  set n2 [$ns node]
  set n3 [$ns node]
  set n4 [$ns node]
  set n5 [$ns node]

  # Create the links:
  $ns duplex-link $n0 $n2   2Mb  10ms DropTail
  $ns duplex-link $n1 $n2   2Mb  10ms DropTail
  $ns duplex-link $n2 $n3 0.3Mb 200ms DropTail
  $ns duplex-link $n3 $n4 0.5Mb  40ms DropTail
  $ns duplex-link $n3 $n5 0.5Mb  30ms DropTail

  # Add a TCP sending module to node n0
  set tcp1 [new Agent/TCP/Reno]
  $ns attach-agent $n0 $tcp1

  # Add a TCP receiving module to node n4
  set sink1 [new Agent/TCPSink]
  $ns attach-agent $n4 $sink1

  # Direct traffic from "tcp1" to "sink1"
  $ns connect $tcp1 $sink1

  # Setup a FTP traffic generator on "tcp1"
  set ftp1 [new Application/FTP]
  $ftp1 attach-agent $tcp1
  $ftp1 set type_ FTP               (no necessary)

  # Schedule start/stop times
  $ns at 0.1   "$ftp1 start"
  $ns at 100.0 "$ftp1 stop"

  # Set simulation end time
  $ns at 125.0 "finish"     (Will invoke "exit 0")   


  ##################################################
  ## Obtain CWND from TCP agent
  ##################################################

  proc plotWindow {tcpSource outfile} {
     global ns

     set now [$ns now]
     set cwnd [$tcpSource set cwnd_]

  ###Print TIME CWND   for  gnuplot to plot progressing on CWND
     puts  $outfile  "$now $cwnd"

     $ns at [expr $now+0.1] "plotWindow $tcpSource  $outfile"
  }

  $ns  at  0.0  "plotWindow $tcp1  stdout"   // Start the probe !!    


  # Run simulation !!!!
  $ns run


his NS Prog prints the (time, cwnd) to the terminal: click here
This NS Prog prints the (time, cwnd) to the output file "WinFile": click here

To plot the window progressing from "winfile", do:

UNIX>> gnuplot
gnuplot>> plot "WinFile" using 1:2 title "Flow 1" with lines 1

Note:
In case you wonder why the cwnd plot look so different, It's because the setting of some parameters.
Add the following statements to the simulation to get the one I used in class:

  # ########################################################
  # Set Queue Size of link (n2-n3) to 10 (default is 50 ?)
  # ########################################################
  $ns queue-limit $n2 $n3 10


  # ########################################################
  # TCP parameters:
  # ########################################################    
  $tcp1 set window_ 8000
  $tcp1 set packetSize_ 552

This NS Prog will draw the CWND: click here

Postscript: Analyzing multiple TCP flows

The easiest way to analyze the behavior of multiple TCP is to open one file to store the progression of one TCP agent's variable values.

 TCP Agents

  set tcp1 [new Agent/TCP/Reno]
  ...
  set tcp2 [new Agent/TCP/Reno]
  ...


  set outfile1  [open  "WinFile1"  w]
  set outfile2  [open  "WinFile2"  w]


  $ns  at  0.0  "plotWindow $tcp1  $outfile1"

  $ns  at  0.0  "plotWindow $tcp2  $outfile2"     

Plot data of  TCP 1 will be store in file "WinFile1"

Plot data of  TCP 2 will be store in file "WinFile2"

Comments

Popular posts from this blog

NS2 INSTALLATION IN UBUNTU 21.04

  Hello, this post explains how to install ns2 in Ubuntu 21.04.  1) First you have to download ns2 all-in-one package from following link;    http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download 2) Extract the downloaded zip file 'ns-allinone-2.35.tar.gz file' to home folder. 3)  Now you need to download some essential packages for ns2,these packages can be downloaded by using the following commands :  applications>accessories>terminal or dashhome>terminal   and   then type the below lines one by one on the terminal window sudo apt-get update sudo apt-get dist-upgrade sudo apt-get update 4) Install the basic libraries; sudo apt install build-essential autoconf automake libxmu-dev 5) Install gcc and g++ and for that please do following; open the file using sudo mode sudo nano /etc/apt/sources.list Include the following line in list;  deb http://in.archive.ubuntu.com/ubuntu bionic main universe then open terminal and exec

Link State Routing Protocol

Link state routing is a method in which each router shares its neighborhood’s knowledge with every other router on the internetwork. In this algorithm, each router in the network understands the network topology and then makes a routing table depending on this topology. Each router will share data about its connection to its neighbor, who will, consecutively, reproduce the data to its neighbors, etc. This appears just before all routers have constructed a topology of the network. In LSP, each node transmits its IP address and the MAC to its neighbor with its signature. Neighbors determine the signature and maintain a record of the combining IP address and the MAC. The Neighbor Lookup Protocol (NLP) of LSP derives and maintains the MAC and IP address of every network frame accepted by a node. The extracted data can support the mapping of MACs and IP addresses. The link-state flooding algorithm prevents the general issues of broadcast in the existence of loops by having every node mainta

HP NETWORK SIMULATOR: A COMWARE OS LEARNING TOOL

  Comware v7 is a network operating system that runs on HP high-end network devices. The HP Network Simulator is an ideal Comware v7 learning tool, which allows users to create, configure, and connect simulated networks. Benefits Beginners  – The HP Network Simulator tool is helpful for users who are new to networking and want to learn how to configure network devices (switches, routers), various topologies, or different routing and switching protocols and features. Experienced users  – The HP Network Simulator learning tool is helpful for users who have experience with non-HP networking devices and want to learn the Comware CLI and features. Extra devices  – Users can create devices using the HP Network Simulator and use them with their physical devices to configure and test topologies that aren’t configurable with just the physical devices they have. For example – A user wants to configure OSPF using 3 or more devices but has only 1 physical router. User can create 2 or more routers