![]() |
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 00031 #include <WIMAC/services/ConnectionManager.hpp> 00032 #include <sstream> 00033 00034 00035 #include <WNS/ldk/fun/FUN.hpp> 00036 #include <WNS/ldk/Compound.hpp> 00037 #include <WNS/service/dll/StationTypes.hpp> 00038 00039 #include <WIMAC/StationManager.hpp> 00040 #include <WIMAC/UpperConvergence.hpp> 00041 00042 #include <WIMAC/ConnectionRule.hpp> 00043 #include <WIMAC/Component.hpp> 00044 #include <WIMAC/Logger.hpp> 00045 #include <WIMAC/Classifier.hpp> 00046 00047 00048 00049 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00050 wimac::service::ConnectionManager, 00051 wns::ldk::ManagementServiceInterface, 00052 "wimac.services.ConnectionManager", 00053 wns::ldk::MSRConfigCreator); 00054 00055 00056 using namespace wimac; 00057 using namespace wimac::service; 00058 00059 ConnectionManager::ConnectionManager( wns::ldk::ManagementServiceRegistry* msr, 00060 const wns::pyconfig::View& config ) : 00061 ManagementService( msr ), 00062 connectionIdentifiers_(), 00063 highestCID_( 1 ), 00064 config_( config ) 00065 { 00066 layer_ = dynamic_cast<Component*>(msr->getLayer()); 00067 assure(layer_, "ConnectionManager can only be used in wimac::Component environmnet." ); 00068 } 00069 00070 ConnectionManager::ConnectionManager( const ConnectionManager& other ) : 00071 wns::ldk::ManagementServiceInterface( other ), 00072 Subject::SubjectType( other ), 00073 ConnectionManagerInterface(), 00074 wns::ldk::ManagementService( other ), 00075 Subject( other ), 00076 connectionIdentifiers_( other.connectionIdentifiers_ ), 00077 highestCID_( other.highestCID_ ), 00078 layer_( other.layer_ ), 00079 config_( other.config_ ) 00080 {} 00081 00082 ConnectionIdentifier 00083 ConnectionManager::appendConnection( const ConnectionIdentifier& connection ) 00084 { 00085 assure(connection.integrityCheck(), 00086 "ConnectionManager::appendConnection: New ConnectionIdentifier doesn't pass the integrityCheck!"); 00087 00088 // append ConnectionIdentifier 00089 ConnectionIdentifierPtr connectionPtr( new ConnectionIdentifier( connection ) ); 00090 00091 if ( connectionPtr->cid_ == -1 ) 00092 connectionPtr->cid_ = getAndIncreaseHighestCellCID(); 00093 00094 00095 if( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) //set CID in AP 00096 { 00097 if(connectionPtr->connectionType_ == ConnectionIdentifier::InitialRanging) 00098 { 00099 if( this->getConnectionWithID(0) ) 00100 { 00101 LOG_INFO( getMSR()->getLayer()->getName(), 00102 " Ranging ConnectionIdentifier (CID: 0) already exist."); 00103 return ConnectionIdentifier(*(this->getConnectionWithID(0))); 00104 }else 00105 { 00106 connectionPtr->cid_ = 0; //Ranging CID 00107 } 00108 } 00109 } 00110 00111 // remove all CI for station if double basic CI happened 00112 //this->doubleBasicCIDeleteAllOtherCI( connectionPtr ); 00113 00114 // Delete ConnectionIdentifier if it always exist 00115 //this->singularityDelete( connectionPtr ); 00116 00117 // Check for validation 00118 assure(connectionPtr->cid_ >= 0, 00119 "ConnectionManager::appendConnection: CID of ConectionIdentifier isn't valid!"); 00120 00121 connectionIdentifiers_.push_back( connectionPtr ); 00122 00123 LOG_INFO( getMSR()->getLayer()->getName() , ": Register", 00124 *connectionPtr ); 00125 00126 return ConnectionIdentifier(*connectionPtr); 00127 } 00128 00129 00130 00131 void 00132 ConnectionManager::deleteAllConnections() 00133 { 00134 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00135 it != connectionIdentifiers_.end(); ++it) { 00136 00137 LOG_INFO( getMSR()->getLayer()->getName() , ": delete ", 00138 **it ); 00139 wns::Subject<ConnectionDeletedNotification>::sendNotifies 00140 (&ConnectionDeletedNotification::notifyAboutConnectionDeleted, **it); 00141 00142 } 00143 connectionIdentifiers_.clear(); 00144 } 00145 00146 00147 00148 void 00149 ConnectionManager::deleteConnectionsForBS( ConnectionIdentifier::StationID baseStation ) 00150 { 00151 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00152 it != connectionIdentifiers_.end(); ) 00153 { 00154 if ( (*it)->baseStation_ == baseStation ) 00155 { 00156 std::ostringstream log; 00157 log << getMSR()->getLayer()->getName() << ": delete " 00158 << **it; 00159 LOG_INFO( log.str() ); 00160 00161 wns::Subject<ConnectionDeletedNotification>::sendNotifies 00162 (&ConnectionDeletedNotification::notifyAboutConnectionDeleted, **it); 00163 00164 connectionIdentifiers_.erase( it++ ); 00165 } else 00166 ++it; 00167 } 00168 } 00169 00170 00171 00172 void 00173 ConnectionManager::deleteConnectionsForSS( ConnectionIdentifier::StationID subscriberStation ) 00174 { 00175 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00176 it != connectionIdentifiers_.end(); ) 00177 { 00178 if ( (*it)->subscriberStation_ == subscriberStation) 00179 { 00180 std::ostringstream log; 00181 log << getMSR()->getLayer()->getName() << ": delete " 00182 << **it; 00183 LOG_INFO( log.str() ); 00184 00185 wns::Subject<ConnectionDeletedNotification>::sendNotifies 00186 (&ConnectionDeletedNotification::notifyAboutConnectionDeleted, **it); 00187 00188 connectionIdentifiers_.erase( it++ ); 00189 } else 00190 ++it; 00191 } 00192 00193 } 00194 00195 void 00196 ConnectionManager::deleteCI( ConnectionIdentifier::CID cid ) 00197 { 00198 int ciDeleted = 0; 00199 00200 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00201 it != connectionIdentifiers_.end(); ) 00202 { 00203 if ( (*it)->cid_ == cid ) 00204 { 00205 std::ostringstream log; 00206 log << getMSR()->getLayer()->getName() << ": delete " 00207 << **it; 00208 LOG_INFO( log.str() ); 00209 00210 wns::Subject<ConnectionDeletedNotification>::sendNotifies 00211 (&ConnectionDeletedNotification::notifyAboutConnectionDeleted, **it); 00212 00213 connectionIdentifiers_.erase( it++ ); 00214 ++ciDeleted; 00215 } else 00216 ++it; 00217 } 00218 00219 std::ostringstream log1, log2; 00220 log1 << getMSR()->getLayer()->getName() 00221 <<"ConnectionManager::deleteCI: No ConnectionIdentifier found! CID:" 00222 << cid << "\n"; 00223 assure( ciDeleted > 0, 00224 log1.str() ); 00225 00226 log2 << getMSR()->getLayer()->getName() 00227 << "ConnectionManager::deleteCI: More than one ConnectoinIdentifer deleted! CID:" 00228 << cid << "\n"; 00229 assure( ciDeleted <= 1, 00230 log2.str() ); 00231 } 00232 00233 00234 void 00235 ConnectionManager::changeConnection( const ConnectionIdentifier& connection ) 00236 { 00237 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00238 it != connectionIdentifiers_.end(); ) 00239 { 00240 if ( **it == connection ) 00241 { 00242 std::ostringstream log; 00243 log << getMSR()->getLayer()->getName() << ": Changes" 00244 << **it; 00245 LOG_INFO( log.str() ); 00246 00247 ConnectionIdentifierPtr connectionPtr( 00248 new ConnectionIdentifier( connection ) ); 00249 connectionIdentifiers_.insert( it, connectionPtr); 00250 connectionIdentifiers_.erase( it++ ); 00251 return; 00252 } else 00253 ++it; 00254 } 00255 throw wns::Exception( "wimac::ConnectionManager::changeConnection: ConnectionIdentifier not found" ); 00256 } 00257 00258 00259 00260 void 00261 ConnectionManager::changeConnections( ConnectionIdentifiers& connections ) 00262 { 00263 for ( ConnectionIdentifiers::iterator it1 = connections.begin(); 00264 it1 != connections.end(); 00265 ++it1) 00266 { 00267 00268 std::ostringstream log; 00269 log << getMSR()->getLayer()->getName() << ": Changes" 00270 << **it1; 00271 LOG_INFO( log.str() ); 00272 00273 bool ciFound = false; 00274 for (ConnectionIdentifiers::iterator it2 = connectionIdentifiers_.begin(); 00275 it2 != connectionIdentifiers_.end(); ) 00276 { 00277 if ( **it1 == **it2 ) 00278 { 00279 ciFound = true; 00280 ConnectionIdentifierPtr connectionPtr( 00281 new ConnectionIdentifier(*(*it1))); 00282 connectionIdentifiers_.insert( it2, connectionPtr); 00283 connectionIdentifiers_.erase( it2++ ); 00284 break; 00285 } else 00286 ++it2; 00287 } 00288 00289 if(!ciFound) 00290 throw wns::Exception("wimac::ConnectionManager::changeConnections: would change a ConnectionIdentifier which isn't available! \n"); 00291 } 00292 } 00293 00294 00295 00296 ConnectionIdentifiers 00297 ConnectionManager::getAllConnections( ) 00298 { 00299 ConnectionIdentifiers connections; 00300 00301 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00302 it != connectionIdentifiers_.end(); ++it ) 00303 { 00304 connections.push_back( ConnectionIdentifierPtr( 00305 new ConnectionIdentifier(*(*it)) ) ); 00306 } 00307 return connections; 00308 } 00309 00310 00311 00312 ConnectionIdentifiers 00313 ConnectionManager::getAllCIForSS( ConnectionIdentifier::StationID subscriberStation ) const 00314 { 00315 ConnectionIdentifiers results 00316 = ConnectionIdentifiers(); 00317 00318 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00319 it != connectionIdentifiers_.end(); 00320 ++it ) 00321 { 00322 if ( (*it)->subscriberStation_ == subscriberStation) 00323 { 00324 results.push_back( ConnectionIdentifierPtr( 00325 new ConnectionIdentifier(*(*it)) ) ); 00326 } 00327 } 00328 00329 return results; 00330 } 00331 00332 00333 ConnectionIdentifiers 00334 ConnectionManager::getAllCIForBS( ConnectionIdentifier::StationID baseStation ) 00335 { 00336 ConnectionIdentifiers results 00337 = ConnectionIdentifiers(); 00338 00339 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00340 it != connectionIdentifiers_.end(); 00341 ++it ) 00342 { 00343 if ( (*it)->baseStation_ == baseStation) 00344 { 00345 results.push_back( ConnectionIdentifierPtr( 00346 new ConnectionIdentifier(*(*it)) ) ); 00347 } 00348 } 00349 00350 return results; 00351 } 00352 00353 00354 ConnectionIdentifiers 00355 ConnectionManager::getIncomingDataConnections( ConnectionIdentifier::StationID from, ConnectionIdentifier::QoSCategory qos) 00356 { 00357 ConnectionIdentifiers connections; 00358 if( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) 00359 { 00360 // all uplink connections are incoming 00361 for ( ConnectionIdentifiers::const_iterator conn = 00362 connectionIdentifiers_.begin(); 00363 conn != connectionIdentifiers_.end(); 00364 ++conn ) 00365 { 00366 if ( ( (*conn)->remoteStation_ == from ) 00367 && ( (*conn)->direction_ == ConnectionIdentifier::Uplink ) 00368 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00369 && ( (*conn)->qos_ == qos ) 00370 ) 00371 connections.push_back( *conn ); 00372 } 00373 }else if (layer_->getStationType() == wns::service::dll::StationTypes::UT() ) 00374 { 00375 // all downlink connections are incoming 00376 for ( ConnectionIdentifiers::const_iterator conn = 00377 connectionIdentifiers_.begin(); 00378 conn != connectionIdentifiers_.end(); 00379 ++conn ) 00380 { 00381 if ( ( (*conn)->baseStation_ == from ) 00382 && ( (*conn)->direction_ == ConnectionIdentifier::Downlink ) 00383 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00384 && ( (*conn)->qos_ == qos ) 00385 ) 00386 connections.push_back( *conn ); 00387 } 00388 }else if( layer_->getStationType() == wns::service::dll::StationTypes::FRS() ) 00389 { 00390 // all downlink connections are incoming 00391 for ( ConnectionIdentifiers::const_iterator conn = 00392 connectionIdentifiers_.begin(); 00393 conn != connectionIdentifiers_.end(); 00394 ++conn ) 00395 { 00396 if ( ( ( (*conn)->baseStation_ == from ) 00397 && ( (*conn)->direction_ == ConnectionIdentifier::Downlink ) 00398 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00399 && ( (*conn)->qos_ == qos ) ) 00400 || 00401 ( ( (*conn)->subscriberStation_ == from ) 00402 && ( (*conn)->direction_ == ConnectionIdentifier::Uplink ) 00403 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00404 && ( (*conn)->qos_ == qos ) ) 00405 ) 00406 connections.push_back( *conn ); 00407 } 00408 }else 00409 { 00410 assure( 0, "unsupported station type" ); 00411 } 00412 return connections; 00413 } 00414 00415 00416 00417 ConnectionIdentifiers 00418 ConnectionManager::getOutgoingDataConnections( ConnectionIdentifier::StationID to, 00419 ConnectionIdentifier::QoSCategory qos) 00420 { 00421 ConnectionIdentifiers connections; 00422 if( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) 00423 { 00424 // all downlink connections are outgoing 00425 for ( ConnectionIdentifiers::const_iterator conn = 00426 connectionIdentifiers_.begin(); 00427 conn != connectionIdentifiers_.end(); 00428 ++conn ) 00429 { 00430 if ( ( (*conn)->remoteStation_ == to ) 00431 && ( (*conn)->direction_ == ConnectionIdentifier::Downlink ) 00432 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00433 && ( (*conn)->qos_ == qos ) 00434 ) 00435 connections.push_back( *conn ); 00436 } 00437 } else if( layer_->getStationType() == wns::service::dll::StationTypes::UT() ) 00438 { 00439 // all uplink connections are outgoing 00440 for ( ConnectionIdentifiers::const_iterator conn = 00441 connectionIdentifiers_.begin(); 00442 conn != connectionIdentifiers_.end(); 00443 ++conn ) 00444 { 00445 if ( ( (*conn)->baseStation_ == to ) 00446 && ( (*conn)->direction_ == ConnectionIdentifier::Uplink ) 00447 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00448 && ( (*conn)->qos_ == qos ) 00449 ) 00450 connections.push_back( *conn ); 00451 } 00452 } else if( layer_->getStationType() == wns::service::dll::StationTypes::RUT() ) 00453 { 00454 for ( ConnectionIdentifiers::const_iterator conn = 00455 connectionIdentifiers_.begin(); 00456 conn != connectionIdentifiers_.end(); 00457 ++conn ) 00458 { 00459 if ( ( ( (*conn)->baseStation_ == to ) 00460 && ( (*conn)->direction_ == ConnectionIdentifier::Uplink ) 00461 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00462 && ( (*conn)->qos_ == qos ) ) 00463 || 00464 ( ( (*conn)->subscriberStation_ == to ) 00465 && ( (*conn)->direction_ == ConnectionIdentifier::Downlink ) 00466 && ( (*conn)->connectionType_ == ConnectionIdentifier::Data ) 00467 && ( (*conn)->qos_ == qos ) ) 00468 ) 00469 connections.push_back( *conn ); 00470 } 00471 } else 00472 { 00473 assure( 0, "unsupported station type" ); 00474 } 00475 return connections; 00476 } 00477 00478 00479 00480 ConnectionIdentifiers 00481 ConnectionManager::getOutgoingConnections( ConnectionIdentifier::StationID to ) 00482 { 00483 ConnectionIdentifiers connections; 00484 if( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) 00485 { 00486 // all downlink connections are outgoing 00487 for ( ConnectionIdentifiers::const_iterator conn = 00488 connectionIdentifiers_.begin(); 00489 conn != connectionIdentifiers_.end(); 00490 ++conn ) 00491 { 00492 if ( ( ( (*conn)->remoteStation_ == to ) || ( (*conn)->subscriberStation_ == to) ) && 00493 ((*conn)->direction_ != ConnectionIdentifier::Uplink) ) 00494 connections.push_back( *conn ); 00495 } 00496 } else if( layer_->getStationType() == wns::service::dll::StationTypes::UT() ) 00497 { 00498 // all uplink connections are outgoing 00499 for ( ConnectionIdentifiers::const_iterator conn = 00500 connectionIdentifiers_.begin(); 00501 conn != connectionIdentifiers_.end(); 00502 ++conn ) 00503 { 00504 if ( ( (*conn)->baseStation_ == to ) && ((*conn)->direction_ != ConnectionIdentifier::Downlink) ) 00505 connections.push_back( *conn ); 00506 } 00507 } else if ( layer_->getStationType() == wns::service::dll::StationTypes::FRS() ) 00508 { 00509 for ( ConnectionIdentifiers::const_iterator conn = 00510 connectionIdentifiers_.begin(); 00511 conn != connectionIdentifiers_.end(); 00512 ++conn ) 00513 { 00514 if ( ( ( (*conn)->baseStation_ == to ) && ( (*conn)->direction_ & ConnectionIdentifier::Uplink ) ) 00515 || ( ( (*conn)->subscriberStation_ == to ) && ( (*conn)->direction_ & ConnectionIdentifier::Downlink ) ) ) 00516 connections.push_back( *conn ); 00517 } 00518 }else 00519 { 00520 std::ostringstream error; 00521 error << "unsupported station type: " << 00522 wns::service::dll::StationTypes::toString(layer_->getStationType()); 00523 throw wns::Exception( error.str() ); 00524 } 00525 return connections; 00526 } 00527 00528 ConnectionIdentifiers 00529 ConnectionManager::getIncomingConnections( ConnectionIdentifier::StationID from ) 00530 { 00531 ConnectionIdentifiers connections; 00532 if( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) 00533 { 00534 // all uplink connections are incomming 00535 for ( ConnectionIdentifiers::const_iterator conn = 00536 connectionIdentifiers_.begin(); 00537 conn != connectionIdentifiers_.end(); 00538 ++conn ) 00539 { 00540 if ( ( ( (*conn)->remoteStation_ == from ) || ( (*conn)->subscriberStation_ == from) ) && 00541 ((*conn)->direction_ != ConnectionIdentifier::Downlink) ) 00542 connections.push_back( *conn ); 00543 } 00544 } else if( layer_->getStationType() == wns::service::dll::StationTypes::UT() ) 00545 { 00546 // all downlink connections are incomming 00547 for ( ConnectionIdentifiers::const_iterator conn = 00548 connectionIdentifiers_.begin(); 00549 conn != connectionIdentifiers_.end(); 00550 ++conn ) 00551 { 00552 if ( ( (*conn)->baseStation_ == from ) && ((*conn)->direction_ != ConnectionIdentifier::Uplink) ) 00553 connections.push_back( *conn ); 00554 } 00555 } else if ( layer_->getStationType() == wns::service::dll::StationTypes::FRS() ) 00556 { 00557 for ( ConnectionIdentifiers::const_iterator conn = 00558 connectionIdentifiers_.begin(); 00559 conn != connectionIdentifiers_.end(); 00560 ++conn ) 00561 { 00562 if ( ( ( (*conn)->baseStation_ == from ) && ( (*conn)->direction_ & ConnectionIdentifier::Downlink ) ) 00563 || ( ( (*conn)->subscriberStation_ == from ) && ( (*conn)->direction_ & ConnectionIdentifier::Uplink ) ) ) 00564 connections.push_back( *conn ); 00565 } 00566 }else 00567 { 00568 std::ostringstream error; 00569 error << "unsupported station type: " << 00570 wns::service::dll::StationTypes::toString(layer_->getStationType()); 00571 throw wns::Exception( error.str() ); 00572 } 00573 return connections; 00574 } 00575 00576 ConnectionIdentifiers 00577 ConnectionManager::getAllDataConnections(int direction, 00578 ConnectionIdentifier::QoSCategory qos) 00579 { 00580 ConnectionIdentifiers connections; 00581 for ( ConnectionIdentifiers::const_iterator it = 00582 connectionIdentifiers_.begin(); 00583 it != connectionIdentifiers_.end(); 00584 ++it ) 00585 { 00586 if ( (*it)->direction_ == direction 00587 &&(*it)->connectionType_ == ConnectionIdentifier::Data 00588 && ( (*it)->qos_ == qos ) ) 00589 { 00590 connections.push_back(*it); 00591 } 00592 } 00593 return connections; 00594 } 00595 00596 ConnectionIdentifiers 00597 ConnectionManager::getAllDataConnections(int direction) 00598 { 00599 ConnectionIdentifiers connections; 00600 for ( ConnectionIdentifiers::const_iterator it = 00601 connectionIdentifiers_.begin(); 00602 it != connectionIdentifiers_.end(); 00603 ++it ) 00604 { 00605 if ( (*it)->direction_ == direction 00606 &&(*it)->connectionType_ == ConnectionIdentifier::Data) 00607 { 00608 connections.push_back(*it); 00609 } 00610 } 00611 return connections; 00612 } 00613 00614 00615 class SpecialConnectionMatcher : 00616 public std::unary_function<ConnectionIdentifierPtr, 00617 bool> 00618 { 00619 public: 00620 SpecialConnectionMatcher( 00621 ConnectionIdentifier::ConnectionType connectionType, 00622 ConnectionIdentifier::StationID baseStation, 00623 ConnectionIdentifier::StationID subscriber 00624 ): 00625 connectionType_( connectionType ), 00626 baseStation_( baseStation ), 00627 subscriberStation_ ( subscriber ) 00628 {} 00629 00630 bool operator()( 00631 const ConnectionIdentifierPtr& identifier ) 00632 { 00633 return ( connectionType_ == identifier->connectionType_ ) 00634 && ( baseStation_ == identifier->baseStation_ ) 00635 && ( subscriberStation_ == identifier->subscriberStation_ ); 00636 } 00637 00638 private: 00639 ConnectionIdentifier::ConnectionType connectionType_; 00640 ConnectionIdentifier::StationID baseStation_; 00641 ConnectionIdentifier::StationID subscriberStation_; 00642 }; 00643 00644 00645 ConnectionIdentifierPtr 00646 ConnectionManager::getSpecialConnection( 00647 ConnectionIdentifier::ConnectionType connectionType, ConnectionIdentifier::StationID baseStation, 00648 ConnectionIdentifier::StationID subscriber ) 00649 { 00650 ConnectionIdentifiers::const_iterator match = 00651 find_if( connectionIdentifiers_.begin(), connectionIdentifiers_.end(), 00652 SpecialConnectionMatcher( connectionType, baseStation, 00653 subscriber ) ); 00654 if ( match == connectionIdentifiers_.end() ) 00655 return ConnectionIdentifierPtr(); 00656 return *match; 00657 } 00658 00659 00660 00661 class ConnectionWithIDMatcher : 00662 public std::unary_function<ConnectionIdentifierPtr, bool> 00663 { 00664 public: 00665 ConnectionWithIDMatcher( ConnectionIdentifier::CID cid ) 00666 : cid_( cid ) 00667 {} 00668 00669 bool operator()(const ConnectionIdentifierPtr& identifier ) 00670 { 00671 return cid_ == identifier->cid_; 00672 } 00673 00674 private: 00675 ConnectionIdentifier::CID cid_; 00676 }; 00677 00678 00679 00680 ConnectionIdentifierPtr 00681 ConnectionManager::getConnectionWithID( ConnectionIdentifier::CID cid ) const 00682 { 00683 ConnectionIdentifiers::const_iterator match = 00684 find_if( connectionIdentifiers_.begin(), connectionIdentifiers_.end(), 00685 ConnectionWithIDMatcher( cid ) ); 00686 00687 if ( match == connectionIdentifiers_.end() ) 00688 { 00689 //std::stringstream ss; 00690 //ss <<": No ConnectionIdentifier registered for cid:" << cid; 00691 //assure( 0, ss.str() ); 00692 return ConnectionIdentifierPtr(); 00693 } 00694 return *match; 00695 } 00696 00697 00698 00699 ConnectionIdentifierPtr 00700 ConnectionManager::getBasicConnectionFor( const ConnectionIdentifier::CID cid ) 00701 { 00702 ConnectionIdentifierPtr ci = getConnectionWithID( cid ); 00703 00704 if ( ci->connectionType_ == ConnectionIdentifier::Basic ) 00705 return ci; 00706 00707 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00708 it != connectionIdentifiers_.end(); ++it ) 00709 { 00710 if( ( (*it)->baseStation_ == ci->baseStation_ ) 00711 && ( (*it)->subscriberStation_ == ci->subscriberStation_ ) 00712 && ( (*it)->connectionType_ == ConnectionIdentifier::Basic ) ) 00713 { 00714 return *it; 00715 } 00716 } 00717 00718 throw CIDNotFound(__LINE__, __FILE__); 00719 } 00720 00721 00722 00723 ConnectionIdentifierPtr 00724 ConnectionManager::getBasicConnectionFor( const StationID subscriberStation ) const 00725 { 00726 ConnectionIdentifierPtr basicConnection; 00727 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00728 it != connectionIdentifiers_.end(); 00729 ++it ) 00730 { 00731 if ( (*it)->subscriberStation_ == subscriberStation && 00732 (*it)->connectionType_ == ConnectionIdentifier::Basic ) 00733 { 00734 return *it; 00735 } 00736 } 00737 throw CIDNotFound(__LINE__, __FILE__); 00738 } 00739 00740 00741 00742 ConnectionIdentifiers 00743 ConnectionManager::getAllBasicConnections( ) const 00744 { 00745 ConnectionIdentifiers basics = ConnectionIdentifiers(); 00746 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00747 it != connectionIdentifiers_.end(); 00748 ++it ) 00749 { 00750 if ( (*it)->connectionType_ == ConnectionIdentifier::Basic ) 00751 basics.push_back( *it ); 00752 } 00753 return basics; 00754 } 00755 00756 00757 00758 ConnectionIdentifierPtr 00759 ConnectionManager::getPrimaryConnectionFor( ConnectionIdentifier::StationID stationID ) 00760 const 00761 { 00762 ConnectionIdentifiers primaryCIs; 00763 ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00764 for (; it != connectionIdentifiers_.end(); ++it ) 00765 { 00766 if ( ( (*it)->connectionType_ == ConnectionIdentifier::PrimaryManagement ) 00767 && ( ( (*it)->subscriberStation_ == stationID ) 00768 || ( (*it)->baseStation_ == stationID ) 00769 ) 00770 ) 00771 { 00772 primaryCIs.push_back(*it); 00773 } 00774 00775 } 00776 00777 assure( primaryCIs.size() <=1, 00778 "ConntionManager::getPrimaryconnectionFor: Only one primary ConnectionIdentifier should exist for each station"); 00779 00780 if( primaryCIs.size() ) 00781 { 00782 return ConnectionIdentifierPtr( new ConnectionIdentifier( *primaryCIs.front() ) ); 00783 }else 00784 { 00785 return ConnectionIdentifierPtr(); 00786 } 00787 } 00788 00789 00790 void 00791 ConnectionManager::onMSRCreated() 00792 {} 00793 00794 void 00795 ConnectionManager::decreaseCINotListening() 00796 { 00797 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00798 it != connectionIdentifiers_.end(); 00799 ++it ) 00800 { 00801 if ( (*it)->ciNotListening_ > 0 ) 00802 { 00803 std::ostringstream log; 00804 log << getMSR()->getLayer()->getName() << ": decrease CINotListening" 00805 << **it; 00806 LOG_INFO( log.str() ); 00807 00808 ((*it)->ciNotListening_)--; 00809 } 00810 } 00811 } 00812 00813 00814 00815 ConnectionIdentifierPtr 00816 ConnectionManager::getConnection( const wns::ldk::CompoundPtr& compound ) const 00817 { 00818 ConnectionIdentifiers connections; 00819 00820 for ( ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00821 it != connectionIdentifiers_.end(); ++it ) 00822 { 00823 if( (*it)->commandKeyClasses_.connectionClassifier ) 00824 { 00825 wns::ldk::ClassifierCommand* cCommand; 00826 cCommand = (*it)->commandKeyClasses_.connectionClassifier 00827 ->getCommand( compound->getCommandPool() ); 00828 00829 if ( (*it)->cid_ == cCommand->peer.id ) 00830 { 00831 connections.push_back( *it ); 00832 } 00833 } 00834 } 00835 00836 assure( connections.size() <= 1 , 00837 "ConnectionManager::getConnections: Only one CI should be found. \n"); 00838 00839 if ( connections.empty() ) 00840 return ConnectionIdentifierPtr(); 00841 return *connections.begin(); 00842 } 00843 00844 00845 void 00846 ConnectionManager::singularityDelete(const ConnectionIdentifierPtr ci ) 00847 { 00848 /* At the moment every connection are singular, in future data connection won't 00849 if ( ci->connectionType == ConnectionIdentifier::Data ) 00850 return; 00851 */ 00852 00853 ConnectionIdentifiers peerCIS 00854 = ConnectionIdentifiers(); 00855 00856 for ( ConnectionIdentifiers::iterator it = connectionIdentifiers_.begin(); 00857 it != connectionIdentifiers_.end(); ++it ) 00858 { 00859 if( (layer_->getStationType() == wns::service::dll::StationTypes::AP()) 00860 || (layer_->getStationType() == wns::service::dll::StationTypes::FRS()) ) 00861 {// Get only CI for this UserTerminal 00862 if( ((*it)->subscriberStation_ == ci->subscriberStation_) 00863 && ((*it)->baseStation_ == ci->baseStation_) ) 00864 { 00865 peerCIS.push_back(*it); 00866 } 00867 } else // Get all CI in this UserTerinal because it can only be connected to 00868 // on AccressPoint 00869 { 00870 peerCIS.push_back(*it); 00871 } 00872 } 00873 00875 for( ConnectionIdentifiers::const_iterator it = peerCIS.begin(); 00876 it != peerCIS.end(); ) 00877 { 00878 ConnectionIdentifiers::const_iterator copyIt = it; 00879 ++it; 00880 00881 if( ( (*copyIt)->connectionType_ == ci->connectionType_ ) 00882 && ( (*copyIt)->direction_ == ci->direction_ ) ) 00883 { 00884 LOG_INFO( getMSR()->getLayer()->getName(), 00885 ": ConnectionIdentifier to append always exist! Only one ConnectionIdentifier of each Typ is allowed!"); 00886 this->deleteCI((*copyIt)->cid_); 00887 } 00888 } 00889 } 00890 00891 00892 00893 void 00894 ConnectionManager::doubleBasicCIDeleteAllOtherCI(const ConnectionIdentifierPtr ci) 00895 { 00896 // Only act on basic ConnectionIdentifier 00897 if(ci->connectionType_ != ConnectionIdentifier::Basic) 00898 return; 00899 00900 ConnectionIdentifiers::const_iterator it = connectionIdentifiers_.begin(); 00901 for(; it != connectionIdentifiers_.end(); ++it ) 00902 { 00903 if ( ( (*it)->connectionType_ == ConnectionIdentifier::Basic ) 00904 && ( (*it)->subscriberStation_ == ci->subscriberStation_ ) 00905 && ( (*it)->baseStation_ == ci->baseStation_ ) 00906 ) 00907 { 00908 break; 00909 } 00910 } 00911 00912 // No basic ConnectionIdentifier found 00913 if(it == connectionIdentifiers_.end()) 00914 return; 00915 00916 // get all ConnectionIdentifier for peer without Ranging 00917 std::list<ConnectionIdentifier::CID> cids; 00918 for(ConnectionIdentifiers::const_iterator it2 = connectionIdentifiers_.begin(); 00919 it2 != connectionIdentifiers_.end(); ++it2 ) 00920 { 00921 if( ( (*it2)->connectionType_ != ConnectionIdentifier::InitialRanging ) 00922 && ( (*it2)->subscriberStation_ == (*it)->subscriberStation_ ) 00923 && ( (*it2)->baseStation_ == (*it)->baseStation_ ) 00924 ) 00925 { 00926 cids.push_back((*it2)->cid_); 00927 } 00928 } 00929 00930 // delete all ConnectionIdentifier without Ranging for peer 00931 while( !cids.empty() ) 00932 { 00933 this->deleteCI(cids.front()); 00934 cids.pop_front(); 00935 } 00936 } 00937 00938 ConnectionIdentifier::CID ConnectionManager::getAndIncreaseHighestCellCID() 00939 { 00940 if ( layer_->getStationType() == wns::service::dll::StationTypes::AP() ) 00941 return highestCID_++; 00942 00943 Component* associatedWith = TheStationManager::getInstance() 00944 ->getStationByID( getBasicConnectionFor( layer_->getID() )->baseStation_ ); 00945 return associatedWith->getManagementService<ConnectionManager>("connectionManager") 00946 ->getAndIncreaseHighestCellCID(); 00947 }
1.5.5