SimpleTCP.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2010 Institut fuer Telematik, Karlsruher Institut fuer Technologie (KIT)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU 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 General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00030 #ifndef __SIMPLETCP_H
00031 #define __SIMPLETCP_H
00032 
00033 //#include <map>
00034 //#include <set>
00035 #include <omnetpp.h>
00036 #include "IPvXAddress.h"
00037 #include <TCPConnection.h>
00038 #include <InitStages.h>
00039 
00040 class SimpleNodeEntry;
00041 
00042 
00043 struct StatisticsAndDelay {
00044 
00045 public:
00046 
00047     // delay fault type string and corresponding map for switch..case
00048     std::string delayFaultTypeString;
00049     enum delayFaultTypeNum {
00050         delayFaultUndefined,
00051         delayFaultLiveAll,
00052         delayFaultLivePlanetlab,
00053         delayFaultSimulation
00054     };
00055     std::map<std::string, delayFaultTypeNum> delayFaultTypeMap;
00056 
00057     // statistics
00058     int numSent; 
00059     int numQueueLost; 
00060     int numPartitionLost; 
00061     int numDestUnavailableLost; 
00062     simtime_t delay; 
00064     simtime_t constantDelay; 
00065     bool useCoordinateBasedDelay; 
00066     double jitter; 
00067     bool faultyDelay; 
00068     GlobalNodeList* globalNodeList; 
00069     GlobalStatistics* globalStatistics; 
00070     SimpleNodeEntry* nodeEntry; 
00071 };
00072 
00073 class SimpleTCPConnection : public TCPConnection {
00074 
00075 public:
00076     SimpleTCPConnection():TCPConnection(){};
00077     SimpleTCPConnection(TCP* mod, int appGateIndex, int connId):TCPConnection(mod, appGateIndex, connId){};
00078 
00080     virtual void sendToIP(TCPSegment *tcpseg);
00081 
00082     static StatisticsAndDelay sad;
00083 
00085     void sendRst(uint32 seq, IPvXAddress src, IPvXAddress dest, int srcPort, int destPort);
00087     void sendRstAck(uint32 seq, uint32 ack, IPvXAddress src, IPvXAddress dest, int srcPort, int destPort);
00088 
00089 protected:
00091     virtual void sendToIP(TCPSegment *tcpseg, IPvXAddress src, IPvXAddress dest);
00092 
00094     SimpleTCPConnection *cloneListeningConnection();
00095 
00096 };
00097 
00098 class SimpleTCP : public TCP {
00099 
00100 public:
00101   SimpleTCP() { sad.globalStatistics = NULL; };
00102   virtual ~SimpleTCP() {};
00103 
00104   void setNodeEntry (SimpleNodeEntry* entry);
00105 
00106   StatisticsAndDelay sad;
00107 
00108 protected:
00109   // utility methods
00110   void segmentArrivalWhileClosed(TCPSegment *tcpseg, IPvXAddress srcAddr, IPvXAddress destAddr);
00111   SimpleTCPConnection *createConnection(int appGateIndex, int connId);
00112   virtual void initialize(int stage);
00113   virtual void handleMessage(cMessage *msg);
00114 
00115   virtual int numInitStages() const
00116   {
00117       return MAX_STAGE_UNDERLAY + 1;
00118   }
00119 
00120   void finish();
00121 };
00122 
00123 #endif