PastryStateObject Class Reference

#include <PastryStateObject.h>

Inheritance diagram for PastryStateObject:

PastryLeafSet PastryNeighborhoodSet PastryRoutingTable

List of all members.


Detailed Description

PastryStateObject Module.

This module class describes the common interface of all Pastry State Objects and implements what all have in common

Author:
Felix Palmen
See also:
PastryRoutingTable, LeafSet, NeighborhoodSet

Public Member Functions

void handleMessage (cMessage *msg)
int numInitStages (void) const
void initialize (int stage)
virtual const
NodeHandle
getDestinationNode (const OverlayKey &destination)
 gets the final node according to the Pastry routing scheme.
virtual const
NodeHandle
findCloserNode (const OverlayKey &destination, bool optimize=false)=0
 try to find a node numerically closer to a given key with the same shared prefix as the current node in the state table.
virtual void findCloserNodes (const OverlayKey &destination, NodeVector *nodes)=0
virtual const
TransportAddress
failedNode (const TransportAddress &failed)=0
 do something about a failed node
virtual const
TransportAddress
repair (const PastryStateMessage *msg, const PastryStateMsgProximity &prox)
 attempt to repair state using a received REPAIR message
virtual void dumpToStateMessage (PastryStateMessage *msg) const =0
 dump content of the set to a PastryStateMessage
bool mergeState (const PastryStateMessage *msg, const PastryStateMsgProximity &prox)
 update own state based on a received PastryStateMessage
virtual void dumpToVector (std::vector< TransportAddress > &affected) const =0
 append all entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.
bool isCloser (const NodeHandle &test, const OverlayKey &destination, const NodeHandle &reference=NodeHandle::UNSPECIFIED_NODE) const
 test a given NodeHandle if it is closer to a given destination
bool specialCloserCondition (const NodeHandle &test, const OverlayKey &destination, const NodeHandle &reference=NodeHandle::UNSPECIFIED_NODE) const
 test a given NodeHandle if it is closer to a given destination, but only if the shared prefix length with the destination is at least equal to the shared prefix length with our own node

Protected Attributes

NodeHandle owner
 stores the NodeHandle of the owner of this PastryStateObject.

Static Protected Attributes

static const
PastryExtendedNode 
unspecNode
 unspecified Node with proximity

Private Member Functions

virtual void earlyInit (void)=0
 initialize watches etc.
virtual bool mergeNode (const NodeHandle &node, simtime_t prox)=0
 try to merge a single node in the state table
const OverlayKeykeyDist (const OverlayKey &a, const OverlayKey &b) const
 compute the distance of two keys on the ring

Member Function Documentation

void PastryStateObject::handleMessage ( cMessage *  msg  ) 

00044 {
00045     throw "a PastryStateObject should never receive a message.";
00046 }

int PastryStateObject::numInitStages ( void   )  const

00032 {
00033     return MAX_STAGE_OVERLAY;
00034 }

void PastryStateObject::initialize ( int  stage  ) 

00037 {
00038     if (stage != MIN_STAGE_OVERLAY)
00039         return;
00040     earlyInit();
00041 }

const NodeHandle & PastryStateObject::getDestinationNode ( const OverlayKey destination  )  [virtual]

gets the final node according to the Pastry routing scheme.

Parameters:
destination the destination key
Returns:
the NodeHandle of the final node or NodeHandle::UNSPECIFIED_NODE if given destination key is outside the leaf set

Reimplemented in PastryLeafSet.

00050 {
00051     return NodeHandle::UNSPECIFIED_NODE;
00052 }

virtual const NodeHandle& PastryStateObject::findCloserNode ( const OverlayKey destination,
bool  optimize = false 
) [pure virtual]

try to find a node numerically closer to a given key with the same shared prefix as the current node in the state table.

this method is to be called, when a regular next hop couldn't be found or wasn't reachable.

Parameters:
destination the destination key
optimize if set, check all nodes and return the best/closest one
Returns:
a closer NodeHandle or NodeHandle::UNSPECIFIED_NODE if none was found

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

virtual void PastryStateObject::findCloserNodes ( const OverlayKey destination,
NodeVector nodes 
) [pure virtual]

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

virtual const TransportAddress& PastryStateObject::failedNode ( const TransportAddress failed  )  [pure virtual]

do something about a failed node

Parameters:
failed the failed node
Returns:
a node to ask for REPAIR or TransportAddress::UNSPECIFIED_NODE

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

const TransportAddress & PastryStateObject::repair ( const PastryStateMessage *  msg,
const PastryStateMsgProximity prox 
) [virtual]

attempt to repair state using a received REPAIR message

Parameters:
msg the state message of type REPAIR
prox record of proximity values matching the state message
Returns:
another node to ask for REPAIR or TransportAddress::UNSPECIFIED_NODE

Reimplemented in PastryLeafSet, and PastryRoutingTable.

00056 {
00057     return TransportAddress::UNSPECIFIED_NODE;
00058 }

virtual void PastryStateObject::dumpToStateMessage ( PastryStateMessage *  msg  )  const [pure virtual]

dump content of the set to a PastryStateMessage

Parameters:
msg the PastryStateMessage to be filled with entries

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

bool PastryStateObject::mergeState ( const PastryStateMessage *  msg,
const PastryStateMsgProximity prox 
)

update own state based on a received PastryStateMessage

