BasePastry.h

Go to the documentation of this file.
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 __BASEPASTRY_H_
00025 #define __BASEPASTRY_H_
00026 
00027 #include <vector>
00028 #include <map>
00029 #include <queue>
00030 #include <algorithm>
00031 
00032 #include <omnetpp.h>
00033 #include <IPvXAddress.h>
00034 
00035 #include <OverlayKey.h>
00036 #include <NodeHandle.h>
00037 #include <BaseOverlay.h>
00038 #include <NeighborCache.h>
00039 
00040 #include "PastryTypes.h"
00041 #include "PastryMessage_m.h"
00042 #include "PastryRoutingTable.h"
00043 #include "PastryLeafSet.h"
00044 #include "PastryNeighborhoodSet.h"
00045 
00046 class PastryLeafSet;
00047 
00048 #define DISCOVERY JOINING_1
00049 
00050 class BasePastry : public BaseOverlay, public ProxListener
00051 {
00052 public:
00053 
00054     virtual ~BasePastry();
00055 
00056     virtual void pingResponse(PingResponse* pingResponse,
00057                               cPolymorphic* context, int rpcId,
00058                               simtime_t rtt);
00059 
00060     void pingTimeout(PingCall* call, const TransportAddress& dest,
00061                      cPolymorphic* context, int rpcId);
00062 
00063     // see BaseOverlay.h
00064     int getMaxNumSiblings();
00065 
00066     // see BaseOverlay.h
00067     int getMaxNumRedundantNodes();
00068 
00074     virtual void handleAppMessage(BaseOverlayMessage* msg);
00075 
00079     virtual void updateTooltip();
00080 
00081     // see BaseOverlay.h
00082     virtual NodeVector* findNode(const OverlayKey& key,
00083                                  int numRedundantNodes,
00084                                  int numSiblings,
00085                                  BaseOverlayMessage* msg);
00086 
00092     virtual void handleStateMessage(PastryStateMessage* msg) = 0;
00093 
00094     // see BaseOverlay.h
00095     virtual void finishOverlay();
00096 
00110     // Note: simtime_t cannot be passes as '...' param, it's non-POD type.
00111     void sendStateTables(const TransportAddress& destination,
00112                          int type = PASTRY_STATE_STD, ...);
00113 
00119     void sendStateDelayed(const TransportAddress& destination);
00120 
00121 
00122     // see BaseOverlay.h
00123     virtual bool isSiblingFor(const NodeHandle& node,
00124                               const OverlayKey& key,
00125                               int numSiblings,
00126                               bool* err);
00127 
00128     // see BaseOverlay.h
00129     virtual AbstractLookup* createLookup(RoutingType routingType = DEFAULT_ROUTING,
00130                                          const BaseOverlayMessage* msg = NULL,
00131                                          const cObject* dummy = NULL,
00132                                          bool appLookup = false);
00133 
00134     uint8_t getBitsPerDigit() { return bitsPerDigit; };
00135 
00136     // statistics
00137     int joins;
00138     int joinTries;
00139     int joinPartial;
00140     int joinSeen;
00141     int joinBytesSeen;
00142     int joinReceived;
00143     int joinBytesReceived;
00144     int joinSent;
00145     int joinBytesSent;
00146     int stateSent;
00147     int stateBytesSent;
00148     int stateReceived;
00149     int stateBytesReceived;
00150     int repairReqSent;
00151     int repairReqBytesSent;
00152     int repairReqReceived;
00153     int repairReqBytesReceived;
00154     int stateReqSent;
00155     int stateReqBytesSent;
00156     int stateReqReceived;
00157     int stateReqBytesReceived;
00158     int totalLookups;
00159     int responsibleLookups;
00160     int routingTableLookups;
00161     int closerNodeLookups;
00162     int closerNodeLookupsFromNeighborhood;
00163 
00164     int leafsetReqSent;
00165     int leafsetReqBytesSent;
00166     int leafsetReqReceived;
00167     int leafsetReqBytesReceived;
00168     int leafsetSent;
00169     int leafsetBytesSent;
00170     int leafsetReceived;
00171     int leafsetBytesReceived;
00172 
00173     int routingTableReqSent;
00174     int routingTableReqBytesSent;
00175     int routingTableReqReceived;
00176     int routingTableReqBytesReceived;
00177     int routingTableSent;
00178     int routingTableBytesSent;
00179     int routingTableReceived;
00180     int routingTableBytesReceived;
00181     uint32_t rowToAsk;
00182 
00183     void proxCallback(const TransportAddress& node, int rpcId,
00184                       cPolymorphic *contextPointer, Prox prox);
00185 
00186   protected:
00187 
00193     virtual void changeState(int toState);
00194 
00195      // parameters
00196     uint32_t bitsPerDigit;
00197     uint32_t numberOfLeaves;
00198     uint32_t numberOfNeighbors;
00199     double readyWaitAmount;
00200     double joinTimeoutAmount;
00201     double repairTimeout;
00202     bool enableNewLeafs;
00203     bool useRegularNextHop;
00204     bool alwaysSendUpdate;
00205     bool optimizeLookup;
00206     bool proximityNeighborSelection;
00207 
00208     simtime_t nearNodeRtt;
00209 
00210     uint32_t pingedNodes;
00211     bool nearNodeImproved;
00212 
00213     bool periodicMaintenance;
00214 
00215     TransportAddress* leaf2ask;
00216 
00217     TransportAddress bootstrapNode;
00218     NodeHandle nearNode;
00219 
00220     simtime_t lastStateChange;
00221 
00225     PastryStateMsgHandle stateCache;
00226 
00230     std::queue<PastryStateMsgHandle> stateCacheQueue;
00231 
00235     PastryStateMsgProximity aliveTable;
00236 
00241     virtual void checkProxCache(void) = 0;
00242 
00243     uint32_t joinHopCount;
00244     cMessage* joinTimeout;
00245     cMessage* readyWait;
00246     cMessage* joinUpdateWait;
00247     std::vector<PastrySendState*> sendStateWait;
00248 
00249     PastryRoutingTable* routingTable;
00250     PastryLeafSet* leafSet;
00251     PastryNeighborhoodSet* neighborhoodSet;
00252 
00257     virtual void purgeVectors(void);
00258 
00262     void baseInit(void);
00263 
00268     void baseChangeState(int);
00269 
00270     OverlayKey distance(const OverlayKey& x,
00271                         const OverlayKey& y,
00272                         bool useAlternative = false) const;
00273 
00274     virtual void iterativeJoinHook(BaseOverlayMessage* msg,
00275                                    bool incrHopCount) { };
00276 
00277     enum StateObject
00278     {
00279         ROUTINGTABLE,
00280         LEAFSET,
00281         NEIGHBORHOODSET
00282     };
00283 
00284     struct PingContext : public cPolymorphic
00285     {
00286         PingContext(StateObject stateObject, uint32_t index, uint32_t nonce)
00287             : stateObject(stateObject), index(index), nonce(nonce)
00288               {};
00289         virtual ~PingContext() {};
00290         StateObject stateObject;
00291         uint32_t index;
00292         uint32_t nonce;
00293     };
00294 
00295     enum
00296     {
00297         PING_RECEIVED_STATE = 1,
00298         PING_NEXT_HOP = 2,
00299         PING_SINGLE_NODE = 3,
00300         PING_DISCOVERY
00301     };
00302 
00307     void prePing(const PastryStateMessage* stateMsg);
00308 
00313     void pingNodes(void);
00314 
00322     void determineAliveTable(const PastryStateMessage* stateMsg);
00323 
00329     void sendRequest(const TransportAddress& ask, int type);
00330 
00336     void sendLeafset(const TransportAddress& tell, bool pull = false);
00337 
00343     void sendRoutingRow(const TransportAddress& tell, int row);
00344 
00345 
00351     void handleRequestMessage(PastryRequestMessage* msg);
00352 
00359     void handleLeafsetMessage(PastryLeafsetMessage* msg, bool mergeSender = false);
00360 
00364     void newLeafs(void);
00365 
00366     friend class PastryLeafSet;
00367 };
00368 
00373 bool stateMsgIsSmaller(const PastryStateMsgHandle& hnd1,
00374                        const PastryStateMsgHandle& hnd2);
00375 
00376 std::ostream& operator<<(std::ostream& os, const PastryStateMsgProximity& pr);
00377 
00378 #endif
00379 
Generated on Wed May 26 16:21:13 2010 for OverSim by  doxygen 1.6.3