![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <TCP/Service.hpp> 00029 #include <TCP/LowerConvergence.hpp> 00030 #include <TCP/UpperConvergence.hpp> 00031 00032 using namespace tcp; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 LowerConvergence, 00036 wns::ldk::FunctionalUnit, 00037 "tcp.lowerConvergence", 00038 wns::ldk::FUNConfigCreator 00039 ); 00040 00041 LowerConvergence::LowerConvergence(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& _config) : 00042 wns::ldk::CommandTypeSpecifier<>(fun), 00043 dataTransmissionService(NULL), 00044 config(_config), 00045 logger(config.get("logger")), 00046 tcpHeaderReader(NULL) 00047 { 00048 } 00049 00050 LowerConvergence::~LowerConvergence() 00051 { 00052 } 00053 00054 void 00055 LowerConvergence::doSendData(const wns::ldk::CompoundPtr& compound) 00056 { 00057 assure(compound, "doSendData called with an invalid compound."); 00058 00059 MESSAGE_BEGIN(VERBOSE, logger, m, getFUN()->getName()); 00060 m << ": TCP::LowerConvergence sendData: Compound backtrace" 00061 << compound->dumpJourney(); // JOURNEY 00062 MESSAGE_END(); 00063 00064 assure(tcpHeaderReader, "No reader for the TCP Header available!"); 00065 TCPCommand* tcpHeader = tcpHeaderReader->readCommand<TCPCommand>(compound->getCommandPool()); 00066 00067 assure(flowIDMapper.knows(tcpHeader->peer.flowID), "You must first establish a flow for :"<<tcpHeader->peer.flowID); 00068 00069 wns::service::dll::FlowID dllFlowID = flowIDMapper.find(tcpHeader->peer.flowID); 00070 00071 MESSAGE_SINGLE(NORMAL, logger, "Sending Data (DLL-FlowID="<<dllFlowID<<") TL-FlowID: " << tcpHeader->peer.flowID); 00072 00073 getDataTransmissionService()->sendData(tcpHeader->peer.flowID.srcAddress, 00074 tcpHeader->peer.flowID.dstAddress, 00075 compound, this->protocolNumber, 00076 dllFlowID); 00077 } 00078 00079 void 00080 LowerConvergence::doOnData(const wns::ldk::CompoundPtr& compound) 00081 { 00082 assure(compound, "doOnData called with an invalid compound."); 00083 00084 assure(tcpHeaderReader, "No reader for the TCP Header available!"); 00085 TCPCommand* tcpHeader = tcpHeaderReader->readCommand<TCPCommand>(compound->getCommandPool()); 00086 00087 // swap the src/dst information of the flow ID 00088 wns::service::tl::FlowID tmpFlowID(tcpHeader->peer.flowID.dstAddress, 00089 tcpHeader->peer.flowID.dstPort, 00090 tcpHeader->peer.flowID.srcAddress, 00091 tcpHeader->peer.flowID.srcPort); 00092 tcpHeader->peer.flowID = tmpFlowID; 00093 00094 // save the incoming DLL-FlowID, in case of an incoming SYN there is not yet a DLL FlowID existent 00095 if(!flowIDMapper.knows(tcpHeader->peer.flowID)) 00096 mapFlowID(tcpHeader->peer.flowID, wns::service::dll::NoFlowID); 00097 00098 MESSAGE_SINGLE(NORMAL, logger, "Incoming data for flow id: " << tcpHeader->peer.flowID); 00099 00100 if (isAccepting(compound)) 00101 getDeliverer()->getAcceptor(compound)->onData(compound); 00102 } 00103 00104 void 00105 LowerConvergence::onFUNCreated() 00106 { 00107 tcpHeaderReader = getFUN()->getCommandReader("tcp.tcpHeader"); 00108 assure(tcpHeaderReader, "No reader for the TCP Header available!"); 00109 } 00110 00111 void 00112 LowerConvergence::setDataTransmissionService(wns::service::nl::Service* service) 00113 { 00114 assure(!dataTransmissionService, "dataTransmissionService already set"); 00115 dataTransmissionService = service; 00116 } 00117 00118 wns::service::nl::Service* 00119 LowerConvergence::getDataTransmissionService() const 00120 { 00121 assure(dataTransmissionService, "dataTransmissionService not set"); 00122 return dataTransmissionService; 00123 } 00124 00125 bool 00126 LowerConvergence::doIsAccepting(const wns::ldk::CompoundPtr& /*compound*/) const 00127 { 00128 // always accepting since IP will not block 00129 return true; 00130 } 00131 00132 void 00133 LowerConvergence::doWakeup() 00134 { 00135 getReceptor()->wakeup(); 00136 } 00137 00138 void 00139 LowerConvergence::setProtocolNumber(wns::service::nl::protocolNumber _protocolNumber) 00140 { 00141 this->protocolNumber = _protocolNumber; 00142 } 00143 00144 void 00145 LowerConvergence::setTLService(Service* _tlService) 00146 { 00147 this->tlService = _tlService; 00148 } 00149 00150 void 00151 LowerConvergence::mapFlowID(wns::service::tl::FlowID flowID, wns::service::dll::FlowID dllFlowID) 00152 { 00153 flowIDMapper.insert(flowID, dllFlowID); 00154 MESSAGE_SINGLE(NORMAL, logger, "DLLFlowID "<< dllFlowID <<" added for TLFlowID " << flowID); 00155 } 00156 00157 void 00158 LowerConvergence::unmapFlowID(wns::service::tl::FlowID flowID) 00159 { 00160 flowIDMapper.erase(flowID); 00161 MESSAGE_SINGLE(NORMAL, logger, "DLLFlowID deleted for TLFlowID " << flowID); 00162 }
1.5.5