- Home Page of ProjectGuideline.com ›
- Forums ›
- Guidelines for Learning ns2 ›
- error model not working in wirless
Hi!
I am working with QoS of wireless but error model isn’t working
i.e. packets aren’t seen to be dropped!
Waiting for reply,
NIRU
My code is:
set val(chan) Channel/WirelessChannel ;
set val(prop) Propagation/TwoRayGround ;
set opt(ant) Antenna/OmniAntenna;
set opt(ll) LL;
set opt(ifq) Queue/DropTail/PriQueue
set opt(ifqlen) 50;
set opt(netif) Phy/WirelessPhy;
set opt(mac) Mac/802_11
set opt(rp) DSDV ;
set val(nn) 5
set opt(nn) 5
set opt(cp) “”
set opt(sc) “../mobility/scene/scen-3-test”
set ns [new Simulator]
set tracefd [open wopen.tr w]
$ns trace-all $tracefd
set namtrace [open wopen1.nam w]
$ns namtrace-all-wireless $namtrace 670 670
set topo [new Topography]
$topo load_flatgrid 670 670
#create god
set god_ [create-god 5]
create-god $opt(nn)
proc UniformErr {} {
set err [new ErrorModel]
$err unit packet
return $err
}
#ns node config
$ns node-config -adhocRouting $opt(rp)
-llType $opt(ll)
-macType $opt(mac)
-ifqType $opt(ifq)
-ifqLen $opt(ifqlen)
-antType $opt(ant)
-propType $val(prop)
-phyType $opt(netif)
-topoInstance $topo
-agentTrace ON
-routerTrace ON
-macTrace ON
-wiredRouting OFF
-channelType Channel/WirelessChannel
-IncmingErrProc UniformErr
-OutgoingErrProc UniformErr
-movementTrace OFF
set node [ $ns node ]
$node random-motion 0
set prop [new Propagation/Shadowing]
$prop set pathlossExp_ 2.0
$prop set std_db_ 4.0
$prop set dist0_ 1.0
$prop seed predef 0
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
#$ns initial_node_pos $node_($i) 20
}
#$ns duplex-link $node_(0) $node_(1) 1Mb 10ms DropTail
#provide initial positions X,Y,Z
$node_(0) set X_ 315.0
$node_(0) set Y_ 312.0
$node_(0) set Z_ 300.0
$node_(1) set X_ 218.0
$node_(1) set Y_ 215.0
$node_(1) set Z_ 214.0
$node_(2) set X_ 111.0
$node_(2) set Y_ 112.0
$node_(2) set Z_ 113.0
$node_(3) set X_ 11.0
$node_(3) set Y_ 12.0
$node_(3) set Z_ 13.0
$node_(4) set X_ 100.0
$node_(4) set Y_ 200.0
$node_(4) set Z_ 300.0
#simple node movements
$ns at 0.05 “$node_(0) setdest 50.0 100.0 13.0”
$ns at 0.15 “$node_(1) setdest 200.0 20.0 330.0”
$ns at 0.024 “$node_(2) setdest 130.0 33.0 130.0”
$ns at 0.65 “$node_(2) setdest 30.0 210.0 200.0”
$ns at 0.75 “$node_(0) setdest 103.0 210.0 200.0”
$ns at 0.65 “$node_(1) setdest 130.0 125.0 120.0”
$ns at 0.15 “$node_(3) setdest 240.0 120.0 315.0”
$ns at 0.024 “$node_(4) setdest 399.0 356.0 330.0”
$ns at 1.12 “$node_(3) setdest 125 125 125 “
$ns at 1.0 “$node_(4) setdest 100 100 100 “
#set tcp conn. betwn node 0 & node 1
set tcp [new Agent/TCP]
$tcp set window_ 50
$tcp set class_ 2
$tcp set fid_ 2
$ns attach-agent $node_(0) $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $node_(2) $tcp
$ns attach-agent $node_(3) $sink
$ns connect $tcp $sink
set sink [new Agent/TCPSink]
$ns attach-agent $node_(1) $tcp
$ns attach-agent $node_(4) $sink
$ns connect $tcp $sink
#set tcp conn. betwn node 2 & node 1
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $node_(2) $tcp
$tcp set class_ 2
#setup sink
#set sink [new Agent/TCPSink/DelAck]
#$ns attach-agent $node_(0) $tcp
#$ns attach-agent $node_(1) $sink
#connect source & sink
$ns connect $tcp $sink
$tcp set fid_ 1
#tcp settings
$tcp set maxcwnd_ 50
$tcp set ssthresh_ 16
$tcp set packetSize_ 100
#set ftp conn.
set ftp [ new Application/FTP ]
$ftp attach-agent $tcp
$ns at 0.10 “$ftp start”
$ns at 1.78 “$ftp stop”
$ftp set type_ FTP
set null0 [new Agent/Null]
$ns attach-agent $node_(1) $null0
#$ns connect $tcp $null0
#$ns at 1.0 “$ftp start”
set f0 [open L.tr w]
set f1 [open L1.tr w ]
set f2 [open L2.tr w]
#create loss monitor
set sink0 [ new Agent/LossMonitor ]
$ns attach-agent $node_(1) $sink0
#connect traffic source with traffic sink
#$ns connect $tcp $sink0
#$ns at 0.0 “$cbr0 start”
proc TwoStateMarkovErr {} {
set tmp0 [new ErrorModel/Uniform 0 pkt]
set tmp1 [new ErrorModel/Uniform .7 pkt]
# Array of states (error models)
set m_states
-
# Durations for each of the states, tmp, tmp1 and tmp2, respectively
set m_periods
-
# Transition state model matrix
set m_transmx { {0.9 0.1 }
{0.7 0.3 } }
set m_trunit byte
# Use time-based transition
set m_sttype time
set m_nstates 2
set m_nstart [lindex $m_states 0]
set em [new ErrorModel/MultiState $m_states $m_periods $m_transmx
$m_trunit $m_sttype $m_nstates $m_nstart]
return $em
}
$ns node-config -IncomingErrProc TwoStateMarkovErr
-OutcomingErrProc TwoStateMarkovErr
proc cac { } {
global ns bw
set bw 2000
set desc 20
set expc 15
set abb [ expr $desc-$expc]
set noac 15
expr $noac+1
set totbw 2000000
set eqsh [ expr $totbw/$noac]
set expbw 1500
for { set i 0 } { $i < 2 } { incr i} {
if {$expbw <= $eqsh } {
puts “accept connection”
} elseif {$expbw <= $abb} {
puts ” accept connection “
} else {
puts “block call”
}
}
}
#set source
set src [ new Agent/TCP ]
$ns attach-agent $node_(1) $src
#$ns simplex-link $node_(1) $node_(2) 2Mb 100ms DropTail
set em [new ErrorModel]
$em unit pkt
$em set rate_ 0.03
$em ranvar [new RandomVariable/Uniform]
$em drop-target [new Agent/Null]
proc sendpacket {} {
global ns ak n src expo1 expo2
set then [$ns now ]
$ns at [expr $then+[$expo1 value]] “sendpacket”
set bytes [expr round([$expo2 value])]
#set n [expr $n+$bytes]
$src send $bytes
#return n
}
set sink [new Agent/Null]
$ns attach-agent $node_(0) $sink
$ns connect $src $sink
proc record { } {
global sink0 sink1 sink2 f0 f1 f2
set ns [Simulator instance]
set time 0.5
set bw0 [ $sink0 set bytes_ ]
set bw1 [ $sink1 set bytes_ ]
set bw2 [ $sink2 set bytes_ ]
set now [ $ns now ]
puts $f0 “$now [ expr $bw0/$time*8/100]”
#puts $f1 “$now [ expr $bw1/$time*8/100]”
#puts $f2 “$now [expr $bw2/$time*8/100]”
$sink0 set bytes 0
$sink1 set bytes 0
$sink2 set bytes 0
$ns at [expr $now+$time] “record”
}
proc finish { } {
global ns tracefd namtrace
$ns flush-trace
close $tracefd
close $namtrace
exec nam wopen1.nam &
exit 0
}
ns at 0.75 “cac”
$ns at 1.75 “finish”
#$ns at 0.55 “sendpacket”
$ns run
BEGIN {
count = 0;
}
{
action = $1;
time = $2;
node_id = $3;
layer = $4;
flags = $5;
seqno = $6;
type = $7;
size = $8;
a = $9;
b = $10;
c = $11;
d = $12;
energy = $14;
for(seqno = 0; seqno < 68; seqno++) { if((node_id = “_5_” && action == “r” && layer == “AGT” && type == “cbr” && size >= 1000) || (node_id = “_6_” && action == “r” && layer == “AGT” && type == “cbr” && size >= 1000)) {
count++;
}
}
}
END {
printf(“%dn”,count);
}
You must be logged in to reply to this topic.