![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WNS (Wireless Network Simulator) * 00003 * __________________________________________________________________________ * 00004 * * 00005 * Copyright (C) 2004-2006 * 00006 * Chair of Communication Networks (ComNets) * 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany * 00008 * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242 * 00009 * email: wns@comnets.rwth-aachen.de * 00010 * www: http://wns.comnets.rwth-aachen.de * 00011 ******************************************************************************/ 00012 00013 #include "ReadyForTransmissionBufferPartlyFilled.hpp" 00014 #include "ReadyForTransmissionBufferEmpty.hpp" 00015 #include "WaitingForACKsBufferFull.hpp" 00016 00017 #include <WNS/Assure.hpp> 00018 #include <WNS/Exception.hpp> 00019 00020 #include <iostream> 00021 00022 using namespace glue::arqfsm::selectiverepeat; 00023 using namespace wns::ldk; 00024 00025 STATIC_FACTORY_REGISTER_WITH_CREATOR(ReadyForTransmissionBufferPartlyFilled, 00026 StateInterface, 00027 "glue_arqfsm_selectiverepeat_ReadyForTransmissionBufferPartlyFilled", 00028 wns::fsm::FSMConfigCreator); 00029 00030 StateInterface* 00031 ReadyForTransmissionBufferPartlyFilled::onSendData(const CompoundPtr& compound) 00032 { 00033 SelectiveRepeatCommand* command = dynamic_cast<SelectiveRepeatCommand*>(getFU()->activateCommand(compound->getCommandPool())); 00034 assure(command, "Command is not a SelectiveRepeatCommand."); 00035 00036 command->peer.type = SelectiveRepeatCommand::I; 00037 command->peer.NS = vars().NS; 00038 00039 MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName()); 00040 m << " processOutgoing" 00041 << " NS -> " << command->peer.NS; 00042 MESSAGE_END(); 00043 00044 vars().sentCompounds[vars().NS] = compound; 00045 00046 vars().NS = (vars().NS + 1) % vars().sequenceNumberSize; 00047 ++vars().levelSendBuffer; 00048 00049 vars().pendingCompoundsQueue.push_back(compound); 00050 00051 tryToSendIs(); 00052 00053 if (vars().levelSendBuffer == vars().windowSize) 00054 return getFSM()->createState<WaitingForACKsBufferFull>(); 00055 00056 return this; 00057 } // onSendData 00058 00059 00060 StateInterface* 00061 ReadyForTransmissionBufferPartlyFilled::onACK(int sequenceNumber) 00062 { 00063 MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName()); 00064 m << " Received ACK frame " 00065 << sequenceNumber; 00066 MESSAGE_END(); 00067 00068 if (sequenceNumber < 0 || sequenceNumber >= vars().sequenceNumberSize) 00069 throw wns::Exception("Sequence number out of bounds"); 00070 00071 CompoundPtr compound = vars().sentCompounds[sequenceNumber]; 00072 00073 if (compound) 00074 { 00075 FSMFU* fsmfu = dynamic_cast<FSMFU*>(getFU()); 00076 if (fsmfu->hasTimeoutSet(compound)) 00077 fsmfu->cancelTimeout(compound); 00078 00079 vars().pendingCompoundsQueue.remove(compound); 00080 00081 vars().sentCompounds[sequenceNumber] = CompoundPtr(); 00082 } 00083 00084 while (!vars().sentCompounds[vars().lowerBoundNS]) 00085 { 00086 vars().lowerBoundNS = (vars().lowerBoundNS + 1) % vars().sequenceNumberSize; 00087 00088 --vars().levelSendBuffer; 00089 00090 if (vars().levelSendBuffer == 0) 00091 return getFSM()->createState<ReadyForTransmissionBufferEmpty>(); 00092 } 00093 00094 return this; 00095 } // onACK 00096 00097 00098 StateInterface* 00099 ReadyForTransmissionBufferPartlyFilled::onWakeup() 00100 { 00101 tryToSendACKs(); 00102 tryToSendIs(); 00103 sendWakeup(); 00104 return this; 00105 } // onWakeup 00106 00107 00108 void 00109 ReadyForTransmissionBufferPartlyFilled::onIsAccepting(bool& accepting) const 00110 { 00111 accepting = true; 00112 } // onIsAccepting 00113 00114 00115 StateInterface* 00116 ReadyForTransmissionBufferPartlyFilled::onTimeout(const CompoundPtr& compound) 00117 { 00118 if (std::find(vars().pendingCompoundsQueue.begin(), 00119 vars().pendingCompoundsQueue.end(), 00120 compound) 00121 == vars().pendingCompoundsQueue.end()) 00122 { 00123 vars().pendingCompoundsQueue.push_back(compound); 00124 } 00125 00126 tryToSendIs(); 00127 return this; 00128 } // onTimeout 00129 00130
1.5.5