OverSim
PastryStateObject Class Reference

PastryStateObject Module. More...

#include <PastryStateObject.h>

Inheritance diagram for PastryStateObject:
PastryLeafSet PastryNeighborhoodSet PastryRoutingTable

Public Member Functions

void handleMessage (cMessage *msg)
int numInitStages (void) const
void initialize (int stage)
virtual const NodeHandlegetDestinationNode (const OverlayKey &destination)
 gets the final node according to the Pastry routing scheme.
virtual const NodeHandlefindCloserNode (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 TransportAddressfailedNode (const TransportAddress &failed)=0
 do something about a failed node
virtual const TransportAddressrepair (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
virtual 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

Static Protected Member Functions

static const PastryExtendedNodeunspecNode ()

Protected Attributes

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

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

Static Private Attributes

static const PastryExtendedNode_unspecNode = NULL
 unspecified Node with proximity

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

Definition at line 48 of file PastryStateObject.h.

Member Function Documentation

virtual void PastryStateObject::dumpToStateMessage ( PastryStateMessage msg) const
pure virtual

dump content of the set to a PastryStateMessage

Parameters
msgthe PastryStateMessage to be filled with entries

Implemented in PastryLeafSet, PastryRoutingTable, and PastryNeighborhoodSet.

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
affectedthe vector to fill with entries

Implemented in PastryRoutingTable, PastryLeafSet, and PastryNeighborhoodSet.

virtual void PastryStateObject::earlyInit ( void  )
privatepure virtual

initialize watches etc.

Referenced by initialize().

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

do something about a failed node

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

Implemented in PastryLeafSet, PastryRoutingTable, and PastryNeighborhoodSet.

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
destinationthe destination key
optimizeif 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, PastryRoutingTable, and PastryNeighborhoodSet.

virtual void PastryStateObject::findCloserNodes ( const OverlayKey destination,
NodeVector nodes 
)
pure virtual
const NodeHandle & PastryStateObject::getDestinationNode ( const OverlayKey destination)
virtual

gets the final node according to the Pastry routing scheme.

Parameters
destinationthe 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.

Definition at line 53 of file PastryStateObject.cc.

void PastryStateObject::handleMessage ( cMessage *  msg)

Definition at line 47 of file PastryStateObject.cc.

{
throw cRuntimeError("A PastryStateObject should never receive a message!");
}
void PastryStateObject::initialize ( int  stage)

Definition at line 39 of file PastryStateObject.cc.

{
if (stage != MIN_STAGE_OVERLAY)
return;
}
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
testthe NodeHandle to test
destinationthe destination Key
referenceNodeHandle to compare to, own node if unset
Returns
true if test is closer to destination than owner

Definition at line 146 of file PastryStateObject.cc.

Referenced by BasePastry::findNode(), PastryLeafSet::getDestinationNode(), PastryLeafSet::isClosestNode(), and specialCloserCondition().

{
const NodeHandle* ref = &reference;
if (ref->isUnspecified()) ref = &owner;
if ((ref->getKey() == destination) || (test == *ref)) {
return false;
}
bool closer = false;
const OverlayKey* refDist = keyDist(ref->getKey(), destination);
const OverlayKey* testDist = keyDist(test.getKey(), destination);
if (*testDist < *refDist)
closer = true;
delete refDist;
delete testDist;
return closer;
}
const OverlayKey * PastryStateObject::keyDist ( const OverlayKey a,
const OverlayKey b 
) const
private

compute the distance of two keys on the ring

Parameters
aone key
banother key
Returns
pointer to distance (must be deleted by caller)

Definition at line 118 of file PastryStateObject.cc.

Referenced by isCloser().

{
const OverlayKey* smaller;
const OverlayKey* bigger;
if (a > b) {
smaller = &b;
bigger = &a;
} else {
smaller = &a;
bigger = &b;
}
OverlayKey diff1(*bigger - *smaller);
OverlayKey diff2(*smaller + (OverlayKey::getMax() - *bigger) + 1);
const OverlayKey* dist;
if (diff1 > diff2) {
dist = new OverlayKey(diff2);
} else {
dist = new OverlayKey(diff1);
}
return dist;
}
virtual bool PastryStateObject::mergeNode ( const NodeHandle node,
simtime_t  prox 
)
privatepure virtual

try to merge a single node in the state table

Parameters
nodehandle of the node
proxproximity value of the node
Returns
true if node was inserted

Implemented in PastryRoutingTable, PastryLeafSet, and PastryNeighborhoodSet.

Referenced by mergeState().

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

update own state based on a received PastryStateMessage

Parameters
msgthe PastryStateMessage to use as source for update
proxrecord of proximity values matching the state message
Returns
true if leafSet was actually changed

Reimplemented in PastryLeafSet.

Definition at line 68 of file PastryStateObject.cc.

Referenced by Bamboo::checkProxCache(), Pastry::checkProxCache(), Pastry::handleStateMessage(), PastryRoutingTable::initStateFromHandleVector(), Pastry::mergeState(), and PastryRoutingTable::repair().

{
bool ret = false;
int lsSize = msg->getLeafSetArraySize();
int rtSize = msg->getRoutingTableArraySize();
int nsSize = msg->getNeighborhoodSetArraySize();
const NodeHandle* node;
simtime_t rtt;
// walk through msg's LeafSet
for (int i = 0; i < lsSize; i++) {
node = &(msg->getLeafSet(i));
rtt = prox ? (*(prox->pr_ls.begin() + i)) : SimTime::getMaxTime();
// unspecified nodes, own node and dead nodes not considered
if (!(rtt < 0 || node->isUnspecified() || *node == owner ||
static_cast<TransportAddress>(*node) == owner)) {
if (mergeNode(*node, rtt)) ret = true;
}
}
// walk through msg's IRoutingTable
for (int i = 0; i < rtSize; i++) {
node = &(msg->getRoutingTable(i));
rtt = prox ? (*(prox->pr_rt.begin() + i)) : SimTime::getMaxTime();
// unspecified nodes, own node and dead nodes not considered
if (!(rtt < 0 || node->isUnspecified() || *node == owner ||
static_cast<TransportAddress>(*node) == owner)) {
if (mergeNode(*node, rtt)) ret = true;
}
}
// walk through msg's NeighborhoodSet
for (int i = 0; i < nsSize; i++) {
node = &(msg->getNeighborhoodSet(i));
rtt = prox ? (*(prox->pr_ns.begin() + i)) : SimTime::getMaxTime();
// unspecified nodes, own node and dead nodes not considered
if (!(rtt < 0 || node->isUnspecified() || *node == owner ||
static_cast<TransportAddress>(*node) == owner)) {
if (mergeNode(*node, rtt)) ret = true;
}
}
return ret;
}
int PastryStateObject::numInitStages ( void  ) const

Definition at line 33 of file PastryStateObject.cc.

{
}
const TransportAddress & PastryStateObject::repair ( const PastryStateMessage msg,
const PastryStateMsgProximity prox 
)
virtual

attempt to repair state using a received REPAIR message

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

Definition at line 60 of file PastryStateObject.cc.

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
testthe NodeHandle to test
destinationthe destination Key
referenceNodeHandle to compare to, own node if unset
Returns
true if test is closer to destination than owner

Definition at line 168 of file PastryStateObject.cc.

Referenced by PastryNeighborhoodSet::findCloserNode(), PastryRoutingTable::findCloserNode(), and PastryLeafSet::findCloserNode().

{
if (test.getKey().sharedPrefixLength(destination, bitsPerDigit)
return false;
}
return isCloser(test, destination, reference);
}
static const PastryExtendedNode& PastryStateObject::unspecNode ( )
inlinestaticprotected

Member Data Documentation

const PastryExtendedNode * PastryStateObject::_unspecNode = NULL
staticprivate

unspecified Node with proximity

Definition at line 172 of file PastryStateObject.h.

Referenced by unspecNode().


The documentation for this class was generated from the following files: