#! ns # This is an ns2 example TCL file for some Web proxy configuration. # Create FTP connection number "n" using a TCP connection. # The FTP connections are created between "source" and "sink". # The "sink" represents the Web client. The "source" represents the # provider of the Web content, which could be the origin Web server # if there are no proxies, or one of the proxies in case of a hit. proc connect_ftp { n srcnode snknode size } { global ns SS connection haveall member packets numconns source sink # puts "in connect_ftp" incr member 1 incr connection 1 # puts "$connection connections start" if {$member == $numconns} { set haveall 1 } set source($n) $srcnode set sink($n) $snknode # create TCP agents. Assume TCP Reno for each flow. set tcpsource($n) [new Agent/TCP/Reno] set tcpsink($n) [new Agent/TCPSink] # attach TCP agents to nodes and connect them $ns attach-agent $source($n) $tcpsource($n) $ns attach-agent $sink($n) $tcpsink($n) $ns connect $tcpsource($n) $tcpsink($n) $tcpsink($n) reset # attach an FTP traffic source to the TCP source set ftp($n) [$tcpsource($n) attach-source FTP] # remember starting time set start($n) [$ns now] set stop($n) $start($n) $tcpsource($n) set fid_ $n # convert transfer size in bytes into an integer number of TCP packets # using the stated global variable for the maximum segment size (SS) set packets($n) [expr int([expr ceil(double($size) / double($SS))])] #puts "num packets for that connection is $packets($n)" $tcpsource($n) proc done {} "disconnect_ftp $n" $ftp($n) produce $packets($n) } # Disconnect FTP connection number "n" when it is done. proc disconnect_ftp { n } { global ns source sink tcpsource tcpsink ftp stop connection haveall packets # remember stop time set stop($n) [$ns now] incr connection -1 # puts "$connection connections are left" if { $connection == 0 && $haveall == 1 } { dump_statistics exit 0 } } # Report simulation results proc dump_statistics { } { global ns start stop packets byte source sink numconns $ns halt puts "conn cli src Tstart Tfinish duration bytes pkts" for { set n 1 } { $n <= $numconns } { incr n } { set elapse($n) [expr $stop($n) - $start($n)] puts "[format %3d $n] $sink($n) $source($n) [format %9.6f $start($n)] [format %9.6f $stop($n)] \ [format %9.6f $elapse($n)] [format %8d $byte($n)] [format %4d $packets($n)]" } } #------------------------------------------------------------------------- # running starts here # global simulator object set ns [new Simulator] # set TCP maximum segment size (in bytes) for packets set SS 500 # initialize some global variables set connection 0 set haveall 0 set member 0 # tell ns2 how many connections to process from the workload file set numconns 20 # set TCP packet size to a reasonable IP wide-area default Agent/TCP set packetSize_ 500 #create the network topology set c0 [$ns node] set c1 [$ns node] set c2 [$ns node] set c3 [$ns node] set p1 [$ns node] set p2 [$ns node] set p3 [$ns node] set server [$ns node] # create the links and their properties $ns duplex-link $c0 $p1 1Mb 1ms DropTail $ns duplex-link $c1 $p1 1Mb 1ms DropTail $ns duplex-link $c2 $p2 1Mb 1ms DropTail $ns duplex-link $c3 $p2 1Mb 1ms DropTail $ns duplex-link $p1 $p3 10Mb 10ms DropTail $ns duplex-link $p2 $p3 10Mb 10ms DropTail $ns duplex-link $p3 $server 100Mb 100ms DropTail # set the buffer sizes on the links $ns queue-limit $c0 $p1 100 $ns queue-limit $c1 $p1 100 $ns queue-limit $c2 $p2 100 $ns queue-limit $c3 $p2 100 $ns queue-limit $p1 $p3 100 $ns queue-limit $p2 $p3 100 $ns queue-limit $p3 $server 100 # read in the connection information from the file workload2.tcl # to set up each connection: start time, client, sender, transfer size source workload.tcl # run the simulation! $ns run