![]() |
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 <GLUE/arqfsm/stopandwait/ReadyForTransmission.hpp> 00014 #include <GLUE/arqfsm/stopandwait/WaitingForACK.hpp> 00015 #include <GLUE/arqfsm/stopandwait/FSMFU.hpp> 00016 00017 #include <WNS/ldk/SuspendSupport.hpp> 00018 00019 using namespace glue::arqfsm::stopandwait; 00020 using namespace wns::ldk; 00021 00022 STATIC_FACTORY_REGISTER_WITH_CREATOR(ReadyForTransmission, 00023 StateInterface, 00024 "glue_arqfsm_stopandwait_ReadyForTransmission", 00025 wns::fsm::FSMConfigCreator); 00026 00027 void 00028 ReadyForTransmission::onInitState() 00029 { 00030 assureType(getFU(), wns::ldk::SuspendSupport*); 00031 dynamic_cast<wns::ldk::SuspendSupport*>(getFU())->trySuspend(); 00032 } // onInitState 00033 00034 00035 StateInterface* 00036 ReadyForTransmission::onSendData(const CompoundPtr& compound) 00037 { 00038 vars().activeCompound = compound; 00039 00040 StopAndWaitCommand* command = dynamic_cast<StopAndWaitCommand*>(getFU()->activateCommand(compound->getCommandPool())); 00041 assure(command, "Command is not a StopAndWaitCommand."); 00042 00043 command->peer.type = StopAndWaitCommand::I; 00044 command->peer.NS = vars().NS; 00045 00046 MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName()); 00047 m << " processOutgoing" 00048 << " NS -> " << command->peer.NS; 00049 MESSAGE_END(); 00050 00051 vars().NS = (vars().NS + 1) % vars().modulo; 00052 00053 if (isAccepting(compound)) 00054 sendSendData(compound->copy()); 00055 else 00056 vars().sendNow = true; 00057 00058 return getFSM()->createState<WaitingForACK>(); 00059 } // onSendData 00060 00061 00062 StateInterface* 00063 ReadyForTransmission::onACK(int sequenceNumber) 00064 { 00065 MESSAGE_BEGIN(NORMAL, vars().logger, m, getFUNName()); 00066 m << " Unexpected RR frame" 00067 << " received " << sequenceNumber; 00068 MESSAGE_END(); 00069 00070 return this; 00071 } // onACK 00072 00073 00074 StateInterface* 00075 ReadyForTransmission::onWakeup() 00076 { 00077 if (vars().ackCompound && isAccepting(vars().ackCompound)) 00078 { 00079 sendSendData(vars().ackCompound); 00080 vars().ackCompound = CompoundPtr(); 00081 } 00082 else 00083 sendWakeup(); 00084 00085 return this; 00086 } // onWakeup 00087 00088 00089 void 00090 ReadyForTransmission::onIsAccepting(bool& accepting) const 00091 { 00092 accepting = true; 00093 } // onIsAccepting 00094 00095 00096 StateInterface* 00097 ReadyForTransmission::onTimeout() 00098 { 00099 assure(false, "Invalid timeout"); 00100 return this; 00101 } // onTimeout 00102 00103
1.5.5