Hello everyone,

I meet a problem when adding more than one Agent to a node, I think my
method is wrong, Here is my question and OTcl script:

My question is:
(1) When attaching tcpb to Node n0, it will invoke "$n0 attach $tcpb", which
have no value for "port", So the default port is 0, it will cover the port
of tcpa, when tcpa want to send packets, it will be an error. But my script
works correctly. Who can explain it? What's the port number for tcpa and
tcpb? Is it the same situation for sinka and sinkb?

(2) When I change the script to: *$ns connect $tcpa $sinka ; **$ns connect
$tcpb $sinka*, The first tcpa syn packet invoke tcpb ACK, why?

Thank you very much.



Node instproc attach { agent { port "" } } {
    $self instvar agents_ address_ dmux_
    #
    # Assign port number (i.e., this agent receives
    # traffic addressed to this host and port)
    #
    lappend agents_ $agent
    #
    # Attach agents to this node (i.e., the classifier inside).
    # We call the entry method on ourself to find the front door
    # (e.g., for multicast the first object is not the unicast classifier)
    #
    # Also, stash the node in the agent and set the local addr of
    # this agent.
    #
    $agent set node_ $self
    $agent set agent_addr_ [AddrParams addr2id $address_]
    #
    # If a port demuxer doesn't exist, create it.
    #
    if { $dmux_ == "" } {
        # Use the default mask_ and port_ values
        set dmux_ [new Classifier/Port]
        # point the node's routing entry to itself
        # at the port demuxer (if there is one)
        $self add-route $address_ $dmux_
    }
    if { $port == "" } {
        set port [$dmux_ alloc-port [[Simulator instance] nullagent]]
    }
    $agent set agent_port_ $port

    $self add-target $agent $port
}


*set ns [new Simulator]

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

#Open the Trace files
set tracefile1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $tracefile1

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


#Define a 'finish' procedure
proc finish {} {
     global ns tracefile1 namfile
     $ns flush-trace
     close $tracefile1
     close $namfile
     exec nam out.nam &
     exit 0
}

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

#Create links between the nodes
$ns duplex-link $n0 $n1 2Mb 20ms DropTail


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

#Setup a TCP connection
set tcpa [new Agent/TCP]
$ns attach-agent $n0 $tcpa

#Setup another TCP connection
set tcpb [new Agent/TCP]
$ns attach-agent $n0 $tcpb

set sinka [new Agent/TCPSink]
$ns attach-agent $n1 $sinka
$ns connect $tcpa $sinka

set sinkb [new Agent/TCPSink]
$ns attach-agent $n1 $sinkb
$ns connect $tcpb $sinkb

$tcpa set fid_ 1
$tcpb set fid_ 2


set ftpa [new Application/FTP]
$ftpa attach-agent $tcpa

set ftpb [new Application/FTP]
$ftpb attach-agent $tcpb


$ns at 0.05 "$ftpa start"
$ns at 0.1 "$ftpb start"
$ns at 63.4 "$ftpb stop"
$ns at 63.5 "$ftpa stop"

$ns at 64.0 "finish"
$ns run*

Reply via email to