Untitled

 avatar
unknown
tcl
2 years ago
1.9 kB
6
Indexable
# Létrehozzuk a szimulátort
set ns [new Simulator]

#Define a 'finish' procedure
proc finish {} {
        global ns
        $ns flush-trace
        exit 0
}

# Létrehozzuk a csomópontokat
set nodeA [$ns node]
set nodeB [$ns node]
set nodeC [$ns node]

Agent/TCP set window_ 100000
Queue/DropTail set limit_ 10

# Létrehozzuk az A-B és B-C linkeket
$ns duplex-link $nodeA $nodeB 25Mb 10ms DropTail
$ns duplex-link $nodeB $nodeC 10Mb 20ms DropTail

#setup tcp sender
set tcp [new Agent/TCP/Vegas]
$ns attach-agent $nodeA $tcp

#setup tcp sink
set sink [new Agent/TCPSink]
$ns attach-agent $nodeC $sink

#setup connection between the sender and the sink
$ns connect $tcp $sink

#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ftp set packetSize_ 1250

# Open a CSV file for writing
set csvFile [open output_Vegas.csv "w"]

# Define a procedure to print congestion window size with formatted timestamp and save to CSV
proc printCwnd {} {
    global ns tcp csvFile
    set cwnd [$tcp set cwnd_]
    set timestamp [$ns now]
    set formatted_timestamp [format "%.1f" $timestamp]
    puts "$formatted_timestamp $cwnd"
    
    # Save the data to the CSV file
    puts $csvFile "$formatted_timestamp,$cwnd"
    
    # Schedule the 'printCwnd' procedure to run again in 0.1 seconds
    $ns at [expr $timestamp + 0.1] "printCwnd"
}
# Schedule the 'printCwnd' procedure to run initially at time 0 and then every 0.1 seconds
$ns at 0.0 "printCwnd"

# Indítjuk a szimulációt TCP Tahoe, TCP Reno és TCP Vegas szállítási protokollokkal
$ns at 0.0 "$ftp start"
$ns at 50.0 "$ftp stop"

#Detach tcp and sink agents (not really necessary)
$ns at 51.0 "$ns detach-agent $nodeA $tcp ; $ns detach-agent $nodeC $sink"

$ns at 52.0 "finish"

#run the simulation
$ns run
Editor is loading...