OverSim
BrooseBucket.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 __BROOSEBUCKET_H_
25 #define __BROOSEBUCKET_H_
26 
27 #include <omnetpp.h>
28 #include "BrooseHandle.h"
29 #include "Broose.h"
30 #include <map>
31 #include <OverlayKey.h>
32 
33 class Broose;
34 
43 class BrooseBucket : public cSimpleModule
44 {
45 public:
46  virtual int numInitStages() const
47  {
48  return MAX_STAGE_OVERLAY + 1;
49  }
50 
51  virtual void initialize(int stage);
52  virtual void handleMessage(cMessage* msg);
53 
54  // bucket functions
63  virtual bool add(const NodeHandle& node, bool isAlive = false,
64  simtime_t rtt = MAXTIME);
65 
71  virtual void remove(const NodeHandle& node);
72 
78  virtual const BrooseHandle& get(uint32_t pos = 0);
79 
85  virtual const OverlayKey& getDist(uint32_t pos = 0);
86 
96  virtual void initializeBucket(int shiftingBits, uint32_t prefix,
97  int size, Broose* overlay,
98  bool isBBucket = false);
99 
105  virtual uint32_t getSize();
106 
112  virtual uint32_t getMaxSize();
113 
120  virtual void fillVector(NodeVector* result);
121 
127  virtual bool isEmpty();
128 
132  virtual void clear();
133 
139  virtual int longestPrefix(void);
140 
147  virtual bool keyInRange(const OverlayKey& key);
148 
155  virtual int getPos(const NodeHandle& node);
156 
163  virtual int getFailedResponses (const NodeHandle& node);
164 
170  virtual void increaseFailedResponses (const NodeHandle& node);
171 
177  virtual void resetFailedResponses (const NodeHandle& node);
178 
185  virtual void setRTT(const NodeHandle& node, simtime_t rpcRTT);
186 
193  virtual simtime_t getRTT(const NodeHandle& node);
194 
201  virtual void setLastSeen(const NodeHandle& node, simtime_t lastSeen);
202 
209  virtual simtime_t getLastSeen(const NodeHandle& node);
210 
216  void output(int maxEntries = 0);
217 
218 
219 protected:
220  // parameter
221  std::map<OverlayKey, BrooseHandle> bucket;
222  std::map<OverlayKey, BrooseHandle>::iterator bucketIter;
224  unsigned int maxSize;
227  bool isBBucket;
228 };
229 #endif