TCP_old.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef __INET_TCPMAIN_OLD_H
00019 #define __INET_TCPMAIN_OLD_H
00020 
00021 #include <map>
00022 #include <set>
00023 #include <omnetpp.h>
00024 #include "IPvXAddress.h"
00025 
00026 class TCPSegment;
00027 
00028 namespace tcp_old {
00029 
00030 class TCPConnection;
00031 
00032 // macro for normal ev<< logging (note: deliberately no parens in macro def)
00033 #define tcpEV (ev.disable_tracing||TCP::testing)?ev:ev
00034 
00035 // macro for more verbose ev<< logging (note: deliberately no parens in macro def)
00036 #define tcpEV2 (ev.disable_tracing||TCP::testing||!TCP::logverbose)?ev:ev
00037 
00038 // testingEV writes log that automated test cases can check (*.test files)
00039 #define testingEV (ev.disable_tracing||!TCP::testing)?ev:ev
00040 
00041 
00042 
00043 
00044 
00097 class INET_API TCP : public cSimpleModule
00098 {
00099   public:
00100     struct AppConnKey  // XXX this class is redundant since connId is already globally unique
00101     {
00102         int appGateIndex;
00103         int connId;
00104 
00105         inline bool operator<(const AppConnKey& b) const
00106         {
00107             if (appGateIndex!=b.appGateIndex)
00108                 return appGateIndex<b.appGateIndex;
00109             else
00110                 return connId<b.connId;
00111         }
00112 
00113     };
00114     struct SockPair
00115     {
00116         IPvXAddress localAddr;
00117         IPvXAddress remoteAddr;
00118         int localPort;   // -1: unspec
00119         int remotePort;  // -1: unspec
00120 
00121         inline bool operator<(const SockPair& b) const
00122         {
00123             if (remoteAddr!=b.remoteAddr)
00124                 return remoteAddr<b.remoteAddr;
00125             else if (localAddr!=b.localAddr)
00126                 return localAddr<b.localAddr;
00127             else if (remotePort!=b.remotePort)
00128                 return remotePort<b.remotePort;
00129             else
00130                 return localPort<b.localPort;
00131         }
00132     };
00133 
00134   protected:
00135     typedef std::map<AppConnKey,TCPConnection*> TcpAppConnMap;
00136     typedef std::map<SockPair,TCPConnection*> TcpConnMap;
00137 
00138     TcpAppConnMap tcpAppConnMap;
00139     TcpConnMap tcpConnMap;
00140 
00141     ushort lastEphemeralPort;
00142     std::multiset<ushort> usedEphemeralPorts;
00143 
00144   protected:
00146     virtual TCPConnection *createConnection(int appGateIndex, int connId);
00147 
00148     // utility methods
00149     virtual TCPConnection *findConnForSegment(TCPSegment *tcpseg, IPvXAddress srcAddr, IPvXAddress destAddr);
00150     virtual TCPConnection *findConnForApp(int appGateIndex, int connId);
00151     virtual void segmentArrivalWhileClosed(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00152     virtual void removeConnection(TCPConnection *conn);
00153     virtual void updateDisplayString();
00154 
00155   public:
00156     static bool testing;    // switches between tcpEV and testingEV
00157     static bool logverbose; // if !testing, turns on more verbose logging
00158 
00159     bool recordStatistics;  // output vectors on/off
00160 
00161   public:
00162     TCP() {}
00163     virtual ~TCP();
00164 
00165   protected:
00166     virtual void initialize();
00167     virtual void handleMessage(cMessage *msg);
00168     virtual void finish();
00169 
00170   public:
00175     virtual void addSockPair(TCPConnection *conn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00176 
00181     virtual void updateSockPair(TCPConnection *conn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00182 
00187     virtual void addForkedConnection(TCPConnection *conn, TCPConnection *newConn, IPvXAddress localAddr, IPvXAddress remoteAddr, int localPort, int remotePort);
00188 
00192     virtual ushort getEphemeralPort();
00193 };
00194 
00195 }
00196 #endif
00197 
00198