File: src_test.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (78 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 
# Contributed by Rishi Bhargava <rishi_bhargava@yahoo.com> May, 2001.
# Example script for source-routing; also see ~ns/src_rtg/README.txt
#

#Create a simulator object
set ns [new Simulator] 

# enable source routing

$ns src_rting 1

$ns color 1 Blue
$ns color 2 Red

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

#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]

#Create links between the nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n3 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail

#Create a TCP agent and attach it to node n0
set cbr0 [new Agent/TCP]
$ns attach-agent $n0 $cbr0
$cbr0 set fid_ 0

#Create a TCP agent and attach it to node n1
set cbr1 [new Agent/TCP]
$ns attach-agent $n3 $cbr1

$cbr1 set fid_ 1

$cbr0 target [$n0 set src_agent_]
$cbr1 target [$n3 set src_agent_]

set temp [$n0 set src_agent_]
$temp install_connection [$cbr0 set fid_] 0 1 0 2 4 3 1
set temp [$n3 set src_agent_]
$temp install_connection [$cbr1 set fid_] 3 4 3 2 4 

set null0 [new Agent/TCPSink]
set null1 [new Agent/TCPSink]

$ns attach-agent $n1 $null0
$ns attach-agent $n4 $null1


$ns connect $cbr0 $null0  
$ns connect $cbr1 $null1

set ftp1 [$cbr0 attach-source FTP]
set ftp2 [$cbr1 attach-source FTP]


$ns at 0.5 "$ftp1 start"
$ns at 0.5 "$ftp2 start"
$ns at 5.0 "$ftp1 stop"
$ns at 10.5 "$ftp2 stop"


$ns at 11.0 "$ns halt"

$ns run