PastryLeafSet.h

Go to the documentation of this file.
00001 #ifndef __PASTRYLEAFSET_H
00002 #define __PASTRYLEAFSET_H
00003 
00004 //
00005 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // This program is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with this program; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 //
00021 
00027 #include <vector>
00028 
00029 #include <omnetpp.h>
00030 
00031 #include <NodeHandle.h>
00032 #include <NodeVector.h>
00033 
00034 #include "PastryStateObject.h"
00035 #include "PastryTypes.h"
00036 #include "PastryMessage_m.h"
00037 
00038 #include "BasePastry.h"
00039 
00040 class BasePastry;
00041 
00045 struct PLSRepairData
00046 {
00047     simtime_t ts;
00048     bool left;
00049     PLSRepairData(simtime_t ts = 0, bool left = true) : ts(ts), left(left) {};
00050 };
00051 
00060 class PastryLeafSet : public PastryStateObject
00061 {
00062   public:
00063 
00073     void initializeSet(uint32_t numberOfLeaves,
00074                        uint32_t bitsPerDigit,
00075                        simtime_t repairTimeout,
00076                        const NodeHandle& owner,
00077                        BasePastry* overlay);
00078 
00086     virtual const NodeHandle& getDestinationNode(const OverlayKey& destination);
00087 
00099     virtual const NodeHandle& findCloserNode(const OverlayKey& destination,
00100                                              bool optimize = false);
00101 
00102     void findCloserNodes(const OverlayKey& destination,
00103                          NodeVector* nodes);
00110     virtual const TransportAddress& failedNode(const TransportAddress& failed);
00111 
00120     virtual const TransportAddress& repair(const PastryStateMessage* msg,
00121                                            const PastryStateMsgProximity* prox);
00122 
00129     bool isClosestNode(const OverlayKey& destination) const;
00130 
00136     virtual void dumpToStateMessage(PastryStateMessage* msg) const;
00137 
00143     virtual void dumpToStateMessage(PastryLeafsetMessage* msg) const;
00144 
00150     virtual const TransportAddress& getRandomNode();
00151 
00159     bool mergeNode(const NodeHandle& node, simtime_t prox);
00160 
00164     const NodeHandle& getPredecessor(void) const;
00165 
00169     const NodeHandle& getSuccessor(void) const;
00170 
00174     bool isValid(void) const;
00175 
00182     virtual void dumpToVector(std::vector<TransportAddress>& affected) const;
00183 
00184     NodeVector* createSiblingVector(const OverlayKey& key, int numSiblings) const;
00185 
00186 
00193     PastryNewLeafsMessage* getNewLeafsMessage(void);
00194 
00195   private:
00196     uint32_t numberOfLeaves;
00197     simtime_t repairTimeout;
00198     BasePastry* overlay; 
00199     std::vector<NodeHandle> leaves;
00200     std::vector<NodeHandle>::iterator smaller;
00201     std::vector<NodeHandle>::iterator bigger;
00202 
00203     std::map<TransportAddress, PLSRepairData> awaitingRepair;
00204 
00205     bool newLeafs;
00206 
00207     bool isFull;
00208     bool wasFull;
00209 
00210     virtual void earlyInit(void);
00211 
00218     const NodeHandle& getBiggestNode(void) const;
00219 
00226     const OverlayKey& getBiggestKey(void) const;
00227 
00234     const NodeHandle& getSmallestNode(void) const;
00235 
00242     const OverlayKey& getSmallestKey(void) const;
00243 
00251     bool isLeft(const OverlayKey& key) const;
00252 
00259     void insertLeaf(std::vector<NodeHandle>::iterator& it,
00260             const NodeHandle& node);
00261 
00262     bool balanceLeafSet();
00263 };
00264 
00265 #endif
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3