| 1 | /* |
| 2 | * Copyright (c) 1997 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the Network Research |
| 16 | * Group at Lawrence Berkeley National Laboratory. |
| 17 | * 4. Neither the name of the University nor of the Laboratory may be used |
| 18 | * to endorse or promote products derived from this software without |
| 19 | * specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | * @(#) $Header: /cvsroot/nsnam/ns-2/baytcp/tcp-full-bay.h,v 1.3 2006/05/30 21:38:42 pradkin Exp $ (LBL) |
| 34 | */ |
| 35 | |
| 36 | #ifndef ns_tcp_full_h |
| 37 | #define ns_tcp_full_h |
| 38 | |
| 39 | #include "tcp.h" |
| 40 | |
| 41 | /* |
| 42 | * these defines are directly from tcp_var.h in "real" TCP |
| 43 | * they are used in the 'tcp_flags_' member variable |
| 44 | */ |
| 45 | |
| 46 | #define TF_ACKNOW 0x0001 /* ack peer immediately */ |
| 47 | #define TF_DELACK 0x0002 /* ack, but try to delay it */ |
| 48 | #define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ |
| 49 | #define TF_NOOPT 0x0008 /* don't use tcp options */ |
| 50 | #define TF_SENTFIN 0x0010 /* have sent FIN */ |
| 51 | #define TF_SENTSYN 0x0020 /* have sent SYN */ |
| 52 | |
| 53 | #define TCPS_CLOSED 0 /* closed */ |
| 54 | #define TCPS_LISTEN 1 /* listening for connection */ |
| 55 | #define TCPS_SYN_SENT 2 /* active, have sent syn */ |
| 56 | #define TCPS_SYN_RECEIVED 3 /* have send and received syn */ |
| 57 | #define TCPS_ESTABLISHED 4 /* established */ |
| 58 | #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ |
| 59 | #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ |
| 60 | #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ |
| 61 | #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ |
| 62 | |
| 63 | #define TCPIP_BASE_PKTSIZE 40 /* base TCP/IP header in real life */ |
| 64 | /* these are used to mark packets as to why we xmitted them */ |
| 65 | #define REASON_NORMAL 0 |
| 66 | #define REASON_TIMEOUT 1 |
| 67 | #define REASON_DUPACK 2 |
| 68 | |
| 69 | /* bits for the tcp_flags field below */ |
| 70 | /* from tcp.h in the "real" implementation */ |
| 71 | /* RST and URG are not used in the simulator */ |
| 72 | |
| 73 | #define TH_FIN 0x01 /* FIN: closing a connection */ |
| 74 | #define TH_SYN 0x02 /* SYN: starting a connection */ |
| 75 | #define TH_PUSH 0x08 /* PUSH: used here to "deliver" data */ |
| 76 | #define TH_ACK 0x10 /* ACK: ack number is valid */ |
| 77 | |
| 78 | #define PF_TIMEOUT 0x04 /* protocol defined */ |
| 79 | |
| 80 | /* |
| 81 | * inserted by kedar |
| 82 | */ |
| 83 | |
| 84 | class BayFullTcpAgent; |
| 85 | |
| 86 | class BayDelAckTimer : public TimerHandler { |
| 87 | public: |
| 88 | BayDelAckTimer(BayFullTcpAgent *a) : TimerHandler(), a_(a) { } |
| 89 | protected: |
| 90 | virtual void expire(Event *); |
| 91 | BayFullTcpAgent *a_; |
| 92 | }; |
| 93 | |
| 94 | class BayReassemblyQueue : public TcpAgent { |
| 95 | struct seginfo { |
| 96 | seginfo* next_; |
| 97 | seginfo* prev_; |
| 98 | int startseq_; |
| 99 | int endseq_; |
| 100 | int flags_; |
| 101 | }; |
| 102 | public: |
| 103 | BayReassemblyQueue(int& nxt) : head_(NULL), tail_(NULL), |
| 104 | rcv_nxt_(nxt) { } |
| 105 | int empty() { return (head_ == NULL); } |
| 106 | int add(Packet*); |
| 107 | void clear(); |
| 108 | protected: |
| 109 | seginfo* head_; |
| 110 | seginfo* tail_; |
| 111 | int& rcv_nxt_; |
| 112 | }; |
| 113 | |
| 114 | /* Added by kmn 8/5/97. A hack to create a template base class for |
| 115 | * application agents that expect to talk to full tcps. Don't want |
| 116 | * to do anything fancy since the vint folks should come up with |
| 117 | * something one of these days. |
| 118 | * kmn - 8/12/97 yet another hack added to keep a list of agents |
| 119 | */ |
| 120 | /* vint project never came through. Added in to recv 6/8/00 -kmn */ |
| 121 | |
| 122 | #define DATA_PUSH 1 |
| 123 | #define CONNECTION_END 2 |
| 124 | |
| 125 | class BayTcpAppAgent : public Agent { |
| 126 | public: |
| 127 | BayTcpAppAgent(packet_t ptype) : Agent(ptype) {} |
| 128 | virtual void recv(Packet*, BayFullTcpAgent*, int) {} |
| 129 | }; |
| 130 | |
| 131 | class BayFullTcpAgent : public TcpAgent { |
| 132 | public: |
| 133 | BayFullTcpAgent(); |
| 134 | ~BayFullTcpAgent(); |
| 135 | void delay_bind_init_all(); |
| 136 | int delay_bind_dispatch(const char *varName, const char *localName, |
| 137 | TclObject *tracer); |
| 138 | virtual void recv(Packet *pkt, Handler*); |
| 139 | virtual void timeout(int tno); // tcp_timers() in real code |
| 140 | void advance(int); |
| 141 | int advance(int, int); //added 7/30/97 by kmn to pass bytes, |
| 142 | // set close_on_empty_ |
| 143 | int command(int argc, const char*const* argv); |
| 144 | int state() { return state_; } |
| 145 | |
| 146 | protected: |
| 147 | int segs_per_ack_; // for window updates |
| 148 | int nodelay_; // disable sender-side Nagle? |
| 149 | int data_on_syn_; // send data on initial SYN? |
| 150 | int tcprexmtthresh_; // fast retransmit threshold |
| 151 | int iss_; // initial send seq number |
| 152 | int dupseg_fix_; // fix bug with dup segs and dup acks? |
| 153 | int dupack_reset_; // zero dupacks on dataful dup acks? |
| 154 | double delack_interval_; |
| 155 | |
| 156 | int headersize(); // a tcp header |
| 157 | int outflags(); // state-specific tcp header flags |
| 158 | int predict_ok(Packet*); // predicate for recv-side header prediction |
| 159 | |
| 160 | void fast_retransmit(int); // do a fast-retransmit on specified seg |
| 161 | inline double now() { return Scheduler::instance().clock(); } |
| 162 | |
| 163 | void reset_rtx_timer(int); // adjust the rtx timer |
| 164 | void reset(); // reset to a known point |
| 165 | void reinit(); // reset to a known point |
| 166 | void connect(); // do active open |
| 167 | void listen(); // do passive open |
| 168 | void usrclosed(); // user requested a close |
| 169 | int need_send(); // need to send ACK/win-update now? |
| 170 | void sendpacket(int seqno, int ackno, int pflags, int datalen, int reason, Packet *p=0); |
| 171 | void output(int seqno, int reason = 0); // output 1 packet |
| 172 | void send_much(int force, int reason, int maxburst = 0); |
| 173 | void newack(Packet* pkt); // process an ACK |
| 174 | void cancel_rtx_timeout(); // cancel the rtx timeout |
| 175 | |
| 176 | /* |
| 177 | * the following are part of a tcpcb in "real" RFC793 TCP |
| 178 | */ |
| 179 | int maxseg_; /* MSS */ |
| 180 | int flags_; /* controls next output() call */ |
| 181 | int state_; /* enumerated type: FSM state */ |
| 182 | int rcv_nxt_; /* next sequence number expected */ |
| 183 | BayReassemblyQueue rq_; /* TCP reassembly queue */ |
| 184 | /* |
| 185 | * the following are part of a tcpcb in "real" RFC1323 TCP |
| 186 | */ |
| 187 | int last_ack_sent_; /* ackno field from last segment we sent */ |
| 188 | /* |
| 189 | * added 7/30/97 by kmn to allow connection to close with FINs |
| 190 | * when empties data and to allow calling recv() on application |
| 191 | */ |
| 192 | int close_on_empty_; |
| 193 | BayTcpAppAgent* app_; |
| 194 | //added 8/12 to start in ack per packet, switch to set value |
| 195 | int switch_spa_thresh_; |
| 196 | int first_data_; |
| 197 | int recover_cause_; |
| 198 | /* |
| 199 | *inserted by kedar |
| 200 | */ |
| 201 | BayDelAckTimer delack_timer_; |
| 202 | }; |
| 203 | |
| 204 | class BayFullTcpList { |
| 205 | public: |
| 206 | BayFullTcpList() : tcp(0), next(0) {} |
| 207 | BayFullTcpAgent* tcp; |
| 208 | BayFullTcpList* next; |
| 209 | }; |
| 210 | |
| 211 | #ifdef notdef |
| 212 | class NewRenoBayFullTcpAgent : public BayFullTcpAgent { |
| 213 | public: |
| 214 | NewRenoBayFullTcpAgent(); |
| 215 | protected: |
| 216 | int save_maxburst_; // saved value of maxburst_ |
| 217 | int recov_maxburst_; // maxburst lim during recovery |
| 218 | void pack_action(Packet*); |
| 219 | void ack_action(Packet*); |
| 220 | }; |
| 221 | |
| 222 | class TahoeBayFullTcpAgent : public BayFullTcpAgent { |
| 223 | protected: |
| 224 | void dupack_action(); |
| 225 | }; |
| 226 | |
| 227 | class SackBayFullTcpAgent : public BayFullTcpAgent { |
| 228 | public: |
| 229 | SackBayFullTcpAgent(); |
| 230 | ~SackBayFullTcpAgent(); |
| 231 | void recv(Packet*, Handler*); |
| 232 | protected: |
| 233 | int build_options(hdr_tcp*); // insert opts, return len |
| 234 | int sack_option_size_; // base # bytes for sack opt (no blks) |
| 235 | int sack_block_size_; // # bytes in a sack block (def: 8) |
| 236 | int sack_min_; // first seq# in sack queue |
| 237 | int sack_max_; // highest seq# seen in any sack block |
| 238 | int sack_nxt_; // next seq# to hole-fill |
| 239 | int max_sack_blocks_; // max # sack blocks to send |
| 240 | |
| 241 | BayReassemblyQueue sq_; // SACK queue, used by sender |
| 242 | |
| 243 | void reset(); |
| 244 | void sendpacket(int seqno, int ackno, int pflags, int datalen, int reason); |
| 245 | void send_much(int force, int reason, int maxburst = 0); |
| 246 | void send_holes(int force, int maxburst); |
| 247 | void pack_action(Packet*); |
| 248 | void ack_action(Packet*); |
| 249 | void dupack_action(); |
| 250 | int hdrsize(int nblks); |
| 251 | void timeout_action(); |
| 252 | }; |
| 253 | #endif |
| 254 | |
| 255 | #endif |