set start_random [0,10]
$cbrstart 10
at $start_random
Codice: Seleziona tutto
# ======================================================================
# Define ions
# ======================================================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ; # MAC type
Mac/802_11 set RTSThreshold_ 500 ;
Mac/802_11 set dataRate_ 24Mb ;
Mac/802_11 set basicRate_ 6Mb ;
Mac/802_11 set CWMin_ 31 ;
Mac/802_11 set CWMAX_ 1023 ;
Mac/802_11 set SlotTime_ 0.000009 ;
Mac/802_11 set SIFS_ 0.000016 ;
Mac/802_11 set ShortRetryLImit_ 7 ;
Mac/802_11 set LOngRetryLimit_ 7 ;
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ifqlen) 50 ;# max packet in ifq
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(adhocRouting) AODV ;# routing protocol
###########################################
set val(x) 250 ;# X dimension of the topography
set val(y) 250 ;# Y dimension of the topography
set val(tr) esercizio1.tr ;# trace file
set val(nn) lindex [$argv 2] ;# how many nodes are simulated
set val(stop) 100.0 ;# simulation time
set val(seed) 0.0
# ======================================================================
# Main Program
# ======================================================================
#
# Initialize Global Variables
#
# create simulator instance
set ns_ [new Simulator]
# define topology
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# create trace object for ns and nam
set tracefd [open $val(tr) w]
$ns_ trace-all $tracefd
# use new trace file format
$ns_ use-newtrace
#
# Create God
#
set god_ [create-god $val(nn)]
#
# define how node should be created
#
#global node setting
$ns_ node-config -adhocRouting $val(adhocRouting) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON
#
# Create the specified number of nodes [$val(nn)] and "attach" them
# to the channel.
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
}
#
# Define node positions
source "mobilita_100.tcl"
# Define traffic flows
source "traffic"
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at $val(stop).000000001 "$node_($i) reset";
}
$ns_ at $val(stop).000000001 "puts \"NS EXITING...\" ; $ns_ halt"
puts "Starting Simulation..."
$ns_ run
Codice: Seleziona tutto
#!/bin/bash
############# script bash che lancia le simulazioni e calcola le statistiche ##############'
echo "Inserisci numero nodi (100-200)"
read n
echo "Inserisci numero flussi (5-10-15-20-25)"
read f
#indica la dimensione del rate
for nodi in 100 200 $n
do
for flusso in 5 10 15 20 25
do
for rate in 64000 512000
do
ns mobilita_source.tcl $rate
#numero di run 20, sim time 40 s
#per ciascun valore di finestra di contesa, lancio 10 run, della durata di 40 s
runs=19
seed_line=1
end_time=119
run=0
#fin quando il numero di run correnti è minore del massimo numero di run passato (runs) lancio simulazioni per uno stesso valore di rate cambiando il seme
while [[ $run -le $runs ]] ;do
seed=$(sed -n "$seed_line"p random.log)
line=1
dir_res=risultati_intermedi__$rate
dir_res_final=risultati_finali
mkdir $dir_res
mkdir $dir_res_final
echo "simulazioni in corso run: $run rate: $rate"
#lancio il file tcl mobilita_source.tcl passando in ingresso il valore del rate e la durata della simulazione
ns mobilita_source.tcl $rate $end_time $n $f
echo "statistiche in corso run: $run rate: $rate"
#calcolo packet delivery ratio
#i risultati di pdr li scrivo nello stesso file in modo da poter fare la media e calcolare gli intervalli di confidenza
awk -f pkt_delivery.awk esercizio1.tr >> "$dir_res"/pdr
awk -f delay.awk esercizio1.tr >> Tesina/delay$rate.dat
awk -f throughput.awk esercizio1.tr >> Tesina/throughput$rate.dat
awk -f pdr_aodv_basic.dat esercizio1.tr >> Tesina/pdr_aodv_basic$rate.dat
#aggiungere sotto altre statistiche (delay, overhead, ecc)
#cancello il file di trace
rm out.tr
#incremento di 1 la linea da cui leggere il seme random per le simulazioni
seed_line=$((seed_line+1))
#incremento di 1 il numero di run
run=$((run+1))
done
#TERMINATI I RUN PER UN DATO VALORE DI rate (esco dal ciclo di while), CALCOLO IL VALOR MEDIO E GLI INTERVALLI DI CONFIDENZA CORRISPONDENTI
#sintassi: file contenenti i valori di pdr per ciascun run, il valore della finestra di contesa, 0.05 = 1- 0.95 (per avere una confidenza al 95%) e il file dove voglio che vengano salvati i risultati
./intconfidence.tcl "$dir_res"/pdr $rate 0.05 "$dir_res_final"/pdr
#eventuali altri file
done
done
done