0% found this document useful (0 votes)
20 views11 pages

CN TCP Udp

Uploaded by

kingmhd1519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views11 pages

CN TCP Udp

Uploaded by

kingmhd1519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

#Q.

Tcl attch with 2 node

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n1 12MB 10ms DropTail
$ns duplex-link $n3 $n4 2MB 1ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n1 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

set tcp2 [new Agent/TCP]


set sink2 [new Agent/TCPSink]

$ns attach-agent $n4 $tcp2


$ns attach-agent $n3 $sink2

set ftp2 [new Application/FTP]


$ftp2 attach-agent $tcp2
$ns connect $tcp2 $sink2

$ns at 1.0 "$ftp start"


$ns at 3.0 "finish"

$ns at 1.0 "$ftp2 start"


$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}
$ns run
#Q. set/attach tcp and then, detach tcp attach attach udp

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n1 12MB 10ms DropTail
$ns duplex-link $n3 $n4 2MB 1ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n1 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 0.2 "$ftp start"


$ns at 1.0 "$ftp stop"

$ns at 1.1 "$ns detach-agent $n0 $tcp"


$ns at 1.1 "$ns detach-agent $n1 $sink"

set udp [new Agent/UDP]


$ns attach-agent $n0 $udp

set null [new Agent/Null]


$ns attach-agent $n1 $null
$ns connect $udp $null
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp

$ns at 1.2 "$cbr start"


$ns at 2.0 "$cbr stop"

$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run
#Q. bus topology

set ns [new Simulator]

set nf [open out.nam w]


$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace

#Close the trace file

close $nf

exec nam out.nam &


exit 0
}

#Create five nodes


set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#Create Lan between the nodes
set lan0 [$ns newLan "$n0 $n1 $n2 $n3 $n4" 0.5Mb 40ms LL Queue/DropTail
MAC/Csma/Cd Channel]

#Create a TCP agent and attach it to node n0


set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0

#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node
n3

set sink0 [new Agent/TCPSink]


$ns attach-agent $n3 $sink0

#Connect the traffic sources with the traffic sink


$ns connect $tcp0 $sink0

# Create a CBR traffic source and attach it to tcp0

set cbr0 [new Application/Traffic/CBR]


$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"

$ns run
#Q. koi bhi file in star topology

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n0 $n2 2.5MB 1ms RED
$ns duplex-link $n0 $n3 2MB 1.5ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n2 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 1.0 "$ftp start"


$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}
$ns run
#Q. ftp [ tcp set in koi bhi topology

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n1 12MB 10ms DropTail
$ns duplex-link $n3 $n4 2MB 1ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n1 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 0.2 "$ftp start"


$ns at 1.0 "$ftp stop"

$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run
#Q. hybrid
set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n1 12MB 10ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n2 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 1.0 "$ftp start"


$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run
#Q. ring

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n0 12MB 10ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n1 $tcp


$ns attach-agent $n3 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 1.0 "$ftp start"


$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run
#Q.star

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n0 $n2 2.5MB 1ms RED
$ns duplex-link $n0 $n3 12MB 10ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n2 $sink

$ns attach-agent $n1 $tcp


$ns attach-agent $n3 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

$ns at 1.0 "$ftp start"


$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run
#Q. tcp and udp swap (Swap tcp and udp)

set ns [new Simulator]

set namf [open wired.nam w]


$ns namtrace-all $namf

set tracef [open wired.tr w]


$ns trace-all $tracef

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$ns duplex-link $n0 $n1 2MB 1ms DropTail


$ns duplex-link $n1 $n2 2.5MB 1ms RED
$ns duplex-link $n2 $n3 2MB 1.5ms DropTail
$ns duplex-link $n3 $n4 2MB 1ms DropTail
$ns duplex-link $n4 $n5 2MB 1ms DropTail
$ns duplex-link $n5 $n0 2MB 1ms DropTail

set tcp [new Agent/TCP]


set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp


$ns attach-agent $n1 $sink

set ftp [new Application/FTP]


$ftp attach-agent $tcp
$ns connect $tcp $sink

set udp [new Agent/UDP]


$ns attach-agent $n3 $udp

set null [new Agent/Null]


$ns attach-agent $n4 $null
$ns connect $udp $null

set cbr [new Application/Traffic/CBR]


$cbr attach-agent $udp

$ns at 0.2 "$ftp start"


$ns at 1.0 "$ftp stop"

$ns at 0.2 "$cbr start"


$ns at 1.0 "$cbr stop"
$ns at 3.0 "finish"

proc finish {} {
global ns namf tracef
$ns flush-trace
close $namf
close $tracef
exec nam wired.nam &
exit 0
}

$ns run

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy