Debian Codegraph @

protolib/src/sim/ns/protoExample.tcl

raw
1 # Protean example agent example
2
3 # Create multicast enabled simulator instance
4 set ns_ [new Simulator -multicast on]
5 $ns_ multicast
6
7 # Open a trace file
8 set f [open protoExample.tr w]
9 $ns_ trace-all $f
10
11 # Create two nodes
12 set n1 [$ns_ node]
13 set n2 [$ns_ node]
14
15 # Put a link between them
16 $ns_ duplex-link $n1 $n2 64kb 100ms DropTail
17 $ns_ queue-limit $n1 $n2 100
18 $ns_ duplex-link-op $n1 $n2 queuePos 0.5
19 $ns_ duplex-link-op $n1 $n2 orient right
20
21 # Configure multicast routing for topology
22 set mproto DM
23 set mrthandle [$ns_ mrtproto $mproto {}]
24 if {$mrthandle != ""} {
25 $mrthandle set_c_rp [list $n1]
26 }
27
28 # 5) Allocate a multicast address to use
29 set group [Node allocaddr]
30
31 puts "Creating Protean agents ..."
32 # Create two Protean example agents and attach to nodes
33 set p1 [new Agent/ProtoExample]
34 $ns_ attach-agent $n1 $p1
35
36 set p2 [new Agent/ProtoExample]
37 $ns_ attach-agent $n2 $p2
38
39 # Have one Protean agent transmit to the other
40 puts "Starting simulation ..."
41
42 # Start example sender and receiver
43 $ns_ at 0.0 "$p2 recv $group/5000"
44 $ns_ at 0.0 "$p1 recv $group/5000"
45
46 $ns_ at 0.0 "$p1 send $group/5000"
47
48 #$ns_ at 0.0 "$p1 startup send [$n2 node-addr]/5000"
49
50 $ns_ at 50.0 "puts {half way there ...}"
51
52 $ns_ at 99.0 "$p2 shutdown"
53 $ns_ at 99.0 "$p1 shutdown"
54
55 # Stop
56 $ns_ at 99.0 "$p1 stop"
57 $ns_ at 99.0 "$p2 stop"
58 $ns_ at 10.0 "finish $ns_ $f"
59
60 proc finish {ns_ f} {
61 $ns_ flush-trace
62 close $f
63 $ns_ halt
64 delete $ns_
65 puts "Simulation complete."
66 }
67
68 $ns_ run
69