00001 // 00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH) 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 // 00018 00024 #ifndef __BROOSEBUCKET_H_ 00025 #define __BROOSEBUCKET_H_ 00026 00027 #include <omnetpp.h> 00028 #include "BrooseHandle.h" 00029 #include "Broose.h" 00030 #include <map> 00031 #include <OverlayKey.h> 00032 00033 class Broose; 00034 00043 class BrooseBucket : public cSimpleModule 00044 { 00045 public: 00046 //omnet 00047 virtual int numInitStages() const 00048 { 00049 return 6; 00050 } 00051 virtual void initialize(int stage); 00052 virtual void handleMessage(cMessage* msg); 00053 00054 // bucket functions 00060 virtual void add(BrooseHandle node); 00061 00067 virtual void remove(BrooseHandle node); 00068 00074 virtual const BrooseHandle& get(uint32_t pos = 0); 00075 00081 virtual const OverlayKey& getDist(uint32_t pos = 0); 00082 00093 virtual void initializeBucket(int shiftingBits, uint32_t prefix, 00094 BrooseHandle node, int size, 00095 Broose* overlay, bool isBBucket = false); 00096 00102 virtual uint32_t getSize(); 00103 00109 virtual uint32_t getMaxSize(); 00110 00116 virtual bool isEmpty(); 00117 00121 virtual void clear(); 00122 00129 virtual BrooseHandle getClosestNode(const OverlayKey& destKey); 00130 00136 virtual int longestPrefix(void); 00137 00144 virtual bool keyInRange(const OverlayKey& key); 00145 00152 virtual bool nodeInBucket(const BrooseHandle& node); 00153 00160 virtual int getFailedResponses (const BrooseHandle& node); 00161 00167 virtual void increaseFailedResponses (const BrooseHandle& node); 00168 00174 virtual void resetFailedResponses (const BrooseHandle& node); 00175 00182 virtual void setRTT(BrooseHandle node, simtime_t rpcRTT); 00183 00190 virtual simtime_t getRTT(BrooseHandle node); 00191 00198 virtual void setLastSeen(BrooseHandle node, simtime_t lastSeen); 00199 00206 virtual simtime_t getLastSeen(BrooseHandle node); 00207 00213 void output(int maxEntries = 0); 00214 00220 void binaryOutput(const OverlayKey& key); 00221 00222 protected: 00223 // parameter 00224 std::map<OverlayKey, BrooseHandle> bucket; 00225 std::map<OverlayKey, BrooseHandle>::iterator bucketIter; 00227 unsigned int maxSize; 00228 BrooseHandle thisNode; 00229 OverlayKey key; 00230 int bits; 00231 Broose* overlay; 00232 bool isBBucket; 00233 }; 00234 #endif
1.5.5