OverSim
PastryNeighborhoodSet Class Reference

PastryNeighborhoodSet module. More...

#include <PastryNeighborhoodSet.h>

Inheritance diagram for PastryNeighborhoodSet:
PastryStateObject

Public Member Functions

void initializeSet (uint32_t numberOfNeighbors, uint32_t bitsPerDigit, const NodeHandle &owner)
 Initializes the neighborhood set.
virtual void dumpToStateMessage (PastryStateMessage *msg) const
 dump content of the set to a PastryStateMessage
virtual const NodeHandlefindCloserNode (const OverlayKey &destination, bool optimize=false)
 try to find a node numerically closer to a given key with the same shared prefix as the current node in the neighborhood set.
void findCloserNodes (const OverlayKey &destination, NodeVector *nodes)
virtual bool mergeNode (const NodeHandle &node, simtime_t prox)
 merge a node into NeighborhoodSet
virtual void dumpToVector (std::vector< TransportAddress > &affected) const
 appends all neighborhood set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.
virtual const TransportAddressfailedNode (const TransportAddress &failed)
 tell the neighborhood set about a failed node
- Public Member Functions inherited from PastryStateObject
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 TransportAddressrepair (const PastryStateMessage *msg, const PastryStateMsgProximity &prox)
 attempt to repair state using a received REPAIR message
virtual bool mergeState (const PastryStateMessage *msg, const PastryStateMsgProximity *prox)
 update own state based on a received PastryStateMessage
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

Private Member Functions

virtual void earlyInit (void)

Private Attributes

uint32_t numberOfNeighbors
std::vector< PastryExtendedNodeneighbors

Additional Inherited Members

- Static Protected Member Functions inherited from PastryStateObject
static const PastryExtendedNodeunspecNode ()
- Protected Attributes inherited from PastryStateObject
NodeHandle owner
 stores the NodeHandle of the owner of this PastryStateObject.
uint32_t bitsPerDigit

Detailed Description

PastryNeighborhoodSet module.

This module contains the NeighborhoodSet of the Pastry implementation.

Author
Felix Palmen
See Also
Pastry

Definition at line 46 of file PastryNeighborhoodSet.h.

Member Function Documentation

void PastryNeighborhoodSet::dumpToStateMessage ( PastryStateMessage msg) const
virtual

dump content of the set to a PastryStateMessage

Parameters
msgthe PastryStateMessage to be filled with entries

Implements PastryStateObject.

Definition at line 52 of file PastryNeighborhoodSet.cc.

Referenced by BasePastry::createStateMessage().

{
uint32_t i = 0;
uint32_t size = 0;
std::vector<PastryExtendedNode>::const_iterator it;
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (!it->node.isUnspecified()) {
++size;
msg->setNeighborhoodSet(i++, it->node);
}
}
}
void PastryNeighborhoodSet::dumpToVector ( std::vector< TransportAddress > &  affected) const
virtual

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

Parameters
affectedthe vector to fill with leaf set entries

Implements PastryStateObject.

Definition at line 136 of file PastryNeighborhoodSet.cc.

Referenced by Pastry::doSecondStage().

{
std::vector<PastryExtendedNode>::const_iterator it;
for (it = neighbors.begin(); it != neighbors.end(); it++)
if (! it->node.isUnspecified())
affected.push_back(it->node);
}
void PastryNeighborhoodSet::earlyInit ( void  )
privatevirtual

Definition at line 31 of file PastryNeighborhoodSet.cc.

{
WATCH_VECTOR(neighbors);
}
const TransportAddress & PastryNeighborhoodSet::failedNode ( const TransportAddress failed)
virtual

tell the neighborhood set about a failed node

Parameters
failedthe failed node

Implements PastryStateObject.

Definition at line 146 of file PastryNeighborhoodSet.cc.

Referenced by Bamboo::handleFailedNode(), and Pastry::handleFailedNode().

