![]() |
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. 5, 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 <GLUE/convergence/Lower2OFDMAPhy.hpp> 00029 #include <GLUE/convergence/Upper.hpp> 00030 00031 #include <WNS/pyconfig/View.hpp> 00032 #include <boost/bind.hpp> 00033 00034 using namespace glue::convergence; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00037 Lower2OFDMAPhy, 00038 wns::ldk::FunctionalUnit, 00039 "glue.convergence.Lower2OFDMAPhy", 00040 wns::ldk::FUNConfigCreator); 00041 00042 Lower2OFDMAPhy::Lower2OFDMAPhy(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00043 wns::ldk::CommandTypeSpecifier<LowerCommand>(fun), 00044 wns::ldk::HasReceptor<>(), 00045 wns::ldk::HasConnector<>(), 00046 wns::ldk::HasDeliverer<>(), 00047 wns::Cloneable<Lower2OFDMAPhy>(), 00048 00049 logger_(config.get<wns::pyconfig::View>("logger")), 00050 transmitting_(false), 00051 upperUnicastName_(config.get<std::string>("unicastRouting")), 00052 upperBroadcastName_(config.get<std::string>("broadcastRouting")), 00053 phyModeMapper_(wns::service::phy::phymode::PhyModeMapperInterface::getPhyModeMapper( 00054 config.getView("phyModeMapper"))), 00055 dataTransmission_(NULL), 00056 notificationService_(NULL) 00057 { 00058 } // Lower2OFDMAPhy 00059 00060 Lower2OFDMAPhy::~Lower2OFDMAPhy() 00061 { 00062 } // ~Lower2OFDMAPhy 00063 00064 void Lower2OFDMAPhy::onFUNCreated() 00065 { 00066 friends_.unicastRouting = 00067 getFUN()->findFriend<glue::convergence::UnicastUpper*>( 00068 upperUnicastName_); 00069 00070 friends_.broadcastRouting = 00071 getFUN()->findFriend<glue::convergence::BroadcastUpper*>( 00072 upperBroadcastName_); 00073 } // onFUNCreated 00074 00075 bool Lower2OFDMAPhy::doIsAccepting(const wns::ldk::CompoundPtr& /* compound */) const 00076 { 00077 return !transmitting_; 00078 } // isAccepting 00079 00080 00081 00082 void 00083 Lower2OFDMAPhy::doSendData(const wns::ldk::CompoundPtr& compound) 00084 { 00085 assure(compound, "sendData called with an invalid compound."); 00086 assure(!transmitting_, "Tried to tranmit while already sending"); 00087 00088 transmitting_ = true; 00089 00090 wns::simulator::Time now = wns::simulator::getEventScheduler()->getTime(); 00091 LowerCommand* lc = activateCommand(compound->getCommandPool()); 00092 lc->magic.txStartTime = now; 00093 00094 assure(phyModeMapper_->getPhyModeCount() == 1, "There should be only one PhyMode"); 00095 wns::service::phy::phymode::PhyModeInterfacePtr phyMode; 00096 phyMode = phyModeMapper_->getPhyModeForIndex(0); 00097 00098 wns::simulator::Time txTime = double(compound->getLengthInBits()) / phyMode->getDataRate(); 00099 assure(txTime > 0, "Transmission time cannot be zero."); 00100 00101 wns::simulator::getEventScheduler()->scheduleDelay( 00102 boost::bind(&Lower2OFDMAPhy::stopTransmitting, this, compound), txTime); 00103 00104 dataTransmission_->startBroadcast(compound, 0, wns::Power::from_dBm(10), phyMode); 00105 } // doSendData 00106 00107 void 00108 Lower2OFDMAPhy::stopTransmitting(const wns::ldk::CompoundPtr& compound) 00109 { 00110 assure(transmitting_, "Called stopTransmitting while still transmitting"); 00111 00112 transmitting_ = false; 00113 dataTransmission_->stopTransmission(compound, 0); 00114 00115 getReceptor()->wakeup(); 00116 } 00117 00118 void Lower2OFDMAPhy::doOnData(const wns::ldk::CompoundPtr& compound) 00119 { 00120 assure(compound, "onData called with an invalid compound."); 00121 00122 MESSAGE_BEGIN(NORMAL, logger_, m, getFUN()->getName()); 00123 m << ": doOnData(), forwading to higher FU"; 00124 MESSAGE_END(); 00125 00126 getDeliverer()->getAcceptor(compound)->onData(compound); 00127 } // doOnData 00128 00129 void 00130 Lower2OFDMAPhy::doWakeup() 00131 { 00132 // This will never be called ... 00133 } // doWakeup 00134 00135 void 00136 Lower2OFDMAPhy::onData(wns::osi::PDUPtr pdu, wns::service::phy::power::PowerMeasurementPtr rx) 00137 { 00138 assure(wns::dynamicCast<wns::ldk::Compound>(pdu), "not a CompoundPtr"); 00139 00140 // FIRST: create a copy instead of working on the real compound 00141 wns::ldk::CompoundPtr compound = wns::staticCast<wns::ldk::Compound>(pdu)->copy(); 00142 00143 double ber = 0.0; 00144 00145 if (hasCommandOf(friends_.unicastRouting, compound)) 00146 { 00147 UnicastUpperCommand* uc = 00148 friends_.unicastRouting->getCommand(compound->getCommandPool()); 00149 if (uc->peer.targetMACAddress == address_) 00150 { 00151 MESSAGE_BEGIN(NORMAL, logger_, m, getFUN()->getName()); 00152 m << ": onData(), got Unicast PDU. SINR is "; 00153 m << rx->getSINR(); 00154 MESSAGE_END(); 00155 00156 LowerCommand* lc = getCommand(compound->getCommandPool()); 00157 lc->local.per = 1.0 - pow(1.0 - ber, pdu->getLengthInBits()); 00158 this->wns::ldk::FunctionalUnit::onData(compound); 00159 } 00160 } 00161 else if (hasCommandOf(friends_.broadcastRouting, compound)) 00162 { 00163 MESSAGE_BEGIN(NORMAL, logger_, m, getFUN()->getName()); 00164 m << ": onData(), got Broadcast PDU. SINR is "; 00165 m << rx->getSINR(); 00166 MESSAGE_END(); 00167 00168 LowerCommand* lc = getCommand(compound->getCommandPool()); 00169 lc->local.per = 1.0 - pow(1.0 - ber, pdu->getLengthInBits()); 00170 this->wns::ldk::FunctionalUnit::onData(compound); 00171 } 00172 } // onData 00173 00174 void 00175 Lower2OFDMAPhy::setDataTransmissionService(wns::service::Service* phy) 00176 { 00177 assure(phy, "must be non-NULL"); 00178 assureType(phy, wns::service::phy::ofdma::DataTransmission*); 00179 dataTransmission_ = dynamic_cast<wns::service::phy::ofdma::DataTransmission*>(phy); 00180 } // setDataTransmissionService 00181 00182 wns::service::phy::ofdma::DataTransmission* 00183 Lower2OFDMAPhy::getDataTransmissionService() const 00184 { 00185 assure(dataTransmission_, "no copper::DataTransmission set. Did you call setDataTransmission()?"); 00186 return dataTransmission_; 00187 } // getDataTransmissionService 00188 00189 void 00190 Lower2OFDMAPhy::setNotificationService(wns::service::Service* phy) 00191 { 00192 assure(phy, "must be non-NULL"); 00193 assureType(phy, wns::service::phy::ofdma::Notification*); 00194 00195 notificationService_ = dynamic_cast<wns::service::phy::ofdma::Notification*>(phy); 00196 notificationService_->registerHandler(this); 00197 } // setNotificationService 00198 00199 wns::service::phy::ofdma::Notification* 00200 Lower2OFDMAPhy::getNotificationService() const 00201 { 00202 assure(notificationService_, "no copper::Notification set. Did you call setNotificationService()?"); 00203 return notificationService_; 00204 } // getNotificationService 00205 00206 void 00207 Lower2OFDMAPhy::setMACAddress(const wns::service::dll::UnicastAddress& address) 00208 { 00209 address_ = address; 00210 MESSAGE_SINGLE(NORMAL, logger_, "setting MAC address of lowerConvergence to: " << address_); 00211 } // setMACAddress
1.5.5