![]() |
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 #ifndef WNS_LDK_TOOLS_BRIDGE_HPP 00029 #define WNS_LDK_TOOLS_BRIDGE_HPP 00030 00031 #include <WNS/ldk/CommandTypeSpecifier.hpp> 00032 #include <WNS/ldk/HasReceptor.hpp> 00033 #include <WNS/ldk/HasConnector.hpp> 00034 #include <WNS/ldk/HasDeliverer.hpp> 00035 00036 namespace wns { namespace ldk { namespace tools { 00037 00038 namespace bridge 00039 { 00040 class Forwarder : 00041 public virtual FunctionalUnit, 00042 public wns::ldk::CommandTypeSpecifier<>, 00043 public wns::ldk::HasReceptor<>, 00044 public wns::ldk::HasConnector<>, 00045 public wns::ldk::HasDeliverer<>, 00046 public Cloneable<Forwarder> 00047 { 00048 public: 00049 Forwarder(fun::FUN* fuNet, double _loss = 0.0) : 00050 wns::ldk::CommandTypeSpecifier<>(fuNet), 00051 wns::ldk::HasReceptor<>(), 00052 wns::ldk::HasConnector<>(), 00053 wns::ldk::HasDeliverer<>(), 00054 Cloneable<Forwarder>(), 00055 00056 other(NULL), 00057 loss(_loss) 00058 {} 00059 00060 void 00061 link(Forwarder* _other) 00062 { 00063 other = _other; 00064 } 00065 00066 virtual void 00067 doOnData(const wns::ldk::CompoundPtr& compound) 00068 { 00069 if((rand() / (RAND_MAX + 1.0)) < loss) { 00070 return; 00071 } 00072 00073 // there must always be an accepting lower functionalUnit. 00074 // no buffering here. 00075 other->getConnector()->getAcceptor(compound)->sendData(compound); 00076 } // doOnData 00077 00078 00079 virtual void 00080 doSendData(const wns::ldk::CompoundPtr& compound) 00081 { 00082 if((rand() / (RAND_MAX + 1.0)) < loss) { 00083 return; 00084 } 00085 00086 other->getDeliverer()->getAcceptor(compound)->onData(compound); 00087 } // doSendData 00088 00089 void 00090 setLoss(double _loss) 00091 { 00092 assure(_loss >= 0.0 && _loss <= 1.0, "Invalid loss value."); 00093 00094 loss = _loss; 00095 } 00096 00097 private: 00098 virtual bool 00099 doIsAccepting(const wns::ldk::CompoundPtr& /* compound */ ) const 00100 { 00101 return true; 00102 } 00103 00104 virtual void 00105 doWakeup() 00106 {} 00107 00108 FunctionalUnit* other; 00109 double loss; 00110 }; 00111 } 00112 00113 00126 class Bridge 00127 { 00128 public: 00139 Bridge(fun::FUN* leftFUN, fun::FUN* rightFUN, double loss = 0.0); 00140 virtual ~Bridge(); 00141 00146 bridge::Forwarder* getLeft() const 00147 { 00148 return a; 00149 } 00150 00155 bridge::Forwarder* getRight() const 00156 { 00157 return b; 00158 } 00159 00165 void setLoss(double loss) 00166 { 00167 a->setLoss(loss); 00168 b->setLoss(loss); 00169 } 00170 00171 private: 00172 bridge::Forwarder *a; 00173 bridge::Forwarder *b; 00174 }; 00175 00176 }}} 00177 00178 00179 #endif // NOT defined WNS_LDK_TOOLS_BRIDGE_HPP 00180 00181
1.5.5