User Manual, Developers Guide and API Documentation

LowerConvergence.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/LowerConvergence.hpp>
00029 #include <IP/Routing.hpp>
00030 #include <IP/trace/PacketTrace.hpp>
00031 
00032 #include <WNS/module/Base.hpp>
00033 
00034 
00035 using namespace ip;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00038     LowerConvergence,
00039     wns::ldk::FunctionalUnit,
00040     "ip.lowerConvergence",
00041     wns::ldk::FUNConfigCreator);
00042 
00043 LowerConvergence::LowerConvergence(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::Cloneable<LowerConvergence>(),
00049     ipHeaderReader(NULL),
00050     pyco(_pyco),
00051     //log("IP", "IP.LowerConvergence", wns::module::Base::getService<wns::logger::Master>("W-NS-MSG"))
00052     log(_pyco.get("logger"))
00053 {
00054 }
00055 
00056 LowerConvergence::~LowerConvergence()
00057 {
00058 }
00059 
00060 void
00061 LowerConvergence::onFUNCreated()
00062 {
00063     ipHeaderReader = getFUN()->getCommandReader("ip.ipHeader");
00064     assure(ipHeaderReader, "No reader for the IP Header available!");
00065 }
00066 
00067 void
00068 LowerConvergence::setDLLs(container::DataLinkContainer _dlls)
00069 {
00070     this->dlls = _dlls;
00071 }
00072 
00073 void
00074 LowerConvergence::doSendData(const wns::ldk::CompoundPtr& compound)
00075 {
00076     assure(compound, "sendData called with an invalid compound.");
00077 
00078     assure(ipHeaderReader, "No reader for the IP Header available!");
00079     IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(compound->getCommandPool());
00080 
00081     // 1. Retrieve NextHop Address from compound
00082     // 2. Retrieve DLLName from compound
00083     // 3. See if ARP on this DLL knows the NextHop
00084     // 4a. Positve dll->sendData to the corresponding MAC Id
00085     // 4b. Negative Destination Unreachable
00086 
00087 
00088     // 3. See if ARP on this DLL knows the NextHop
00089     try{
00090         container::DataLink dll = dlls.find(ipHeader->local.dllName);
00091 
00092         MESSAGE_BEGIN(NORMAL, log, m, "");
00093         m << "nextHop : " << ipHeader->local.nextHop
00094           << " -> macId : " << ipHeader->local.macID
00095           << " DLL FlowID : " << ipHeader->local.dllFlowID;
00096         MESSAGE_END();
00097 
00098         dll.dts->sendData(ipHeader->local.macID, compound, wns::service::dll::IP, ipHeader->local.dllFlowID);
00099 
00100         if (dll.traceEnabled == true)
00101         {
00102             trace::PacketTrace pt(wns::simulator::getEventScheduler()->getTime(),
00103                                   ipHeader->local.macID,
00104                                   dll.dts->getMACAddress(),
00105                                   ipHeader->peer.source,
00106                                   ipHeader->peer.destination,
00107                                   ipHeader->peer.TTL,
00108                                   ipHeader->peer.protocol,
00109                                   compound->getData()->getLengthInBits());
00110 
00111             assure(dll.traceCollector, "No TraceCollector given in DataLink structure");
00112             dll.traceCollector->addPacketTrace(pt);
00113         }
00114     }
00115     catch(container::DataLinkContainer::UnknownKeyValue)
00116       {
00117           MESSAGE_BEGIN(NORMAL, log, m, "Destination unreachable : ");
00118           m << ipHeader->local.nextHop;
00119           m << " via iface : " << ipHeader->local.dllName;
00120           MESSAGE_END()
00121       }
00122 }
00123 
00124 bool
00125 LowerConvergence::doIsAccepting(const wns::ldk::CompoundPtr& /* compound */) const
00126 {
00127     return true;
00128 }
00129 
00130 void
00131 LowerConvergence::doOnData(const wns::ldk::CompoundPtr& compound)
00132 {
00133     // test:
00134     assure(compound, "onData called with an invalid compound.");
00135 
00136     // end test;
00137 
00138     assure(compound != wns::ldk::CompoundPtr(), "onData called with an invalid compound.");
00139 
00140     MESSAGE_BEGIN(NORMAL, log, m, getFUN()->getName());
00141     m << ": doOnData(), forwading to higher FU";
00142     MESSAGE_END();
00143 
00144     getDeliverer()->getAcceptor(compound)->onData(compound);
00145 
00146     // We now activate upper FUs to try to send their pending data
00147     getReceptor()->wakeup();
00148 }
00149 
00150 void
00151 LowerConvergence::doWakeup()
00152 {
00153 }
00154 
00155 void
00156 LowerConvergence::onData(const wns::osi::PDUPtr& pdu, wns::service::dll::FlowID dllFlowID)
00157 {
00158     MESSAGE_BEGIN(NORMAL, log, m,"" );
00159     m << "Incoming PDU with DLLFlowID: "<< dllFlowID;
00160     MESSAGE_END();
00161 
00162     assure(wns::dynamicCast<wns::ldk::Compound>(pdu), "not a CompoundPtr");
00163     wns::ldk::CompoundPtr compound = wns::staticCast<wns::ldk::Compound>(pdu)->copy();
00164 
00165     assure(ipHeaderReader, "No reader for the IP Header available!");
00166     IPCommand* ipHeader = ipHeaderReader->readCommand<IPCommand>(compound->getCommandPool());
00167     assure(ipHeader, "IP Header not set");
00168     ipHeader->local.dllFlowID = dllFlowID;
00169 
00170     this->wns::ldk::FunctionalUnit::onData(compound);
00171 }

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