![]() |
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-2009 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * email: info@openwns.org 00009 * www: http://www.openwns.org 00010 * _____________________________________________________________________________ 00011 * 00012 * openWNS is free software; you can redistribute it and/or modify it under the 00013 * terms of the GNU Lesser General Public License version 2 as published by the 00014 * Free Software Foundation; 00015 * 00016 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00017 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00018 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 * details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 ******************************************************************************/ 00025 00026 00027 #include <WIMAC/Logger.hpp> 00028 #include <WIMAC/Component.hpp> 00029 00030 #include <WIMAC/scheduler/PseudoBWRequestGenerator.hpp> 00031 #include <WIMAC/services/ConnectionManager.hpp> 00032 #include <WIMAC/ConnectionIdentifier.hpp> 00033 #include <WIMAC/Classifier.hpp> 00034 #include <WIMAC/scheduler/Scheduler.hpp> 00035 #include <WIMAC/StationManager.hpp> 00036 00037 #include <WNS/StaticFactory.hpp> 00038 00039 #include <WNS/scheduler/SchedulerTypes.hpp> 00040 #include <WNS/ldk/helper/FakePDU.hpp> 00041 #include <WNS/scheduler/queue/QueueInterface.hpp> 00042 00043 #include <map> 00044 00045 using namespace wns; 00046 using namespace wns::ldk; 00047 using namespace wimac; 00048 using namespace wimac::scheduler; 00049 00050 PseudoBWRequestGenerator::PseudoBWRequestGenerator( const wns::pyconfig::View& config ) : 00051 Cloneable<PseudoBWRequestGenerator>(), 00052 component_(0), 00053 friends_(), 00054 packetSize(config.get<int>("packetSize")) 00055 { 00056 //ip overhead of 20 byte 00057 packetSize += 8 * 20; 00058 //overhead due to MAC header (48 bits without CRC) 00059 packetSize += config.get<int>("pduOverhead"); 00060 00061 friends_.connectionManagerName = config.get<std::string>("connectionManager"); 00062 friends_.classifierName = config.get<std::string>("classifier"); 00063 00064 friends_.connectionManager = NULL; 00065 friends_.ulScheduler = NULL; 00066 friends_.classifier = NULL; 00067 } 00068 00069 void PseudoBWRequestGenerator::setFUN(wns::ldk::fun::FUN* fun) 00070 { 00071 component_ = dynamic_cast<wimac::Component*>(fun->getLayer()); 00072 assure(component_, "Could not get Layer2 from FUN"); 00073 } 00074 00075 void 00076 PseudoBWRequestGenerator::setScheduler(wimac::scheduler::Interface* scheduler) 00077 { 00078 friends_.connectionManager = component_ 00079 ->getManagementService<service::ConnectionManager> 00080 (friends_.connectionManagerName); 00081 00082 friends_.ulScheduler = dynamic_cast<Scheduler*>(scheduler); 00083 assureNotNull(friends_.ulScheduler); 00084 00085 friends_.classifier = component_->getFUN()->findFriend<wimac::ConnectionClassifier*> 00086 (friends_.classifierName); 00087 } 00088 00094 struct UpgoingConnection 00095 : public std::unary_function< wimac::ConnectionIdentifierPtr, bool> 00096 { 00097 explicit UpgoingConnection(int myID): myID_( myID) {} 00098 bool operator()(const wimac::ConnectionIdentifierPtr& ptr) 00099 { 00100 return ptr->subscriberStation_ == myID_; 00101 } 00102 private: 00103 int myID_; 00104 }; 00105 00112 void 00113 PseudoBWRequestGenerator::wakeup() { 00114 // Delete all old fake packets from last generation, because fake pdus (aquivalent to peerQueues) is generated every frame. 00115 friends_.ulScheduler->resetAllQueues(); 00116 00117 ConnectionIdentifiers allBasicConnIDs = 00118 friends_.connectionManager->getAllBasicConnections (); 00119 00120 allBasicConnIDs.remove_if( UpgoingConnection( component_->getID()) ); 00121 00122 std::map<wns::scheduler::UserID, ConnectionIdentifier::CID> userIDs; 00123 userIDs.clear(); 00124 00125 // FIXME BWrequest shortcut. 00126 std::map<wns::scheduler::UserID, int> peerQueuePDUSize; 00127 peerQueuePDUSize.clear(); 00128 00129 // first get a list of users having registered connections and one of the 00130 // respective CIDs. 00131 00132 for (ConnectionIdentifier::List::const_iterator iter = allBasicConnIDs.begin(); 00133 iter != allBasicConnIDs.end(); ++iter) { 00134 ConnectionIdentifier::Ptr cidPtr = *iter; 00135 00136 // No bandwidth request for subscriber stations, which aren't listening 00137 if(cidPtr->ciNotListening_ > 0) 00138 continue; 00139 00140 ConnectionIdentifier::StationID peerStationId = cidPtr->subscriberStation_; 00141 00142 Component* peerComponent = dynamic_cast<wimac::Component*>( 00143 TheStationManager::getInstance()->getStationByID(peerStationId) ); 00144 00145 assure(peerComponent, "Invalid peer layer pointer"); 00146 assure(peerComponent->getNode(), "No valid Node pointer in peer FUN"); 00147 00148 //FIXME BWrequest shortcut 00149 wimac::ConnectionIdentifiers cis = 00150 friends_.connectionManager->getIncomingConnections(peerStationId); 00151 int queueSize = peerComponent->getNumberOfQueuedPDUs(cis); 00152 if(queueSize == 0) 00153 continue; 00154 peerQueuePDUSize[wns::scheduler::UserID(peerComponent->getNode())] = queueSize; 00155 00156 userIDs[wns::scheduler::UserID(peerComponent->getNode())] = cidPtr->getID(); 00157 } 00158 00159 // then create PDUs for every user and hand them down to the lower layer 00160 for (std::map<wns::scheduler::UserID, ConnectionIdentifier::CID>::const_iterator iter = userIDs.begin(); 00161 iter != userIDs.end(); ++iter) { 00162 LOG_INFO(component_->getName(), " PseudoBWReqGenerator: is going to generate ", 00163 peerQueuePDUSize[iter->first], " Fake PDUs for CID ", iter->second); 00164 for( int i = 1; i <= peerQueuePDUSize[iter->first]; ++i) 00165 { 00166 CompoundPtr pdu = 00167 CompoundPtr(new Compound(component_->getFUN()->getProxy()->createCommandPool(), 00168 wns::ldk::helper::FakePDUPtr(new helper::FakePDU(packetSize)))); 00169 00170 wns::ldk::ClassifierCommand* command = 00171 friends_.classifier->activateCommand(pdu->getCommandPool()); 00172 command->peer.id = iter->second; 00173 00174 if(friends_.ulScheduler->isAccepting(pdu)){ 00175 friends_.ulScheduler->schedule(pdu); 00176 LOG_TRACE(component_->getFUN()->getName(), " PseudoBWRequestGenerator: generated a Fake PDU for CID ", iter->second); 00177 } 00178 else 00179 break; 00180 } 00181 } 00182 }
1.5.5