File: MySnoop.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 (152 lines) | stat: -rw-r--r-- 3,313 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
puts "sourcing ../../lan/vlan.tcl..."
source ../..//lan/vlan.tcl
source ../../lan/ns-mac.tcl


set opt(tr)   out.tr
set opt(namtr)        "MySnoop.nam"
set opt(seed) 0
set opt(stop) 10
set opt(node) 2

set opt(qsize)        100
set opt(bw)   10Mb
set opt(delay)        1ms
set opt(ll)   LL
set opt(ifq)  Queue/DropTail
set opt(mac)  Mac/802_3
set opt(chan) Channel
set opt(tcp)  TCP/Reno
set opt(sink) TCPSink

set opt(app)  FTP

set loss_prob 10


proc finish {} {
      global ns opt

      $ns flush-trace

      exec nam $opt(namtr) &

      exit 0
}


proc create-trace {} {
      global ns opt

      if [file exists $opt(tr)] {
              catch "exec rm -f $opt(tr) $opt(tr)-bw [glob $opt(tr).*]"
      }

      set trfd [open $opt(tr) w]
      $ns trace-all $trfd
      if {$opt(namtr) != ""} {
              $ns namtrace-all [open $opt(namtr) w]
      }
      return $trfd
}

proc add-error {LossyLink} {

    global loss_prob
    
    # creating the uniform distribution random variable
    set loss_random_variable [new RandomVariable/Uniform] 
    $loss_random_variable set min_ 0    # set the range of the random variable;
    $loss_random_variable set max_ 100
    
    # create the error model;
    set loss_module [new ErrorModel]  
    $loss_module drop-target [new Agent/Null] 
    $loss_module set rate_ $loss_prob  # set error rate to (0.1 = 10 / (100 - 0));
    # error unit: packets (the default);
    $loss_module unit pkt      
    
    # attach random var. to loss module;
    $loss_module ranvar $loss_random_variable 

    # keep a handle to the loss module;
    #set sessionhelper [$ns create-session $n0 $tcp0] 
    $LossyLink errormodule $loss_module



}

proc create-topology {} {
      global ns opt 
      global lan node s d

      set num $opt(node)
      for {set i 1} {$i < $num} {incr i} {
              set node($i) [$ns node]
              lappend nodelist $node($i)
      }

      set lan [$ns make-lan $nodelist $opt(bw) \
                      $opt(delay) $opt(ll) $opt(ifq) $opt(mac) $opt(chan)]
      

      set opt(ll) LL/LLSnoop

      set opt(ifq) Queue/DropTail
      $opt(ifq) set limit_ 100

      # set up snoop agent
      set node(0) [$ns node]
      $lan addNode [list $node(0)]  $opt(bw) $opt(delay) $opt(ll) $opt(ifq) $opt(mac)
      
      # set source and connect to node(0)
      set s [$ns node]
      $ns duplex-link $s $node(0) 5Mb 20ms DropTail
      $ns queue-limit $s $node(0) 100000
      $ns duplex-link-op $s $node(0) orient right

      # set dest and connect to node(1)
      set d [$ns node]
      $ns duplex-link $node(1) $d 5Mb 10ms DropTail
      $ns queue-limit $node(1) $d 100000
      $ns duplex-link-op $d $node(1) orient left



      set LossyLink [$ns link $node(1) $d]  

      add-error $LossyLink
}

## MAIN ##

set ns [new Simulator]

set trfd [create-trace]

create-topology

#set tcp0 [$ns create-connection TCP/Reno $s TCPSink $node(1) 0]
#$tcp0 set window_ 30


#Create a infinite source agent (FTP) tcp and attach it to node n0
set tcp0 [new Agent/TCP/Reno]
$tcp0 set backoff_ 2 
$tcp0 set window_ 30
$ns attach-agent $s $tcp0

set tcp_snk0 [new Agent/TCPSink]
$ns attach-agent $d $tcp_snk0

$ns connect $tcp0 $tcp_snk0


set ftp0 [$tcp0 attach-app FTP]

$ns at 0.0 "$ftp0 start"
$ns at $opt(stop) "finish"
$ns run