00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __INET_TCPCONNECTION_OLD_H
00019 #define __INET_TCPCONNECTION_OLD_H
00020
00021 #include <omnetpp.h>
00022 #include "INETDefs.h"
00023 #include "IPvXAddress.h"
00024 #include "TCP_old.h"
00025
00026 class TCPSegment;
00027 class TCPCommand;
00028 class TCPOpenCommand;
00029
00030 namespace tcp_old {
00031 using namespace tcp_old;
00032
00033 class TCPSendQueue;
00034 class TCPReceiveQueue;
00035 class TCPAlgorithm;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 enum TcpState
00058 {
00059 TCP_S_INIT = 0,
00060 TCP_S_CLOSED = FSM_Steady(1),
00061 TCP_S_LISTEN = FSM_Steady(2),
00062 TCP_S_SYN_SENT = FSM_Steady(3),
00063 TCP_S_SYN_RCVD = FSM_Steady(4),
00064 TCP_S_ESTABLISHED = FSM_Steady(5),
00065 TCP_S_CLOSE_WAIT = FSM_Steady(6),
00066 TCP_S_LAST_ACK = FSM_Steady(7),
00067 TCP_S_FIN_WAIT_1 = FSM_Steady(8),
00068 TCP_S_FIN_WAIT_2 = FSM_Steady(9),
00069 TCP_S_CLOSING = FSM_Steady(10),
00070 TCP_S_TIME_WAIT = FSM_Steady(11)
00071 };
00072
00073
00074
00075
00076
00077
00078 enum TCPEventCode
00079 {
00080 TCP_E_IGNORE,
00081
00082
00083
00084 TCP_E_OPEN_ACTIVE,
00085 TCP_E_OPEN_PASSIVE,
00086 TCP_E_SEND,
00087 TCP_E_CLOSE,
00088 TCP_E_ABORT,
00089 TCP_E_STATUS,
00090
00091
00092 TCP_E_RCV_DATA,
00093 TCP_E_RCV_ACK,
00094 TCP_E_RCV_SYN,
00095 TCP_E_RCV_SYN_ACK,
00096 TCP_E_RCV_FIN,
00097 TCP_E_RCV_FIN_ACK,
00098 TCP_E_RCV_RST,
00099
00100 TCP_E_RCV_UNEXP_SYN,
00101
00102
00103 TCP_E_TIMEOUT_2MSL,
00104 TCP_E_TIMEOUT_CONN_ESTAB,
00105 TCP_E_TIMEOUT_FIN_WAIT_2,
00106
00107
00108
00109 };
00110
00111
00114 #define TCP_TIMEOUT_CONN_ESTAB 75 // 75 seconds
00115 #define TCP_TIMEOUT_FIN_WAIT_2 600 // 10 minutes
00116 #define TCP_TIMEOUT_2MSL 240 // 2 * 2 minutes
00117 #define TCP_TIMEOUT_SYN_REXMIT 3 // initially 3 seconds
00118 #define TCP_TIMEOUT_SYN_REXMIT_MAX 240 // 4 mins (will only be used with SYN+ACK: with SYN CONN_ESTAB occurs sooner)
00119
00120
00121 #define MAX_SYN_REXMIT_COUNT 12 // will only be used with SYN+ACK: with SYN CONN_ESTAB occurs sooner
00122
00123 #define TCP_MAX_WIN 65535 // largest value (16 bit) for (unscaled) window size
00124
00127 inline bool seqLess(uint32 a, uint32 b) {return a!=b && b-a<(1UL<<31);}
00128 inline bool seqLE(uint32 a, uint32 b) {return b-a<(1UL<<31);}
00129 inline bool seqGreater(uint32 a, uint32 b) {return a!=b && a-b<(1UL<<31);}
00130 inline bool seqGE(uint32 a, uint32 b) {return a-b<(1UL<<31);}
00132
00133
00147 class INET_API TCPStateVariables : public cPolymorphic
00148 {
00149 public:
00150 TCPStateVariables();
00151 virtual std::string info() const;
00152 virtual std::string detailedInfo() const;
00153 public:
00154 bool active;
00155 bool fork;
00156
00157 uint snd_mss;
00158
00159
00160 uint32 snd_una;
00161 uint32 snd_nxt;
00162 uint32 snd_max;
00163
00164 uint snd_wnd;
00165 uint32 snd_up;
00166 uint32 snd_wl1;
00167 uint32 snd_wl2;
00168 uint32 iss;
00169
00170
00171 uint32 rcv_nxt;
00172 uint32 rcv_wnd;
00173 uint32 rcv_up;
00174 uint32 irs;
00175
00176
00177
00178 short dupacks;
00179
00180
00181
00182 int syn_rexmit_count;
00183 simtime_t syn_rexmit_timeout;
00184
00185
00186
00187
00188 bool fin_ack_rcvd;
00189
00190 bool send_fin;
00191 uint32 snd_fin_seq;
00192
00193 bool fin_rcvd;
00194 uint32 rcv_fin_seq;
00195
00196 bool afterRto;
00197
00198 uint32 last_ack_sent;
00199
00200
00201
00202
00203
00204 };
00205
00206
00207
00256 class INET_API TCPConnection
00257 {
00258 public:
00259
00260 int appGateIndex;
00261 int connId;
00262
00263
00264 IPvXAddress localAddr;
00265 IPvXAddress remoteAddr;
00266 int localPort;
00267 int remotePort;
00268
00269 protected:
00270 TCP *tcpMain;
00271
00272
00273 cFSM fsm;
00274
00275
00276 TCPStateVariables *state;
00277
00278
00279 TCPSendQueue *sendQueue;
00280 TCPReceiveQueue *receiveQueue;
00281
00282
00283 TCPAlgorithm *tcpAlgorithm;
00284
00285
00286 cMessage *the2MSLTimer;
00287 cMessage *connEstabTimer;
00288 cMessage *finWait2Timer;
00289 cMessage *synRexmitTimer;
00290
00291
00292 cOutVector *sndWndVector;
00293 cOutVector *sndNxtVector;
00294 cOutVector *sndAckVector;
00295 cOutVector *rcvSeqVector;
00296 cOutVector *rcvAckVector;
00297 cOutVector *unackedVector;
00298
00299 protected:
00303 virtual TCPEventCode preanalyseAppCommandEvent(int commandCode);
00305 virtual bool performStateTransition(const TCPEventCode& event);
00307 virtual void stateEntered(int state);
00309
00312 virtual void process_OPEN_ACTIVE(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00313 virtual void process_OPEN_PASSIVE(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00314 virtual void process_SEND(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00315 virtual void process_CLOSE(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00316 virtual void process_ABORT(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00317 virtual void process_STATUS(TCPEventCode& event, TCPCommand *tcpCommand, cMessage *msg);
00319
00326 virtual bool tryFastRoute(TCPSegment *tcpseg);
00331 virtual TCPEventCode process_RCV_SEGMENT(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00332 virtual TCPEventCode processSegmentInListen(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00333 virtual TCPEventCode processSegmentInSynSent(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00334 virtual TCPEventCode processSegment1stThru8th(TCPSegment *tcpseg);
00335 virtual TCPEventCode processRstInSynReceived(TCPSegment *tcpseg);
00336 virtual bool processAckInEstabEtc(TCPSegment *tcpseg);
00338
00341 virtual void process_TIMEOUT_2MSL();
00342 virtual void process_TIMEOUT_CONN_ESTAB();
00343 virtual void process_TIMEOUT_FIN_WAIT_2();
00344 virtual void process_TIMEOUT_SYN_REXMIT(TCPEventCode& event);
00346
00348 virtual TCPConnection *cloneListeningConnection();
00349
00351 virtual void initConnection(TCPOpenCommand *openCmd);
00352
00354 virtual void configureStateVariables();
00355
00357 virtual void selectInitialSeqNum();
00358
00360 virtual bool isSegmentAcceptable(TCPSegment *tcpseg);
00361
00363 virtual void sendSyn();
00364
00366 virtual void sendSynAck();
00367
00368 public:
00370 virtual void sendAck();
00371
00377 virtual bool sendData(bool fullSegmentsOnly, int congestionWindow=-1);
00378
00380 virtual bool sendProbe();
00381
00383 virtual void retransmitOneSegment(bool called_at_rto);
00384
00386 virtual void retransmitData();
00387
00389 virtual void sendRst(uint32 seqNo);
00391 virtual void sendRst(uint32 seq, IPvXAddress src, IPvXAddress dest, int srcPort, int destPort);
00393 virtual void sendRstAck(uint32 seq, uint32 ack, IPvXAddress src, IPvXAddress dest, int srcPort, int destPort);
00394
00396 virtual void sendFin();
00397
00402 virtual void sendSegment(uint32 bytes);
00403
00405 virtual void sendToIP(TCPSegment *tcpseg);
00406
00411 virtual TCPSegment *createTCPSegment(const char *name);
00412
00414 virtual void startSynRexmitTimer();
00415
00417 virtual void signalConnectionTimeout();
00418
00420 void scheduleTimeout(cMessage *msg, simtime_t timeout)
00421 {tcpMain->scheduleAt(simTime()+timeout, msg);}
00422
00423 protected:
00425 cMessage *cancelEvent(cMessage *msg) {return tcpMain->cancelEvent(msg);}
00426
00428 static void sendToIP(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00429
00431 virtual void sendToApp(cMessage *msg);
00432
00434 virtual void sendIndicationToApp(int code);
00435
00437 virtual void sendEstabIndicationToApp();
00438
00439 public:
00441 virtual void printConnBrief();
00443 static void printSegmentBrief(TCPSegment *tcpseg);
00445 static const char *stateName(int state);
00447 static const char *eventName(int event);
00449 static const char *indicationName(int code);
00450
00451 public:
00455 TCPConnection(TCP *mod, int appGateIndex, int connId);
00456
00461 TCPConnection();
00462
00466 virtual ~TCPConnection();
00467
00474 virtual void segmentArrivalWhileClosed(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00475
00476
00478 int getFsmState() const {return fsm.getState();}
00479 TCPStateVariables *getState() {return state;}
00480 TCPSendQueue *getSendQueue() {return sendQueue;}
00481 TCPReceiveQueue *getReceiveQueue() {return receiveQueue;}
00482 TCPAlgorithm *getTcpAlgorithm() {return tcpAlgorithm;}
00483 TCP *getTcpMain() {return tcpMain;}
00485
00491 virtual bool processTimer(cMessage *msg);
00492
00498 virtual bool processTCPSegment(TCPSegment *tcpSeg, IPvXAddress srcAddr, IPvXAddress destAddr);
00499
00505 virtual bool processAppCommand(cMessage *msg);
00506 };
00507
00508 }
00509 #endif
00510
00511