Ошибка в графике симулятора NS2 X - PullRequest
0 голосов
/ 05 мая 2018

В следующем коде tcl я надеюсь создать TCP-связь между двумя узлами через 2 маршрутизатора в симуляторе NS2 и построить график для полосы пропускания с помощью Xgraph.

 #step:-1 define global simulator object

set sn [new Simulator]

#step:-2 Define different colors for data flows (for NAM)
$sn color 1 Red
$sn color 2 Blue

# Step:-3 Opening the NAM trace file
set nt [open simulate.nam w]
$sn namtrace-all $nt

#Step:-4 Opening the Trace file
set tr [open simulate.tr w]
$sn trace-all $tr


#Step:5 Define a 'finish' procedure
proc finish {} {
        global sn nt tr
        $sn flush-trace
        #Close the NAM trace file
        close $nt
        close $tr
        exec nam simulate.nam &
        exec xgraph simulate.tr -geometry 800x400 &
        exit 0
}
#Step:-6 Creation of six nodes
set na [$sn node]
set nb [$sn node]
set nc [$sn node]
set nd [$sn node]
set ne [$sn node]
set nf [$sn node]

#Step:-7 Creating links between the nodes
$sn duplex-link $na $nc 2Mb 10ms DropTail
$sn duplex-link $nb $nc 2Mb 10ms DropTail
$sn duplex-link $nc $nd 1.7Mb 20ms DropTail
$sn duplex-link $nd $ne 2Mb 20ms DropTail
$sn duplex-link $nd $nf 2Mb 20ms DropTail


#Step:-8 Setting Queue Size of link (nc-nd) to 10
$sn queue-limit $nc $nd 10

#Step:-9 Provide node positions to visualize in NAM window
$sn duplex-link-op $na $nc orient right-down
$sn duplex-link-op $nb $nc orient right-up
$sn duplex-link-op $nc $nd orient right
$sn duplex-link-op $nd $ne orient right-up
$sn duplex-link-op $nd $nf orient right-down

#Step:-10 Monitoring the queue for link (nc-nd) (nd-ne). (for NAM)
$sn duplex-link-op $nc $nd queuePos 0.5
$sn duplex-link-op $nd $ne queuePos 0.5

#Step:-11 Setting up a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 1
$sn attach-agent $na $tcp

#Step:-12 If we setup tcp traffic source then connect it with tcp sink 
set sink [new Agent/TCPSink]
$sn attach-agent $ne $sink
$sn connect $tcp $sink
$tcp set fid_ 2


#Step:-13 Setting up a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
proc record {} {
        global sink tr
    #Get an instance of the simulator
    set ns [Simulator instance]
    #Set the time after which the procedure should be called again
        set time 0.5
    #How many bytes have been received by the traffic sinks?
        set bw0 [$sink set bytes_]
    #Get the current time
        set now [$ns now]
    #Calculate the bandwidth (in MBit/s) and write it to the files
        puts $tr "$now [expr $bw0/$time*8/1000000]"
    #Reset the bytes_ values on the traffic sinks
        $sink set bytes_ 0
    #Re-schedule the procedure
        $ns at [expr $now+$time] "record"
}
#Step:-17 Scheduling events for the CBR and FTP agents

$sn at 0.0 "record"
$sn at 0.5 "$ftp start"
$sn at 4.0 "$ftp stop"
$sn at 5.0 "finish"

#Step:-18 Run the simulation
$sn run

когда я запускаю скрипт, я получаю сообщение об ошибке

error in file simulate.tr
unknown line type

Но когда линии

$sn at 0.5 "$ftp start"
$sn at 4.0 "$ftp stop"

удалены, график появляется, хотя симуляция не происходит и ошибки нет! Так как я могу исправить свой код и просмотреть пропускную способность в xgraph?

...