40.2.1 Attaching transport agents to nodes

This step is typically done at OTcl level. Agent management was also briefly discussed in Section 5.2.

        set src [new Agent/TCP/FullTcp]
        set sink [new Agent/TCP/FullTcp]
        $ns_ attach-agent $node_(s1) $src
        $ns_ attach-agent $node_(k1) $sink
        $ns_ connect $src $sink

The above code illustrates that in ns, agents are first attached to a node via attach-agent. Next, the connect instproc sets each agent's destination target to the other. Note that, in ns, connect() has different semantics than in regular sockets. In ns, connect() simply establishes the destination address for an agent, but does not set up the connection. As a result, the overlying application does not need to know its peer's address. For TCPs that exchange SYN segments, the first call to send() will trigger the SYN exchange.

To detach an agent from a node, the instproc detach-agent can be used; this resets the target for the agent to a null agent.

Tom Henderson 2011-11-05