OverSim
DiscoveryMode Class Reference

#include <DiscoveryMode.h>

Inheritance diagram for DiscoveryMode:
RpcListener ProxListener

Public Member Functions

virtual ~DiscoveryMode ()
void init (NeighborCache *neighborCache)
void start (const TransportAddress &bootstrapNode)
void stop ()
double getImprovement ()
bool isFinished ()
bool handleRpcCall (BaseCallMessage *msg)
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor

Protected Member Functions

void proxCallback (const TransportAddress &node, int rpcId, cPolymorphic *contextPointer, Prox prox)
void sendNewRequest (DiscoveryNodesType type, uint8_t numNodes)
- Protected Member Functions inherited from RpcListener
virtual void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcResponse (BaseResponseMessage *msg, const RpcState &rpcState, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
virtual void handleRpcTimeout (const RpcState &rpcState)
 This method is called if an RPC timeout has been reached.

Protected Attributes

int16_t step
uint8_t maxSteps
int8_t spreadedSteps
uint8_t queries
int8_t maxIndex
simtime_t nearNodeRtt
bool nearNodeImproved
TransportAddress nearNode

Private Attributes

NeighborCacheneighborCache
uint8_t numCloseNodes
uint8_t numSpreadedNodes
double firstRtt
double improvement
bool finished
BasePastrybasePastry

Additional Inherited Members

- Private Member Functions inherited from ProxListener
virtual void proxCallback (const TransportAddress &node, int rpcId, cPolymorphic *contextPointer, Prox prox)=0

Detailed Description

Definition at line 17 of file DiscoveryMode.h.

Constructor & Destructor Documentation

virtual DiscoveryMode::~DiscoveryMode ( )
inlinevirtual

Definition at line 48 of file DiscoveryMode.h.

{};

Member Function Documentation

double DiscoveryMode::getImprovement ( )
inline

Definition at line 54 of file DiscoveryMode.h.

Referenced by stop().

{ return improvement; };
bool DiscoveryMode::handleRpcCall ( BaseCallMessage msg)

Definition at line 97 of file DiscoveryMode.cc.

Referenced by NeighborCache::handleRpcCall().

{
if (dynamic_cast<DiscoveryCall*>(msg)) {
DiscoveryCall* discoveryCall = static_cast<DiscoveryCall*>(msg);
std::vector<TransportAddress>* temp;
DiscoveryResponse* discoveryResponse =
new DiscoveryResponse("DiscoveryResponse");
if (discoveryCall->getNodesType() == SPREADED_NODES) {
if (basePastry) {
} else {
temp = neighborCache->getSpreadedNodes(discoveryCall->getNumberOfNodes());
}
} else {
if (basePastry) {
if (discoveryCall->getIndex() == 0) {
discoveryResponse->setMaxIndex(basePastry->getRTLastRow() - 1);
}
int16_t rowIndex = basePastry->getRTLastRow()
- discoveryCall->getIndex();
if (rowIndex < 1) rowIndex = 1;
temp = basePastry->getRTRow(rowIndex);
} else {
temp = neighborCache->getClosestNodes(discoveryCall->getNumberOfNodes());
}
}
discoveryResponse->setNodesArraySize(temp->size());
for (uint16_t i = 0; i < temp->size(); ++i) {
discoveryResponse->setNodes(i, (*temp)[i]);
}
delete temp;
neighborCache->sendRpcResponse(discoveryCall, discoveryResponse);
return true;
}
return false;
}
void DiscoveryMode::handleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)

Definition at line 140 of file DiscoveryMode.cc.

{
if (dynamic_cast<DiscoveryResponse*>(msg)) {
DiscoveryResponse* discoveryResponse =
static_cast<DiscoveryResponse*>(msg);
EV << "[DiscoveryMode::handleRpcResponse() @ " << neighborCache->getThisNode().getIp()
<< " (" << neighborCache->getThisNode().getKey().toString(16) << ")]\n"
<< " receiving DiscoveryResponse from "
<< msg->getSrcNode().getIp()
<< " (step = " << (int)step << ")"
<< endl;
if (nearNodeRtt > rtt) {
if (nearNode.isUnspecified() || nearNode != discoveryResponse->getSrcNode()) {
EV << " , which is now the closest known neighbor."
<< endl;
nearNode = discoveryResponse->getSrcNode();
}
nearNodeRtt = rtt;
if (step == 0) firstRtt = SIMTIME_DBL(rtt);
}
const TransportAddress* node;
for (uint16_t i = 0; i < discoveryResponse->getNodesArraySize(); i++) {
node = &(discoveryResponse->getNodes(i));
// unspecified nodes not considered
if (!(node->isUnspecified() || *node == neighborCache->getThisNode())) {
-1, this, NULL);
if (temp == Prox::PROX_TIMEOUT
|| temp == Prox::PROX_UNKNOWN
|| temp == Prox::PROX_WAITING) {
} else if (nearNodeRtt > temp.proximity) {
nearNode = *node;
}
}
}
int16_t ind = discoveryResponse->getMaxIndex();
if (ind != -1) maxIndex = ind;
EV << "[DiscoveryMode::handleRpcResponse() @ " << neighborCache->getThisNode().getIp()
<< " (" << neighborCache->getThisNode().getKey().toString(16) << ")]\n"
<< " maxIndex of " << msg->getSrcNode().getIp()
<< " is " << (int)maxIndex << "."
<< endl;
//if (--spreadedSteps >= 0) {
//} else {
//sendNewRequest(CLOSE_NODES, numCloseNodes);
//}
}
}
void DiscoveryMode::handleRpcTimeout ( BaseCallMessage msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey 
)

