![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * Glue * 00003 * __________________________________________________________________________ * 00004 * * 00005 * Copyright (C) 2005-2006 * 00006 * Lehrstuhl fuer Kommunikationsnetze (ComNets) * 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany * 00008 * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242 * 00009 * email: wns@comnets.rwth-aachen.de * 00010 * www: http://wns.comnets.rwth-aachen.de * 00011 ******************************************************************************/ 00012 00013 #ifndef GLUE_CONVERGENCE_UPPER_HPP 00014 #define GLUE_CONVERGENCE_UPPER_HPP 00015 00016 #include <DLL/UpperConvergence.hpp> 00017 00018 #include <WNS/logger/Logger.hpp> 00019 #include <WNS/ldk/CommandTypeSpecifier.hpp> 00020 #include <WNS/ldk/HasConnector.hpp> 00021 #include <WNS/ldk/HasReceptor.hpp> 00022 #include <WNS/ldk/HasDeliverer.hpp> 00023 #include <WNS/ldk/Forwarding.hpp> 00024 #include <WNS/ldk/Command.hpp> 00025 #include <WNS/node/component/Interface.hpp> 00026 00027 #include <WNS/pyconfig/View.hpp> 00028 00029 namespace glue { namespace convergence { 00030 00034 class UpperCommand : 00035 public wns::ldk::Command 00036 { 00037 public: 00038 struct Local { 00039 } local; 00040 struct Peer { 00041 wns::service::dll::UnicastAddress sourceMACAddress; 00042 } peer; 00043 struct Magic { 00044 } magic; 00045 protected: 00046 UpperCommand() 00047 { 00048 this->peer.sourceMACAddress = wns::service::dll::UnicastAddress(); 00049 } 00050 }; // UpperCommand 00051 00055 class UnicastUpperCommand : 00056 public UpperCommand 00057 { 00058 public: 00059 typedef wns::service::dll::UnicastAddress Address; 00060 00061 UnicastUpperCommand() 00062 { 00063 } // UnicastUpperCommand 00064 00065 struct Peer : 00066 public UpperCommand::Peer 00067 { 00068 Address targetMACAddress; 00069 } peer; 00070 }; // UnicastUpperCommand 00071 00072 00077 class BroadcastUpperCommand : 00078 public UpperCommand 00079 { 00080 public: 00081 typedef wns::service::dll::BroadcastAddress Address; 00082 00086 BroadcastUpperCommand() 00087 { 00088 } // BroadcastUpperCommand 00089 00093 struct Peer : 00094 public UpperCommand::Peer 00095 { 00096 Address targetMACAddress; 00097 } peer; 00098 }; // BroadcastUpperCommand 00099 00106 template<class COMMAND> 00107 class Upper : 00108 virtual public wns::service::dll::DataTransmission<typename COMMAND::Address>, 00109 virtual public wns::service::dll::Notification, 00110 public wns::ldk::CommandTypeSpecifier<COMMAND>, 00111 public wns::ldk::HasReceptor<>, 00112 public wns::ldk::HasConnector<>, 00113 public wns::ldk::HasDeliverer<>, 00114 public wns::ldk::FunctionalUnit, 00115 public wns::Cloneable< Upper<COMMAND> > 00116 { 00117 public: 00118 using FunctionalUnit::sendData; 00119 typedef COMMAND Command; 00120 00121 Upper(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00122 wns::ldk::CommandTypeSpecifier<Command>(fun), 00123 wns::ldk::HasReceptor<>(), 00124 wns::ldk::HasConnector<>(), 00125 wns::ldk::HasDeliverer<>(), 00126 wns::ldk::FunctionalUnit(), 00127 wns::Cloneable<Upper>(), 00128 00129 logger_(config.get<wns::pyconfig::View>("logger")), 00130 sourceMACAddress_() 00131 { 00132 } // Upper 00133 00134 virtual void 00135 registerFlowHandler(wns::service::dll::FlowHandler*){}; 00136 00137 virtual void 00138 registerIRuleControl(wns::service::dll::IRuleControl*){}; 00139 00140 virtual void 00141 registerHandler(wns::service::dll::protocolNumber protocol, wns::service::dll::Handler* dh) 00142 { 00143 if (NULL == dh) 00144 { 00145 throw wns::Exception("invalid data handler (NULL)"); 00146 } 00147 assure(!dataHandlerRegistry_.knows(protocol), "data handler already set"); 00148 dataHandlerRegistry_.insert(protocol, dh); 00149 } // registerHandler 00150 00151 virtual void 00152 setMACAddress(const wns::service::dll::UnicastAddress& sourceMACAddress) 00153 { 00154 sourceMACAddress_ = sourceMACAddress; 00155 } // setMACAddress 00156 00157 virtual void 00158 sendData(const typename Command::Address& targetMACAddress, 00159 const wns::osi::PDUPtr& sdu, 00160 wns::service::dll::protocolNumber protocol, 00161 int /* _dllFlowID = 0 */) 00162 { 00163 sdu->setPDUType(protocol); 00164 wns::ldk::CompoundPtr compound( 00165 new wns::ldk::Compound( 00166 this->getFUN()->getProxy()->createCommandPool(), sdu)); 00167 00168 Command* command = this->activateCommand(compound->getCommandPool()); 00169 command->peer.sourceMACAddress = sourceMACAddress_; 00170 command->peer.targetMACAddress = targetMACAddress; 00171 00172 sendData(compound); 00173 } // sendData 00174 00175 virtual wns::service::dll::UnicastAddress 00176 getMACAddress() const 00177 { 00178 return sourceMACAddress_; 00179 } 00180 00181 protected: 00182 wns::logger::Logger logger_; 00183 wns::service::dll::UnicastAddress sourceMACAddress_; 00184 00185 private: 00189 typedef wns::container::Registry<wns::service::dll::protocolNumber, wns::service::dll::Handler*> DataHandlerRegistry; 00190 00191 virtual void 00192 doOnData(const wns::ldk::CompoundPtr& compound) 00193 { 00194 MESSAGE_BEGIN(NORMAL, logger_, m, this->getFUN()->getName()); 00195 m << ": doOnData(), forwarding to upper Component"; 00196 MESSAGE_END(); 00197 00198 MESSAGE_BEGIN(VERBOSE, logger_, m, this->getFUN()->getName()); 00199 m << ": Compound backtrace" 00200 << compound->dumpJourney(); // JOURNEY 00201 MESSAGE_END(); 00202 00203 // Forward to upper layer 00204 try 00205 { 00206 wns::service::dll::protocolNumber protocolNr = 00207 wns::service::dll::protocolNumberOf(compound->getData()); 00208 00209 wns::service::dll::Handler* handler = dataHandlerRegistry_.find(protocolNr); 00210 ; 00211 handler->onData(compound->getData()); 00212 } 00213 catch(const DataHandlerRegistry::UnknownKeyValue& ukv) 00214 { 00215 wns::Exception e; 00216 e << "No handler for this upper layer protocol registered.\n"; 00217 e << ukv; 00218 throw e; 00219 } 00220 catch(...) 00221 { 00222 throw; 00223 } 00224 } // doOnData 00225 00226 virtual void 00227 doSendData(const wns::ldk::CompoundPtr& compound) 00228 { 00229 if (this->isAccepting(compound)) { 00230 this->getConnector()->getAcceptor(compound)->sendData(compound); 00231 } 00232 } // doSendData 00233 00234 virtual bool 00235 doIsAccepting(const wns::ldk::CompoundPtr& compound) const 00236 { 00237 return this->getConnector()->hasAcceptor(compound); 00238 } // doIsAccepting 00239 00240 virtual void 00241 doWakeup() 00242 { 00243 getReceptor()->wakeup(); 00244 } // doWakeUp 00245 00250 DataHandlerRegistry dataHandlerRegistry_; 00251 }; // class Upper 00252 00256 class UnicastUpper : 00257 public Upper<UnicastUpperCommand> 00258 { 00259 public: 00263 UnicastUpper(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00264 Upper<UnicastUpperCommand>(fun, config) 00265 { 00266 } // UnicastUpper 00267 00271 virtual wns::ldk::CommandPool* 00272 createReply(const wns::ldk::CommandPool* original) const; 00273 }; // UnicastUpper 00274 00279 class BroadcastUpper : 00280 public Upper<BroadcastUpperCommand> 00281 { 00282 public: 00286 BroadcastUpper(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00287 Upper<BroadcastUpperCommand>(fun, config) 00288 { 00289 } // BroadcastUpper 00290 00294 virtual wns::ldk::CommandPool* 00295 createReply(const wns::ldk::CommandPool* original) const; 00296 }; // BroadcastUpper 00297 } 00298 } 00299 00300 #endif // NOT defined GLUE_CONVERGENCE_UPPER_HPP
1.5.5