ns-allinone-2.35/tcp/tcp-full.cc
void
FullTcpAgent::sendpacket(int seqno, int ackno, int pflags, int datalen, int reason, Packet *p)
{
        if (!p) p = allocpkt();
        hdr_tcp *tcph = hdr_tcp::access(p);
	hdr_flags *fh = hdr_flags::access(p);

	/* build basic header w/options */

        tcph->seqno() = seqno;
        tcph->ackno() = ackno;
        tcph->flags() = pflags;
        tcph->reason() |= reason; // make tcph->reason look like ns1 pkt->flags?
	tcph->sa_length() = 0;    // may be increased by build_options()
        tcph->hlen() = tcpip_base_hdr_size_;
	tcph->hlen() += build_options(tcph);

	/*
	 * Explicit Congestion Notification (ECN) related:
	 * Bits in header:
	 * 	ECT (EC Capable Transport),
	 * 	ECNECHO (ECHO of ECN Notification generated at router),
	 * 	CWR (Congestion Window Reduced from RFC 2481)
	 * States in TCP:
	 *	ecn_: I am supposed to do ECN if my peer does
	 *	ect_: I am doing ECN (ecn_ should be T and peer does ECN)
	 */

	if (datalen > 0 && ecn_ ){
	        // set ect on data packets 
		fh->ect() = ect_;	// on after mutual agreement on ECT
        } else if (ecn_ && ecn_syn_ && ecn_syn_next_ && (pflags & TH_SYN) && (pflags & TH_ACK)) {
                // set ect on syn/ack packet, if syn packet was negotiating ECT
               	fh->ect() = ect_;
	} else {
		/* Set ect() to 0.  -M. Weigle 1/19/05 */
		fh->ect() = 0;
	}
	if (ecn_ && ect_ && recent_ce_ ) { 
		// This is needed here for the ACK in a SYN, SYN/ACK, ACK
		// sequence.
		pflags |= TH_ECE;
	}
        // fill in CWR and ECE bits which don't actually sit in
        // the tcp_flags but in hdr_flags
        if ( pflags & TH_ECE) {
                fh->ecnecho() = 1;
        } else {
                fh->ecnecho() = 0;
        }
        if ( pflags & TH_CWR ) {
                fh->cong_action() = 1;
        }
	else {
		/* Set cong_action() to 0  -M. Weigle 1/19/05 */
		fh->cong_action() = 0;
	}

	/* actual size is data length plus header length */

        hdr_cmn *ch = hdr_cmn::access(p);
        ch->size() = datalen + tcph->hlen();

        if (datalen <= 0)
                ++nackpack_;
        else {
                ++ndatapack_;
                ndatabytes_ += datalen;
		last_send_time_ = now();	// time of last data
        }
        if (reason == REASON_TIMEOUT || reason == REASON_DUPACK || reason == REASON_SACK) {
                ++nrexmitpack_;
                nrexmitbytes_ += datalen;
        }

	last_ack_sent_ = ackno;

//if (state_ != TCPS_ESTABLISHED) {
//printf("%f(%s)[state:%s]: sending pkt ", now(), name(), statestr(state_));
//prpkt(p);
//}

	send(p, 0);

	return;
}
/*
 * sendpacket: 
 *	allocate a packet, fill in header fields, and send
 *	also keeps stats on # of data pkts, acks, re-xmits, etc
 *
 * fill in packet fields.  Agent::allocpkt() fills
 * in most of the network layer fields for us.
 * So fill in tcp hdr and adjust the packet size.
 *
 * Also, set the size of the tcp header.
 */
allocate a packet, fill in header fields, and send
also keeps stats on # of data pkts, acks, re-xmits, etc

fill in packet fields.  Agent::allocpkt() fills
in most of the network layer fields for us.
So fill in tcp hdr and adjust the packet size.

