![]() |
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/pathselection/StationForwarding.hpp> 00030 #include <WIFIMAC/Layer2.hpp> 00031 00032 #include <WNS/ldk/CommandPool.hpp> 00033 #include <WNS/Exception.hpp> 00034 #include <WNS/service/dll/StationTypes.hpp> 00035 00036 using namespace wifimac::pathselection; 00037 00038 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00039 wifimac::pathselection::StationForwarding, 00040 wns::ldk::FunctionalUnit, 00041 "wifimac.pathselection.StationForwarding", 00042 wns::ldk::FUNConfigCreator); 00043 00044 StationForwarding::StationForwarding(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config_) : 00045 wns::ldk::fu::Plain<StationForwarding, ForwardingCommand>(fun), 00046 config(config_), 00047 logger(config.get("logger")), 00048 ucName(config.get<std::string>("upperConvergenceName")) 00049 { 00050 MESSAGE_SINGLE(NORMAL, this->logger, "created"); 00051 } 00052 00053 StationForwarding::~StationForwarding() 00054 { 00055 00056 } 00057 00058 void 00059 StationForwarding::onFUNCreated() 00060 { 00061 layer2 = getFUN()->getLayer<wifimac::Layer2*>(); 00062 00063 if(layer2->getStationType() != wns::service::dll::StationTypes::UT()) 00064 { 00065 throw wns::Exception("StationForwarding is only allowed for StationType = UT"); 00066 } 00067 } 00068 00069 bool 00070 StationForwarding::doIsAccepting(const wns::ldk::CompoundPtr& _compound) const 00071 { 00072 00073 if(layer2->getControlService<dll::services::control::Association>("ASSOCIATION")->hasAssociation()) 00074 { 00075 return getConnector()->hasAcceptor(_compound); 00076 } 00077 else 00078 { 00079 // No association, no delivery, no acceptance 00080 return false; 00081 } 00082 } 00083 00084 void 00085 StationForwarding::doWakeup() 00086 { 00087 // simply forward the wakeup call 00088 getReceptor()->wakeup(); 00089 } 00090 00091 void 00092 StationForwarding::doOnData(const wns::ldk::CompoundPtr& _compound) 00093 { 00094 // Received compound from a transceiver 00095 00096 // First: copy the compound 00097 wns::ldk::CompoundPtr compound = _compound->copy(); 00098 00099 ForwardingCommand* fc = getCommand(compound); 00100 dll::UpperCommand* uc = getFUN()->getProxy()->getCommand<dll::UpperCommand>(compound->getCommandPool(), ucName); 00101 00102 ++fc->magic.hopCount; 00103 fc->magic.path.push_back(layer2->getDLLAddress()); 00104 00105 00106 MESSAGE_BEGIN(NORMAL, this->logger, m, "doOnData with fromDS " << fc->peer.fromDS << " toDS " << fc->peer.toDS); 00107 if(fc->peer.fromDS == true) 00108 { 00109 m << " " << fc->peer.originalSource << " ->"; 00110 } 00111 if(fc->peer.addressExtension == true) 00112 { 00113 m << " " << fc->peer.meshSource << " ->"; 00114 } 00115 m << " " << uc->peer.sourceMACAddress << " -> " << uc->peer.targetMACAddress << " -> "; 00116 if(fc->peer.addressExtension == true) 00117 { 00118 m << " " << fc->peer.meshDestination << " ->"; 00119 } 00120 if(fc->peer.toDS == true) 00121 { 00122 m << fc->peer.finalDestination; 00123 } 00124 m << " hc: " << fc->magic.hopCount; 00125 MESSAGE_END(); 00126 00127 // fromDS, the first source is saved in the fc 00128 assure(fc->peer.fromDS, "received frame NOT from DS"); 00129 uc->peer.sourceMACAddress = fc->peer.originalSource; 00130 00131 getDeliverer()->getAcceptor(compound)->onData(compound); 00132 00133 } 00134 00135 void 00136 StationForwarding::doSendData(const wns::ldk::CompoundPtr& _compound) 00137 { 00138 // First: copy the compound 00139 wns::ldk::CompoundPtr compound = _compound->copy(); 00140 00141 // Received fresh packet from upper layer -> activate command 00142 ForwardingCommand* fc = activateCommand(compound->getCommandPool()); 00143 // Get the upperCommand, which contains the final source and destination 00144 dll::UpperCommand* uc = getFUN()->getProxy()->getCommand<dll::UpperCommand>(compound->getCommandPool(), ucName); 00145 00146 fc->magic.isUplink = true; 00147 fc->peer.toDS = true; 00148 fc->peer.fromDS = false; 00149 fc->peer.finalDestination = uc->peer.targetMACAddress; 00150 uc->peer.sourceMACAddress = layer2->getDLLAddress(); 00151 uc->peer.targetMACAddress = layer2->getControlService<dll::services::control::Association>("ASSOCIATION")->getAssociation(); 00152 00153 fc->magic.path.push_back(layer2->getDLLAddress()); 00154 00155 getConnector()->getAcceptor(compound)->sendData(compound); 00156 }
1.5.5