Definition at line 208 of file DiscoveryMode.cc.

{
}
void DiscoveryMode::init ( NeighborCache neighborCache)

Definition at line 16 of file DiscoveryMode.cc.

Referenced by NeighborCache::initializeApp().

{
this->neighborCache = neighborCache;
nearNodeRtt = MAXTIME;
firstRtt = SIMTIME_DBL(MAXTIME);
maxIndex = -1;
finished = false;
basePastry = NULL;//dynamic_cast<BasePastry*>(neighborCache->overlay);
numCloseNodes = neighborCache->par("discoveryModeNumCloseNodes");
numSpreadedNodes = neighborCache->par("discoveryModeNumSpreadedNodes");
maxSteps = neighborCache->par("discoveryModeMaxSteps");
spreadedSteps = (int)neighborCache->par("discoveryModeSpreadedSteps");
}
bool DiscoveryMode::isFinished ( )
inline

Definition at line 55 of file DiscoveryMode.h.

Referenced by NeighborCache::prepareOverlay().

{ return finished; };
void DiscoveryMode::proxCallback ( const TransportAddress node,
int  rpcId,
cPolymorphic *  contextPointer,
Prox  prox 
)
protected

Definition at line 217 of file DiscoveryMode.cc.

{
if (prox != Prox::PROX_TIMEOUT && prox != Prox::PROX_SELF &&
nearNode = node;
}
//sendNewRequest(CLOSE_NODES, numCloseNodes);
}
void DiscoveryMode::sendNewRequest ( DiscoveryNodesType  type,
uint8_t  numNodes 
)
protected

Definition at line 233 of file DiscoveryMode.cc.

Referenced by handleRpcResponse(), and proxCallback().

{
const SVivaldi& svivaldi = dynamic_cast<const SVivaldi&>(neighborCache->getNcsAccess());
if (queries == 0) {
if (/*(step < maxSteps || maxSteps == -1) && */svivaldi.getOwnError() > 0.02 && svivaldi.getLoss() < 0.95
/*(nearNodeImproved || step <= maxIndex)*/) {
//std::cout << (int)step << " " << (int)maxIndex << std::endl;
++step;
DiscoveryCall* discoveryCall1 = new DiscoveryCall("DiscoveryCall");
DiscoveryCall* discoveryCall2 = new DiscoveryCall("DiscoveryCall");
discoveryCall1->setNodesType(CLOSE_NODES);
discoveryCall2->setNodesType(SPREADED_NODES);
discoveryCall1->setNumberOfNodes(numCloseNodes);
//discoveryCall->setIndex(step - 1);
//std::vector<TransportAddress>* temp =
// neighborCache->getClosestNodes(1);
//if (temp->size() < 1) {
// throw cRuntimeError("no node for discovery available");
//}
EV << "[DiscoveryMode::sendNewRequest() @ " << neighborCache->getThisNode().getIp()
<< " (" << neighborCache->getThisNode().getKey().toString(16) << ")]\n"
<< " sending new DiscoveryCall to "
<< nearNode.getIp() << " for "
<< (basePastry ? "routing table row" : "close nodes")
<< ". (step = " << (int)step << ")"
<< endl;
nearNode/*(*temp)[0]*/, discoveryCall1, NULL,
NO_OVERLAY_ROUTING, -1, 0, -1,
this);
nearNode/*(*temp)[0]*/, discoveryCall2, NULL,
NO_OVERLAY_ROUTING, -1, 0, -1,
this);
//delete temp;
} else {
stop();
}
}
}
void DiscoveryMode::start ( const TransportAddress bootstrapNode)