{
std::vector<PastryExtendedNode>::iterator it;
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (it->node.isUnspecified()) break;
if (it->node.getIp() == failed.getIp()) {
neighbors.erase(it);
neighbors.push_back(unspecNode());
break;
}
}
// never ask for repair
}
const NodeHandle & PastryNeighborhoodSet::findCloserNode ( const OverlayKey destination,
bool  optimize = false 
)
virtual

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

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

Implements PastryStateObject.

Definition at line 69 of file PastryNeighborhoodSet.cc.

Referenced by BasePastry::findNode().

{
std::vector<PastryExtendedNode>::const_iterator it;
if (optimize) {
// pointer to later return value, initialize to unspecified, so
// the specialCloserCondition() check will be done against our own
// node as long as no node closer to the destination than our own was
// found.
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (it->node.isUnspecified()) break;
if (specialCloserCondition(it->node, destination, *ret))
ret = &(it->node);
}
return *ret;
} else {
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (it->node.isUnspecified()) break;
if (specialCloserCondition(it->node, destination)) return it->node;
}
}
}
void PastryNeighborhoodSet::findCloserNodes ( const OverlayKey destination,
NodeVector nodes 
)
virtual

Implements PastryStateObject.

Definition at line 97 of file PastryNeighborhoodSet.cc.

Referenced by BasePastry::findNode().

{
std::vector<PastryExtendedNode>::const_iterator it;
for (it = neighbors.begin(); it != neighbors.end(); it++)
if (! it->node.isUnspecified())
nodes->add(it->node);
}
void PastryNeighborhoodSet::initializeSet ( uint32_t  numberOfNeighbors,
uint32_t  bitsPerDigit,
const NodeHandle owner 
)

Initializes the neighborhood set.

This should be called on startup

Parameters
numberOfNeighborsPastry configuration parameter
bitsPerDigitnumber of bits per digits
ownerthe node this table belongs to

Definition at line 37 of file PastryNeighborhoodSet.cc.

Referenced by BasePastry::baseChangeState().

{
this->owner = owner;
if (!neighbors.empty()) neighbors.clear();
// fill Set with unspecified node handles
for (uint32_t i = numberOfNeighbors; i>0; i--)
neighbors.push_back(unspecNode());
}
bool PastryNeighborhoodSet::mergeNode ( const NodeHandle node,
simtime_t  prox 
)
virtual

merge a node into NeighborhoodSet

Parameters
nodethe node to merge
proxproximity value of the node
Returns
true if node was merged

Implements PastryStateObject.

Definition at line 108 of file PastryNeighborhoodSet.cc.

{
std::vector<PastryExtendedNode>::iterator it;
bool nodeAlreadyInVector = false; // was the node already in the list?
bool nodeValueWasChanged = false; // true if the list was changed, false if the rtt was too big
// look for node in the set, if it's there and the value was changed, erase it (since the position is no longer valid)
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (!it->node.isUnspecified() && it->node == node) {
if (prox == SimTime::getMaxTime() || it->rtt == prox) return false; // nothing to do!
neighbors.erase(it);
nodeAlreadyInVector = true;
break;
}
}
// look for the correct position for the node
for (it = neighbors.begin(); it != neighbors.end(); it++) {
if (it->node.isUnspecified() || (it->rtt > prox)) {
nodeValueWasChanged = true;
break;
}
}
neighbors.insert(it, PastryExtendedNode(node, prox)); // insert the entry there
if (!nodeAlreadyInVector) neighbors.pop_back(); // if a new entry was inserted, erase the last entry
return !nodeAlreadyInVector && nodeValueWasChanged; // return whether a new entry was added
}

Member Data Documentation

std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors
private
uint32_t PastryNeighborhoodSet::numberOfNeighbors
private

Definition at line 112 of file PastryNeighborhoodSet.h.

Referenced by dumpToStateMessage(), and initializeSet().


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