Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set ns [new Simulator]
- set outputfile [open out.tr w]
- $ns trace-all $outputfile
- set nf [open out.nam w]
- $ns namtrace-all $nf
- #fichiers d'output
- proc finish {} {
- global ns nf outputfile
- $ns flush-trace
- close $nf
- close $outputfile
- puts "nam se lance.."
- exec nam -a out.nam &
- exit 0
- }
- #parsing des fichiers
- proc plotWindow {tcpSource outfile} {
- global ns
- set time 0.1
- set now [$ns now]
- set cwnd [$tcpSource set cwnd_]
- set ssth [$tcpSource set ssthresh_]
- set window [$tcpSource set window_]
- set maxseq [$tcpSource set maxseq_]
- set debitUtile [expr $maxseq/$now]
- ###Print TIME CWND for gnuplot to plot progressing on CWND
- puts $outfile "$now $cwnd $ssth $window $maxseq $debitUtile"
- $ns at [expr $now+$time] "plotWindow $tcpSource $outfile"
- }
- #decrementer une variable
- proc decr { n reste } {
- set reste [expr $reste - $n]
- return $reste
- }
- #volume aleatoire
- proc randomVolume { value } {
- set min_volume 1500
- set res [expr {int($value*rand()) - $min_volume}]
- return $res
- }
- #depart aleatoire
- proc randomDeparture { min max } {
- set res [expr {int($max*rand()) - $min}]
- return $res
- }
- if { 0 } {
- proc randomDeparture05 { } {
- set maxFactor [expr [expr $max + 1] - $min]
- set res [expr int([expr rand() * 100])]
- set res [expr [expr $res % $maxFactor] + $min]
- }
- }
- #parse le fichier traff
- set fp_traf [open "traff.traf" r]
- set file_traf [read $fp_traf]
- close $fp_traf
- #creation des noeuds
- set n_ -1
- set data_traf [split $file_traf "\n"]
- foreach line $data_traf {
- if { $n_ < [lindex $line 0] } {
- set n_ [lindex $line 0]
- set n($n_) [$ns node]
- }
- }
- #parse le fichier topo
- set fp_topo [open "topo.top" r]
- set file_topo [read $fp_topo]
- close $fp_topo
- set data [split $file_topo "\n"]
- foreach line $data {
- #creation des liens
- $ns duplex-link $n([lindex $line 0]) $n([lindex $line 1]) [lindex $line 2]Gb/s [lindex $line 3]ms DropTail
- $ns queue-limit $n([lindex $line 0]) $n([lindex $line 1]) 30
- #position queue
- $ns duplex-link-op $n([lindex $line 0]) $n([lindex $line 1]) queuePos 0.1
- #puts "$n([lindex $line 0]) [lindex $line 1]"
- }
- set flux 0
- #traff en Mb donc tout passer octets d'abord
- #pour chaque volume de donnees
- #rrajouter borne sur le temps
- set sent 0
- #set time 0.1
- #set now [$ns now]
- #vérifier qu'on envoie bien au minimum 1500 octets
- foreach line $data_traf {
- set noeud1 [lindex $line 0]
- set noeud2 [lindex $line 1]
- #[ createTCP $ns $flux $noeud1 $noeud2 ]
- set tcp($flux) [new Agent/TCP/Reno]
- $ns attach-agent $n($noeud1) $tcp($flux)
- $tcp($flux) set packetSize_ 1500
- #tcp sink
- set sink($flux) [new Agent/TCPSink]
- $ns attach-agent $n($noeud2) $sink($flux)
- #Connection between the TCP source and the TCP sink
- $ns connect $tcp($flux) $sink($flux)
- set volume [lindex $line 2]
- set volume [expr $volume * 125000]
- set sent $volume
- set vol_sent [ randomVolume $volume ]
- set reste [expr $sent - $vol_sent]
- set dep [format "%.4f" [expr {5.0*rand()}]]
- #set dep [ randomDeparture 0 5 ]
- $ns at $dep "$tcp($flux) send $vol_sent"
- puts "$reste $vol_sent $dep $flux"
- #incr flux
- #envoie des donnees
- while { $reste > 0 && $vol_sent >= 0 } {
- incr flux
- #depart aleatoire
- set dep [ randomDeparture 0 250 ]
- #volume envoyé aléatoire
- set vol_sent [ randomVolume $reste ]
- #cas ou vol_sent etait egal a -1
- if { $vol_sent < 0 } {
- set vol_sent $reste
- }
- #cas ou volume = 0
- if { $vol_sent == 0 } {
- set vol_sent $reste
- set tcp($flux) [new Agent/TCP/Reno]
- $ns attach-agent $n($noeud1) $tcp($flux)
- $tcp($flux) set packetSize_ 1500
- #tcp sink
- set sink($flux) [new Agent/TCPSink]
- $ns attach-agent $n($noeud2) $sink($flux)
- #Connection between the TCP source and the TCP sink
- $ns connect $tcp($flux) $sink($flux)
- $ns at $dep "$tcp($flux) send $vol_sent"
- puts "$reste $vol_sent $dep $flux"
- incr flux
- break
- } else {
- if { $vol_sent <= $reste && $vol_sent >= 1500 } {
- set tcp($flux) [new Agent/TCP/Reno]
- $ns attach-agent $n($noeud1) $tcp($flux)
- $tcp($flux) set packetSize_ 1500
- #tcp sink
- set sink($flux) [new Agent/TCPSink]
- $ns attach-agent $n($noeud2) $sink($flux)
- #Connection between the TCP source and the TCP sink
- $ns connect $tcp($flux) $sink($flux)
- $ns at $dep "$tcp($flux) send vol_sent"
- puts "$reste $vol_sent $dep $flux"
- #on soustrait le volume envoye au total
- set reste [decr $vol_sent $reste]
- incr flux
- }
- }
- }
- }
- #set test1 [randomDeparture]
- #puts [format "%.4f" $test1]
- $ns at 300.0 "finish"
- $ns run
- #https://gitlab.unistra.fr/felsoci/ns2/blob/master/produce.py
- #https://wiki.tcl-lang.org/page/How+do+I+read+and+write+files+in+Tcl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement