GiaNeighbors.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 __GIANEIGHBORS_H_
00025 #define __GIANEIGHBORS_H_
00026
00027 #include <vector>
00028
00029 #include <omnetpp.h>
00030
00031 #include <OverlayKey.h>
00032 #include <InitStages.h>
00033
00034 #include "GiaNode.h"
00035 #include "GiaKeyList.h"
00036
00037
00038 struct GiaNeighborInfo
00039 {
00040 unsigned int connectionDegree;
00041 unsigned int receivedTokens;
00042 unsigned int sentTokens;
00043 simtime_t timestamp;
00044 GiaKeyList keyList;
00045 };
00046
00047 struct FullGiaNodeInfo
00048 {
00049 GiaNode node;
00050 GiaNeighborInfo* info;
00051 };
00052
00053
00054 std::ostream& operator<<(std::ostream& os, const GiaNeighborInfo& info);
00055
00059 class GiaNeighbors : public cSimpleModule
00060 {
00061 public:
00062
00066 virtual int numInitStages() const
00067 {
00068 return MAX_STAGE_OVERLAY + 1;
00069 }
00070
00075 virtual void initialize( int stage );
00076
00081 virtual void handleMessages( cMessage* msg );
00082
00083
00087 virtual unsigned int getSize() const;
00088
00093 virtual bool contains(const GiaNode& node) const;
00094
00095
00100 virtual bool contains(const OverlayKey& key) const;
00101
00107 virtual void add(const GiaNode& node, unsigned int degree);
00108
00109
00114 virtual void remove(const GiaNode& node);
00115
00121 virtual const GiaNode& get(unsigned int position);
00122
00128 virtual const GiaNode& get(const OverlayKey& key);
00129
00130
00131 GiaNeighborInfo* get(const GiaNode& node);
00132
00136 void updateTimestamp(const GiaNode& node);
00137
00141 void removeTimedoutNodes();
00142
00148 void setNeighborKeyList(const GiaNode& node, const GiaKeyList& keyList);
00149 GiaKeyList* getNeighborKeyList(const GiaNode& node);
00150
00151 double getCapacity(const GiaNode& node) const;
00152
00153
00154 void setConnectionDegree(const GiaNode& node, unsigned int degree);
00155 unsigned int getConnectionDegree(const GiaNode& node) const;
00156
00157 void setReceivedTokens(const GiaNode& node, unsigned int tokens);
00158 void increaseReceivedTokens(const GiaNode& node);
00159 void decreaseReceivedTokens(const GiaNode& node);
00160 unsigned int getReceivedTokens(const GiaNode& node) const;
00161
00162 void setSentTokens(const GiaNode& node, unsigned int tokens);
00163 void increaseSentTokens(const GiaNode& node);
00164 unsigned int getSentTokens(const GiaNode& node) const;
00165
00166 const GiaNode& getDropCandidate(double capacity,
00167 unsigned int degree) const;
00168
00169 protected:
00170 std::map<GiaNode, GiaNeighborInfo> neighbors;
00171 typedef std::map<GiaNode, GiaNeighborInfo>::iterator NeighborsIterator;
00172 typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator NeighborsConstIterator;
00173 GiaNode thisNode;
00174 simtime_t timeout;
00175 };
00176
00177 #endif