Landmark.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #include <cassert>
00025 
00026 #include <SimpleUnderlayConfigurator.h>
00027 #include <BootstrapList.h>
00028 //#include <CoordBasedRouting.h>
00029 #include <NeighborCache.h>
00030 #include <GlobalNodeList.h>
00031 #include <GlobalStatistics.h>
00032 //#include <CoordMessages_m.h>
00033 
00034 #include "Landmark.h"
00035 
00036 Define_Module(Landmark);
00037 
00038 Landmark::~Landmark() {
00039 }
00040 
00041 void Landmark::initializeApp(int stage)
00042 {
00043     if (stage != MIN_STAGE_APP)
00044         return;
00045 
00046     SimpleNodeEntry* entry =
00047         dynamic_cast<SimpleInfo*>(globalNodeList->
00048                                   getPeerInfo(thisNode.getAddress()))->getEntry();
00049 
00050     //globalNodeList->setOverlayReadyIcon(getThisNode(), false);
00051 
00052     // Get the responsible Landmark churn generator
00053     ChurnGenerator* lmChurnGen = NULL;
00054     for (uint8_t i = 0; i < underlayConfigurator->getChurnGeneratorNum(); i++) {
00055         ChurnGenerator* searchedGen;
00056         searchedGen = underlayConfigurator->getChurnGenerator(i);
00057         if (searchedGen->getNodeType().overlayType == "oversim.common.cbr.LandmarkModules") {
00058             lmChurnGen = searchedGen;
00059         }
00060     }
00061 
00062     // If number of landmarks < dim+1: Place magic landmark
00063     // Else: BaseOverlay will take care of the coordinate calculation
00064     //if (!neighborCache->coordBasedRouting) return;
00065 
00066     //uint8_t dim = neighborCache->/*coordBasedRouting->*/getXmlDimensions();
00067     //if (lmChurnGen && lmChurnGen->terminalCount < dim + 1) {
00068         //PeerInfo* thisInfo = globalNodeList->getPeerInfo(getThisNode());
00069 
00070     if (true) { //TODO
00071         // magic placement using underlays coords
00072         //std::vector<double> coords;
00073         for (uint8_t i = 0; i < entry->getDim(); i++) {
00074             ownCoords.push_back(entry->getCoords(i));
00075         }
00076 
00077         //neighborCache->nps->setOwnCoordinates(coords);
00078         neighborCache->getNpsAccess().setOwnLayer(0);
00079 
00080         thisNode = overlay->getThisNode();
00081         globalNodeList->setOverlayReadyIcon(getThisNode(), true);
00082         globalNodeList->refreshEntry(getThisNode());
00083     } else {
00084         //TODO
00085     }
00086 
00087     WATCH_VECTOR(ownCoords);
00088 }
00089 
00090 /*
00091 void Landmark::joinOverlay() {
00092     // Coordinate calculation via BaseOverlay finished
00093     // Simple Layer 1 node now, ignoring NodeID stuff
00094     globalNodeList->setOverlayReadyIcon(getThisNode(), true);
00095     globalNodeList->refreshEntry(getThisNode());
00096     state = READY;
00097 }
00098 */
00099 
00100 void Landmark::finishApp()
00101 {
00102     if (neighborCache->getNpsAccess().getReceivedCalls() != 0) {
00103         globalStatistics->recordOutVector("Calls to Landmarks",
00104             neighborCache->getNpsAccess().getReceivedCalls());
00105     }
00106 }
00107 
00108 /*
00109 void Landmark::handleUDPMessage(BaseOverlayMessage* msg) {
00110     std::cout << "I received something!" << endl;
00111 }
00112 
00113 void Landmark::handleTimerEvent(cMessage* msg) {
00114 }
00115 
00116 void Landmark::handleRpcResponse(BaseResponseMessage *msg,
00117                                      cPolymorphic* context,
00118                                      int rpcId, simtime_t rtt) {
00119 }
00120 
00121 void Landmark::handleRpcTimeout(BaseCallMessage *msg,
00122                                     const TransportAddress &dest,
00123                                     cPolymorphic* context, int rpcId,
00124                                     const OverlayKey &destKey) {
00125 }
00126 
00127 void Landmark::updateTooltip() {
00128 }
00129 
00130 NodeVector* Landmark::findNode(const OverlayKey& key,
00131                              int numRedundantNodes,
00132                              int numSiblings,
00133                              BaseOverlayMessage* msg) {
00134     NodeVector* dummy = new NodeVector(0);
00135     return dummy;
00136 }
00137 */
00138 /*
00139 bool Landmark::handleRpcCall(BaseCallMessage* msg)
00140 {
00141     RPC_SWITCH_START( msg );
00142         RPC_DELEGATE( CoordsOfNode, coordsOfNodeRpc);
00143 #ifdef EXTJOIN_DISCOVERY
00144         RPC_DELEGATE( RttToNode, rttToNodeRpc);
00145 #endif
00146     RPC_SWITCH_END( );
00147 
00148     return RPC_HANDLED;// || BaseRpc::internalHandleRpcCall(msg);
00149 }
00150 
00151 void Landmark::coordsOfNodeRpc(CoordsOfNodeCall* msg)
00152 {
00153     neighborCache->incReceivedCalls();
00154     CoordsOfNodeResponse* coordRes = new CoordsOfNodeResponse("CoordsOfNodeRes");
00155     coordRes->setLayer(neighborCache->getOwnLayer());
00156     std::vector<double> ownCoordinates = neighborCache->getOwnCoordinates();
00157     uint dim = neighborCache->getXmlDimensions();
00158     coordRes->setCoordsArraySize(dim);
00159     for (uint i = 0; i < ownCoordinates.size(); i++) {
00160         coordRes->setCoords(i, ownCoordinates[i]);
00161     }
00162 //    coordRes->setLength(COORDRESPONSE_L(coordRes));
00163     sendRpcResponse(msg, coordRes);
00164 }
00165 */

Generated on Tue Sep 8 17:26:53 2009 for OverSim by  doxygen 1.5.8