User Manual, Developers Guide and API Documentation

Keys.cpp

Go to the documentation of this file.
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 "Keys.hpp"
00030 
00031 #include <WNS/ldk/FlowSeparator.hpp>
00032 
00033 #include <sstream>
00034 
00035 using namespace wifimac::helper;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(NoKeyBuilder,
00038                                      wns::ldk::KeyBuilder,
00039                                      "wifimac.noKey",
00040                                      wns::ldk::FUNConfigCreator);
00041 
00042 STATIC_FACTORY_REGISTER_WITH_CREATOR(TransmitterReceiverBuilder,
00043                                      wns::ldk::KeyBuilder,
00044                                      "wifimac.TransmitterReceiver",
00045                                      wns::ldk::FUNConfigCreator);
00046 
00047 STATIC_FACTORY_REGISTER_WITH_CREATOR(LinkByReceiverBuilder,
00048                                      wns::ldk::KeyBuilder,
00049                                      "wifimac.LinkByReceiver",
00050                                      wns::ldk::FUNConfigCreator);
00051 
00052 STATIC_FACTORY_REGISTER_WITH_CREATOR(LinkByTransmitterBuilder,
00053                                      wns::ldk::KeyBuilder,
00054                                      "wifimac.LinkByTransmitter",
00055                                      wns::ldk::FUNConfigCreator);
00056 
00057 // LinkByReceiver Implementation
00058 LinkByReceiver::LinkByReceiver(
00059     const LinkByReceiverBuilder* factory,
00060     const wns::ldk::CompoundPtr& compound,
00061     int direction)
00062 {
00063     dll::UpperCommand* uc = factory->fun->getCommandReader("upperConvergence")->readCommand<dll::UpperCommand>(compound->getCommandPool());
00064 
00065     if(direction == wns::ldk::Direction::OUTGOING())
00066     {
00067         linkId = uc->peer.targetMACAddress;
00068     }
00069     else
00070     {
00071         linkId = uc->peer.sourceMACAddress;
00072     }
00073 }
00074 
00075 LinkByReceiver::LinkByReceiver(wns::service::dll::UnicastAddress _linkId)
00076 {
00077     assure(_linkId.isValid(), "Invalid key for linkId");
00078     linkId = _linkId;
00079 }
00080 
00081 bool LinkByReceiver::operator<(const wns::ldk::Key& _other) const
00082 {
00083     assureType(&_other, const LinkByReceiver*);
00084 
00085     const LinkByReceiver* other = static_cast<const LinkByReceiver*>(&_other);
00086     return linkId < other->linkId;
00087 }
00088 
00089 std::string LinkByReceiver::str() const
00090 {
00091     std::stringstream ss;
00092     ss << "LinkId " << linkId;
00093     return ss.str();
00094 }
00095 
00096 LinkByReceiverBuilder::LinkByReceiverBuilder(const wns::ldk::fun::FUN* _fun, const wns::pyconfig::View& /*config*/) :
00097     fun(_fun)
00098 {
00099 }
00100 
00101 void LinkByReceiverBuilder::onFUNCreated()
00102 {
00103 
00104 }
00105 
00106 wns::ldk::ConstKeyPtr LinkByReceiverBuilder::operator () (const wns::ldk::CompoundPtr& compound, int direction) const
00107 {
00108     return wns::ldk::ConstKeyPtr(new LinkByReceiver(this, compound, direction));
00109 }
00110 
00111 // LinkByTransmitter Implementation
00112 LinkByTransmitter::LinkByTransmitter(
00113     const LinkByTransmitterBuilder* factory,
00114     const wns::ldk::CompoundPtr& compound,
00115     int direction)
00116 {
00117     dll::UpperCommand* uc = factory->fun->getCommandReader("upperConvergence")->readCommand<dll::UpperCommand>(compound->getCommandPool());
00118 
00119     if(direction == wns::ldk::Direction::OUTGOING())
00120     {
00121         linkId = uc->peer.sourceMACAddress;
00122     }
00123     else
00124     {
00125         linkId = uc->peer.targetMACAddress;
00126     }
00127 }
00128 
00129 LinkByTransmitter::LinkByTransmitter(wns::service::dll::UnicastAddress _linkId)
00130 {
00131     assure(_linkId.isValid(), "Invalid key for linkId");
00132     linkId = _linkId;
00133 }
00134 
00135 bool LinkByTransmitter::operator<(const wns::ldk::Key& _other) const
00136 {
00137     assureType(&_other, const LinkByTransmitter*);
00138 
00139     const LinkByTransmitter* other = static_cast<const LinkByTransmitter*>(&_other);
00140     return linkId < other->linkId;
00141 }
00142 
00143 std::string LinkByTransmitter::str() const
00144 {
00145     std::stringstream ss;
00146     ss << "LinkId " << linkId;
00147     return ss.str();
00148 }
00149 
00150 LinkByTransmitterBuilder::LinkByTransmitterBuilder(const wns::ldk::fun::FUN* _fun, const wns::pyconfig::View& /*config*/) :
00151     fun(_fun)
00152 {
00153 }
00154 
00155 void LinkByTransmitterBuilder::onFUNCreated()
00156 {
00157 
00158 }
00159 
00160 wns::ldk::ConstKeyPtr LinkByTransmitterBuilder::operator () (const wns::ldk::CompoundPtr& compound, int direction) const
00161 {
00162     return wns::ldk::ConstKeyPtr(new LinkByTransmitter(this, compound, direction));
00163 }
00164 
00165 // TransmitterReceiver Implementation
00166 TransmitterReceiver::TransmitterReceiver(
00167     const TransmitterReceiverBuilder* factory,
00168     const wns::ldk::CompoundPtr& compound,
00169     int direction)
00170 {
00171     dll::UpperCommand* uc = factory->fun->getCommandReader("upperConvergence")->readCommand<dll::UpperCommand>(compound->getCommandPool());
00172 
00173     if(direction == wns::ldk::Direction::OUTGOING())
00174     {
00175         tx = uc->peer.sourceMACAddress;
00176         rx = uc->peer.targetMACAddress;
00177     }
00178     else
00179     {
00180         // reverse the keys, so that replies go to the correct initiator
00181         rx = uc->peer.sourceMACAddress;
00182         tx = uc->peer.targetMACAddress;
00183     }
00184 }
00185 
00186 TransmitterReceiver::TransmitterReceiver(wns::service::dll::UnicastAddress txAdr, wns::service::dll::UnicastAddress rxAdr)
00187 {
00188     assure(txAdr.isValid(), "Invalid key for tx");
00189     assure(rxAdr.isValid(), "Invalid key for rx");
00190     tx = txAdr;
00191     rx = rxAdr;
00192 }
00193 
00194 bool TransmitterReceiver::operator<(const wns::ldk::Key& _other) const
00195 {
00196     assureType(&_other, const TransmitterReceiver*);
00197 
00198     const TransmitterReceiver* other = static_cast<const TransmitterReceiver*>(&_other);
00199     if (tx == other->tx)
00200         return rx < other->rx;
00201     else
00202         return tx < other->tx;
00203 }
00204 
00205 std::string TransmitterReceiver::str() const
00206 {
00207     std::stringstream ss;
00208     ss << "TX " << tx << " / RX " << rx;
00209     return ss.str();
00210 }
00211 
00212 TransmitterReceiverBuilder::TransmitterReceiverBuilder(const wns::ldk::fun::FUN* _fun, const wns::pyconfig::View& /*config*/) :
00213     fun(_fun)
00214 {
00215 }
00216 
00217 void TransmitterReceiverBuilder::onFUNCreated()
00218 {
00219 
00220 }
00221 
00222 wns::ldk::ConstKeyPtr TransmitterReceiverBuilder::operator () (const wns::ldk::CompoundPtr& compound, int direction) const
00223 {
00224     return wns::ldk::ConstKeyPtr(new TransmitterReceiver(this, compound, direction));
00225 }

Generated on Sun May 27 03:32:04 2012 for openWNS by  doxygen 1.5.5