Wednesday, 13 May 2015

BIC implementaion in NS2

There are many congestion avoidance mechanism like BIC,CUBIC,HSTCP,HYBLA etc. All these protocols are present in ns-2.35/tcp/linux/src.(in my case as i am suing NS 2.35). If using lower version then you need to run a patch file and then follow with the code.The description of congestion control avoidance mechanism available in NS2 can be seen here .
I am implementing the algorithms on dumbbell topology with link speed of 1Gbps and 100ms. References to the same can be found in the Link.
The figure will give complete info about the access to these algorithms
  

                  
Code for BIC


  set ns [new Simulator]

#Define different colors for data flows (for NAM)
  $ns color 1 Blue
  $ns color 2 Red

  set file2 [open out.nam w]
  $ns namtrace-all $file2
  set tf [open ui.tr w]  
  $ns trace-all $tf

# Open the Window trace file
  set winfile [open WinFile1.tr w]


  proc finish {} {
     global ns file2 tf
     $ns flush-trace
     close $tf
     close $file2
     exec nam out.nam &
     exit 0
  }

# ################################################
# Create the configuration:
#
#            0                 4
#    2Gb/10ms \  1.0Gb/100ms  / 2.0Mb/40ms
#              2 ----------- 3
#    2Gb/10ms /               \ 2.0Mb/30ms
#            1                 5
#
#  TCP1:  0 -> 4
# ################################################


# 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]

  $ns duplex-link $n0 $n2 2Gb 10ms DropTail
  $ns duplex-link $n1 $n2 2Gb 10ms DropTail
  $ns simplex-link $n2 $n3 1.0Gb 200ms DropTail
  $ns simplex-link $n3 $n2 1.0Gb 200ms DropTail
  $ns duplex-link $n3 $n4 2.0Gb 40ms DropTail
  $ns duplex-link $n3 $n5 2.0Mb 30ms DropTail

$ns duplex-link-op $n2 $n3 queuePos 0.1

# Give node position (for NAM)
  $ns duplex-link-op  $n0 $n2 orient right-down
  $ns duplex-link-op  $n1 $n2 orient right-up
  $ns simplex-link-op $n2 $n3 orient right
  $ns simplex-link-op $n3 $n2 orient left
  $ns duplex-link-op  $n3 $n4 orient right-up
  $ns duplex-link-op  $n3 $n5 orient right-down
  $ns queue-limit $n2 $n3 10

# ########################################################
# Setup a TCP connection
 set tcp [new Agent/TCP/Linux]
#(i)#
  $ns at 0 "$tcp select_ca bic" #(ii)#

  $ns attach-agent $n0 $tcp

  set sink [new Agent/TCPSink/Sack1]#(iii)#
  $sink set ts_echo_rfc1323_ true


  $ns attach-agent $n4 $sink

  $ns connect $tcp $sink
  $tcp set fid_ 1
  $tcp set window_ 8000
  $tcp set packetSize_ 552



  set ftp [new Application/FTP]
  $ftp attach-agent $tcp
  $ftp set type_ FTP


# Schedule start/stop times
  $ns at 0.1 "$ftp start"
  $ns at 500.0 "$ftp stop"


  proc plotWindow {tcpSource file} {
     global ns

     set time 0.1
     set now [$ns now]
     set cwnd [$tcpSource set cwnd_]
     set wnd [$tcpSource set window_]
     puts $file "$now $cwnd"
     $ns at [expr $now+$time] "plotWindow $tcpSource $file"
  }


  $ns at 0.1 "plotWindow $tcp $winfile"



  $ns at 140.0 "finish"
  $ns run
The highlighted  area (i) is where the tcp calls linux and searches for the algorithm.And in (ii) the algorithm is called upon.The lines under (iii) are to be mentioned as it is for implementing the new sink.
Syntax: $ns at 0 "$tcp select_ca $TCP_Name" 
Change the $TCP_Name in the above syntax to any of the congestion control algorithm names
The nam will be something like this.
The plot of congestion window versus time is as obtained below


 

No comments:

Post a Comment