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     uint32_t pingRetries;
00200     double timeoutPing;
00201     double readyWaitAmount;
00202     double joinTimeoutAmount;
00203     double pingCacheExpireTime;
00204     double repairTimeout;
00205     double sendStateWaitAmount;
00206     bool enableNewLeafs;
00207     bool useRegularNextHop;
00208     bool alwaysSendUpdate;
00209     bool optimizeLookup;
00210     bool optimisticForward;
00211     bool avoidDuplicates;
00212 
00213     simtime_t nearNodeRtt;
00214     simtime_t routingTableMaintenanceInterval;
00215 
00216     uint32_t unspecNodes;
00217     uint32_t pingedNodes;
00218     bool nearNodeImproved;
00219     bool sendPullFlag;
00220 
00221     bool useDiscovery;
00222     bool periodicMaintenance;
00223 
00224     TransportAddress* leaf2ask;
00225 
00226     TransportAddress bootstrapNode;
00227     NodeHandle nearNode;
00228 
00229     simtime_t lastStateChange;
00230 
00234     std::vector<PastryStateMsgHandle> stReceived;
00235     std::vector<PastryStateMsgHandle>::iterator stReceivedPos;
00236 
00240     std::vector<TransportAddress> notifyList;
00241 
00245     PastryStateMsgHandle stateCache;
00246 
00250     std::queue<PastryStateMsgHandle> stateCacheQueue;
00251 
00255     PastryStateMsgProximity aliveTable;
00256 
00261     virtual void checkProxCache(void) = 0;
00262 
00266     std::map<TransportAddress, BaseRouteMessage*> recFwdQueue;
00267 
00268     uint32_t joinHopCount;
00269     cMessage* joinTimeout;
00270     cMessage* readyWait;
00271     cMessage* joinUpdateWait;
00272     std::vector<PastrySendState*> sendStateWait;
00273 
00274     //cMessage* repairTaskTimeout;
00275 
00276     PastryRoutingTable* routingTable;
00277     PastryLeafSet* leafSet;
00278     PastryNeighborhoodSet* neighborhoodSet;
00279 
00280     virtual bool recursiveRoutingHook(const TransportAddress& dest,
00281                                          BaseRouteMessage* msg);
00282 
00287     void purgeVectors(void);
00288 
00292     void baseInit(void);
00293 
00298     void baseChangeState(int);
00299 
00305     void doRoutingTableMaintenance();
00306 
00307     int getNextRowToMaintain();
00308 
00309     enum StateObject
00310     {
00311         ROUTINGTABLE,
00312         LEAFSET,
00313         NEIGHBORHOODSET
00314     };
00315 
00316     struct PingContext : public cPolymorphic
00317     {
00318         PingContext(StateObject stateObject, uint32_t index, uint32_t nonce)
00319             : stateObject(stateObject), index(index), nonce(nonce)
00320               {};
00321         virtual ~PingContext() {};
00322         StateObject stateObject;
00323         uint32_t index;
00324         uint32_t nonce;
00325     };
00326 
00327     enum
00328     {
00329         PING_RECEIVED_STATE = 1,
00330         PING_NEXT_HOP = 2,
00331         PING_SINGLE_NODE = 3
00332     };
00333 
00338     void prePing(const PastryStateMessage* stateMsg);
00339 
00344     void pingNodes(void);
00345 
00353     void determineAliveTable(const PastryStateMessage* stateMsg);
00354 
00360     void sendRequest(const TransportAddress& ask, int type);
00361 
00367     void sendLeafset(const TransportAddress& tell, bool pull = false);
00368 
00374     void sendRoutingRow(const TransportAddress& tell, int row);
00375 
00376 
00382     void handleRequestMessage(PastryRequestMessage* msg);
00383 
00390     void handleLeafsetMessage(PastryLeafsetMessage* msg, bool mergeSender = false);
00391 
00395     void newLeafs(void);
00396 
00397 
00398     friend class PastryLeafSet;
00399 
00400 };
00401 
00406 bool stateMsgIsSmaller(const PastryStateMsgHandle& hnd1,
00407                        const PastryStateMsgHandle& hnd2);
00408 
00409 std::ostream& operator<<(std::ostream& os, const PastryStateMsgProximity pr);
00410 
00411 #endif
00412 

Generated on Tue Sep 8 17:26:51 2009 for OverSim by  doxygen 1.5.8