User Manual, Developers Guide and API Documentation

RANG.cpp

Go to the documentation of this file.
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 #include <WIMAC/RANG.hpp>
00026 
00027 #include <WNS/node/component/FQSN.hpp>
00028 #include <WNS/module/Base.hpp>
00029 
00030 #include <WIMAC/UpperConvergence.hpp>
00031 
00032 #include <sstream>
00033 
00034 using namespace wimac;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(RANG,
00037                                      wns::node::component::Interface,
00038                                      "wimac.RANG",
00039                                      wns::node::component::ConfigCreator);
00040 
00041 RANG::RANG(wns::node::Interface* node, const wns::pyconfig::View& _config) :
00042     wns::node::component::Component(node, _config),
00043     config(_config),
00044     accessPointLookup(),
00045     logger(config.get("logger"))
00046 {
00047 }
00048 
00049 void
00050 RANG::doStartup()
00051 {
00052     addService(config.get<std::string>("dataTransmission"), this);
00053     addService(config.get<std::string>("notification"), this);
00054 }
00055 
00056 void
00057 RANG::onData(const wns::SmartPtr<wns::osi::PDU>& _data,
00058         wns::service::dll::FlowID dllFlowID)
00059 {
00060     assure(dataHandlerRegistry.knows(wns::service::dll::protocolNumberOf(_data)), "no data handler set");
00061     dataHandlerRegistry.find(wns::service::dll::protocolNumberOf(_data))->onData(_data, dllFlowID);
00062 }
00063 
00064 void
00065 RANG::onData(const wns::SmartPtr<wns::osi::PDU>& _data,
00066              wns::service::dll::UnicastAddress _sourceMACAddress,
00067              wns::service::dll::UnicastDataTransmission* _ap,
00068              wns::service::dll::FlowID _dllFlowID)
00069 {
00070     updateAPLookUp(_sourceMACAddress, _ap);
00071 
00072     MESSAGE_BEGIN(NORMAL, logger, m,"Receiving incoming data from MAC Address: ");
00073     m << _sourceMACAddress;
00074     MESSAGE_END();
00075 
00076     assure(dataHandlerRegistry.knows(wns::service::dll::protocolNumberOf(_data)), "no data handler set");
00077     dataHandlerRegistry.find(wns::service::dll::protocolNumberOf(_data))->onData(_data, _dllFlowID);
00078 }
00079 
00080 void
00081 RANG::sendData(
00082     const wns::service::dll::UnicastAddress& _peer,
00083     const wns::SmartPtr<wns::osi::PDU>& pdu,
00084     wns::service::dll::protocolNumber protocol,
00085     wns::service::dll::FlowID _dllFlowID)
00086 {
00087     wns::service::dll::UnicastDataTransmission* ap = NULL;
00088     if( knowsAddress(_peer) )
00089     {
00090         ap = getAccessPointFor(_peer);
00091     } else
00092     {
00093         MESSAGE_BEGIN(NORMAL, logger, m, "No valid access point found. Dropping packet to ");
00094         m << _peer;
00095         MESSAGE_END();
00096         return;
00097     }
00098     MESSAGE_BEGIN(NORMAL, logger, m, getName());
00099     m << ": doSendData(), RANG forwarding to convergence::Upper\n";
00100     m << "target is ";
00101     m << _peer;
00102     m << " DLLFlowID: ";
00103     m << _dllFlowID;
00104     MESSAGE_END();
00105 
00106     ap->sendData(_peer, pdu, protocol, _dllFlowID);
00107 }
00108 
00109 void
00110 RANG::registerHandler(wns::service::dll::protocolNumber protocol, wns::service::dll::Handler* dh)
00111 {
00112     assure(dh, "no data handler set");
00113     assure(!dataHandlerRegistry.knows(protocol), "data handler already registered");
00114     dataHandlerRegistry.insert(protocol, dh);
00115 }
00116 
00117 void
00118 RANG::onNodeCreated()
00119 {
00120 }
00121 
00122 
00123 void
00124 RANG::onWorldCreated()
00125 {
00126     int numAPs = config.len("dllDataTransmissions");
00127     assure( numAPs == config.len("dllNotifications"),
00128             "mismatch in number of DataTransmission / Notification services");
00129     // browse through the list of connected APs
00130     for (int i=0; i<numAPs; ++i)
00131     {
00132         wns::node::component::FQSN dataTransmission(config.get<wns::pyconfig::View>("dllDataTransmissions",i));
00133         wns::node::component::FQSN notification(config.get<wns::pyconfig::View>("dllNotifications",i));
00134 
00135         UpperConvergence* dataTransmissionService =
00136             getRemoteService<UpperConvergence*>(dataTransmission);
00137         UpperConvergence* notificationService =
00138             getRemoteService<UpperConvergence*>(notification);
00139 
00140         wns::service::dll::UnicastAddress macAdr = dataTransmissionService->getMACAddress();
00141 
00142         notificationService->registerHandler(wns::service::dll::TUNNEL, this);
00143         accessPointLookup.insert(macAdr, dataTransmissionService);
00144 
00145         MESSAGE_BEGIN(NORMAL, logger, m, "Added AP");
00146         m << i+1 << " with MAC Adr.: " << macAdr << " to RANG!";
00147         MESSAGE_END();
00148     }
00149 }
00150 
00151 bool
00152 RANG::knowsAddress(wns::service::dll::UnicastAddress _sourceMACAddress)
00153 {
00154     return accessPointLookup.knows(_sourceMACAddress);
00155 }
00156 
00157 wns::service::dll::UnicastDataTransmission*
00158 RANG::getAccessPointFor(wns::service::dll::UnicastAddress _sourceMACAddress)
00159 {
00160     assure(knowsAddress(_sourceMACAddress), "No valid access point found.");
00161     return accessPointLookup.find(_sourceMACAddress);
00162 }
00163 
00164 // Modified Handler Interface for APs
00165 void
00166 RANG::updateAPLookUp( wns::service::dll::UnicastAddress _sourceMACAddress,
00167                       wns::service::dll::UnicastDataTransmission* _ap)
00168 {
00169     // keep the MAC Address table up to date
00170     if (knowsAddress(_sourceMACAddress))
00171         accessPointLookup.erase(_sourceMACAddress);
00172 
00173     accessPointLookup.insert(_sourceMACAddress, _ap);
00174 
00175     MESSAGE_BEGIN(NORMAL, logger, m, "updated APLookup for UT with MAC Adr.: ");
00176     m << _sourceMACAddress << " (AP with MAC Adr.: "
00177       << dynamic_cast<wimac::UpperConvergence*>(_ap)->getMACAddress() << ").";
00178     MESSAGE_END();
00179 }
00180 
00181 void
00182 RANG::removeAddress(wns::service::dll::UnicastAddress _sourceMACAddress,
00183                     wns::service::dll::UnicastDataTransmission* _ap)
00184 {
00185     if (knowsAddress(_sourceMACAddress))
00186     {
00187         if (getAccessPointFor(_sourceMACAddress) == _ap)
00188         {
00189             accessPointLookup.erase(_sourceMACAddress);
00190 
00191             MESSAGE_BEGIN(NORMAL, logger, m,"removed UT with MAC Adr.: ");
00192             m << _sourceMACAddress << " from APLookup.";
00193             MESSAGE_END();
00194         }
00195         else
00196         {
00197             throw wns::Exception("AP unrelated to UT tried to remove its routing entry!");
00198         }
00199     }
00200     else
00201         throw wns::Exception("Tried to remove unknown UT address from RANG APlookup table!");
00202 }
00203 
00204 void
00205 RANG::onShutdown()
00206 {
00207 }
00208 

Generated on Sun May 27 03:31:36 2012 for openWNS by  doxygen 1.5.5