Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __INET_TCPMAIN_H
00019 #define __INET_TCPMAIN_H
00020
00021 #include <map>
00022 #include <set>
00023 #include <omnetpp.h>
00024 #include "IPvXAddress.h"
00025
00026
00027 class TCPConnection;
00028 class TCPSegment;
00029
00030
00031 #define tcpEV (ev.disable_tracing||TCP::testing)?ev:ev
00032
00033
00034 #define tcpEV2 (ev.disable_tracing||TCP::testing||!TCP::logverbose)?ev:ev
00035
00036
00037 #define testingEV (ev.disable_tracing||!TCP::testing)?ev:ev
00038
00039
00040
00041
00042
00096 class INET_API TCP : public cSimpleModule
00097 {
00098 public:
00099 struct AppConnKey
00100 {
00101 int appGateIndex;
00102 int connId;
00103
00104 inline bool operator<(const AppConnKey& b) const
00105 {
00106 if (appGateIndex!=b.appGateIndex)
00107 return appGateIndex<b.appGateIndex;
00108 else
00109 return connId<b.connId;
00110 }
00111
00112 };
00113 struct SockPair
00114 {
00115 IPvXAddress localAddr;
00116 IPvXAddress remoteAddr;
00117 int localPort;
00118 int remotePort;
00119
00120 inline bool operator<(const SockPair& b) const
00121 {
00122 if (remoteAddr!=b.remoteAddr)
00123 return remoteAddr<b.remoteAddr;
00124 else if (localAddr!=b.localAddr)
00125 return localAddr<b.localAddr;
00126 else if (remotePort!=b.remotePort)
00127 return remotePort<b.remotePort;
00128 else
00129 return localPort<b.localPort;
00130 }
00131 };
00132
00133 protected:
00134 typedef std::map<AppConnKey,TCPConnection*> TcpAppConnMap;
00135 typedef std::map<SockPair,TCPConnection*> TcpConnMap;
00136
00137 TcpAppConnMap tcpAppConnMap;
00138 TcpConnMap tcpConnMap;
00139
00140 ushort lastEphemeralPort;
00141 std::multiset<ushort> usedEphemeralPorts;
00142
00143 protected:
00145 virtual TCPConnection *createConnection(int appGateIndex, int connId);
00146
00147
00148 virtual TCPConnection *findConnForSegment(TCPSegment *tcpseg, IPvXAddress srcAddr, IPvXAddress destAddr);
00149 virtual TCPConnection *findConnForApp(int appGateIndex, int connId);
00150 virtual void segmentArrivalWhileClosed(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00151 virtual void removeConnection(TCPConnection *conn);
00152 virtual void updateDisplayString();
00153
00154 public:
00155 static bool testing;
00156 static bool logverbose;
00157
00158 bool recordStatistics;
00159
00160 public:
00161 TCP() {}
00162 virtual ~TCP();
00163
00164 protected:
00165 virtual void initialize();
00166 virtual void handleMessage(cMessage *msg);
00167 virtual void finish();
00168
00169 public:
00174 virtual void addSockPair(TCPConnection *conn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00175
00180 virtual void updateSockPair(TCPConnection *conn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00181
00186 virtual void addForkedConnection(TCPConnection *conn, TCPConnection *newConn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00187
00191 virtual ushort getEphemeralPort();
00192 };
00193
00194 #endif
00195
00196