Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CN LAB
- PART-B
- 1. Simulate a three nodes point – to – point network with duplex links between
- them.Set the queue size and vary the bandwidth and find the number of packets
- dropped.
- set ns [new Simulator]
- set tf [open out.tr w]
- $ns trace-all $tf
- set nf [open out.nam w]
- $ns namtrace-all $nf
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- $ns duplex-link $n0 $n2 10Mb 300ms DropTail
- $ns duplex-link $n1 $n2 10Mb 300ms DropTail
- $ns duplex-link $n2 $n3 1Mb 300ms DropTail
- $ns queue-limit $n0 $n2 10
- $ns queue-limit $n1 $n2 10
- $ns queue-limit $n2 $n3 10
- set udp0 [new Agent/UDP]
- set udp1 [new Agent/UDP]
- set null3 [new Agent/Null]
- $ns attach-agent $n0 $udp0
- $ns attach-agent $n1 $udp1
- $ns attach-agent $n3 $null3
- set cbr0 [new Application/Traffic/CBR]
- set cbr1 [new Application/Traffic/CBR]
- $cbr0 attach-agent $udp0
- $cbr1 attach-agent $udp1
- $ns connect $udp0 $null3
- $ns connect $udp1 $null3
- $cbr0 set packetSize_ 500Mb
- $cbr1 set packetSize_ 500Mb
- $cbr0 set interval_ 0.005
- $cbr1 set interval_ 0.005
- proc finish {} {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $tf
- close $nf
- set count 0
- set tf [open out.tr r]
- while {[gets $tf line] != -1} {
- if { [string match "d*" $line] } {
- set count [expr $count + 1]
- }
- }
- puts "Number of packets dropped: $count"
- exit 0
- }
- $ns at 0.01 "$cbr0 start"
- $ns at 0.01 "$cbr1 start"
- $ns at 5.0 "finish"
- $ns run
- ############# output #############
- # Number of packets dropped: 700
- ---------------------------------------------------------------------------------------------------
- 2. Simulate the different types of Internet traffic such as FTP and TELNET over
- a network and analyze the throughput.
- set ns [new Simulator]
- set tf [open out.tr w]
- $ns trace-all $tf
- set nf [open out.nam w]
- $ns namtrace-all $nf
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- $ns duplex-link $n0 $n2 2Mb 1ms DropTail
- $ns duplex-link $n1 $n2 2Mb 1ms DropTail
- $ns duplex-link $n2 $n3 2Mb 1ms DropTail
- set tcp0 [new Agent/TCP]
- set tcp1 [new Agent/TCP]
- $ns attach-agent $n0 $tcp0
- $ns attach-agent $n1 $tcp1
- set TCPS0 [new Agent/TCPSink]
- set TCPS1 [new Agent/TCPSink]
- $ns attach-agent $n3 $TCPS0
- $ns attach-agent $n3 $TCPS1
- set ftp0 [new Application/FTP]
- $ftp0 attach-agent $tcp0
- set tel1 [new Application/Telnet]
- $tel1 attach-agent $tcp1
- $tel1 set packetSize_ 500Mb
- $tel1 set interval_ 0.001
- $ns connect $tcp0 $TCPS0
- $ns connect $tcp1 $TCPS1
- proc finish { } {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $tf
- close $nf
- set time 2
- set fCount 0
- set tCount 0
- set tf [open out.tr r]
- while {[gets $tf line] != -1} {
- if { [string match "*tcp*0.0*3.0*" $line] } {
- set fCount [expr $fCount + 1]
- }
- if { [string match "*tcp*1.0*3.1*" $line] } {
- set tCount [expr $tCount + 1]
- }
- }
- puts "Throughput of FTP: [expr $fCount/$time]"
- puts "Throughput of TELNET: [expr $tCount/$time]"
- exit 0
- }
- $ns at 0.01 "$ftp0 start"
- $ns at 0.01 "$tel1 start"
- $ns at 2.01 "finish"
- $ns run
- ############### output #################
- # No of FTP packets: 767
- # No of TELNET packets: 750
- -------------------------------------------------------------------------------------------------------------
- 3. Simulate an Ethernet LAN using n nodes (6-10), change error rate and data
- rate and compare the throughput.
- set ns [new Simulator]
- set tf [open out.tr w]
- set nf [open out.nam w]
- $ns trace-all $tf
- $ns namtrace-all $nf
- puts "Enter error rate (<1) : "
- gets stdin erate
- puts "Enter data rate (in Mbps) : "
- gets stdin drate
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- set n6 [$ns node]
- # set label and color (OPTIONAL)
- $n1 label "udp/source"
- $n5 label "udp/null"
- $n0 color "blue"
- $n1 color "blue"
- $n2 color "blue"
- $n3 color "blue"
- $n4 color "red"
- $n5 color "red"
- $n6 color "red"
- $ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3
- $ns make-lan "$n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3
- $ns duplex-link $n3 $n6 10Mb 10ms DropTail
- set udp1 [new Agent/UDP]
- set null5 [new Agent/Null]
- $ns attach-agent $n1 $udp1
- $ns attach-agent $n5 $null5
- set cbr1 [new Application/Traffic/CBR]
- $cbr1 attach-agent $udp1
- $ns connect $udp1 $null5
- set err [new ErrorModel]
- $ns lossmodel $err $n3 $n6
- $err set rate_ $erate
- $cbr1 set packetSize_ $drate.Mb
- $cbr1 set interval_ 0.001
- proc finish { } {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $nf
- close $tf
- set count 0
- set tr [open out.tr r]
- while {[gets $tr line] != -1} {
- if {[string match "* 8 5 *" $line]} {
- set count [expr $count+1]
- }
- }
- set thr [expr $count/5]
- puts "Throughput : $thr"
- exit 0
- }
- $ns at 0.1 "$cbr1 start"
- $ns at 5.1 "finish"
- $ns run
- -------------------------------------------------------------------------------------------------------------------
- 4. Simulate an Ethernet LAN using n nodes and set multiple traffic nodes and
- determine the collision across different nodes.
- set ns [new Simulator]
- set tf [open out.tr w]
- set nf [open out.nam w]
- $ns trace-all $tf
- $ns namtrace-all $nf
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- $ns make-lan -trace on "$n0 $n1 $n2 $n3" 100Mb 10ms LL Queue/DropTail Mac/802_3
- set tcp0 [new Agent/TCP]
- set tcp1 [new Agent/TCP]
- set udp2 [new Agent/UDP]
- set null1 [new Agent/Null]
- set sink2 [new Agent/TCPSink]
- set sink3 [new Agent/TCPSink]
- $ns attach-agent $n0 $tcp0
- $ns attach-agent $n1 $tcp1
- $ns attach-agent $n2 $udp2
- $ns attach-agent $n1 $null1
- $ns attach-agent $n2 $sink2
- $ns attach-agent $n3 $sink3
- set ftp0 [new Application/FTP]
- set ftp1 [new Application/FTP]
- set cbr2 [new Application/Traffic/CBR]
- $ftp0 attach-agent $tcp0
- $ftp1 attach-agent $tcp1
- $cbr2 attach-agent $udp2
- $ns connect $tcp0 $sink2
- $ns connect $udp2 $null1
- $ns connect $tcp1 $sink3
- $ftp0 set interval_ 0.001
- $ftp1 set interval_ 0.001
- $cbr2 set interval_ 0.01
- proc finish {} {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $tf
- close $nf
- set count 0
- set tr [open out.tr r]
- while {[gets $tr line] !=-1 } {
- if { [string match "c*" $line] } {
- set count [expr $count + 1]
- }
- }
- puts "No of packets collided: $count"
- exit 0
- }
- $ns at 0.1 "$cbr2 start"
- $ns at 0.1 "$ftp0 start"
- $ns at 0.1 "$ftp1 start"
- $ns at 5.0 "finish"
- $ns run
- ############ output ############
- # No of packets collided: 242
- --------------------------------------------------------------------------------------------------------
- 5. Simulate the transmission of ping messages over a network topology
- consisting of 6 nodes and find the number of packets dropped due to congestion.
- set ns [new Simulator]
- set tf [open out.tr w]
- set nf [open out.nam w]
- $ns trace-all $tf
- $ns namtrace-all $nf
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- set n3 [$ns node]
- set n4 [$ns node]
- set n5 [$ns node]
- set n6 [$ns node]
- $ns duplex-link $n0 $n2 100Mb 300ms DropTail
- $ns duplex-link $n5 $n2 100Mb 300ms DropTail
- $ns duplex-link $n1 $n2 100Mb 300ms DropTail
- $ns duplex-link $n3 $n2 100Mb 300ms DropTail
- $ns duplex-link $n2 $n4 100Mb 300ms DropTail
- $ns duplex-link $n2 $n6 100Mb 300ms DropTail
- set ping0 [new Agent/Ping]
- set ping4 [new Agent/Ping]
- set ping5 [new Agent/Ping]
- set ping6 [new Agent/Ping]
- $ns attach-agent $n0 $ping0
- $ns attach-agent $n4 $ping4
- $ns attach-agent $n5 $ping5
- $ns attach-agent $n6 $ping6
- $ns connect $ping0 $ping4
- $ns connect $ping5 $ping6
- Agent/Ping instproc recv {from rtt} {
- $self instvar node_
- puts "The node [$node_ id] recieved $from with round trip time $rtt"
- }
- proc finish { } {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $nf
- close $tf
- set count 0
- set tr [open out.tr r]
- while {[gets $tr line]!=-1} {
- if {[string match "d*" $line]} {
- set count [expr $count + 1]
- }
- }
- puts "No. of packet dropped : $count"
- exit 0
- }
- $ns rtmodel-at 1 down $n2 $n6
- $ns rtmodel-at 2 up $n2 $n6
- for {set i 0.1} {$i<2} {set i [expr $i+0.1]} {
- $ns at $i "$ping0 send"
- $ns at $i "$ping5 send"
- }
- $ns at 5.0 "finish"
- $ns run
- ----------------------------------------------------------------------------------------------------------
- 6. A Simple ESS with transmitting nodes in Wireless LAN
- 7. A simple ad-hoc network with transmitting nodes
- set ns [new Simulator]
- set tf [open out.tr w]
- $ns trace-all $tf
- set nf [open out.nam w]
- $ns namtrace-all-wireless $nf 500 500
- set topo [new Topography]
- $topo load_flatgrid 500 500
- $ns node-config -adhocRouting DSDV \
- -llType LL \
- -macType Mac/802_11 \
- -ifqType Queue/DropTail \
- -ifqLen 50 \
- -phyType Phy/WirelessPhy \
- -channelType Channel/WirelessChannel \
- -propType Propagation/TwoRayGround \
- -antType Antenna/OmniAntenna \
- -topoInstance $topo \
- -agentTrace ON \
- -routerTrace ON \
- -macTrace OFF
- # Create a god object
- create-god 3
- set n0 [$ns node]
- set n1 [$ns node]
- set n2 [$ns node]
- $n0 set X_ 10
- $n0 set Y_ 10
- $n0 set Z_ 0
- $n1 set X_ 100
- $n1 set Y_ 100
- $n1 set Z_ 0
- $n2 set X_ 400
- $n2 set Y_ 400
- $n2 set Z_ 0
- $ns at 0.0 "$n0 setdest 10 10 15"
- $ns at 0.0 "$n1 setdest 100 100 15"
- $ns at 0.0 "$n2 setdest 400 400 15"
- $ns at 50 "$n1 setdest 300 300 15"
- $ns at 100 "$n1 setdest 100 100 15"
- set tcp0 [new Agent/TCP]
- set tcp1 [new Agent/TCP]
- $ns attach-agent $n0 $tcp0
- $ns attach-agent $n1 $tcp1
- set sink1 [new Agent/TCPSink]
- set sink2 [new Agent/TCPSink]
- $ns attach-agent $n1 $sink1
- $ns attach-agent $n2 $sink2
- set ftp0 [new Application/FTP]
- set ftp1 [new Application/FTP]
- $ftp0 attach-agent $tcp0
- $ftp1 attach-agent $tcp1
- $ns connect $tcp0 $sink1
- $ns connect $tcp1 $sink2
- proc finish { } {
- global ns nf tf
- $ns flush-trace
- exec nam out.nam &
- close $tf
- set ctr1 0
- set ctr2 0
- set tf [open out.tr r]
- while {[gets $tf line] != -1} {
- if {[string match "r*_1_*AGT*" $line]} {
- set ctr1 [expr $ctr1 + 1]
- }
- if {[string match "r*_2_*AGT*" $line]} {
- set ctr2 [expr $ctr2 + 1]
- }
- }
- puts "\nThroughput from n0 to n1: $ctr1"
- puts "Throughput from n1 to n2: $ctr2"
- exit 0
- }
- $ns at 1 "$ftp0 start"
- $ns at 1 "$ftp1 start"
- $ns at 150 "finish"
- $ns run
- ######################## output ###########################
- # num_nodes is set 3
- # INITIALIZE THE LIST xListHead
- # channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
- # highestAntennaZ_ = 1.5, distCST_ = 550.0
- # SORTING LISTS ...DONE!
- #
- # Throughput from n0 to n1: 8438
- # Throughput from n1 to n2: 3000
- ###########################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement