![]() |
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 #include <GLUE/mac/Aloha.hpp> 00014 #include <WNS/container/UntypedRegistry.hpp> 00015 #include <WNS/events/MemberFunction.hpp> 00016 #include <WNS/simulator/ISimulator.hpp> 00017 00018 using namespace glue; 00019 00020 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00021 Aloha, 00022 wns::ldk::FunctionalUnit, 00023 "glue.mac.Aloha", 00024 wns::ldk::FUNConfigCreator); 00025 00026 00027 Aloha::Aloha(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& config) : 00028 wns::ldk::CommandTypeSpecifier<AlohaCommand>(fun), 00029 wns::ldk::HasReceptor<>(), 00030 wns::ldk::HasConnector<>(), 00031 wns::ldk::HasDeliverer<>(), 00032 wns::Cloneable<Aloha>(), 00033 logger(config.get("logger")), 00034 allowTransmission(false), 00035 maxWait(config.get<wns::simulator::Time>("maximumWaitingTime")), 00036 uniform(0.0, 1.0, wns::simulator::getRNG()) 00037 { 00038 MESSAGE_SINGLE(NORMAL, this->logger, "created"); 00039 00040 wns::simulator::Time randomBackoff = uniform() * this->maxWait; 00041 MESSAGE_SINGLE( 00042 NORMAL, 00043 this->logger, 00044 "First Compound will be sent in " << randomBackoff << " seconds the earliest"); 00045 wns::events::MemberFunction<Aloha> ev (this, &Aloha::allowTransmissionAfterElapsedBackoff); 00046 wns::simulator::getEventScheduler()->scheduleDelay(ev, randomBackoff); 00047 } 00048 00049 00050 Aloha::~Aloha() 00051 { 00052 00053 } 00054 00055 00056 bool 00057 Aloha::doIsAccepting(const wns::ldk::CompoundPtr& /*_compound*/) const 00058 { 00059 return allowTransmission; 00060 } 00061 00062 00063 void 00064 Aloha::doSendData(const wns::ldk::CompoundPtr& compound) 00065 { 00066 assure(allowTransmission, "doSendData called although backoff timer has not yet elapsed"); 00067 assure(this->getConnector()->hasAcceptor(compound) == true, "Not able to send data. Aloha may only be used over NON-BLOCKING PHYs"); 00068 00069 MESSAGE_SINGLE(NORMAL, this->logger, "Sending compound: " << *compound); 00070 this->getConnector()->getAcceptor(compound)->sendData(compound); 00071 00072 allowTransmission = false; 00073 00074 // start random backoff for the next compound 00075 wns::simulator::Time randomBackoff = uniform() * this->maxWait; 00076 MESSAGE_SINGLE( 00077 NORMAL, 00078 this->logger, 00079 "Next Compound ("<< *compound <<") will be sent in " << randomBackoff << " seconds the earliest"); 00080 wns::events::MemberFunction<Aloha> ev (this, &Aloha::allowTransmissionAfterElapsedBackoff); 00081 wns::simulator::getEventScheduler()->scheduleDelay(ev, randomBackoff); 00082 } 00083 00084 void 00085 Aloha::doWakeup() 00086 { 00087 // simply forward the wakeup call 00088 this->getReceptor()->wakeup(); 00089 } 00090 00091 00092 void 00093 Aloha::doOnData(const wns::ldk::CompoundPtr& compound) 00094 { 00095 this->getDeliverer()->getAcceptor(compound)->onData(compound); 00096 } 00097 00098 00099 void 00100 Aloha::allowTransmissionAfterElapsedBackoff() 00101 { 00102 allowTransmission = true; 00103 this->getReceptor()->wakeup(); 00104 }
1.5.5