left.gif (284 bytes) up.gif (289 bytes) right.gif (280 bytes)

#lan2.tcl
#Create a simulator object
set ns [new Simulator]

#Open the nam trace file
set nf [open lan2.nam w]
$ns namtrace-all $nf

set tf [open lan2.tr w]
$ns trace-all $tf

$ns color 1 Blue
$ns color 2 Red

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        global tf
	$ns flush-trace
	#Close the trace file
        close $nf
	close $tf
	#Execute nam on the trace file
        exec nam lan2.nam &
        exit 0
}

for {set i 0} {$i < 8 } {incr i} {
	set n($i) [$ns node]
	lappend nodelist $n($i)
}

set lan [$ns newLan $nodelist 10Mb 20us \
		-llType LL \
		-ifqType Queue/DropTail \
		-macType Mac/Csma/Cd \
		-chanType Channel ]

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

$ns duplex-link $n0 $n(0) 1Mb 0.05ms DropTail
$ns duplex-link $n0 $n1 1Mb 0.05ms DropTail
$ns duplex-link $n0 $n2 1Mb 0.05ms DropTail

$ns duplex-link-op $n0 $n(0) orient right
$ns duplex-link-op $n0 $n1 orient left-up
$ns duplex-link-op $n0 $n2 orient left-down

set tcp1 [new Agent/TCP]
set tcp2 [new Agent/TCP]

$tcp1 set packetSize_ 100
$tcp2 set packetSize_ 100

set sink1 [new Agent/TCPSink]
set sink2 [new Agent/TCPSink]

$ns attach-agent $n(1) $tcp1
$ns attach-agent $n(2) $tcp2
$ns attach-agent $n1 $sink1
$ns attach-agent $n2 $sink2

$ns connect $tcp1 $sink1
$ns connect $tcp2 $sink2

set ftp1 [new Application/FTP]
set ftp2 [new Application/FTP]

$ftp1 attach-agent $tcp1
$ftp2 attach-agent $tcp2

$ftp1 set fid_ 1
$ftp2 set fid_ 2

$ns at 0.0 "$ftp1 start"
$ns at 0.0 "$ftp2 start"

#Call the finish procedure after 1 seconds simulation time
$ns at 0.5 "finish"

#Run the simulation
$ns run

left.gif (284 bytes) up.gif (289 bytes) right.gif (280 bytes)