SCTP.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2008 Irene Ruengeler
00003 // Copyright (C) 2009 Thomas Dreibholz
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #ifndef __SCTP_H
00020 #define __SCTP_H
00021 
00022 #ifdef _MSC_VER
00023 #pragma warning(disable : 4786)
00024 #endif
00025 
00026 #include <omnetpp.h>
00027 #include <map>
00028 #include "IPvXAddress.h"
00029 #include "UDPSocket.h"
00030 
00031 
00032 class SCTPAssociation;
00033 class SCTPMessage;
00034 
00035 
00036 #define sctpEV3 (!SCTP::testing==true)?std::cerr:std::cerr
00037 
00038 
00039 
00084 class INET_API SCTP : public cSimpleModule
00085 {
00086     public:
00087         struct AppConnKey
00088         {
00089             int32 appGateIndex;
00090             int32 assocId;
00091 
00092             inline bool operator<(const AppConnKey& b) const
00093             {
00094                 if (appGateIndex!=b.appGateIndex)
00095                     return appGateIndex<b.appGateIndex;
00096                 else
00097                     return assocId<b.assocId;
00098             }
00099 
00100         };
00101         struct SockPair
00102         {
00103             IPvXAddress localAddr;
00104             IPvXAddress remoteAddr;
00105             uint16 localPort;
00106             uint16 remotePort;
00107 
00108             inline bool operator<(const SockPair& b) const
00109             {
00110                 if (remoteAddr!=b.remoteAddr)
00111                     return remoteAddr<b.remoteAddr;
00112                 else if (localAddr!=b.localAddr)
00113                     return localAddr<b.localAddr;
00114                 else if (remotePort!=b.remotePort)
00115                     return remotePort<b.remotePort;
00116                 else
00117                     return localPort<b.localPort;
00118             }
00119         };
00120         struct VTagPair
00121         {
00122             uint32 peerVTag;
00123             uint32 localVTag;
00124             uint16 localPort;
00125             uint16 remotePort;
00126 
00127             /*inline bool operator<(const VTagPair& b) const
00128             {
00129                 if (peerVTag!=b.peerVTag)
00130                     return peerVTag<b.peerVTag;
00131                 else if (remotePort!=b.remotePort)
00132                     return remotePort<b.remotePort;
00133                 else
00134                     return localPort<b.localPort;
00135             }*/
00136         };
00137         typedef struct
00138         {
00139             int32 assocId;
00140             simtime_t start;
00141             simtime_t stop;
00142             uint64 rcvdBytes;
00143             uint64 sentBytes;
00144             uint64 transmittedBytes;
00145             uint64 ackedBytes;
00146             uint32 numFastRtx;
00147             uint32 numDups;
00148             uint32 numT3Rtx;
00149             uint32 numPathFailures;
00150             uint32 numForwardTsn;
00151             double throughput;
00152             simtime_t lifeTime;
00153         }AssocStat;
00154 
00155         typedef std::map<int32,AssocStat> AssocStatMap;
00156         AssocStatMap assocStatMap;
00157         typedef std::map<int32, VTagPair> SctpVTagMap;
00158         SctpVTagMap sctpVTagMap;
00159 
00160 
00161         typedef std::map<AppConnKey,SCTPAssociation*> SctpAppConnMap;
00162         typedef std::map<SockPair,SCTPAssociation*> SctpConnMap;
00163 
00164 
00165         SctpAppConnMap sctpAppConnMap;
00166         SctpConnMap sctpConnMap;
00167         std::list<SCTPAssociation*>assocList;
00168     protected:
00169         int32 sizeConnMap;
00170         static int32 nextConnId;
00171 
00172         uint16 nextEphemeralPort;
00173 
00174         SCTPAssociation *findAssocForMessage(IPvXAddress srcAddr, IPvXAddress destAddr, uint32 srcPort, uint32 destPort, bool findListen);
00175         SCTPAssociation *findAssocForApp(int32 appGateIndex, int32 assocId);
00176         void sendAbortFromMain(SCTPMessage* sctpmsg, IPvXAddress srcAddr, IPvXAddress destAddr);
00177         void sendShutdownCompleteFromMain(SCTPMessage* sctpmsg, IPvXAddress srcAddr, IPvXAddress destAddr);
00178         void updateDisplayString();
00179 
00180     public:
00181         static bool testing;         // switches between sctpEV and testingEV
00182         static bool logverbose;  // if !testing, turns on more verbose logging
00183         void printInfoConnMap();
00184         void printVTagMap();
00185 
00186         void removeAssociation(SCTPAssociation *assoc);
00187         simtime_t testTimeout;
00188         uint32 numGapReports;
00189         uint32 numPacketsReceived;
00190         uint32 numPacketsDropped;
00191         //double failover();
00192     public:
00193         //Module_Class_Members(SCTP, cSimpleModule, 0);
00194         virtual ~SCTP();
00195         virtual void initialize();
00196         virtual void handleMessage(cMessage *msg);
00197         virtual void finish();
00198 
00199         inline AssocStat* getAssocStat(uint32 assocId) {
00200             SCTP::AssocStatMap::iterator found = assocStatMap.find(assocId);
00201             if(found != assocStatMap.end()) {
00202               return(&found->second);
00203             }
00204             return(NULL);
00205         }
00206 
00210         void updateSockPair(SCTPAssociation *assoc, IPvXAddress localAddr, IPvXAddress remoteAddr, int32 localPort, int32 remotePort);
00211         void addLocalAddress(SCTPAssociation *conn, IPvXAddress address);
00212         void addLocalAddressToAllRemoteAddresses(SCTPAssociation *conn, IPvXAddress address, std::vector<IPvXAddress> remAddresses);
00213         void addRemoteAddress(SCTPAssociation *conn, IPvXAddress localAddress, IPvXAddress remoteAddress);
00214         void removeLocalAddressFromAllRemoteAddresses(SCTPAssociation *conn, IPvXAddress address, std::vector<IPvXAddress> remAddresses);
00215         void removeRemoteAddressFromAllConnections(SCTPAssociation *conn, IPvXAddress address, std::vector<IPvXAddress> locAddresses);
00220         void addForkedAssociation(SCTPAssociation *assoc, SCTPAssociation *newAssoc, IPvXAddress localAddr, IPvXAddress remoteAddr, int32 localPort, int32 remotePort);
00221 
00225         uint16 getEphemeralPort();
00226 
00231         static int32 getNewConnId() {return ++nextConnId;}
00232 
00233         SCTPAssociation* getAssoc(int32 assocId);
00234         SCTPAssociation *findAssocWithVTag(uint32 peerVTag, uint32 remotePort, uint32 localPort);
00235         SctpVTagMap getVTagMap() {return sctpVTagMap;};
00236 
00237         void bindPortForUDP();
00238 };
00239 
00240 #endif
00241 
00242 
00243