[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Asking for a favour
Dear sir ,
i'm asking about small help on cmu ns extensions , hope to find an answer.
i had run a file in the TCL examples directory from ns snapshot called
wired-cum-wireless-sim.tcl , when i reviewed the results i didint noticed
any
pakets labled Drop (No droped packets) , i reviwed the file it self , and
changed some parameters such as power , but no cahnge occur.
i'm asking how i can intrdocue an errors to the packets in such a file.
sorry for what i'm asking , but i really confused and need a help.
thanks a lot to any one who can help.
i'm attachinh with this email that file (code) , it's and easy and short file.
so please if you can review and suggest how i just can add and error model to
the wireless part of the file.
i also attached a file caleed ns-errmodel.tcl so it may help . i tried to do
that my self but i really
failed. soory agian , but i need a guide and help.
hoping to hear from you soon.
best regards ,
aiman sirhan
____________________________________________________________________
Get free email and a permanent address at http://www.netaddress.com/?N=1
### This simulation is an example of combination of wired and wireless
### topologies.
# o W1 WIRED NODES
# |
# o W2
# / \
# / \
#--*--*--*--*--*--*- o o base-stn nodes --*-*-*-*-*-*-*-
# BS1 BS2
# o
# o WL2 o WIRELESS NODES
# WL1 WL3
#
#
#===============================================================
#options
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) 670 ;# X & Y dimension of the topography
set opt(y) 670 ;# hard wired for now...
##set opt(cp) "../mobility/scene/cbr-3-test" ;# connection pattern file
set opt(cp) ""
set opt(sc) "../mobility/scene/scen-3-test" ;# scenario file
set opt(rp) dsdv ;# for now, supports only dsdv
set opt(ifqlen) 50 ;# max packet in ifq
set opt(seed) 0.0
set opt(stop) 1000.0 ;# simulation time
set opt(cc) "off"
set opt(tr) wired-and-wireless-out.tr ;# trace file
set opt(ftp1-start) 200.0
set opt(ftp2-start) 160.0
set opt(cbr-start) 200.0
# =================================================================
## Default settings
set num_wired_nodes 2
set num_bs_nodes 2
set num_wireless_nodes 3
set opt(nn) 5 ;# total number of wireless nodes
#==================================================================
# Other class settings
set AgentTrace ON
set RouterTrace ON
set MacTrace OFF
LL set mindelay_ 50us
LL set delay_ 25us
Agent/Null set sport_ 0
Agent/Null set dport_ 0
Agent/CBR set sport_ 0
Agent/CBR set dport_ 0
Agent/TCPSink set sport_ 0
Agent/TCPSink set dport_ 0
Agent/TCP set sport_ 0
Agent/TCP set dport_ 0
Agent/TCP set packetSize_ 1460
Queue/DropTail/PriQueue set Prefer_Routing_Protocols 1
# unity gain, omni-directional antennas
# set up the antennas to be centered in the node and 1.5 meters above it
Antenna/OmniAntenna set X_ 0
Antenna/OmniAntenna set Y_ 0
Antenna/OmniAntenna set Z_ 1.5
Antenna/OmniAntenna set Gt_ 1.0
Antenna/OmniAntenna set Gr_ 1.0
# Initialize the SharedMedia interface with parameters to make
# it work like the 914MHz Lucent WaveLAN DSSS radio interface
Phy/WirelessPhy set CPThresh_ 10.0
Phy/WirelessPhy set CSThresh_ 1.559e-11
Phy/WirelessPhy set RXThresh_ 3.652e-10
Phy/WirelessPhy set Rb_ 2*1e6
Phy/WirelessPhy set Pt_ 0.2818
Phy/WirelessPhy set freq_ 914e+6
Phy/WirelessPhy set L_ 1.0
# ======================================================================
proc create-god { nodes } {
global ns_ god_ tracefd
set god_ [new God]
$god_ num_nodes $nodes
}
proc cmu-trace { ttype atype node } {
global ns_ tracefd
if { $tracefd == "" } {
return ""
}
set T [new CMUTrace/$ttype $atype]
$T target [$ns_ set nullAgent_]
$T attach $tracefd
$T set src_ [$node id]
$T node $node
return $T
}
# intial setup - set addressing to hierarchical
set ns [new Simulator]
$ns set-address-format hierarchical
set namtrace [open wired-wireless-out.nam w]
$ns namtrace-all $namtrace
set trace [open wired-wireless-out.tr w]
$ns trace-all $trace
AddrParams set domain_num_ 3
lappend cluster_num 2 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 4 1
AddrParams set nodes_num_ $eilastlevel
# setup the wired nodes
set temp {0.0.0 0.1.0}
for {set i 0} {$i < $num_wired_nodes} {incr i} {
set W($i) [$ns node [lindex $temp $i]]
}
### setup base stations & wireless nodes
# First create common objects & other stuff for wireless topology
source ../lib/ns-bsnode.tcl
source ../mobility/com.tcl
source ../mobility/dsr.tcl
if { $opt(x) == 0 || $opt(y) == 0 } {
puts "No X-Y boundary values given for wireless topology\n"
}
set chan [new $opt(chan)]
set prop [new $opt(prop)]
set topo [new Topography]
set tracefd [open $opt(tr) w]
#setup topography and propagation model
$topo load_flatgrid $opt(x) $opt(y)
$prop topography $topo
# Create God
create-god $opt(nn)
# create base stations
set temp {1.0.0 1.0.1 1.0.2 1.0.3}
set BS(0) [create-base-station-node [lindex $temp 0]]
set BS(1) [create-base-station-node 2.0.0]
#provide some co-ord (fixed) to base stations
$BS(0) set X_ 1.0
$BS(0) set Y_ 2.0
$BS(0) set Z_ 0.0
$BS(1) set X_ 650.0
$BS(1) set Y_ 600.0
$BS(1) set Z_ 0.0
#create some mobilenodes in the same domain as BS_0
for {set j 0} {$j < $num_wireless_nodes} {incr j} {
set node_($j) [ $opt(rp)-create-mobile-node $j [lindex $temp [expr $j+1]] ]
#set node_($j) [$opt(rp)-create-mobile-node $j [lindex $temp $j] ]
$node_($j) base-station $BS(0)
}
if { $opt(x) == 0 || $opt(y) == 0 } {
usage $argv0
exit 1
}
if {$opt(seed) > 0} {
puts "Seeding Random number generator with $opt(seed)\n"
ns-random $opt(seed)
}
#
# Source the Connection and Movement scripts
#
if { $opt(cp) == "" } {
puts "*** NOTE: no connection pattern specified."
set opt(cp) "none"
} else {
puts "Loading connection pattern..."
source $opt(cp)
}
if { $opt(sc) == "" } {
puts "*** NOTE: no scenario file specified."
set opt(sc) "none"
} else {
puts "Loading scenario file..."
source $opt(sc)
puts "Load complete..."
}
#create links between wired and BS nodes
$ns duplex-link $W(0) $W(1) 5Mb 2ms DropTail
$ns duplex-link $W(1) $BS(0) 5Mb 2ms DropTail
$ns duplex-link $W(1) $BS(1) 5Mb 2ms DropTail
$ns duplex-link-op $W(0) $W(1) orient down
$ns duplex-link-op $W(1) $BS(0) orient left-down
$ns duplex-link-op $W(1) $BS(1) orient right-down
# setup TCP connections
set tcp1 [new Agent/TCP]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink]
$ns attach-agent $node_(0) $tcp1
$ns attach-agent $W(0) $sink1
$ns connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at $opt(ftp1-start) "$ftp1 start"
set tcp2 [new Agent/TCP]
$tcp2 set class_ 2
set sink2 [new Agent/TCPSink]
$ns attach-agent $W(1) $tcp2
$ns attach-agent $node_(2) $sink2
$ns connect $tcp2 $sink2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ns at $opt(ftp2-start) "$ftp2 start"
set udp_(0) [new Agent/UDP]
$ns_ attach-agent $node_(0) $udp_(0)
set null_(0) [new Agent/Null]
$ns_ attach-agent $W(0) $null_(0)
set cbr_(0) [new Application/Traffic/CBR]
$cbr_(0) set packetSize_ 512
$cbr_(0) set interval_ 4.0
$cbr_(0) set random_ 1
$cbr_(0) set maxpkts_ 10000
$cbr_(0) attach-agent $udp_(0)
$ns_ connect $udp_(0) $null_(0)
$ns_ at $opt(cbr-start) "$cbr_(0) start"
#
# Tell all the nodes when the simulation ends
#
for {set i 0} {$i < $num_wireless_nodes } {incr i} {
$ns_ at $opt(stop).0000010 "$node_($i) reset";
}
$ns_ at $opt(stop).0000010 "$BS(0) reset";
$ns_ at $opt(stop).0000010 "$BS(1) reset";
$ns_ at $opt(stop).21 "finish"
$ns_ at $opt(stop).20 "puts \"NS EXITING...\" ; "
###$ns_ halt"
proc finish {} {
global ns_ trace namtrace
$ns_ flush-trace
close $namtrace
close $trace
#puts "running nam..."
#exec nam out.nam &
puts "Finishing ns.."
exit 0
}
puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y) rp $opt(rp)"
puts $tracefd "M 0.0 sc $opt(sc) cp $opt(cp) seed $opt(seed)"
puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
puts "Starting Simulation..."
$ns_ run
#
# Copyright (c) 1996 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the Daedalus Research
# Group at the University of California Berkeley.
# 4. Neither the name of the University nor of the Research Group may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Contributed by the Daedalus Research Group, UC Berkeley
# (http://daedalus.cs.berkeley.edu)
#
#
# There are three levels to error generation.
# 1. Single State
# rate_: uniform error rate in pkt or byte
# 2. Two State
# error-free (0) and error (1) states
# each state has a ranvar determining the length each state
# 3. Multi-State: extending Two-State in OTcl
# each state has a ranvar determining the length each state
# a matrix specifying transition probabilities
#
# Each state is an error model (which could be 1-state or multi-state),
# In addtion, the error model has a matrix of transition probabilities,
# and a start state for the model. These usually corresond to
# homogeneous Markov chains, but are not restricted to them, because it
# is possible to change the transition probabilities on the fly and
# depending on past history, if you so desire. Multi-state error models
# reside entirely in Tcl and aren't split between C and Tcl. One-state
# error models are split objects and ErrorModel is derived from
# Connector. As an example, a 2-state Markov error model is built-in,
# as ErrorModel/MultiState/TwoStateMarkov Finally, an error *module*
# contains a classifier, a set of dynamically-added ErrorModels, and
# enough plumbing to construct flow-based Errors.
#
ErrorModel/Trace instproc init {{filename ""}} {
$self instvar file_
$self next
set file_ ""
if {$filename != ""} {
$self open $filename
}
}
ErrorModel/Trace instproc open {filename} {
$self instvar file_
if {! [file readable $filename]} {
puts "$class: cannot open $filename"
return
}
if {$file_ != ""} {
close $file_
}
set file_ [open $filename]
$self read
}
ErrorModel/Trace instproc read {} {
$self instvar file_ good_ loss_
if {$file_ != ""} {
set line [gets $file_]
set good_ [lindex $line 0]
set loss_ [lindex $line 1]
} else {
set good_ 123456789
set loss_ 0
}
}
ErrorModel/TwoState instproc init {rv0 rv1 {unit "pkt"}} {
$self next
$self unit $unit
$self ranvar 0 $rv0
$self ranvar 1 $rv1
}
Class ErrorModel/Uniform -superclass ErrorModel
Class ErrorModel/Expo -superclass ErrorModel/TwoState
Class ErrorModel/Empirical -superclass ErrorModel/TwoState
ErrorModel/Uniform instproc init {rate {unit "pkt"}} {
$self next
$self unit $unit
$self set rate_ $rate
}
ErrorModel/Expo instproc init {avgList {unit "pkt"}} {
set rv0 [new RandomVariable/Exponential]
set rv1 [new RandomVariable/Exponential]
$rv0 set avg_ [lindex $avgList 0]
$rv1 set avg_ [lindex $avgList 1]
$self next $rv0 $rv1 $unit
}
ErrorModel/Empirical instproc init {fileList {unit "pkt"}} {
set rv0 [new RandomVariable/Empirical]
set rv1 [new RandomVariable/Empirical]
$rv0 loadCDF [lindex $fileList 0]
$rv1 loadCDF [lindex $fileList 1]
$self next $rv0 $rv1 $unit
}
ErrorModel/MultiState instproc init {states trans transunit nstates start} {
# states_ is an array of states (errmodels),
# transmatrix_ is the transition state model matrix,
# nstates_ is the number of states
# transunit_ is pkt/byte/time, and curstate_ is the current state
# start is the start state, which curstate_ is initialized to
$self instvar states_ transmatrix_ transunit_ nstates_ curstate_ eu_
set states_ $states
set transmatrix_ $trans
set transunit_ $transunit
set nstates_ $nstates
set curstate_ $start
set eu_ $transunit
$self next
}
ErrorModel/MultiState instproc corrupt { } {
$self instvar states_ transmatrix_ transunit_ curstate_
set cur $curstate_
# XXX
set retval [$curstate_ next]
set curstate_ [$self transition]
if { $cur != $curstate_ } {
# If transitioning out, reset erstwhile current state
$cur reset
}
return $retval
}
# XXX eventually want to put in expected times of staying in each state
# before transition here. Punt on this for now.
#ErrorModel instproc insert-error { parent } {
# return [$self corrupt $parent]
#}
# Decide whom to transition to
ErrorModel/MultiState instproc transition { } {
$self instvar states_ transmatrix_ transunit_ curstate_ nstates_
for { set i 0 } { $i < $nstates_ } {incr i} {
if { [lindex $states_ $i] == $curstate_ } {
break
}
}
# get the right transition list
set trans [lindex $transmatrix_ $i]
set p [uniform 0 1]
set total 0
for { set i 0 } { $i < $nstates_ } {incr i } {
set total [expr $total + [lindex $trans $i]]
if { $p <= $total } {
return [lindex $states_ $i]
}
}
puts "Misconfigured state transition: prob $p total $total $nstates_"
return $curstate_
}
Class ErrorModel/TwoStateMarkov -superclass ErrorModel/TwoState
ErrorModel/TwoStateMarkov instproc init {rate eu {transition}} {
$self next
$self unit time
set rv0 [new RandomVariable/Exponential]
set rv1 [new RandomVariable/Exponential]
$rv0 set avg_ [lindex $rate 0]
$rv1 set avg_ [lindex $rate 1]
$self ranvar 0 $rv0
$self ranvar 1 $rv1
# set p01 [lindex $transition 0]
# set p10 [lindex $transition 1]
# set trans [list [list [expr 1 - $p01] $p01] \
# [list [expr 1 - $p01] $p01]]
# # state 0 is the start state
# $self next $states_ $trans $eu $i [lindex $states_ 0]
}
#
# the following is a "ErrorModule";
# it contains a classifier, a set of dynamically-added ErrorModels, and enough
# plumbing to construct flow-based Errors.
#
# It's derived from a connector
#
ErrorModule instproc init { cltype { clslots 29 } } {
$self next
set nullagent [[Simulator instance] set nullAgent_]
set classifier [new Classifier/Hash/$cltype $clslots]
$self cmd classifier $classifier
$self cmd target [new Connector]
$self cmd drop-target [new Connector]
$classifier proc unknown-flow { src dst fid bucket } {
puts "warning: classifier $self unknown flow s:$src, d:$dst, fid:$fid, bucket:$bucket"
}
}
#
# set a default behavior within the error module.
# Called as follows
# $errormodule default $em
# where $em is the name of an error model to pass default traffic to.
# note that if $em is "pass", then default just goes through untouched
#
ErrorModule instproc default errmodel {
set cl [$self cmd classifier]
if { $errmodel == "pass" } {
set target [$self cmd target]
set pslot [$cl installNext $target]
$cl set default_ $pslot
return
}
set emslot [$cl findslot $errmodel]
if { $emslot == -1 } {
puts "ErrorModule: couldn't find classifier entry for error model $errmodel"
return
}
$cl set default_ $emslot
}
ErrorModule instproc insert errmodel {
$self instvar models_
$errmodel target [$self cmd target]
$errmodel drop-target [$self cmd drop-target]
if { [info exists models_] } {
set models_ [concat $models_ $errmodel]
} else {
set models_ $errmodel
}
}
ErrorModule instproc errormodels {} {
$self instvar models_
return $models_
}
ErrorModule instproc bind args {
# this is to perform '$fem bind $errmod id'
# and '$fem bind $errmod idstart idend'
set nargs [llength $args]
set errmod [lindex $args 0]
set a [lindex $args 1]
if { $nargs == 3 } {
set b [lindex $args 2]
} else {
set b $a
}
# bind the errmodel to the flow id's [a..b]
set cls [$self cmd classifier]
while { $a <= $b } {
# first install the class to get its slot number
# use the flow id as the hash bucket
set slot [$cls installNext $errmod]
$cls set-hash $a 0 0 $a $slot
incr a
}
}
ErrorModule instproc target args {
if { $args == "" } {
return [[$self cmd target] target]
}
set obj [lindex $args 0]
[$self cmd target] target $obj
[$self cmd target] drop-target $obj
}
ErrorModule instproc drop-target args {
if { $args == "" } {
return [[$self cmd drop-target] target]
}
set obj [lindex $args 0]
[$self cmd drop-target] drop-target $obj
[$self cmd drop-target] target $obj
}