Also, set the size of the tcp header.
allocate a packet fill in header fields and send also keeps stats on # of data pkts acks re - xmits etc fill in packet fields . Agent :: allocpkt () fills in most of the network layer fields for us . So fill in tcp hdr and adjust the packet size . Also set the size of the tcp header .
void
FullTcpAgent::sendpacket(int seqno, int ackno, int pflags, int datalen, int reason, Packet *p)
{
        if (!p) p = allocpkt();
        hdr_tcp *tcph = hdr_tcp::access(p);
	hdr_flags *fh = hdr_flags::access(p);
        tcph->seqno() = seqno;
        tcph->ackno() = ackno;
        tcph->flags() = pflags;
        tcph->reason() |= reason; 
	tcph->sa_length() = 0;    
        tcph->hlen() = tcpip_base_hdr_size_;
	tcph->hlen() += build_options(tcph);
	if (datalen > 0 && ecn_ ){
		fh->ect() = ect_;	
        } else if (ecn_ && ecn_syn_ && ecn_syn_next_ && (pflags & TH_SYN) && (pflags & TH_ACK)) {
               	fh->ect() = ect_;
	} else {
		fh->ect() = 0;
	}
	if (ecn_ && ect_ && recent_ce_ ) { 
		pflags |= TH_ECE;
	}
        if ( pflags & TH_ECE) {
                fh->ecnecho() = 1;
        } else {
                fh->ecnecho() = 0;
        }
        if ( pflags & TH_CWR ) {
                fh->cong_action() = 1;
        }
	else {
		fh->cong_action() = 0;
	}
        hdr_cmn *ch = hdr_cmn::access(p);
        ch->size() = datalen + tcph->hlen();
        if (datalen <= 0)
                ++nackpack_;
        else {
                ++ndatapack_;
                ndatabytes_ += datalen;
		last_send_time_ = now();	
        }
        if (reason == REASON_TIMEOUT || reason == REASON_DUPACK || reason == REASON_SACK) {
                ++nrexmitpack_;
                nrexmitbytes_ += datalen;
        }
	last_ack_sent_ = ackno;
	send(p, 0);
	return;
}
void FullTcpAgent :: sendpacket ( int seqno , int ackno , int pflags , int datalen , int reason , Packet * p ) { if ( ! p ) p = allocpkt ( ) ; hdr_tcp * tcph = hdr_tcp :: access ( p ) ; hdr_flags * fh = hdr_flags :: access ( p ) ; tcph -> seqno ( ) = seqno ; tcph -> ackno ( ) = ackno ; tcph -> flags ( ) = pflags ; tcph -> reason ( ) |= reason ; tcph -> sa_length ( ) = 0 ; tcph -> hlen ( ) = tcpip_base_hdr_size_ ; tcph -> hlen ( ) += build_options ( tcph ) ; if ( datalen > 0 && ecn_ ) { fh -> ect ( ) = ect_ ; } else if ( ecn_ && ecn_syn_ && ecn_syn_next_ && ( pflags & TH_SYN ) && ( pflags & TH_ACK ) ) { fh -> ect ( ) = ect_ ; } else { fh -> ect ( ) = 0 ; } if ( ecn_ && ect_ && recent_ce_ ) { pflags |= TH_ECE ; } if ( pflags & TH_ECE ) { fh -> ecnecho ( ) = 1 ; } else { fh -> ecnecho ( ) = 0 ; } if ( pflags & TH_CWR ) { fh -> cong_action ( ) = 1 ; } else { fh -> cong_action ( ) = 0 ; } hdr_cmn * ch = hdr_cmn :: access ( p ) ; ch -> size ( ) = datalen + tcph -> hlen ( ) ; if ( datalen <= 0 ) ++ nackpack_ ; else { ++ ndatapack_ ; ndatabytes_ += datalen ; last_send_time_ = now ( ) ; } if ( reason == REASON_TIMEOUT || reason == REASON_DUPACK || reason == REASON_SACK ) { ++ nrexmitpack_ ; nrexmitbytes_ += datalen ; } last_ack_sent_ = ackno ; send ( p , 0 ) ; return ; }
sendpacket:
      allocate a packet, fill in header fields, and send
      also keeps stats on # of data pkts, acks, re-xmits, etc
sendpacket : allocate a packet fill in header fields and send also keeps stats on # of data pkts acks re - xmits etc
/* build basic header w/options */ // make tcph->reason look like ns1 pkt->flags? // may be increased by build_options() /*
	 * Explicit Congestion Notification (ECN) related:
	 * Bits in header:
	 * 	ECT (EC Capable Transport),
	 * 	ECNECHO (ECHO of ECN Notification generated at router),
	 * 	CWR (Congestion Window Reduced from RFC 2481)
	 * States in TCP:
	 *	ecn_: I am supposed to do ECN if my peer does
	 *	ect_: I am doing ECN (ecn_ should be T and peer does ECN)
	 */ // set ect on data packets  // on after mutual agreement on ECT // set ect on syn/ack packet, if syn packet was negotiating ECT /* Set ect() to 0.  -M. Weigle 1/19/05 */ // This is needed here for the ACK in a SYN, SYN/ACK, ACK // sequence. // fill in CWR and ECE bits which don't actually sit in // the tcp_flags but in hdr_flags /* Set cong_action() to 0  -M. Weigle 1/19/05 */ /* actual size is data length plus header length */ // time of last data //if (state_ != TCPS_ESTABLISHED) { //printf("%f(%s)[state:%s]: sending pkt ", now(), name(), statestr(state_)); //prpkt(p); //}