PastryStateObject Module. More...
#include <PastryStateObject.h>
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 | |
Static Protected Member Functions | |
static const PastryExtendedNode & | unspecNode () |
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 OverlayKey * | keyDist (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 |
PastryStateObject Module.
This module class describes the common interface of all Pastry State Objects and implements what all have in common
Definition at line 47 of file PastryStateObject.h.
virtual void PastryStateObject::dumpToStateMessage | ( | PastryStateMessage * | msg | ) | const [pure virtual] |
dump content of the set to a PastryStateMessage
msg | the PastryStateMessage to be filled with entries |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
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.
affected | the vector to fill with entries |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
virtual void PastryStateObject::earlyInit | ( | void | ) | [private, pure virtual] |
initialize watches etc.
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
Referenced by initialize().
virtual const TransportAddress& PastryStateObject::failedNode | ( | const TransportAddress & | failed | ) | [pure virtual] |
do something about a failed node
failed | the failed node |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
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.
destination | the destination key | |
optimize | if set, check all nodes and return the best/closest one |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
virtual void PastryStateObject::findCloserNodes | ( | const OverlayKey & | destination, | |
NodeVector * | nodes | |||
) | [pure virtual] |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
const NodeHandle & PastryStateObject::getDestinationNode | ( | const OverlayKey & | destination | ) | [virtual] |
gets the final node according to the Pastry routing scheme.
destination | the destination key |
Reimplemented in PastryLeafSet.
Definition at line 48 of file PastryStateObject.cc.
00050 { 00051 return NodeHandle::UNSPECIFIED_NODE; 00052 }
void PastryStateObject::handleMessage | ( | cMessage * | msg | ) |
Definition at line 43 of file PastryStateObject.cc.
void PastryStateObject::initialize | ( | int | stage | ) |
Definition at line 36 of file PastryStateObject.cc.
00037 { 00038 if (stage != MIN_STAGE_OVERLAY) 00039 return; 00040 earlyInit(); 00041 }
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
test | the NodeHandle to test | |
destination | the destination Key | |
reference | NodeHandle to compare to, own node if unset |
Definition at line 134 of file PastryStateObject.cc.
Referenced by BasePastry::findNode(), PastryLeafSet::getDestinationNode(), PastryLeafSet::isClosestNode(), and specialCloserCondition().
00137 { 00138 // assert: (! test.isUnspecified()) && (! owner.isUnspecified()) 00139 00140 const NodeHandle* ref = &reference; 00141 if (ref->isUnspecified()) ref = &owner; 00142 00143 if ((ref->getKey() == destination) || (test == *ref)) { 00144 return false; 00145 } 00146 00147 bool closer = false; 00148 const OverlayKey* refDist = keyDist(ref->getKey(), destination); 00149 const OverlayKey* testDist = keyDist(test.getKey(), destination); 00150 if (*testDist < *refDist) 00151 closer = true; 00152 delete refDist; 00153 delete testDist; 00154 return closer; 00155 }
const OverlayKey * PastryStateObject::keyDist | ( | const OverlayKey & | a, | |
const OverlayKey & | b | |||
) | const [private] |
compute the distance of two keys on the ring
a | one key | |
b | another key |
Definition at line 107 of file PastryStateObject.cc.
Referenced by isCloser().
00109 { 00110 const OverlayKey* smaller; 00111 const OverlayKey* bigger; 00112 00113 if (a > b) { 00114 smaller = &b; 00115 bigger = &a; 00116 } else { 00117 smaller = &a; 00118 bigger = &b; 00119 } 00120 00121 OverlayKey diff1(*bigger - *smaller); 00122 OverlayKey diff2(*smaller + (OverlayKey::getMax() - *bigger) + 1); 00123 00124 const OverlayKey* dist; 00125 if (diff1 > diff2) { 00126 dist = new OverlayKey(diff2); 00127 } else { 00128 dist = new OverlayKey(diff1); 00129 } 00130 00131 return dist; 00132 }
virtual bool PastryStateObject::mergeNode | ( | const NodeHandle & | node, | |
simtime_t | prox | |||
) | [private, pure virtual] |
try to merge a single node in the state table
node | handle of the node | |
prox | proximity value of the node |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
Referenced by mergeState().
bool PastryStateObject::mergeState | ( | const PastryStateMessage * | msg, | |
const PastryStateMsgProximity * | prox | |||
) |
update own state based on a received PastryStateMessage
msg | the PastryStateMessage to use as source for update | |
prox | record of proximity values matching the state message |
Definition at line 61 of file PastryStateObject.cc.
Referenced by Pastry::checkProxCache(), Bamboo::checkProxCache(), Pastry::handleStateMessage(), Bamboo::handleStateMessage(), PastryRoutingTable::initStateFromHandleVector(), Pastry::mergeState(), PastryRoutingTable::repair(), and PastryLeafSet::repair().
00063 { 00064 bool ret = false; 00065 int lsSize = msg->getLeafSetArraySize(); 00066 int rtSize = msg->getRoutingTableArraySize(); 00067 int nsSize = msg->getNeighborhoodSetArraySize(); 00068 const NodeHandle* node; 00069 simtime_t rtt; 00070 00071 // walk through msg's LeafSet 00072 for (int i = 0; i < lsSize; i++) { 00073 node = &(msg->getLeafSet(i)); 00074 rtt = prox ? (*(prox->pr_ls.begin() + i)) : SimTime::getMaxTime(); 00075 00076 // unspecified nodes, own node and dead nodes not considered 00077 if (!(rtt < 0 || node->isUnspecified() || *node == owner)) { 00078 if (mergeNode(*node, rtt)) ret = true; 00079 } 00080 } 00081 00082 // walk through msg's IRoutingTable 00083 for (int i = 0; i < rtSize; i++) { 00084 node = &(msg->getRoutingTable(i)); 00085 rtt = prox ? (*(prox->pr_rt.begin() + i)) : SimTime::getMaxTime(); 00086 00087 // unspecified nodes, own node and dead nodes not considered 00088 if (!(rtt < 0 || node->isUnspecified() || *node == owner)) { 00089 if (mergeNode(*node, rtt)) ret = true; 00090 } 00091 } 00092 00093 // walk through msg's NeighborhoodSet 00094 for (int i = 0; i < nsSize; i++) { 00095 node = &(msg->getNeighborhoodSet(i)); 00096 rtt = prox ? (*(prox->pr_ns.begin() + i)) : SimTime::getMaxTime(); 00097 00098 // unspecified nodes, own node and dead nodes not considered 00099 if (!(rtt < 0 || node->isUnspecified() || *node == owner)) { 00100 if (mergeNode(*node, rtt)) ret = true; 00101 } 00102 } 00103 00104 return ret; 00105 }
int PastryStateObject::numInitStages | ( | void | ) | const |
Definition at line 31 of file PastryStateObject.cc.
00032 { 00033 return MAX_STAGE_OVERLAY; 00034 }
const TransportAddress & PastryStateObject::repair | ( | const PastryStateMessage * | msg, | |
const PastryStateMsgProximity & | prox | |||
) | [virtual] |
attempt to repair state using a received REPAIR message
msg | the state message of type REPAIR | |
prox | record of proximity values matching the state message |
Definition at line 54 of file PastryStateObject.cc.
00057 { 00058 return TransportAddress::UNSPECIFIED_NODE; 00059 }
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.
test | the NodeHandle to test | |
destination | the destination Key | |
reference | NodeHandle to compare to, own node if unset |
Definition at line 157 of file PastryStateObject.cc.
Referenced by PastryRoutingTable::findCloserNode(), PastryNeighborhoodSet::findCloserNode(), and PastryLeafSet::findCloserNode().
00161 { 00162 // std::cout << ((test.getKey().sharedPrefixLength(destination, bitsPerDigit) 00163 // < owner.getKey().sharedPrefixLength(destination, bitsPerDigit)) 00164 // != (test.getKey().sharedPrefixLength(destination) 00165 // < owner.getKey().sharedPrefixLength(destination)) ? "X\n" : ""); 00166 00167 if (test.getKey().sharedPrefixLength(destination, bitsPerDigit) 00168 < owner.getKey().sharedPrefixLength(destination, bitsPerDigit)) { 00169 return false; 00170 } 00171 00172 return isCloser(test, destination, reference); 00173 }
static const PastryExtendedNode& PastryStateObject::unspecNode | ( | ) | [inline, static, protected] |
Definition at line 174 of file PastryStateObject.h.
Referenced by PastryRoutingTable::addRow(), PastryNeighborhoodSet::failedNode(), PastryNeighborhoodSet::initializeSet(), and PastryRoutingTable::nodeAt().
00175 { 00176 if (_unspecNode == NULL) 00177 _unspecNode = new PastryExtendedNode(); 00178 return *_unspecNode; 00179 }
const PastryExtendedNode * PastryStateObject::_unspecNode = NULL [static, private] |
unspecified Node with proximity
Definition at line 171 of file PastryStateObject.h.
Referenced by unspecNode().
uint32_t PastryStateObject::bitsPerDigit [protected] |
Definition at line 165 of file PastryStateObject.h.
Referenced by PastryRoutingTable::digitAt(), PastryRoutingTable::findCloserNode(), PastryRoutingTable::lookupNextHop(), PastryRoutingTable::mergeNode(), and specialCloserCondition().
NodeHandle PastryStateObject::owner [protected] |
stores the NodeHandle of the owner of this PastryStateObject.
Derived classes have to initialize it.
Definition at line 163 of file PastryStateObject.h.
Referenced by PastryRoutingTable::addRow(), PastryLeafSet::createSiblingVector(), PastryRoutingTable::findCloserNode(), PastryRoutingTable::findNextNodeToAsk(), PastryLeafSet::getDestinationNode(), isCloser(), PastryLeafSet::isClosestNode(), PastryRoutingTable::lookupNextHop(), PastryRoutingTable::mergeNode(), PastryLeafSet::mergeNode(), mergeState(), and specialCloserCondition().