Debian Codegraph @

protolib/src/sim/ns/example.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 example.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 agent ..."
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 # Run a single Protean agent looping back to itself
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 send $group/5000"
45 #$ns_ at 0.0 "$p1 send [$n2 node-addr] [$p2 port]"
46
47 # Stop
48 $ns_ at 99.0 "$p1 shutdown"
49 $ns_ at 99.0 "$p2 shutdown"
50 $ns_ at 100.0 "finish $ns_ $f"
51
52 proc finish {ns_ f} {
53 $ns_ flush-trace
54 close $f
55 $ns_ halt
56 delete $ns_
57 }
58
59 $ns_ run
60