flavours/DumbTCP.cc

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 #include "DumbTCP.h"
00019 #include "TCP.h"
00020 
00021 Register_Class(DumbTCP);
00022 
00023 
00024 // just a dummy value
00025 #define REXMIT_TIMEOUT 2
00026 
00027 
00028 DumbTCP::DumbTCP() : TCPAlgorithm(),
00029   state((DumbTCPStateVariables *&)TCPAlgorithm::state)
00030 {
00031     rexmitTimer = NULL;
00032 }
00033 
00034 DumbTCP::~DumbTCP()
00035 {
00036     // cancel and delete timers
00037     if (rexmitTimer)
00038         delete conn->getTcpMain()->cancelEvent(rexmitTimer);
00039 }
00040 
00041 void DumbTCP::initialize()
00042 {
00043     TCPAlgorithm::initialize();
00044 
00045     rexmitTimer = new cMessage("REXMIT");
00046     rexmitTimer->setContextPointer(conn);
00047 }
00048 
00049 void DumbTCP::established(bool active)
00050 {
00051     if (active)
00052     {
00053         // finish connection setup with ACK (possibly piggybacked on data)
00054         tcpEV << "Completing connection setup by sending ACK (possibly piggybacked on data)\n";
00055         if (!conn->sendData(false,65535))
00056             conn->sendAck();
00057     }
00058 }
00059 
00060 void DumbTCP::connectionClosed()
00061 {
00062     conn->getTcpMain()->cancelEvent(rexmitTimer);
00063 }
00064 
00065 void DumbTCP::processTimer(cMessage *timer, TCPEventCode& event)
00066 {
00067     if (timer!=rexmitTimer)
00068         throw cRuntimeError(timer, "unrecognized timer");
00069 
00070     conn->retransmitData();
00071     conn->scheduleTimeout(rexmitTimer, REXMIT_TIMEOUT);
00072 }
00073 
00074 void DumbTCP::sendCommandInvoked()
00075 {
00076     // start sending
00077     conn->sendData(false,65535);
00078 }
00079 
00080 void DumbTCP::receivedOutOfOrderSegment()
00081 {
00082     tcpEV << "Out-of-order segment, sending immediate ACK\n";
00083     conn->sendAck();
00084 }
00085 
00086 void DumbTCP::receiveSeqChanged()
00087 {
00088     // new data received, ACK immediately (more sophisticated algs should
00089     // wait a little to see if piggybacking is possible)
00090     tcpEV << "rcv_nxt changed to " << state->rcv_nxt << ", sending immediate ACK\n";
00091     conn->sendAck();
00092 }
00093 
00094 void DumbTCP::receivedDataAck(uint32)
00095 {
00096     // ack may have freed up some room in the window, try sending.
00097     // small segments also OK (Nagle off)
00098     conn->sendData(false,65535);
00099 }
00100 
00101 void DumbTCP::receivedDuplicateAck()
00102 {
00103     tcpEV << "Duplicate ACK #" << state->dupacks << "\n";
00104 }
00105 
00106 void DumbTCP::receivedAckForDataNotYetSent(uint32 seq)
00107 {
00108     tcpEV << "ACK acks something not yet sent, sending immediate ACK\n";
00109     conn->sendAck();
00110 }
00111 
00112 void DumbTCP::ackSent()
00113 {
00114 }
00115 
00116 void DumbTCP::dataSent(uint32 fromseq)
00117 {
00118     if (rexmitTimer->isScheduled())
00119         conn->getTcpMain()->cancelEvent(rexmitTimer);
00120     conn->scheduleTimeout(rexmitTimer, REXMIT_TIMEOUT);
00121 }
00122 
00123 void DumbTCP::restartRexmitTimer()
00124 {
00125 }
00126 
00127 void DumbTCP::rttMeasurementCompleteUsingTS(uint32 echoedTS)
00128 {
00129 }