NS2 simulation under the UDP protocol

Source: Internet
Author: User

From SIMPLE.TCL

Set NS [New Simulator]

$ns Color 0 Blue
$ns Color 1 red
$ns Color 2 White

Set n0 [$ns node]
Set n1 [$ns node]
Set N2 [$ns node]
Set N3 [$ns node]

Set f [Open out.tr W]
$ns Trace-all $f
Set NF [Open Out.nam W]
$ns Namtrace-all $NF

$ns duplex-link $n 0 $n 2 5Mb 2ms droptail
$ns duplex-link $n 1 $n 2 5Mb 2ms droptail
$ns duplex-link $n 2 $n 3 1.5Mb 10ms droptail

$ns duplex-link-op $n 0 $n 2 Orient right-up
$ns duplex-link-op $n 1 $n 2 Orient Right-down
$ns duplex-link-op $n 2 $n 3 Orient Right

$ns duplex-link-op $n 2 $n 3 Queuepos 0.5

Set udp0 [New AGENT/UDP]
$ns attach-agent $n 0 $udp 0
Set cbr0 [New APPLICATION/TRAFFIC/CBR]
$CBR 0 attach-agent $udp 0

Set UDP1 [New AGENT/UDP]
$ns attach-agent $n 3 $udp 1
$UDP 1 Set Class_ 1
Set CBR1 [New APPLICATION/TRAFFIC/CBR]
$CBR 1 attach-agent $udp 1

Set null0 [New Agent/null]
$ns attach-agent $n 3 $null 0

Set NULL1 [New Agent/null]
$ns attach-agent $n 1 $null 1

$ns Connect $UDP 0 $null 0
$ns Connect $udp 1 $null 1

$ns at 1.0 "$CBR 0 start"
$ns at 1.1 "$CBR 1 Start"

Set TCP [New AGENT/TCP]
$tcp Set Class_ 2
Set sink [New Agent/tcpsink]
$ns attach-agent $n 0 $tcp
$ns attach-agent $n 3 $sink
$ns Connect $tcp $sink
Set FTP [New APPLICATION/FTP]
$ftp attach-agent $tcp
$ns at 1.2 "$ftp start"

$ns at 1.35 "$ns detach-agent $n 0 $tcp; $ns detach-agent $n 3 $sink "

puts [$CBR 0 set Packetsize_]
puts [$CBR 0 set Interval_]

$ns at 3.0 "Finish"

Proc Finish {} {
Global NS F NF
$ns Flush-trace
Close $f
Close $NF

Puts "Running nam ..."
exec Nam Out.nam &
Exit 0
}

$ns Run

NS2 simulation under the UDP protocol

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.