使用无线场景的错误模型不会丢包?

发布于 2024-07-07 17:30:25 字数 6467 浏览 13 评论 0原文

我正在尝试将 ns2 中的错误模型与无线链路一起使用,我正在使用 ns2.33。 我尝试了统一误差模型和马尔可夫链模型。 ns 没有错误,但是当我尝试查找由于损坏而丢失的数据包时,我无法使用统一或马尔可夫模型找到任何数据包。 因此,如果我在使用错误模型时犯了任何错误,请帮助我。

为了搜索我正在使用的丢弃的数据包

eid@eid-laptop:~/code/ns2/noisy$ 猫混合.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

您还可以在此处找到相同的代码

I am trying to use the error model in ns2 with wireless links, I am using ns2.33. I tried the uniform error model and the markov chain model. No errors from ns but when I am trying to find the dropped packets due to corruption I can not find any of them using either the uniform or markov models. So please help me if I made any error in using the error model.

To search for dropped packets I am using

eid@eid-laptop:~/code/ns2/noisy$ cat mixed.tr | grep d

Here is a whole code:

### 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

You can also find same code here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱桃奶球 2024-07-14 17:30:25

尝试:

grep d mixed.tr

Try:

grep d mixed.tr
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文