12.07.2015 Views

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

The ns Manual (formerly ns Notes and Documentation)1 - NM Lab at ...

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

{}Packet* p = allocpkt();hdr_tcp *tcph = (hdr_tcp*)p->access(off_tcp_);double now = Scheduler::i<strong>ns</strong>tance().clock();tcph->seqno() = seqno;tcph->ts() = now;tcph->reason() = reason;Connector::send(p, 0);...if (!(rtx_timer_.st<strong>at</strong>us() == TIMER_PENDING))/* No timer pending. Schedule one. */set_rtx_timer();Here we see an illustr<strong>at</strong>ion of the use of the Agent::allocpkt() method. This output routine first alloc<strong>at</strong>es a new packet(with its common <strong>and</strong> IP headers already filled in), but then must fill in the appropri<strong>at</strong>e TCP-layer header fields. To findthe TCP header in a packet (assuming it has been enabled (Section 12.2.4)) the off_tcp_ must be properly initialized, asillustr<strong>at</strong>ed in the co<strong>ns</strong>tructor. <strong>The</strong> packet access() method retur<strong>ns</strong> a pointer to the TCP header, its sequence number <strong>and</strong>time stamp fields are filled in, <strong>and</strong> the send() method of the class Connector is called to send the packet dow<strong>ns</strong>tream one hop.Note th<strong>at</strong> the C++ :: scoping oper<strong>at</strong>or is used here to avoid calling TcpSimpleAgent::send() (which is also defined).<strong>The</strong> check for a pending timer uses the timer method st<strong>at</strong>us() which is defined in the base class TimerH<strong>and</strong>ler. It is usedhere to set a retra<strong>ns</strong>mission timer if one is not already set (a TCP sender only sets one timer per window of packets on eachconnection).10.5.3 Processing Input <strong>at</strong> ReceiverMany of the TCP agents can be used with the class TCPSink as the peer. This class defines the recv() <strong>and</strong> ack()methods as follows:void TcpSink::recv(Packet* pkt, H<strong>and</strong>ler*){hdr_tcp *th = (hdr_tcp*)pkt->access(off_tcp_);acker_->upd<strong>at</strong>e(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_);101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!