Definition at line 34 of file DiscoveryMode.cc.

Referenced by NeighborCache::handleReadyMessage().

{
step = 0;
queries = 0;
if (bootstrapNode.isUnspecified()) {
stop();
} else {
EV << "[DiscoveryMode::start() @ " << neighborCache->getThisNode().getIp()
<< " (" << neighborCache->getThisNode().getKey().toString(16) << ")]\n"
<< " starting Discovery Mode (first asking "
<< bootstrapNode.getIp() << " for "
<< (basePastry ? "leafSet" : "spreaded nodes)") << ")"
<< endl;
// 1. ask bootstrap node for other nodes and his coordinates
DiscoveryCall* discoveryCall = new DiscoveryCall("DiscoveryCall");
discoveryCall->setNodesType(SPREADED_NODES);
bootstrapNode, discoveryCall, NULL,
NO_OVERLAY_ROUTING, -1, 0, -1, this);
// 2. probe other nodes and optionally ask them for more nodes
// (try to get close as well as distant nodes)
// sendReadyMessage();
}
}
void DiscoveryMode::stop ( )

Definition at line 66 of file DiscoveryMode.cc.

Referenced by sendNewRequest(), and start().

{
improvement = firstRtt - SIMTIME_DBL(nearNodeRtt);
EV << "[DiscoveryMode::stop() @ " << neighborCache->getThisNode().getIp()
<< " (" << neighborCache->getThisNode().getKey().toString(16) << ")]\n"
<< " stopping Discovery mode with "
<< nearNode.getIp() << " as closest node, which is "
<< improvement << " s closer (RTT) than the original bootstrap node."
<< endl;
neighborCache->getParentModule()->bubble("Discovery Mode finished!");
finished = true;
//RECORD_STATS(
neighborCache->globalStatistics->addStdDev("NeighborCache: Discovery Mode Improvement",
if (dynamic_cast<const Vivaldi*>(&(neighborCache->getNcsAccess()))) {
neighborCache->globalStatistics->addStdDev("NeighborCache: Vivaldi-Error after Discovery Mode",
static_cast<const Vivaldi&>(neighborCache->getNcsAccess()).getOwnError());
}
}
//);
const SVivaldi& svivaldi = dynamic_cast<const SVivaldi&>(neighborCache->getNcsAccess());
std::cout << "step: " << step << ", e: " << svivaldi.getOwnError() << ", l: " << svivaldi.getLoss() << std::endl;
const_cast<SVivaldi&>(svivaldi).stopAdaptation();
}

Member Data Documentation

BasePastry* DiscoveryMode::basePastry
private

Definition at line 30 of file DiscoveryMode.h.

Referenced by handleRpcCall(), init(), sendNewRequest(), and start().

bool DiscoveryMode::finished
private

Definition at line 28 of file DiscoveryMode.h.

Referenced by init(), isFinished(), and stop().

double DiscoveryMode::firstRtt
private

Definition at line 25 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), init(), and stop().

double DiscoveryMode::improvement
private

Definition at line 26 of file DiscoveryMode.h.

Referenced by getImprovement(), init(), and stop().

int8_t DiscoveryMode::maxIndex
protected

Definition at line 37 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), and init().

uint8_t DiscoveryMode::maxSteps
protected

Definition at line 34 of file DiscoveryMode.h.

Referenced by init().

TransportAddress DiscoveryMode::nearNode
protected

Definition at line 40 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), proxCallback(), sendNewRequest(), and stop().

bool DiscoveryMode::nearNodeImproved
protected

Definition at line 39 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), init(), proxCallback(), and sendNewRequest().

simtime_t DiscoveryMode::nearNodeRtt
protected

Definition at line 38 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), init(), proxCallback(), and stop().

NeighborCache* DiscoveryMode::neighborCache
private

Definition at line 20 of file DiscoveryMode.h.

Referenced by handleRpcCall(), handleRpcResponse(), init(), sendNewRequest(), start(), and stop().

uint8_t DiscoveryMode::numCloseNodes
private

Definition at line 22 of file DiscoveryMode.h.

Referenced by init(), and sendNewRequest().

uint8_t DiscoveryMode::numSpreadedNodes
private

Definition at line 23 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), init(), proxCallback(), sendNewRequest(), and start().

uint8_t DiscoveryMode::queries
protected
int8_t DiscoveryMode::spreadedSteps
protected

Definition at line 35 of file DiscoveryMode.h.

Referenced by init().

int16_t DiscoveryMode::step
protected

Definition at line 33 of file DiscoveryMode.h.

Referenced by handleRpcResponse(), sendNewRequest(), start(), and stop().


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