Parameters:
msg the PastryStateMessage to use as source for update
prox record of proximity values matching the state message
Returns:
true if leafSet was actually changed
00062 {
00063     bool ret = false;
00064     int lsSize = msg->getLeafSetArraySize();
00065     int rtSize = msg->getRoutingTableArraySize();
00066     int nsSize = msg->getNeighborhoodSetArraySize();
00067     const NodeHandle* node;
00068     simtime_t rtt;
00069 
00070     // walk through msg's LeafSet
00071     for (int i = 0; i < lsSize; i++) {
00072         node = &(msg->getLeafSet(i));
00073         rtt = *(prox.pr_ls.begin() + i);
00074 
00075         // unspecified nodes, own node and dead nodes not considered
00076         if (!(rtt < 0 || node->isUnspecified() || *node == owner)) {
00077             if (mergeNode(*node, rtt)) ret = true;
00078         }
00079     }
00080 
00081     // walk through msg's RoutingTable
00082     for (int i = 0; i < rtSize; i++) {
00083         node = &(msg->getRoutingTable(i));
00084         rtt = *(prox.pr_rt.begin() + i);
00085 
00086         // unspecified nodes, own node and dead nodes not considered
00087         if (!(rtt < 0 || node->isUnspecified() || *node == owner)) {
00088             if (mergeNode(*node, rtt)) ret = true;
00089         }
00090     }
00091 
00092     // walk through msg's NeighborhoodSet
00093     for (int i = 0; i < nsSize; i++) {
00094         node = &(msg->getNeighborhoodSet(i));
00095         rtt = *(prox.pr_ns.begin() + i);
00096 
00097         // unspecified nodes, own node and dead nodes not considered
00098         if (!(rtt < 0 || node->isUnspecified() || *node == owner)) {
00099             if (mergeNode(*node, rtt)) ret = true;
00100         }
00101     }
00102 
00103     return ret;
00104 }

virtual void PastryStateObject::dumpToVector ( std::vector< TransportAddress > &  affected  )  const [pure virtual]

append all entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.

Parameters:
affected the vector to fill with entries

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

bool PastryStateObject::isCloser ( const NodeHandle test,
const OverlayKey destination,
const NodeHandle reference = NodeHandle::UNSPECIFIED_NODE 
) const

test a given NodeHandle if it is closer to a given destination

Parameters:
test the NodeHandle to test
destination the destination Key
reference NodeHandle to compare to, own node if unset
Returns:
true if test is closer to destination than owner
00141 {
00142     // assert: (! test.isUnspecified()) && (! owner.isUnspecified())
00143 
00144     const NodeHandle* ref = &reference;
00145     if (ref->isUnspecified()) ref = &owner;
00146 
00147     if ((ref->key == destination) || (test == *ref))
00148     {
00149         return false;
00150     }
00151 
00152     bool closer = false;
00153     const OverlayKey* refDist = keyDist(ref->key, destination);
00154     const OverlayKey* testDist = keyDist(test.key, destination);
00155     if (*testDist < *refDist) closer = true;
00156     delete refDist;
00157     delete testDist;
00158     return closer;
00159 }

bool PastryStateObject::specialCloserCondition ( const NodeHandle test,
const OverlayKey destination,
const NodeHandle reference = NodeHandle::UNSPECIFIED_NODE 
) const

test a given NodeHandle if it is closer to a given destination, but only if the shared prefix length with the destination is at least equal to the shared prefix length with our own node

This is needed for the "rare case" in the Pastry routing algorithm.

Parameters:
test the NodeHandle to test
destination the destination Key
reference NodeHandle to compare to, own node if unset
Returns:
true if test is closer to destination than owner
00163 {
00164     // assert: (! test.isUnspecified()) && (! owner.isUnspecified())
00165 
00166     if (test.key.sharedPrefixLength(destination)
00167             < owner.key.sharedPrefixLength(destination))
00168     {
00169         return false;
00170     }
00171 
00172     return isCloser(test, destination, reference);
00173 }

virtual void PastryStateObject::earlyInit ( void   )  [private, pure virtual]

initialize watches etc.

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

virtual bool PastryStateObject::mergeNode ( const NodeHandle node,
simtime_t  prox 
) [private, pure virtual]

try to merge a single node in the state table

Parameters:
node handle of the node
prox proximity value of the node
Returns:
true if node was inserted

Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.

const OverlayKey * PastryStateObject::keyDist ( const OverlayKey a,
const OverlayKey b 
) const [private]

compute the distance of two keys on the ring

Parameters:
a one key
b another key
Returns:
pointer to distance (must be deleted by caller)
00108 {
00109     const OverlayKey* smaller;
00110     const OverlayKey* bigger;
00111 
00112     if (a > b)
00113     {
00114         smaller = &b;
00115         bigger = &a;
00116     }
00117     else
00118     {
00119         smaller = &a;
00120         bigger = &b;
00121     }
00122 
00123     OverlayKey diff1(*bigger - *smaller);
00124     OverlayKey diff2(*smaller + (OverlayKey::max() - *bigger) + 1);
00125     
00126     const OverlayKey* dist;
00127     if (diff1 > diff2)
00128     {
00129         dist = new OverlayKey(diff2);
00130     }
00131     else
00132     {
00133         dist = new OverlayKey(diff1);
00134     }
00135 
00136     return dist;
00137 }


Member Data Documentation

NodeHandle PastryStateObject::owner [protected]

stores the NodeHandle of the owner of this PastryStateObject.

Derived classes have to initialize it.

const PastryExtendedNode PastryStateObject::unspecNode [static, protected]

unspecified Node with proximity


The documentation for this class was generated from the following files:
Generated on Thu Apr 17 13:19:30 2008 for ITM OverSim by  doxygen 1.5.3