Debian Codegraph @

protolib/src/sim/ns/protoTCPExample.tcl

raw
1 set ns_ [new Simulator]
2
3 # Open a trace file
4 set f [open protoExample.tr w]
5 $ns_ trace-all $f
6
7 # Create two nodes
8 set n1 [$ns_ node]
9 set n2 [$ns_ node]
10
11 # Put a link between them
12 $ns_ duplex-link $n1 $n2 64kb 100ms DropTail
13 $ns_ queue-limit $n1 $n2 100
14 $ns_ duplex-link-op $n1 $n2 queuePos 0.5
15 $ns_ duplex-link-op $n1 $n2 orient right
16
17 puts "Creating Protean agents ..."
18 # Create two Protean example agents and attach to nodes
19 set p1 [new Agent/ProtoExample]
20 set p2 [new Agent/ProtoExample]
21
22 $ns_ attach-agent $n1 $p1
23 $ns_ attach-agent $n2 $p2
24
25 puts "Starting simulation ..."
26
27 $ns_ at 1.0 "$p1 startup listen 44"
28
29 $ns_ at 2.0 "$p2 startup connect 0/44"
30
31 $ns_ at 400.0 "$p2 shutdown"
32
33 $ns_ at 500.0 "puts {half way there ...}"
34
35 $ns_ at 1000.0 "finish $ns_ $f"
36
37 proc finish {ns_ f} {
38 $ns_ flush-trace
39 close $f
40 $ns_ halt
41 delete $ns_
42 puts "Simulation complete."
43 }
44
45 $ns_ run
46