Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create an ns ofject
- set ns [new Simulator]
- #create and open trace file
- set tr wired.tr
- set nm wired.nam
- set tracefile [open $tr w]
- $ns trace-all $tracefile
- set namfile [open $nm w]
- $ns namtrace-all $namfile
- #taking inputs from shell
- set num_node [lindex $argv 0]
- set num_flows [lindex $argv 1]
- set packet_rate [lindex $argv 2]
- #packet_rate = packet per second
- set cbr_size 1000
- set cbr_rate 11.0Mb
- set cbr_interval [expr 1.0/$packet_rate]
- set grid_x_dim 500
- set grid_y_dim 500
- #Creating nodes
- puts "starting node creation..."
- for {set i 0} {$i < $num_node} {incr i} {
- set node_($i) [$ns node]
- set row [expr ($i/10)]
- set colm [expr ($i%10)]
- set row [expr ($row * 50)]
- set colm [expr ($colm * 50)]
- set x_pos [expr int($row)] ; #random settings
- set y_pos [expr int($colm)] ; #random settings
- $node_($i) set X_ $x_pos;
- $node_($i) set Y_ $y_pos;
- $node_($i) set Z_ 0.0
- # puts -nonewline $topo_file "$i x: [$node_($i) set X_] y: [$node_($i) set Y_] \n"
- }
- #creating edges in a grid-like way
- puts "Creating Edges between the nodes..."
- for {set i 0} {$i < $num_node} {incr i} {
- set right [expr $i + 1]
- set down [expr $i + 10]
- set val [expr $i % 10]
- if {$val != 9} {
- $ns duplex-link $node_($i) $node_($right) 5Mb 2ms DropTail
- }
- if {$down < [expr $num_node-1]} {
- $ns duplex-link $node_($i) $node_($down) 5Mb 2ms DropTail
- }
- }
- #Create flows and associate them with nodes
- for {set i 0} {$i < $num_flows} {incr i} {
- set tcp_($i) [new Agent/TCP]
- $tcp_($i) set class_ $i
- $tcp_($i) set fid_ $i
- set tcpsink_($i) [new Agent/TCPSink]
- if { [expr $i%2] == 0} {
- $ns color $i Blue
- } else {
- $ns color $i Red
- }
- }
- for {set i 0} {$i < $num_flows} {incr i} {
- set t [expr (rand() * $num_node)]
- set tt [expr int($t)]
- set t1 [expr (rand() * $num_node)]
- set tt1 [expr int($t1)]
- set src_no [expr $tt % $num_node]
- set sink_no [expr $tt1 % $num_node]
- while {$src_no == $sink_no} {
- set t [expr (rand() * $num_node)]
- set tt [expr int($t)]
- set t1 [expr (rand() * $num_node)]
- set tt1 [expr int($t1)]
- set src_no [expr $tt % $num_node]
- set sink_no [expr $tt1 % $num_node]
- }
- # puts "src_no = $src_no && sink_no = $sink_no"
- $ns attach-agent $node_($src_no) $tcp_($i)
- $ns attach-agent $node_($sink_no) $tcpsink_($i)
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp_($i)
- $ns at 2.0 "$ftp start"
- $ns at 10.0 "finish"
- }
- for {set i 0} {$i < $num_flows } {incr i} {
- $ns connect $tcp_($i) $tcpsink_($i)
- }
- for {set i 0} {$i < $num_flows } {incr i} {
- set cbr_($i) [new Application/Traffic/CBR]
- $cbr_($i) set packetSize_ $cbr_size
- $cbr_($i) set rate_ $cbr_rate
- $cbr_($i) set interval_ $cbr_interval
- $cbr_($i) attach-agent $tcp_($i)
- }
- for {set i 0} {$i < $num_flows } {incr i} {
- $ns at 1 "$cbr_($i) start"
- }
- #finish procedure
- proc finish {} {
- puts "finishing"
- global ns tr nm namfile tracefile
- $ns flush-trace
- close $namfile
- close $tracefile
- # exec nam $nm &
- exit 0
- }
- $ns run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement