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

[ns] some question about simple TCP simulation system(link delay and queue length)



Hi,friends,
    I am a new user of ns-2. now I am just simulating a simple TCP system with two nodes and a duplex-link connect them.I found two interesting phenomenon, 
first, when the link delay is very short, the ACK packet from receiver to sender will be less,when the link delay increase, the ACK packet will increase, too.
second,for TCP protocol, the sender's sending is determined by the ACK packet from receiver, so we think that the output queue of TCP packet sender should be 
empty ( here, we think the packets in congestion window is buffered in  the TCP agent , they are not sent to the output queue on the link),but in simulation, 
there are always packets in the sender's output queue. I am confused by these phenomenon. who can tell me the reason.the following is the tcl script of my 
simulation system. thanks for your help very much!
#Create a simulator object
set ns [new Simulator]

#Define different colors for data flows (for NAM)
$ns color 1 Blue

#Open the NAM trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
        #Close the NAM trace file
        close $nf
        #Execute NAM on the trace file
        exec nam out.nam &
        exit 0
}

#Create four nodes
set n0 [$ns node]
set n1 [$ns node]

#Create links between the nodes
$ns duplex-link $n0 $n1 2Mb 10ms DropTail
#Set Queue Size of link (n0-n1) to 20
$ns queue-limit $n0 $n1 20
#Give node position (for NAM)
$ns duplex-link-op $n0 $n1 orient right

#Monitor the queue for link (n0-n1). (for NAM)
$ns duplex-link-op $n0 $n1 queuePos 0.5


#Setup a TCP connection
set tcp [new Agent/TCP]
$tcp set class_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

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


#Schedule events 
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"

#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink"

#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"


#Run the simulation
$ns run
In this script, in the command "$ns duplex-link $n0 $n1 2Mb 10ms DropTail", 
if 10ms is replaced by 0.001ms, then the ACK packet come back to sender will
be very less. and in the command "$ns queue-limit $n0 $n1 20", if 20 is replaced 
by 15,then some packets in the queue(n0-n1) will be discarded.and the queue (n0-n1) 
always has packets .
 
 

�Ѻ���������24Сʱ����
�����ܿ��ж� ���ٸ�����������ϻ�
���Ǻ�����˹���ú������Ը�����
���¡����¡������£������Ѻ���������

  �ѽ�ϲ˫�꣬ʱ������ѡ
--�������侫Ʒ�����˫��