OverSim
GiaNeighbors.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 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 __GIANEIGHBORS_H_
25 #define __GIANEIGHBORS_H_
26 
27 #include <vector>
28 
29 #include <omnetpp.h>
30 
31 #include <OverlayKey.h>
32 #include <InitStages.h>
33 
34 #include "GiaNode.h"
35 #include "GiaKeyList.h"
36 
37 
39 {
40  unsigned int connectionDegree;
41  unsigned int receivedTokens;
42  unsigned int sentTokens;
43  simtime_t timestamp;
45 };
46 
48 {
51 };
52 
53 
54 std::ostream& operator<<(std::ostream& os, const GiaNeighborInfo& info);
55 
59 class GiaNeighbors : public cSimpleModule
60 {
61  public:
62  // OMNeT++ methodes
66  virtual int numInitStages() const
67  {
68  return MAX_STAGE_OVERLAY + 1;
69  }
70 
75  virtual void initialize( int stage );
76 
81  virtual void handleMessages( cMessage* msg );
82 
83  // class methodes
87  virtual unsigned int getSize() const;
88 
93  virtual bool contains(const GiaNode& node) const;
94  //virtual bool contains(const NodeHandle& node) const;
95 
100  virtual bool contains(const OverlayKey& key) const;
101 
107  virtual void add(const GiaNode& node, unsigned int degree);
108  //virtual void add(const NodeHandle& node);
109 
114  virtual void remove(const GiaNode& node);
115 
121  virtual const GiaNode& get(unsigned int position);
122 
128  virtual const GiaNode& get(const OverlayKey& key);
129 
130  //bullshit
131  GiaNeighborInfo* get(const GiaNode& node);
132 
136  void updateTimestamp(const GiaNode& node);
137 
141  void removeTimedoutNodes();
142 
148  void setNeighborKeyList(const GiaNode& node, const GiaKeyList& keyList);
149  GiaKeyList* getNeighborKeyList(const GiaNode& node);
150 
151  double getCapacity(const GiaNode& node) const;
152  //void setCapacity(const GiaNode& node, double capacity);
153 
154  void setConnectionDegree(const GiaNode& node, unsigned int degree);
155  unsigned int getConnectionDegree(const GiaNode& node) const;
156 
157  void setReceivedTokens(const GiaNode& node, unsigned int tokens);
158  void increaseReceivedTokens(const GiaNode& node);
159  void decreaseReceivedTokens(const GiaNode& node);
160  unsigned int getReceivedTokens(const GiaNode& node) const;
161 
162  void setSentTokens(const GiaNode& node, unsigned int tokens);
163  void increaseSentTokens(const GiaNode& node);
164  unsigned int getSentTokens(const GiaNode& node) const;
165 
166  const GiaNode& getDropCandidate(double capacity,
167  unsigned int degree) const;
168 
169  protected:
170  std::map<GiaNode, GiaNeighborInfo> neighbors;
171  typedef std::map<GiaNode, GiaNeighborInfo>::iterator NeighborsIterator;
172  typedef std::map<GiaNode, GiaNeighborInfo>::const_iterator NeighborsConstIterator;
174  simtime_t timeout;
175 };
176 
177 #endif