Ns-2 TCP-UDP Simulation Experiment

Source: Internet
Author: User

Simulates a network environment that contains two transport nodes s1,s2, router R, and data receive side D.

Probably as shown:

Source:

Set NS [New Simulator]
$ns Color 1 Blue
$ns Color 2 Red

Set NF [Open Out.nam W]
$ns Namtrace-all $NF

set nd [Open out.tr W]
$ns Trace-all $nd

Proc Finish {} {
Global NS NF ND
$ns Flush-trace
Close $NF
Close $nd

exec Nam Out.nam &
Exit 0
}

Set S1 [$ns node]
Set s2 [$ns node]

Set r [$ns node]

Set d [$ns node]

$ns Duplex-link $s 1 $r 2Mb 10ms droptail
$ns Duplex-link $s 2 $r 2Mb 10ms droptail
$ns duplex-link $r $d 1.7Mb 20ms droptail

$ns queue-limit $r $d 10

$ns Duplex-link-op $s 1 $r Orient Right-down
$ns Duplex-link-op $s 2 $r Orient right-up
$ns duplex-link-op $r $d Orient Right

$ns duplex-link-op $r $d queuepos 0.5

Set TCP [New AGENT/TCP]
$ns attach-agent $s 1 $tcp
Set sink [New Agent/tcpsink]
$ns attach-agent $d $sink
$ns Connect $tcp $sink

$tcp Set fid_ 1

Set FTP [New APPLICATION/FTP]
$ftp attach-agent $tcp
$ftp Set Type_ FTP

Set UDP [New AGENT/UDP]
$ns Attach-agent $s 2 $udp
Set NULL [New Agent/null]
$ns attach-agent $d $null
$ns Connect $udp $null

$UDP Set Fid_ 2

Set CBR [New APPLICATION/TRAFFIC/CBR]
$CBR attach-agent $UDP
$CBR set Type_ CBR

$CBR Set Packet_size_ 1000

$CBR Set Rate_ 1MB
$CBR Set Random_ False

$ns at 0.1 "$CBR start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp Stop"
$ns at 4.5 "$CBR stop"

$ns at 4.5 "$ns detach-agent $s 1 $tcp"
$ns at 4.5 "$ns detach-agent $d $sink"

$ns at 5.0 "Finish"

$ns Run

Program Run diagram

out.tr Partial records:

+ 0.1 1 2 CBR-------2 1.0 3.1 0 0

-0.1 1 2 CBR-------2 1.0 3.1 0 0

+ 0.108 1 2 CBR-------2 1.0 3.1 1 1

-0.108 1 2 CBR-------2 1.0 3.1 1 1

R 0.114 1 2 CBR-------2 1.0 3.1 0 0

The data format is as follows:

R:receive (at To-node) src-addr:node.port

+:enqueue (at queue) Dst-addr:node.port

-:d Equeue (at queue)

D:drop (at queue)

Taking the first row of data as an example, there is probably a packet packet ID 0, the data flow ID is 2, the ordinal is 0, the length is 1000 bytes, the type is CBR, it is from the source 1.0 to the destination 3.1, in the time of 0.1 seconds, from Node 1 (S2) entered the Node 2 (r) In the queue.

To be Continued

Ns-2 TCP-UDP Simulation Experiment

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.