我正在尝试在ns2中使用带有无线链接的错误模型,我使用的是ns2.33。我尝试了统一误差模型和马尔可夫链模型。没有来自ns的错误,但是当我试图找到由于损坏而丢弃的数据包时,我无法使用统一模型或马尔可夫模型找到它们中的任何一个。如果我在使用错误模型时出错,请帮助我。
要搜索我正在使用的丢弃数据包
eid @ eid-laptop:〜/ code / ns2 / noisy $ cat mixed.tr | grep d
这是一个完整的代码:
### This simulation is an example of combination of wired and wireless
### topologies.
#-------------------------------------------------------------------------------
#defining a new hashtable to store values
global opt
set adhocRouting DSDV
set stop 350
set num_wired_nodes 1
set num_bs_nodes 1
set num_wireless_nodes 2
set x 300
set y 300
#-------------------------------------------------------------------------------
proc plotWindow { tcpSource file } {
global ns_
set time 0.1
set now [$ns_ now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns_ at [expr $now+$time] "plotWindow $tcpSource $file"
}
proc wireless_node_config {ns topo em} {
$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propInstance [new Propagation/TwoRayGround] \
-phyType Phy/WirelessPhy \
-channel [new Channel/WirelessChannel] \
-topoInstance $topo \
-wiredRouting ON \
-agentTrace ON \
-routerTrace OFF \
-macTrace OFF \
@@ -outgoingErrProc $em
@@ -incomingErrProc $em
}
proc nam {ns namFile trFile namOutFile} {
$ns flush-trace
close $namFile
close $trFile
puts "running nam..."
# exec nam $namOutFile &
puts "I am in nam"
}
proc finish { } {
exit 0
}
#-------------------------------------------------------------------------------
# The global simulator instance
set ns_ [new Simulator]
#-------------------------------------------------------------------------------
#Hierarchical routing is needed to in mixed environments
#each of wireless and wired environment must be in seperated domains
#so at least we want 2 domains
# set up for hierarchical routing
$ns_ node-config -addressType hierarchical
AddrParams set domain_num_ 2
lappend cluster_num 1 2
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 1 2
AddrParams set nodes_num_ $eilastlevel
#-------------------------------------------------------------------------------
#set the Topology
set topo [new Topography]
$topo load_flatgrid x y
# god needs to know the number of all wireless interfaces
create-god [expr $num_wireless_nodes+$num_wired_nodes]
#-------------------------------------------------------------------------------
#trace output file
set trFile [open mixed.tr w]
$ns_ trace-all $trFile
# nam output files
set namFile [open mixed.nam w]
$ns_ namtrace-all $namFile
$ns_ namtrace-all-wireless $namFile x y
#xgraph output files
set x0 [open xgraph0.tr w]
#extra files
set cwndFile [open cwndFile.wtc w]
#-------------------------------------------------------------------------------
#Define different colors for data flows (for NAM)
$ns_ color 1 Blue
$ns_ color 2 Red
$ns_ color 3 Green
#-------------------------------------------------------------------------------
@@#creating the error model
@@set m1_ubstate 27.0
@@set m1_bstate 12.0
@@set m2_ubstate 0.4
@@set m2_bstate 0.4
@@set durlist "$m1_ubstate $m1_bstate $m2_ubstate $m2_bstate"
@@set errmodel [new ErrorModel/ComplexTwoStateMarkov $durlist time]
@@$errmodel unit packet
@@$errmodel drop-target [new Agent/Null]
#the option below is for wired links, there is no links in wireless environment
#$ns_ link-lossmodel $loss_module $BS(0) $node_(0)
#-------------------------------------------------------------------------------
#Creating the nodes
# The wired nodes
set addresses {0.0.0 1.0.0 1.1.0 1.1.1}
set W(0) [$ns_ node [lindex $addresses 0]]
#The wireless nodes
wireless_node_config $ns_ $topo $errmodel
set BS(0) [$ns_ node [lindex $addresses 1]]
$ns_ node-config -wiredRouting OFF
#base stations nodes
$BS(0) random-motion 0
#mobile nodes
for {set j 0} {$j < [expr $num_wired_nodes + $num_bs_nodes]} {incr j} {
set node_($j) [ $ns_ node [lindex $addresses [expr $j+2]] ]
#attach nodes to base station
$node_($j) base-station [AddrParams addr2id [$BS(0) node-addr]]
}
# End Creating the Nodes
#-------------------------------------------------------------------------------
# Positioning the nodes
$BS(0) set X_ 50.0
$BS(0) set Y_ 50.0
$BS(0) set Z_ 0.0
$node_(0) set X_ 0.0
$node_(0) set Y_ 0.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 100.0
$node_(1) set Y_ 0.0
$node_(1) set Z_ 0.0
#-------------------------------------------------------------------------------
#create links between wired and BS nodes
$ns_ duplex-link $W(0) $BS(0) 2Mb 2ms DropTail down
$ns_ duplex-link-op $W(0) $BS(0) orient down
$ns_ queue-limit $W(0) $BS(0) 2020Mb
#$ns_ duplex-link-op $W(0) $BS(0) queuePos 0.5
#-------------------------------------------------------------------------------
#Sizing the mobile nodes this will make them appear in NAM
for {set i 0} {$i < $num_wireless_nodes} {incr i} {
$ns_ initial_node_pos $node_($i) 10
}
#-------------------------------------------------------------------------------
# setup TCP connections
set tcp1 [new Agent/TCP/Newreno]
$tcp1 set class_ 2
set sink1 [new Agent/TCPSink/DelAck]
$ns_ attach-agent $W(0) $tcp1
$ns_ attach-agent $node_(0) $sink1
$ns_ connect $tcp1 $sink1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
#-------------------------------------------------------------------------------
#time line scenario.
$ns_ at 1.5 "$ftp1 start"
$ns_ at [expr $stop-10] "$ftp1 stop"
#reset nodes after finishing
for {set i 0} {$i < $num_wireless_nodes } {incr i} {
$ns_ at $stop.000000 "$node_($i) reset";
}
$ns_ at $stop.000000 "$BS(0) reset";
puts "Starting Simulation..."
$ns_ at 0.1 "plotWindow $tcp1 $cwndFile"
$ns_ at $stop.1 "nam $ns_ $namFile $trFile mixed.nam"
$ns_ at $stop.2 "finish"
#-------------------------------------------------------------------------------
$ns_ run
您还可以找到相同的代码here
答案 0 :(得分:0)
尝试:
grep d mixed.tr