Nps.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2009 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 #ifndef NPS_H_
00025 #define NPS_H_
00026 
00027 #include <yang.h>
00028 #include <simplex.h>
00029 
00030 #include <RpcListener.h>
00031 #include <Nps_m.h>
00032 #include <CoordinateSystem.h>
00033 
00034 class CoordBasedRouting;
00035 
00040 struct LandmarkDataEntry
00041 {
00042     simtime_t rtt;
00043     int8_t layer;
00044     std::vector<double> coordinates;
00045     const IPvXAddress* ip;
00046 };
00047 
00048 struct RttMeasurement
00049 {
00050     TransportAddress measuredNode;
00051     char rttsPending;
00052     char rttsSent;
00053     char coordsPassed;
00054 #ifdef EXTJOIN_DISCOVERY
00055     RttToNodeCall* message;
00056 #endif
00057 };
00058 
00062 class CoordCalcFunction
00063 {
00064   private:
00065     std::vector<LandmarkDataEntry> landmarks;
00066 
00067     double endnodeDistance(const Vec_DP& nodeCoordinates,
00068                            LandmarkDataEntry landmark) const;
00069 
00070   public:
00071     CoordCalcFunction(const std::vector<LandmarkDataEntry> myLandmarks) : landmarks(myLandmarks) { };
00072     double f(const Vec_DP& initCoordinates) const;
00073     static double simplex_min(CoordCalcFunction *functionObject, Vec_DP& init);
00074 };
00075 
00076 class Nps : public RpcListener, public AbstractNcs
00077 {
00078     friend class Landmark;
00079 
00080   private:
00081     NeighborCache* neighborCache;
00082     BaseOverlay* overlay;
00083     GlobalNodeList* globalNodeList;
00084     CoordBasedRouting* coordBasedRouting;
00085 
00086     uint8_t npsMaxLayer;
00087     uint8_t npsDimensions;
00088     simtime_t landmarkTimeout;
00089 
00090     GnpNpsCoordsInfo* ownCoords; //TODO
00091 
00092     int16_t pendingRequests;
00093     uint8_t coordCalcRuns;
00094 
00095     std::vector<TransportAddress> landmarkSet;
00096 
00097     uint16_t receivedCalls;
00098 
00099     cMessage* landmarkTimer;
00100 
00101   public:
00102     Nps() {};
00103     void init(NeighborCache* neighborCache);
00104 
00105     virtual bool isAdapting() { return false; }
00106     void handleTimerEvent(cMessage* msg);
00107     virtual bool handleRpcCall(BaseCallMessage* msg);
00108 
00109     Prox getCoordinateBasedProx(const AbstractNcsNodeInfo& info) const;
00110     AbstractNcsNodeInfo* getUnvalidNcsInfo() const {return new GnpNpsCoordsInfo; };
00111     AbstractNcsNodeInfo* createNcsInfo(const std::vector<double>& coords) const;
00112     virtual const AbstractNcsNodeInfo& getOwnNcsInfo() const { return *ownCoords; };
00113 
00114     const std::vector<double>& getOwnCoordinates() const { return ownCoords->getCoords(); };
00115     double getOwnCoordinates(uint8_t i) const { return ownCoords->getCoords(i); };
00116     uint8_t getOwnLayer() const { return ownCoords->getLayer(); };
00117 
00118   protected:
00122     void computeOwnLayer (const std::vector<LandmarkDataEntry>& landmarks);
00123 
00127     void computeOwnCoordinates (const std::vector<LandmarkDataEntry>& landmarks);
00128 
00132     void setOwnLayer(int8_t layer);
00133     void setOwnCoordinates(const std::vector<double>& coords) {
00134         for (uint8_t i = 0; i < coords.size(); ++i) {
00135             ownCoords->setCoords(i, coords[i]);
00136         }
00137     };
00138 
00143     void sendCoordRequests();
00144     void sendCoordRequests(const std::vector<TransportAddress>& landmarks);
00145     void sendCoordsReqCall(const TransportAddress& dest,
00146                               simtime_t timeout);
00147 
00148     void handleRpcResponse(BaseResponseMessage* msg,
00149                            cPolymorphic* context,
00150                            int rpcId, simtime_t rtt);
00151 
00152     void handleRpcTimeout(BaseCallMessage* msg,
00153                           const TransportAddress& dest,
00154                           cPolymorphic* context, int rpcId,
00155                           const OverlayKey& destKey);
00156 
00157     void coordsReqRpcResponse(CoordsReqResponse* response,
00158                               cPolymorphic* context,
00159                               int rpcId, simtime_t rtt);
00160 
00161     void coordsReqRpc(CoordsReqCall* msg);
00162 
00163     std::vector<LandmarkDataEntry> getLandmarkData() const;
00164 
00171     std::vector<TransportAddress> getLandmarks(uint8_t howmany);
00172     const std::vector<TransportAddress>& getLandmarkSet() const { return landmarkSet; };
00173     uint16_t getLandmarkSetSize() const { return landmarkSet.size(); };
00174     //bool setLandmarkSet(uint8_t dim, uint8_t maxLayer);
00175     bool setLandmarkSet(uint8_t howManyLM, uint8_t maxLayer,
00176                         std::vector<TransportAddress>* landmarkSet);
00177     bool enoughLandmarks();
00178 
00179     std::vector<RttMeasurement> nodeMeasurements;
00180 
00181     void updateNodeMeasurement(const TransportAddress& node,
00182                                uint8_t pending = 0,
00183                                uint8_t sent = 0,
00184                                uint8_t passed = 0);
00185 
00186     void deleteNodeMeasurement(const TransportAddress& node);
00187 
00188     uint16_t getReceivedCalls() const { return receivedCalls; };
00189 };
00190 
00191 #endif /* NPS_H_ */
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3