![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiFiMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2007 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 16, D-52074 Aachen, Germany 00009 * phone: ++49-241-80-27910, 00010 * fax: ++49-241-80-22242 00011 * email: info@openwns.org 00012 * www: http://www.openwns.org 00013 * _____________________________________________________________________________ 00014 * 00015 * openWNS is free software; you can redistribute it and/or modify it under the 00016 * terms of the GNU Lesser General Public License version 2 as published by the 00017 * Free Software Foundation; 00018 * 00019 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00020 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00021 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00022 * details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00026 * 00027 ******************************************************************************/ 00028 00029 #include <WIFIMAC/lowerMAC/DuplicateFilter.hpp> 00030 00031 #include <WNS/ldk/arq/StopAndWait.hpp> 00032 00033 using namespace wifimac::lowerMAC; 00034 00035 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00036 DuplicateFilter, 00037 wns::ldk::FunctionalUnit, 00038 "wifimac.lowerMAC.DuplicateFilter", 00039 wns::ldk::FUNConfigCreator); 00040 00041 DuplicateFilter::DuplicateFilter(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config): 00042 wns::ldk::fu::Plain<DuplicateFilter, DuplicateFilterCommand>(fun), 00043 00044 logger(config.get("logger")), 00045 nextSN(1), 00046 managerName(config.get<std::string>("managerName")), 00047 arqCommandName(config.get<std::string>("arqCommandName")) 00048 { 00049 00050 } 00051 00052 DuplicateFilter::~DuplicateFilter() 00053 { 00054 00055 } 00056 00057 void DuplicateFilter::onFUNCreated() 00058 { 00059 friends.manager = getFUN()->findFriend<wifimac::lowerMAC::Manager*>(managerName); 00060 assure(friends.manager, "Management entity not found"); 00061 } 00062 00063 void DuplicateFilter::doSendData(const wns::ldk::CompoundPtr& compound) 00064 { 00065 // add duplicate filter command 00066 DuplicateFilterCommand* command = activateCommand(compound->getCommandPool()); 00067 command->peer.sn = nextSN; 00068 ++nextSN; 00069 00070 getConnector()->getAcceptor(compound)->sendData(compound); 00071 } 00072 00073 void DuplicateFilter::doOnData(const wns::ldk::CompoundPtr& compound) 00074 { 00075 // retransmission, check sequence number 00076 DuplicateFilterCommand* command = getCommand(compound); 00077 00078 if(not lastReceivedSN.knows(friends.manager->getTransmitterAddress(compound->getCommandPool()))) 00079 { 00080 // first compound from source 00081 MESSAGE_SINGLE(NORMAL, logger, "Received first frame from " << friends.manager->getTransmitterAddress(compound->getCommandPool()) << " -> deliver"); 00082 lastReceivedSN.insert(friends.manager->getTransmitterAddress(compound->getCommandPool()), command->peer.sn); 00083 getDeliverer()->getAcceptor(compound)->onData(compound); 00084 } 00085 else 00086 { 00087 if(lastReceivedSN.find(friends.manager->getTransmitterAddress(compound->getCommandPool())) != command->peer.sn) 00088 { 00089 // compound has different sn 00090 MESSAGE_SINGLE(NORMAL, logger, "Received frame from " << friends.manager->getTransmitterAddress(compound->getCommandPool()) << " with unknown sn -> deliver"); 00091 getDeliverer()->getAcceptor(compound)->onData(compound); 00092 lastReceivedSN.update(friends.manager->getTransmitterAddress(compound->getCommandPool()), command->peer.sn); 00093 } 00094 else 00095 { 00096 MESSAGE_SINGLE(NORMAL, logger, "Received duplicate frame from " << friends.manager->getTransmitterAddress(compound->getCommandPool()) << " -> drop"); 00097 } 00098 } 00099 } 00100 00101 bool DuplicateFilter::doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00102 { 00103 return getConnector()->hasAcceptor(compound); 00104 } 00105 00106 void DuplicateFilter::doWakeup() 00107 { 00108 // simply forward the wakeup call 00109 getReceptor()->wakeup(); 00110 }
1.5.5