#include <PastryStateObject.h>
Inheritance diagram for PastryStateObject:
This module class describes the common interface of all Pastry State Objects and implements what all have in common
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 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 OverlayKey * | keyDist (const OverlayKey &a, const OverlayKey &b) const |
compute the distance of two keys on the ring |
void PastryStateObject::handleMessage | ( | cMessage * | msg | ) |
int PastryStateObject::numInitStages | ( | void | ) | const |
void PastryStateObject::initialize | ( | int | stage | ) |
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.
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.
destination | the destination key | |
optimize | if set, check all nodes and return the best/closest one |
Implemented in PastryLeafSet, PastryNeighborhoodSet, and PastryRoutingTable.
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.
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 |
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
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
msg | the PastryStateMessage to use as source for update | |
prox | record of proximity values matching the state message |
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 { 00073 node = &(msg->getLeafSet(i)); 00074 rtt = *(prox.pr_ls.begin() + i); 00075 00076 // unspecified nodes, own node and dead nodes not considered 00077 if ( !(rtt < 0 || node->isUnspecified() || *node == owner) ) 00078 { 00079 if (mergeNode(*node, rtt)) ret = true; 00080 } 00081 } 00082 00083 // walk through msg's RoutingTable 00084 for (int i = 0; i < rtSize; i++) 00085 { 00086 node = &(msg->getRoutingTable(i)); 00087 rtt = *(prox.pr_rt.begin() + i); 00088 00089 // unspecified nodes, own node and dead nodes not considered 00090 if ( !(rtt < 0 || node->isUnspecified() || *node == owner) ) 00091 { 00092 if (mergeNode(*node, rtt)) ret = true; 00093 } 00094 } 00095 00096 // walk through msg's NeighborhoodSet 00097 for (int i = 0; i < nsSize; i++) 00098 { 00099 node = &(msg->getNeighborhoodSet(i)); 00100 rtt = *(prox.pr_ns.begin() + i); 00101 00102 // unspecified nodes, own node and dead nodes not considered 00103 if ( !(rtt < 0 || node->isUnspecified() || *node == owner) ) 00104 { 00105 if (mergeNode(*node, rtt)) ret = true; 00106 } 00107 } 00108 00109 return ret; 00110 }
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.
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 |
00147 { 00148 // assert: (! test.isUnspecified()) && (! owner.isUnspecified()) 00149 00150 const NodeHandle* ref = &reference; 00151 if (ref->isUnspecified()) ref = &owner; 00152 00153 if ((ref->key == destination) || (test == *ref)) 00154 { 00155 return false; 00156 } 00157 00158 bool closer = false; 00159 const OverlayKey* refDist = keyDist(ref->key, destination); 00160 const OverlayKey* testDist = keyDist(test.key, destination); 00161 if (*testDist < *refDist) closer = true; 00162 delete refDist; 00163 delete testDist; 00164 return closer; 00165 }
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 |
00169 { 00170 // assert: (! test.isUnspecified()) && (! owner.isUnspecified()) 00171 00172 if (test.key.sharedPrefixLength(destination) 00173 < owner.key.sharedPrefixLength(destination)) 00174 { 00175 return false; 00176 } 00177 00178 return isCloser(test, destination, reference); 00179 }
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
node | handle of the node | |
prox | proximity value of the node |
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
a | one key | |
b | another key |
00114 { 00115 const OverlayKey* smaller; 00116 const OverlayKey* bigger; 00117 00118 if (a > b) 00119 { 00120 smaller = &b; 00121 bigger = &a; 00122 } 00123 else 00124 { 00125 smaller = &a; 00126 bigger = &b; 00127 } 00128 00129 OverlayKey diff1(*bigger - *smaller); 00130 OverlayKey diff2(*smaller + (OverlayKey::max() - *bigger) + 1); 00131 00132 const OverlayKey* dist; 00133 if (diff1 > diff2) 00134 { 00135 dist = new OverlayKey(diff2); 00136 } 00137 else 00138 { 00139 dist = new OverlayKey(diff1); 00140 } 00141 00142 return dist; 00143 }
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