NS2のTcpAppの使い方とか

使いまわせない

set tcp1 [new Agent/TCP/FullTcp]
set tcp2 [new Agent/TCP/FullTcp]
set tcp3 [new Agent/TCP/FullTcp]

$ns attach-agent $n1 $tcp1
$ns attach-agent $n2 $tcp2
$ns attach-agent $n2 $tcp3

set app1 [new Application/TcpApp $tcp1]
set app2 [new Application/TcpApp $tcp2]
set app3 [new Application/TcpApp $tcp3]

$ns connect $tcp1 $tcp2
$app1 connect $app2
#Call the finish procedure after 5 seconds of simulation time
$ns at 0.1 "$tcp2 listen ;  $app1 send 100 \"$app2 app-recv $app1 100\""
$ns at 4.0 "$ns connect $tcp2 $tcp3 ; $app2 connect $app3; $tcp3 listen ; $app2 send 100 \"$app3 app-recv $app2 100\""
$ns at 7.0 "finish"
#Run the simulation
$ns run

って感じで,tcpエージェントを2回使うとエラーを吐く.

$ ns tcpapp.tcl
0.34207999999999994 _o65 recieves data 100 from _o64
4.000000: FullTcpAgent::recv(_o60) got packet lacking ACK (seq 101)
4.100000: (_o61) unexpected timeout 3 in state 1
4.600000: FullTcpAgent::recv(_o60) got packet lacking ACK (seq 101)
4.600000: (_o61) unexpected timeout 3 in state 1
5.800000: FullTcpAgent::recv(_o60) got packet lacking ACK (seq 101)
5.800000: (_o61) unexpected timeout 3 in state 1

(一回目はうまく受信できてるけど,二回目はわけわからんことになってる)


[ns] Problems using TcpApp wit FullTcp

対処法

なんかいろいろしなきゃだめみたいだけど(tcp-full.cとかをいじる形),面倒だから毎回tcpエージェントを作る.(対処でも何でもないけどw単純に使いまわさないようにするだけ)

モバイルノードだとやっぱりエラーを吐く

固定ノードだと別に大丈夫だけど,モバイルノードだとtcpエージェントを255個ぐらいくっつけるとエラーを吐く.

Application/TcpApp instproc app-recv {src size} {
	global ns_ node_
	puts "[$ns_ now] $self recieves data $size from $src"
}

proc MessageTest { counter } {
	global ns_ node_
	puts "counter = $counter"
	set tcp1 [new Agent/TCP/FullTcp]
	set tcp2 [new Agent/TCP/FullTcp]

	$ns_ attach-agent $node_(1) $tcp1
	$ns_ attach-agent $node_(2) $tcp2

	set app1 [new Application/TcpApp $tcp1]
	set app2 [new Application/TcpApp $tcp2]

	$ns_ connect $tcp1 $tcp2
	$app1 connect $app2
	$tcp2 listen
	$app1 send 100 "$app2 app-recv $app1 100"
}

for {set i 0} {$i < 10000 } {incr i} {
	$ns_ at [expr 1.0+($i*5)] "MessageTest $i"
}

こんな感じでループさせまくると

ns: MessageTest 254: 
    (_o3098 cmd line 1)
    invoked from within
"_o3098 cmd port-dmux _o35"
    invoked from within
"catch "$self cmd $args" ret"
    invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
    (procedure "_o3098" line 2)
    (SplitObject unknown line 2)
    invoked from within
"$agent port-dmux $dmux_"
    (procedure "_o32" line 11)
    (Node/MobileNode add-target-rtagent line 11)
    invoked from within
"$self add-target-rtagent $agent $port"
    (procedure "_o32" line 23)
    (Node/MobileNode add-target line 23)
    invoked from within
"$self add-target $agent $port"
    (procedure "_o32" line 15)
    (Node attach line 15)
    invoked from within
"$node attach $agent"
    (procedure "_o3" line 2)
    (Simulator attach-agent line 2)
    invoked from within
"$ns_ attach-agent $node_(1) $tcp1"
    (procedure "MessageTest" line 7)
    invoked from within
"MessageTest 254"

ってエラーを吐く.

使い終わったらtcpエージェントを取り外す

どうもモバイルノードにtcpエージェントをくっつけすぎると出るエラーらしいので,app-recvとかをこんな感じにする.

Application/TcpApp instproc app-recv {src size tcp_from tcp_to} {
	global ns_ node_
	puts "[$ns_ now] $self recieves data $size from $src"
	puts "tcp_from = $tcp_from tcp_to = $tcp_to"

	$ns_ detach-agent $node_(1) $tcp_from
	$ns_ detach-agent $node_(2) $tcp_to
}

proc MessageTest { counter } {
	global ns_ node_
	puts "counter = $counter"
	set tcp1 [new Agent/TCP/FullTcp]
	set tcp2 [new Agent/TCP/FullTcp]

	$ns_ attach-agent $node_(1) $tcp1
	$ns_ attach-agent $node_(2) $tcp2

	set app1 [new Application/TcpApp $tcp1]
	$app1 setNodeID 1
	set app2 [new Application/TcpApp $tcp2]
	$app2 setNodeID 2

	$ns_ connect $tcp1 $tcp2
	$app1 connect $app2
	$tcp2 listen
	$app1 send 100 "$app2 app-recv $app1 100 $tcp1 $tcp2"
}

for {set i 0} {$i < 10000 } {incr i} {
	$ns_ at [expr 1.0+($i*5)] "MessageTest $i"
}

これでなんとかなる.