User Manual, Developers Guide and API Documentation

UpperConvergence.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-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 #include <IP/UpperConvergence.hpp>
00029 
00030 #include <WNS/module/Base.hpp>
00031 #include <WNS/Assure.hpp>
00032 
00033 #include <iomanip>
00034 
00035 using namespace ip;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00038     UpperConvergence,
00039     wns::ldk::FunctionalUnit,
00040     "ip.upperConvergence",
00041     wns::ldk::FUNConfigCreator);
00042 
00043 UpperConvergence::UpperConvergence(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& _pyco) :
00044     wns::ldk::CommandTypeSpecifier<>(fun),
00045     wns::ldk::HasReceptor<>(),
00046     wns::ldk::HasConnector<>(),
00047     wns::ldk::HasDeliverer<>(),
00048     wns::ldk::Forwarding<UpperConvergence>(),
00049     wns::Cloneable<UpperConvergence>(),
00050     pyco(_pyco),
00051     //log("IP", "IP.UpperConvergence", wns::module::Base::getService<wns::logger::Master>("W-NS-MSG")),
00052     log(_pyco.get("logger")),
00053     ipHeaderReader(NULL),
00054     ipHeaderFU(NULL)
00055 {
00056     MESSAGE_SINGLE(VERBOSE, log, "UpperConvergence started.");
00057 }
00058 
00059 void
00060 UpperConvergence::onFUNCreated()
00061 {
00062     ipHeaderFU = getFUN()->findFriend<IPHeader*>("ip.ipHeader");
00063     assure(ipHeaderFU, "No FU for the IP Header available!");
00064     ipHeaderReader = getFUN()->getCommandReader("ip.ipHeader");
00065     assure(ipHeaderReader, "No reader for the IP Header available!");
00066 } // onFUNCreated
00067 
00068 void
00069 UpperConvergence::sendData(
00070     const wns::service::nl::Address& sourceAddress,
00071     const wns::service::nl::Address& peerAddress,
00072     const wns::osi::PDUPtr& sdu,
00073     wns::service::nl::protocolNumber protocol,
00074     wns::service::dll::FlowID dllFlowID)
00075 {
00076     Bit payloadSize = sdu->getLengthInBits();
00077 
00078     MESSAGE_BEGIN(NORMAL, log, m, "OUT : " << std::setw(18) << sourceAddress);
00079     m << " -> " << std::setw(18) << peerAddress;
00080     m << " (" << payloadSize/8 << " bytes)";
00081     m << " DLL FlowID : " << dllFlowID;
00082     MESSAGE_END()
00083 
00084     wns::ldk::CompoundPtr compound(new wns::ldk::Compound(getFUN()->getProxy()->createCommandPool(), sdu));
00085 
00086     assure(ipHeaderFU, "No FU for the IP Header available!");
00087     ipHeaderFU->activateCommand(compound->getCommandPool());
00088 
00089     assure(ipHeaderReader, "No reader for the IP Header available!");
00090     IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(compound->getCommandPool());
00091 
00092     ipHeader->peer.destination = peerAddress;
00093     ipHeader->peer.source = sourceAddress;
00094     ipHeader->peer.protocol = protocol;
00095     ipHeader->local.dllFlowID = dllFlowID;
00096 
00097     if(this->isAccepting(compound)) {
00098         wns::ldk::Forwarding<UpperConvergence>::doSendData(compound);
00099     } else {
00100         // do nothing (throw away compound)
00101     }
00102 }
00103 
00104 void
00105 UpperConvergence::processIncoming(const wns::ldk::CompoundPtr& compound)
00106 {
00107     assure(ipHeaderReader, "No reader for the IP Header available!");
00108     IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(compound->getCommandPool());
00109 
00110     assure(handlerRegistry.knows(ipHeader->peer.protocol), "No DataHandler for protocol ");
00111 
00112     MESSAGE_BEGIN(NORMAL, log, m, "IN  : " << std::setw(18) << ipHeader->peer.destination);
00113     m << " <- " << std::setw(18) << ipHeader->peer.source;
00114     m << " (" << compound->getData()->getLengthInBits()/8 << " bytes)";
00115     MESSAGE_END()
00116 
00117     handlerRegistry.find(ipHeader->peer.protocol)->onData(ipHeader->peer.source, compound->getData());
00118 }
00119 
00120 void
00121 UpperConvergence::registerHandler(wns::service::nl::protocolNumber  protocol, wns::service::nl::DataHandler* _dh)
00122 {
00123     assure(_dh, "No valid Handler!");
00124 
00125     this->handlerRegistry.insert(protocol, _dh);
00126 }
00127 
00128 const wns::service::nl::Address&
00129 UpperConvergence::getAddress() const
00130 {
00131     return sourceAddress;
00132 }
00133 
00134 void
00135 UpperConvergence::setSourceAddress(wns::service::nl::Address src)
00136 {
00137     sourceAddress = src;
00138 }

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