OverSim
Nps.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2009 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef NPS_H_
25 #define NPS_H_
26 
27 #include <yang.h>
28 #include <simplex.h>
29 
30 #include <RpcListener.h>
31 #include <Nps_m.h>
32 #include <CoordinateSystem.h>
33 
34 class CoordBasedRouting;
35 
41 {
42  simtime_t rtt;
43  int8_t layer;
44  std::vector<double> coordinates;
45  const IPvXAddress* ip;
46 };
47 
49 {
52  char rttsSent;
54 #ifdef EXTJOIN_DISCOVERY
55  RttToNodeCall* message;
56 #endif
57 };
58 
63 {
64  private:
65  std::vector<LandmarkDataEntry> landmarks;
66 
67  double endnodeDistance(const Vec_DP& nodeCoordinates,
68  LandmarkDataEntry landmark) const;
69 
70  public:
71  CoordCalcFunction(const std::vector<LandmarkDataEntry> myLandmarks) : landmarks(myLandmarks) { };
72  double f(const Vec_DP& initCoordinates) const;
73  static double simplex_min(CoordCalcFunction *functionObject, Vec_DP& init);
74 };
75 
76 class Nps : public RpcListener, public AbstractNcs
77 {
78  friend class Landmark;
79 
80  private:
85 
86  uint8_t maxLayer;
87  uint8_t dimensions;
88  simtime_t landmarkTimeout;
89 
91 
92  int16_t pendingRequests;
93  uint8_t coordCalcRuns;
94 
95  std::vector<TransportAddress> landmarkSet;
96 
97  uint16_t receivedCalls;
98 
99  cMessage* landmarkTimer;
100 
101  bool ready;
102 
103  public:
104  Nps() {};
106 
107  bool isReady() { return ready; };
108 
109  void handleTimerEvent(cMessage* msg);
110  virtual bool handleRpcCall(BaseCallMessage* msg);
111 
114  AbstractNcsNodeInfo* createNcsInfo(const Coords& coords) const;
115  virtual const AbstractNcsNodeInfo& getOwnNcsInfo() const { return *ownCoords; };
116 
117  const Coords& getOwnCoordinates() const { return ownCoords->getCoords(); };
118  double getOwnCoordinates(uint8_t i) const { return ownCoords->getCoords(i); };
119  uint8_t getOwnLayer() const { return ownCoords->getLayer(); };
120 
121  protected:
125  uint8_t computeOwnLayer (const std::vector<LandmarkDataEntry>& landmarks);
126 
130  Coords computeOwnCoordinates (const std::vector<LandmarkDataEntry>& landmarks);
131 
135  void setOwnLayer(int8_t layer);
136  void setOwnCoordinates(const Coords& coords) {
137  for (uint8_t i = 0; i < coords.size(); ++i) {
138  ownCoords->setCoords(i, coords[i]);
139  }
140  };
141 
146  void sendCoordRequests();
147  void sendCoordRequests(const std::vector<TransportAddress>& landmarks);
148  void sendCoordsReqCall(const TransportAddress& dest,
149  simtime_t timeout);
150 
152  cPolymorphic* context,
153  int rpcId, simtime_t rtt);
154 
156  const TransportAddress& dest,
157  cPolymorphic* context, int rpcId,
158  const OverlayKey& destKey);
159 
161  cPolymorphic* context,
162  int rpcId, simtime_t rtt);
163 
164  void coordsReqRpc(CoordsReqCall* msg);
165 
166  std::vector<LandmarkDataEntry> getLandmarkData() const;
167 
174  std::vector<TransportAddress> getLandmarks(uint8_t howmany);
175  const std::vector<TransportAddress>& getLandmarkSet() const { return landmarkSet; };
176  uint16_t getLandmarkSetSize() const { return landmarkSet.size(); };
177  //bool setLandmarkSet(uint8_t dim, uint8_t maxLayer);
178  bool setLandmarkSet(uint8_t howManyLM, uint8_t maxLayer,
179  std::vector<TransportAddress>* landmarkSet);
180  bool enoughLandmarks();
181 
182  std::vector<RttMeasurement> nodeMeasurements;
183 
184  void updateNodeMeasurement(const TransportAddress& node,
185  uint8_t pending = 0,
186  uint8_t sent = 0,
187  uint8_t passed = 0);
188 
189  void deleteNodeMeasurement(const TransportAddress& node);
190 
191  uint16_t getReceivedCalls() const { return receivedCalls; };
192 };
193 
194 #endif /* NPS_H_ */