[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] How to monitor flow?



Hi,

I tried to monitor some flow states but failed. I have
read ns document carefully and searched old archive.
After spending two days reading some samples, such as
test-suite-red.tcl, many_tcp.tcl and
test-suite-cbq.tcl, I failed.

What I want to do is to monitor each flow's packets
been dropped and number of packets been queued. I do,
however, get some flow statistics. But I don't know
how to process the data. I guess I have to write some
awk code to parse the trace data first, then to write
some perl script to translate it to xgraph format, to
use xgraph to display it finally. Due to my poor
knowledge in linux/unix, I knew little about awk,
perl, tcl (I am a windows user but have to use ns
under linux for some reason). 

I attached the tcl script I used. Any of your
suggestion, comments are highly appreciated.

Thanks in advance.

Canhui

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/
#Create a simulator object
set ns [new Simulator]

#Open the nam trace file
set nf [open udp1.nam w]
set fstate [open flows.tr w]
$ns namtrace-all $nf

set fmon [$ns makeflowmon Fid]
$fmon attach $fstate

# I tried to put the following stuff into a procedure but failed with error
#  --- Classfier::no-slot{} default handler (tcl/lib/ns-lib.tcl) ---
#        _o46: no target for slot -1
#        _o46 type: Classifier/Hash/Dest
#  content dump:
# So I have to give it up and use this stupid paragraph

	# Define a test topology
	for {set i 0} {$i < 2} {incr i} {
    	set R($i) [$ns node]
	}

	$ns duplex-link $R(0) $R(1) 4Mb 10ms RED

	# attache flow monitor to our interested link
	set bottlelink [$ns link $R(0) $R(1)]
	$ns attach-fmon $bottlelink $fmon

	# Define end host
	for {set i 0} {$i < 3} {incr i} {
    	set H($i) [$ns node]
        $ns duplex-link $H($i) $R(0) 2Mb 10ms RED
	}
	for {set i 3} {$i < 6} {incr i} {
    	set H($i) [$ns node]
        $ns duplex-link $H($i) $R(1) 2Mb 10ms RED
	}

	# Control layout
	$ns duplex-link-op $R(0) $R(1) orient right
	$ns duplex-link-op $H(0) $R(0) orient right-down
	$ns duplex-link-op $H(1) $R(0) orient right
	$ns duplex-link-op $H(2) $R(0) orient right-up
	$ns duplex-link-op $H(3) $R(1) orient left-up
	$ns duplex-link-op $R(1) $H(4) orient right
	$ns duplex-link-op $H(5) $R(1) orient left-down

	# Create UDP agents
	for {set i 0} {$i < 2} {incr i} {
		set udp($i) [new Agent/UDP]
		$udp($i) set fid_ $i
	
		# attach to host
		$ns attach-agent $H($i) $udp($i)
	
		set cbr($i) [new Application/Traffic/CBR]
		$cbr($i) attach-agent $udp($i)

		set null($i) [new Agent/Null]
		set index $i
		incr index 3
		$ns attach-agent $H($index) $null($i)
		$ns connect $udp($i) $null($i)
		$ns at 0.0 "$cbr($i) start"
	}	
	$cbr(0) set rate_ 2Mb
	$cbr(1) set rate_ 1Mb

	# Create TCP agents
	set tcp1 [$ns create-connection TCP/Reno $H(2) TCPSink $H(5) 2]
	$tcp1 set window_ 15
	set ftp1 [$tcp1 attach-app FTP]
	$ns at 0.0 "$ftp1 start"

	# Monitor queue
	$ns duplex-link-op $R(0) $R(1) queuePos 0.5
	$ns duplex-link-op $H(2) $R(0) queuePos 0.5

	# Color flows
	$ns color 0 Black
	$ns color 1 Green
	$ns color 2 Red
# End of the paragraph I want to put into a procedure
	
#Define a 'finish' procedure
proc finish {} {
    global ns nf fstate
    $ns flush-trace
    # I should use perl script and awkcode to format
    # the output here (?), but how?
	# I should use xgraph to plot the figure I want,
	# but how?
    close $fstate
    #Close the trace file
    close $nf
    #Execute nam on the trace file
    #exec nam udp1.nam &
    exit 0
}

proc flowdump {interval} {
	global ns fmon fstate

	$fmon dump
	flush $fstate
	foreach f [$fmon flows] {
		$f reset
	}
	$fmon reset
    $ns at [expr [$ns now] + $interval] "flowdump $interval"
}

$ns at 0.0 "flowdump 0.5"
$ns at 2.0 "finish"
$ns run