[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ns] CSMA/CD
Hi all,
I'm trying to simulate a LAN with almost 20 nodes and CSMA/CD(802.3) as
MAC. My goal is to represent features like the "CSMA-curve" where the
dependence of the "throughput of packet" on"generated packets" - both
in packet-time - can be shown(see below).
T ^
h |
r |
o | *
u | * *
g | * *
h | * *
p | * *
u | * *
t | * *
|* *
------------------------------------------------------------------>
Generation
I've been trying this with the following settings for LAN:
- agent: UDP
- traffic: CBR
- sink: LossMonitor
- MAC: Mac/802_3
- channel: Channel
- LL: ll
- queue: DropTail
- bandwidth: 10Mb
- delay: 1ms
- packetsize: 300
My first attempt was to record the number of the arriving packets([$sink
set npkts_]) in a sink while changing the rate of traffic($traffic set
rate_ ...). But it didn't give the expected result: the throughput(arrived
packets during a certain packet-time) reached an upper limit
(almost a constant value) for big generation-values(the rate at source).
My next attempt to hold the number of arrived packets while varying the
interval of the traffic($traffic set interval_ ...) brought the same
result.
Please help me if you have experience with such things or if you have a
fantastic idea about this.
Thank you very much.
Glenson.
P.S.: I'm working with the ns version 2.1b7 on Win98
tcl-code:
set opt(vtr) "lan06.tr"
set opt(timev) 0.04; #for recording
set opt(tr) "out"
set opt(namtr) "out.nam"
set opt(stop) 2.5
set opt(tstep) 0.06; #for varying the interval
set opt(nodepairs) 10
set opt(qsize) 300
set opt(intrvlstart) 0.02
set opt(intrvlstep) 0.0008
set opt(bw) 10Mb
set opt(delay) 1ms
set opt(ll) LL
set opt(ifq) Queue/DropTail
set opt(mac) Mac/802_3
set opt(chan) Channel
set opt(agt) UDP
set opt(sink) LossMonitor
set opt(app) Traffic/CBR;
proc finish {} {
global ns opt trfd
$ns flush-trace
close $trfd
exit 0
}
proc create-trace {} {
global ns opt
set vtr [open $opt(vtr) w]
puts $vtr "time interval rcvpkts lostpkts"; #heading
set trfd [open $opt(tr) w]
$ns trace-all $trfd
if {$opt(namtr) != ""} {
$ns namtrace-all [open $opt(namtr) w]
}
set trlist [list $trfd $vtr]
return $trlist
}
proc create-topology {} {
global ns opt
global lan node source node0
set num [expr $opt(nodepairs)*2]
for {set i 0} {$i < $num} {incr i} {
set node($i) [$ns node]
lappend nodelist $node($i)
}
set lan [$ns newLan $nodelist $opt(bw) $opt(delay) \
-llType $opt(ll) -ifqType $opt(ifq) \
-macType $opt(mac) -chanType $opt(chan)]
set node0 [$ns node]; #only for a better lay-out
$ns duplex-link $node0 $node(0) 2Mb 1ms DropTail
$ns duplex-link-op $node0 $node(0) orient right
}
proc record {} {
global ns traffic sink vtr opt
set time $opt(timev)
set rcvps 0
set lps 0
set intval 0
for {set i 0} {$i<$opt(nodepairs)} {incr i} {
set rcvps [expr $rcvps+[$sink($i) set npkts_]]
set lps [expr $lps+[$sink($i) set nlost_]]
set intval [expr $intval+[$traffic($i) set interval_]]
}
set rcvps [expr $rcvps/$opt(nodepairs)] ; #compute the meanvalues
set lps [expr $lps/$opt(nodepairs)]
set intval [expr $intval/$opt(nodepairs)]
set nw [$ns now]
puts $vtr "$nw $intval $rcvps $lps"
for {set i 0} {$i<$opt(nodepairs)} {incr i} {
$sink($i) set npkts_ 0; #reset
$sink($i) set nlost_ 0
}
$ns at [expr $nw+$time] "record"
}
proc schedule-interval {} {
global ns traffic rng opt
set oldintrvl [$traffic(0) set interval_]
set factor [expr $opt(intrvlstep)/10];
#certain factor for computing the random-range
if {[expr ($oldintrvl-$opt(intrvlstep))>$opt(intrvlstep)]} {
$traffic(0) set interval_ [expr $oldintrvl-$opt(intrvlstep)]
for {set i 1} {$i<$opt(nodepairs)} {incr i} {
set rndmdelta [$rng uniform $factor [expr $factor*9]];
#random-range for randomizing the intervals
$traffic($i) set interval_ [expr $oldintrvl-$opt(intrvlstep)+$rndmdelta];
#lessen interval
}
}
set nw [$ns now]
$ns at [expr $nw+$opt(tstep)] "schedule-interval"
}
## MAIN ##
global srcdst agent traffic sink vtr rng
set rng [new RNG]
$rng seed 0
set ns [new Simulator]
set traces [create-trace]
set trfd [lindex $traces 0]
set vtr [lindex $traces 1]; #important trace file
create-topology
#connections
for {set j 0} {$j < $opt(nodepairs)} {incr j} {
#connect even nodes with odd nodes
set srcdst [$ns create-connection-list $opt(agt) $node([expr $j*2]) \
$opt(sink) $node([expr $j*2+1]) 0]
set agent($j) [lindex $srcdst 0]
set sink($j) [lindex $srcdst 1]
puts "$j : [expr $j*2] -> [expr $j*2+1]"
set traffic($j) [$agent($j) attach-app $opt(app)]
$traffic($j) set packetSize_ $opt(qsize); #set start values
$traffic($j) set interval_ $opt(intrvlstart)
}
#data-recording
$ns at 0.0 "record"
#time-schedule
set now [$ns now]
for {set i 0} {$i<$opt(nodepairs)} {incr i} {
$ns at 0.0 "$traffic($i) start"
}
$ns at 0.0 "schedule-interval"
$ns at [expr $now+$opt(stop)] "finish"
$ns run
----------------------