Nps.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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(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
00077 {
00078 friend class Landmark;
00079
00080 private:
00081 NeighborCache* neighborCache;
00082 GlobalNodeList* globalNodeList;
00083 CoordBasedRouting* coordBasedRouting;
00084
00085 uint8_t npsMaxLayer;
00086 uint8_t npsDimensions;
00087 simtime_t landmarkTimeout;
00088
00089 std::vector<double> ownCoordinates;
00090 int8_t ownLayer;
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 initNps(NeighborCache* neighborCache);
00104
00105 void handleTimerEvent(cMessage* msg);
00106 void coordsReqRpc(CoordsReqCall* msg);
00107
00108 Prox getCoordinateBasedProx(const NodeCoordsInfo& info);
00109
00110 const std::vector<double>& getOwnCoordinates() const { return ownCoordinates; };
00111 double getOwnCoordinates(uint8_t i) const { return ownCoordinates[i]; };
00112 uint8_t getOwnLayer() const { return ownLayer; };
00113
00114 protected:
00118 void computeOwnLayer (const std::vector<LandmarkDataEntry>& landmarks);
00119
00123 void computeOwnCoordinates (const std::vector<LandmarkDataEntry>& landmarks);
00124
00128 void setOwnLayer(int8_t layer);
00129 void setOwnCoordinates(const std::vector<double>& coords) { ownCoordinates = coords; };
00130
00135 void sendCoordRequests();
00136 void sendCoordRequests(const std::vector<TransportAddress>& landmarks);
00137 void sendCoordsReqCall(const TransportAddress& dest,
00138 simtime_t timeout);
00139
00140 void handleRpcResponse(BaseResponseMessage* msg,
00141 cPolymorphic* context,
00142 int rpcId, simtime_t rtt);
00143
00144 void handleRpcTimeout(BaseCallMessage* msg,
00145 const TransportAddress& dest,
00146 cPolymorphic* context, int rpcId,
00147 const OverlayKey& destKey);
00148
00149 void coordsReqRpcResponse(CoordsReqResponse* response,
00150 cPolymorphic* context,
00151 int rpcId, simtime_t rtt);
00152
00156 void showReceivedCoords();
00157
00158 std::vector<LandmarkDataEntry> getLandmarkData() const;
00159 std::vector<TransportAddress> getLandmarks(uint8_t howmany);
00160 const std::vector<TransportAddress>& getLandmarkSet() const { return landmarkSet; };
00161 uint16_t getLandmarkSetSize() const { return landmarkSet.size(); };
00162 bool setLandmarkSet(uint8_t dim, uint8_t maxLayer);
00163 bool enoughLandmarks();
00164
00165 std::vector<RttMeasurement> nodeMeasurements;
00166
00167 void updateNodeMeasurement(const TransportAddress& node,
00168 uint8_t pending = 0,
00169 uint8_t sent = 0,
00170 uint8_t passed = 0);
00171
00172 void deleteNodeMeasurement(const TransportAddress& node);
00173
00174 uint16_t getReceivedCalls() const { return receivedCalls; };
00175 };
00176
00177 #endif