Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Star Topology
- set ns [new Simulator]
- set nf [open st.nam w]
- $ns namtrace-all $nf
- proc finish {} {
- global ns nf
- $ns flush-trace
- close $nf
- exec nam st.nam &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- $ns duplex-link $n0 $n2 10Mb 10ms DropTail
- $ns duplex-link $n1 $n2 10Mb 10ms DropTail
- $ns duplex-link $n2 $n3 10Mb 10ms DropTail
- $ns duplex-link-op $n0 $n2 orient right-down
- $ns duplex-link-op $n1 $n2 orient right-up
- $ns duplex-link-op $n2 $n3 orient right
- $ns at 5.0 "finish"
- $ns run
- -----------------------------------------------------------------------------------------------------------
- #Throuhput Latency
- set ns [new Simulator]
- $ns color 1 red
- $ns color 2 green
- set nf [open tl.nam w]
- $ns namtrace-all $nf
- set nt [open tl.tr w]
- $ns trace-all $nt
- proc finish {} {
- global ns nf nt
- $ns flush-trace
- close $nf
- close $nt
- exec nam tl.nam &
- exec awk -f throughput.awk tl.tr &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- $ns duplex-link $n0 $n2 10Mb 10ms DropTail
- $ns duplex-link $n1 $n2 10Mb 10ms DropTail
- $ns duplex-link $n2 $n3 10Mb 10ms DropTail
- $ns duplex-link-op $n0 $n2 orient right-down
- $ns duplex-link-op $n1 $n2 orient right-up
- $ns duplex-link-op $n2 $n3 orient right
- set tcp [new Agent/TCP]
- $tcp set class_ 2
- $ns attach-agent $n0 $tcp
- set sink [new Agent/TCPSink]
- $ns attach-agent $n3 $sink
- $ns connect $tcp $sink
- $tcp set fid_ 1
- set ftp [new Application/FTP]
- $ftp attach-agent $tcp
- $ftp set type_ FTP
- $ftp set packet_size_ 1000
- $ftp set rate_ 1mb
- set udp [new Agent/UDP]
- $ns attach-agent $n1 $udp
- set null [new Agent/Null]
- $ns attach-agent $n3 $null
- $ns connect $udp $null
- $udp set fid_ 2
- set cbr [new Application/Traffic/CBR]
- $cbr attach-agent $udp
- $cbr set type_ UDP
- $cbr set packet_size_ 1000
- $cbr set rate_ 1mb
- $ns at 1.0 "$ftp start"
- $ns at 2.0 "$ftp stop"
- $ns at 1.2 "$cbr start"
- $ns at 2.2 "$cbr stop"
- $ns at 5.0 "finish"
- $ns run
- # throughput.awk
- BEGIN {
- stime=0
- ftime=0
- flag=0
- fsize=0
- throughput=0
- latecy=0
- }
- {
- if($1=="r" && $4==3)
- {
- fsize+=$6
- if(flag==0)
- {
- stime=$2
- flag=1
- }
- ftime=$2
- }
- }
- END {
- latency=ftime-stime
- throughput=(fsize*8)/latency
- printf("\nLatency: %f",latency)
- printf("\nThroughput: %f",throughput)
- }
- ----------------------------------------------------------------------------------------
- #ping
- set ns [new Simulator]
- set tracefile [open out.tr w]
- $ns trace-all $tracefile
- set namfile [open out.nam w]
- $ns namtrace-all $namfile
- proc finish {} {
- global ns tracefile namfile
- $ns flush-trace
- close $tracefile
- close $namfile
- exec nam out.nam &
- exec awk -f pingtp.awk out.tr &
- exit 0
- }
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- $n0 label "ping0"
- $n1 label "ping1"
- $n2 label "R1"
- $n3 label "R2"
- $n4 label "ping4"
- $n5 label "ping5"
- $ns color 1 red
- $ns color 2 blue
- $ns color 3 green
- $ns color 4 orange
- $ns duplex-link $n0 $n2 1Mb 10ms DropTail
- $ns duplex-link $n1 $n2 0.4Mb 10ms DropTail
- $ns duplex-link $n2 $n3 4Kb 10ms DropTail
- $ns duplex-link $n3 $n4 1Mb 10ms DropTail
- $ns duplex-link $n3 $n5 1Mb 10ms DropTail
- $ns duplex-link-op $n0 $n2 orient right-down
- $ns duplex-link-op $n1 $n2 orient right-up
- $ns duplex-link-op $n2 $n3 orient right
- $ns duplex-link-op $n3 $n4 orient right-up
- $ns duplex-link-op $n3 $n5 orient right-down
- set ping0 [new Agent/Ping]
- $ns attach-agent $n0 $ping0
- set ping1 [new Agent/Ping]
- $ns attach-agent $n1 $ping1
- set ping4 [new Agent/Ping]
- $ns attach-agent $n4 $ping4
- set ping5 [new Agent/Ping]
- $ns attach-agent $n5 $ping5
- $ns connect $ping0 $ping4
- $ns connect $ping1 $ping5
- $ping0 set class_ 1
- $ping1 set class_ 2
- $ping4 set class_ 3
- $ping5 set class_ 4
- proc sendPingPacket {} {
- global ns ping0 ping1
- set intervalTime 0.001
- set now [$ns now]
- $ns at [expr $now + $intervalTime] "$ping0 send"
- $ns at [expr $now + $intervalTime] "$ping1 send"
- $ns at [expr $now + $intervalTime] "sendPingPacket"
- }
- Agent/Ping instproc recv {from rtt} {
- global seq
- $self instvar node_
- puts "The node [$node_ id] received an ACK from the node $from with RTT $rtt ms"
- }
- $ns at 0.01 "sendPingPacket"
- $ns at 10.0 "finish"
- $ns run
- # Pingtp.awk
- BEGIN {
- count=0
- }
- {
- event=$1
- if(event=="d") {
- count++
- }
- }
- END {
- printf("No. of Packets dropped: %d\n",count);
- }
- ----------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement