set ns [new Simulator] set nf [open main.nam w] $ns namtrace-all $nf set tf [open main.tr w] $ns trace-all $tf set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set n5 [$ns node] $n4 shape box $ns duplex-link $n0 $n4 1005Mb 1ms DropTail $ns duplex-link $n1 $n4 50Mb 1ms DropTail $ns duplex-link $n2 $n4 2000Mb 1ms DropTail $ns duplex-link $n3 $n4 200Mb 1ms DropTail $ns duplex-link $n4 $n5 1Mb 1ms DropTail set p1 [new Agent/Ping] $ns attach-agent $n0 $p1 $p1 set packetSize_ 50000 $p1 set interval_ 0.0001 set p2 [new Agent/Ping] $ns attach-agent $n1 $p2 set p3 [new Agent/Ping] $ns attach-agent $n2 $p3 $p3 set packetSize_ 30000 $p3 set interval_ 0.00001 set p4 [new Agent/Ping] $ns attach-agent $n3 $p4 $p1 set interval_ 0.0001 set p5 [new Agent/Ping] $ns attach-agent $n5 $p5 $ns queue-limit $n0 $n4 5 $ns queue-limit $n2 $n4 3 $ns queue-limit $n4 $n5 2 Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] receivred answer from $from in round trip time of $rtt nsec" } $ns connect $p1 $p5 $ns connect $p3 $p4 proc finish {} { global ns nf tf $ns flush-trace close $nf close $tf exec nam main.nam & exit 0 } $ns at 0.1 "$p1 send" $ns at 0.2 "$p1 send" $ns at 0.3 "$p1 send" $ns at 0.4 "$p1 send" $ns at 0.5 "$p1 send" $ns at 0.6 "$p1 send" $ns at 0.7 "$p1 send" $ns at 0.8 "$p1 send" $ns at 0.9 "$p1 send" $ns at 1.0 "$p1 send" $ns at 1.1 "$p1 send" $ns at 1.2 "$p1 send" $ns at 1.3 "$p1 send" $ns at 1.4 "$p1 send" $ns at 1.5 "$p1 send" $ns at 1.6 "$p1 send" $ns at 1.7 "$p1 send" $ns at 1.8 "$p1 send" $ns at 1.9 "$p1 send" $ns at 2.0 "$p1 send" $ns at 2.1 "$p1 send" $ns at 2.2 "$p1 send" $ns at 2.3 "$p1 send" $ns at 2.4 "$p1 send" $ns at 2.5 "$p1 send" $ns at 2.6 "$p1 send" $ns at 2.7 "$p1 send" $ns at 2.8 "$p1 send" $ns at 2.9 "$p1 send" $ns at 0.1 "$p3 send" $ns at 0.2 "$p3 send" $ns at 0.3 "$p3 send" $ns at 0.4 "$p3 send" $ns at 0.5 "$p3 send" $ns at 0.6 "$p3 send" $ns at 0.7 "$p3 send" $ns at 0.8 "$p3 send" $ns at 0.9 "$p3 send" $ns at 1.0 "$p3 send" $ns at 1.1 "$p3 send" $ns at 1.2 "$p3 send" $ns at 1.3 "$p3 send" $ns at 1.4 "$p3 send" $ns at 1.5 "$p3 send" $ns at 1.6 "$p3 send" $ns at 1.7 "$p3 send" $ns at 1.8 "$p3 send" $ns at 1.9 "$p3 send" $ns at 2.0 "$p3 send" $ns at 2.1 "$p3 send" $ns at 2.2 "$p3 send" $ns at 2.3 "$p3 send" $ns at 2.4 "$p3 send" $ns at 2.5 "$p3 send" $ns at 2.6 "$p3 send" $ns at 2.7 "$p3 send" $ns at 2.8"$p3 send" $ns at 2.9"$p3 send" $ns at 3.0"finish" $ns run
set ns [new Simulator] set tf [open main.tf w] $ns trace-all $tf set nf [open main.nam w] $ns namtrace-all $nf set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] $ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3 $n0 label "source1" $n2 label "source2" $n1 label "destination1" $n3 label "destination2" $ns color 1 "red" $ns color 2 "blue" set tcp0 [new Agent/TCP] $ns attach-agent $n0 $tcp0 set tcp2 [new Agent/TCP] $ns attach-agent $n2 $tcp2 set sink1 [new Agent/TCPSink] $ns attach-agent $n1 $sink1 set sink3 [new Agent/TCPSink] $ns attach-agent $n3 $sink3 set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 set ftp2 [new Application/FTP] $ftp2 attach-agent $tcp2 $ns connect $tcp0 $sink3 $ns connect $tcp2 $sink1 $tcp0 set class_ 1 $tcp2 set class_ 2 set file0 [open file0.tr w] $tcp0 attach $file0 $tcp0 trace cwnd_ $tcp0 set maxcwnd_ 10 set file2 [open file2.tr w] $tcp2 attach $file2 $tcp2 trace cwnd_ proc finish { } { global ns nf tf $ns flush-trace exec nam main.nam & close $nf exit 0 } $ns at 0.1 "$ftp0 start" $ns at 1.5 "$ftp0 stop" $ns at 2 "$ftp0 start" $ns at 3 "$ftp0 stop" $ns at 0.2 "$ftp2 start" $ns at 2 "$ftp2 stop" $ns at 2.5 "$ftp2 start" $ns at 4 "$ftp2 stop" $ns at 5.0 "finish" $ns run
proc sort {l m n} { set a $l set b $m set c $n if { $m > $a } { set a $m set b $l set c $n } if { $n > $a } { set a $n set b $m set c $l } if { $c > $b } { set t $b set b $c set c $t } return [expr "$a$b$c"] } puts "ENTER 1st NUMBER FOR SORT :" set x [gets stdin] puts "ENTER 2nd NUMBER FOR SORT :" set y [gets stdin] puts "ENTER 3rd NUMBER FOR SORT :" set z [gets stdin] set r [sort $x $y $z] puts $r
proc fun arg { return [expr $arg*2] } set sum [ apply {{sum x } { foreach z $x { set sum [expr [fun $z] + $sum] } ; return $sum }} {0} { 2 5 } ] puts $sum coroutine accumulator apply {{} { set x 0 while 1 { puts $x incr x [yield $x] } }} #for {set i 0} {$i < 10} {incr i} { # puts "$i -> [accumulator $]" #} accumulator [fun 43] accumulator [fun 123] set hex 07 scan $hex %x decimal # set signShort [binary format s1 0x10111111] puts $signShort
proc fun arg { return [expr $arg*2] } set sum [apply {{sum x } { foreach z $x { set sum [expr [fun $z] + $sum] } ; return $sum }} {0} { 2 5 } ] puts $sum
set ns [new Simulator] #Use colors to differentiate the traffic $ns color 1 Blue $ns color 2 Red $ns color 3 Green $ns color 4 Yellow $ns color 5 Cyan $ns color 0 Black #Open trace and NAM trace file set ntrace [open pg2.tr w] $ns trace-all $ntrace set namfile [open pg2.nam w] $ns namtrace-all $namfile #Finish Procedure proc Finish {} { global ns ntrace namfile #Dump all trace data and close the file $ns flush-trace close $ntrace close $namfile #Execute the nam animation file exec 0 } #Create six nodes for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } #Create Links between nodes for {set j 0} {$j < 4} {incr j} { $ns duplex-link $n($j) $n(5) 1Mb 10ms DropTail } $ns duplex-link $n(5) $n(4) 1Mb 10ms DropTail # Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from $from with round-trip-time $rtt ms." } #connections set p0 [$ns create-connection Ping $n(0) Ping $n(1) 1] set p1 [$ns create-connection Ping $n(1) Ping $n(3) 2] set p2 [$ns create-connection Ping $n(2) Ping $n(4) 3] set p3 [$ns create-connection Ping $n(3) Ping $n(5) 4] set p4 [$ns create-connection Ping $n(4) Ping $n(1) 0] set p5 [$ns create-connection Ping $n(5) Ping $n(2) 5] #Queue size is set to 2 to observe the drop in ping packets $ns queue-limit $n(4) $n(5) 2 $ns duplex-link-op $n(4) $n(5) queuePos 0.5 #Schedule events for { set i 0} {$i < 6} {incr i} { for {set j 0} {$j < 6} {incr j} { $ns at [expr $i+.1+$j/10] "$p0 send" $ns at [expr $i+.1+$j/10] "$p1 send" $ns at [expr $i+.1+$j/10] "$p2 send" $ns at [expr $i+.1+$j/10] "$p3 send" $ns at [expr $i+.1+$j/10] "$p4 send" set ns [new Simulator] #Use colors to differentiate the traffic $ns color 1 Blue $ns color 2 Red $ns color 3 Green $ns color 4 Yellow $ns color 5 Cyan $ns color 0 Black #Open trace and NAM trace file set ntrace [open pg2.tr w] $ns trace-all $ntrace set namfile [open pg2.nam w] $ns namtrace-all $namfile #Finish Procedure proc Finish {} { global ns ntrace namfile #Dump all trace data and close the file $ns flush-trace close $ntrace close $namfile #Execute the nam animation file exec nam prog4.nam & } #Create six nodes for {set i 0} {$i < 6} {incr i} { set n($i) [$ns node] } #Create Links between nodes for {set j 0} {$j < 4} {incr j} { $ns duplex-link $n($j) $n(5) 1Mb 10ms DropTail } $ns duplex-link $n(5) $n(4) 1Mb 10ms DropTail # Define a 'recv' function for the class 'Agent/Ping' Agent/Ping instproc recv {from rtt} { $self instvar node_ puts "node [$node_ id] received ping answer from $from with round-trip-time $rtt ms." } #connections set p0 [$ns create-connection Ping $n(0) Ping $n(1) 1] set p1 [$ns create-connection Ping $n(1) Ping $n(3) 2] set p2 [$ns create-connection Ping $n(2) Ping $n(4) 3] set p3 [$ns create-connection Ping $n(3) Ping $n(5) 4] set p4 [$ns create-connection Ping $n(4) Ping $n(1) 0] set p5 [$ns create-connection Ping $n(5) Ping $n(2) 5] #Queue size is set to 2 to observe the drop in ping packets $ns queue-limit $n(4) $n(5) 2 $ns duplex-link-op $n(4) $n(5) queuePos 0.5 #Schedule events for { set i 0} {$i < 6} {incr i} { for {set j 0} {$j < 6} {incr j} { $ns at [expr $i+.1+$j/10] "$p0 send" $ns at [expr $i+.1+$j/10] "$p1 send" $ns at [expr $i+.1+$j/10] "$p2 send" $ns at [expr $i+.1+$j/10] "$p3 send" $ns at [expr $i+.1+$j/10] "$p4 send" $ns at [expr $i+.1+$j/10] "$p5 send" } } $ns at 6.0 "Finish" #Run the Simulation $ns run
proc qf {a b c} { if {$a == 0} {error "Denominator can not be zero"} set s [expr sqrt($b*$b-4*$a*$c)] set d [expr 2*$a] list [expr (-$b+$s)/$d] \ [expr (-$b-$s)/$d] } qf 1 0 -2 catch {qf 0 0 -2} roots set roots puts $roots
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more