11.5.3 Processing Input at Receiver

Many of the TCP agents can be used with the TCPSink../ns-2/tcp-sink.h as the peer. This class defines the []recv and []ack methods as follows:

        void TcpSink::recv(Packet* pkt, Handler*)
        {
                hdr_tcp *th = (hdr_tcp*)pkt-\>access(off_tcp_);
                acker_-\>update(th-\>seqno());
                ack(pkt);
                Packet::free(pkt);
        }

        void TcpSink::ack(Packet* opkt)
        {
                Packet* npkt = allocpkt();
        
                hdr_tcp *otcp = (hdr_tcp*)opkt-\>access(off_tcp_);
                hdr_tcp *ntcp = (hdr_tcp*)npkt-\>access(off_tcp_);
                ntcp-\>seqno() = acker_-\>Seqno();
                ntcp-\>ts() = otcp-\>ts();
        
                hdr_ip* oip = (hdr_ip*)opkt-\>access(off_ip_);
                hdr_ip* nip = (hdr_ip*)npkt-\>access(off_ip_);
                nip-\>flowid() = oip-\>flowid();
        
                hdr_flags* of = (hdr_flags*)opkt-\>access(off_flags_);
                hdr_flags* nf = (hdr_flags*)npkt-\>access(off_flags_);
                nf-\>ecn_ = of-\>ecn_;
        
                acker_-\>append_ack((hdr_cmn*)npkt-\>access(off_cmn_),
                                   ntcp, otcp-\>seqno());
                send(npkt, 0);
        }
The []recv method overrides the []Agent::recv method (which merely discards the received packet). It updates some internal state with the sequence number of the received packet (and therefore requires the off_tcp_ variable to be properly initialized. It then generates an acknowledgment for the received packet. The []ack method makes liberal use of access to packet header fields including separate accesses to the TCP header, IP header, Flags header, and common header. The call to []send invokes the []Connector::send method.



Tom Henderson 2014-12-17