Hi i simulated a tcl tcp script for wireless-wired toplogy with ns2. i'am newer with awk i need a little script awk for calculating the sending rate and the loss rate .
Please help me .
Thanks here is the code tcl that i have used .
Please reply me .
Code:
### This simulation is an example of combination of wired and wireless
### topologies.
Phy/WirelessPhy set bandwidth_ 11Mb
Mac/802_11 set dataRate_ 11Mb
#Mac/802_11 set basicRate_ 0
Mac/802_11 set bandwidth_ 11Mb
global opt
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 500
set opt(y) 500
set opt(ifqlen) 50
set opt(tr) tcp-wireless.tr
set opt(namtr) tcp-wireless.nam
#number of mobile nodes
set opt(nn) 4 ;#Nombre de noeuds mobiles
set opt(adhocRouting) DSDV
set opt(cp) ""
set opt(stop) 400
set num_wired_nodes [expr $opt(nn)+1]
set num_bs_nodes 1
set ns_ [new Simulator]
#$ns_ use-newtrace
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 3
lappend cluster_num 1 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 101 3 1
AddrParams set nodes_num_ $eilastlevel
set tracefd [open $opt(tr) w]
$ns_ trace-all $tracefd
set namtracefd [open $opt(namtr) w]
$ns_ namtrace-all-wireless $namtracefd $opt(x) $opt(y)
set topo [new Topography]
$topo load_flatgrid $opt(x) $opt(y)
# god needs to know the number of all wireless interfaces
create-god [expr $opt(nn) + $num_bs_nodes]
#create wired nodes
set temp {0.0.0 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 0.0.10 \
0.0.11 0.0.12 0.0.13 0.0.14 0.0.15 0.0.16 0.0.17 0.0.18 0.0.19 0.0.20 \
0.0.21 0.0.22 0.0.23 0.0.24 0.0.25 0.0.26 0.0.27 0.0.28 0.0.29 0.0.30 \
0.0.31 0.0.32 0.0.33 0.0.34 0.0.35 0.0.36 0.0.37 0.0.38 0.0.39 0.0.40 \
0.0.41 0.0.42 0.0.43 0.0.44 0.0.45 0.0.46 0.0.47 0.0.48 0.0.49 0.0.50 \
0.0.51 0.0.52 0.0.53 0.0.54 0.0.55 0.0.56 0.0.57 0.0.58 0.0.59 0.0.60 \
0.0.61 0.0.62 0.0.63 0.0.64 0.0.65 0.0.66 0.0.67 0.0.68 0.0.69 0.0.70 \
0.0.71 0.0.72 0.0.73 0.0.74 0.0.75 0.0.76 0.0.77 0.0.78 0.0.79 0.0.80 \
0.0.81 0.0.82 0.0.83 0.0.84 0.0.85 0.0.86 0.0.87 0.0.88 0.0.89 0.0.90 \
0.0.91 0.0.92 0.0.93 0.0.94 0.0.95 0.0.96 0.0.97 0.0.98 0.0.99 0.0.100}
for {set i 0} {$i < $num_wired_nodes} {incr i} {
#Simulator set node_factory_ Node/MIPMH
set W($i) [$ns_ node [lindex $temp $i ]]
}
$ns_ node-config -mobileIP ON \
-adhocRouting $opt(adhocRouting) \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen $opt(ifqlen) \
-antType $opt(ant) \
-propInstance [new $opt(prop)] \
-phyType $opt(netif) \
-channel [new $opt(chan)] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace ON
set BS(0) [$ns_ node 1.0.0]
#set BS(1) [$ns_ node 2.0.0]
$BS(0) random-motion 0
#$BS(1) random-motion 0
#configure for mobilenodes
$ns_ node-config -wiredRouting OFF \
-ifqType Queue/DropTail/PriQueue \
set temp2 {1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.0.10 \
1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 \
1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 \
1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 \
1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 \
1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 \
1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.70 \
1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.80 \
1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.90 \
1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.0.100}
for {set j 0} {$j < $opt(nn)} {incr j} {
set node_($j) [ $ns_ node [lindex $temp2 $j]]
set HAaddress [AddrParams addr2id [$node_($j) node-addr]]
[$node_($j) set regagent_] set home_agent_ $HAaddress
$node_($j) set Z_ 0.000000000000
$node_($j) set Y_ 2.000000000000
$node_($j) set X_ 20.000000000000
}
#create links between wired and BS nodes
$ns_ duplex-link $W(0) $W(1) 15Mb 10ms DropTail
for {set k 2} {$k < $num_wired_nodes} {incr k} {
$ns_ duplex-link $W($k) $W(1) 15Mb 10ms DropTail
}
$ns_ duplex-link $W(1) $BS(0) 10Mb 100ms DropTail
Agent/TCP set df_ 0.95
Agent/TCP set ca_ 1
Agent/TCPSink set smooth_ 1
Agent/TCPSink set discount_ 1
Agent/TCP set window_ 100
# setup tcp connections
set tcp(1) [new Agent/TCP]
$tcp(1) set class_ 2
set sink(1) [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $sink(1)
$ns_ attach-agent $W(0) $tcp(1)
$ns_ connect $tcp(1) $sink(1)
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp(1)
$ns_ at 0.0 "$ftp1 start"
for {set i 2} {$i < $num_wired_nodes} {incr i} {
set tcp($i) [new Agent/TCP]
$tcp($i) set class_ 2
set sink($i) [new Agent/TCPSink]
$ns_ attach-agent $node_([expr $i-1]) $sink($i)
$ns_ attach-agent $W($i) $tcp($i)
$ns_ connect $tcp($i) $sink($i)
set ftp($i) [new Application/FTP]
$ftp($i) attach-agent $tcp($i)
$ns_ at 0.$i "$ftp($i) start"
}
#start agents
#$ns_ at 0.1 "$rtp(2) start"
#$ns_ at 0.2 "$rtp(3) start"
#$ns_ at 0.3 "$rtp(4) start"
#trace rtp agents bw
for {set i 1} {$i < $num_wired_nodes} {incr i} {
#set tchan_($i) [open /Abir/rate$i.q w]
#$sink($i) attach $tchan_($i)
#$sink($i) trace recv_rate
}
#start mouvement
#$ns_ at 5.00 "$node_(0) setdest 299.0 1.494 15.0"
#$ns_ at 26.00 "$node_(0) setdest 2.0 2.494 20.0"
#$ns_ at 100.00 "$node_(0) setdest 299.0 2.0 20.0"
#$ns_ at 26.00 "$node_(0) setdest 2.0 2.494 20.0"
for {set i 0} {$i < $opt(nn)} {incr i} {
$ns_ initial_node_pos $node_($i) 20
}
for {set i } {$i < $opt(nn) } {incr i} {
$ns_ at $opt(stop).0000010 "$node_($i) reset";
}
$ns_ at $opt(stop).0000010 "$BS(0) reset";
$ns_ at $opt(stop).1 " finish"
proc finish {} {
global ns_ tchan_ opt num_wired_nodes
$ns_ flush-trace
for {set i 1} {$i < $num_wired_nodes} {incr i} {
}
puts "NS EXITING..."
exit 0
}
puts "Starting Simulation..."
$ns_ run