OverSim
GlobalViewBuilder Class Reference

#include <GlobalViewBuilder.h>

Inheritance diagram for GlobalViewBuilder:
AbstractTreeMsgClient RpcListener

Public Member Functions

 GlobalViewBuilder ()
virtual ~GlobalViewBuilder ()
void initializeViewBuilder (NeighborCache *neighborCache, BaseOverlay *overlay)
 .cc
void start ()
void cleanup ()
void handleTimerEvent (cMessage *msg)
void handleCoordSendTimer (cMessage *msg)
void handleCoordinateRpcCall (GlobalViewBuilderCall *globalViewBuilderCall)
void handleCapReqRpcCall (CapReqCall *call)
void sendCapRequest (const TransportAddress &node)
bool handleRpcCall (BaseCallMessage *msg)
void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
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.
cPar & parProxy (const char *parname)
void newParent ()
bool isCapReady ()
bool isCapValid ()
const APgetCAP ()
- Public Member Functions inherited from AbstractTreeMsgClient
virtual void newChild (const TransportAddress &child=TransportAddress::UNSPECIFIED_NODE)
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor

Protected Member Functions

void spreadGlobalView ()
 Send the calculated global view down the tree to the children.
bool checkOverlayReady ()

Protected Attributes

NeighborCacheneighborCache
TreeManagementtreeManager
AbstractSendStrategysendStrategy
BaseOverlayoverlay

Private Attributes

double meanCoordSendInterval
 mean time interval between sending test messages
double deviation
 deviation of time interval
cMessage * coordSendTimer
cMessage * spreadCapTimer
std::string activeStrategy
bool onlyAcceptCompleteCCD
SendStrategyFactory sendStrategyFactory
AP cap
bool capReady
uint32_t oldCcdSize

Detailed Description

Definition at line 57 of file GlobalViewBuilder.h.

Constructor & Destructor Documentation

GlobalViewBuilder::GlobalViewBuilder ( )
inline

Definition at line 91 of file GlobalViewBuilder.h.

{
sendStrategy = NULL;
};
virtual GlobalViewBuilder::~GlobalViewBuilder ( )
inlinevirtual

Definition at line 97 of file GlobalViewBuilder.h.

{
delete sendStrategy;
neighborCache->cancelAndDelete(coordSendTimer);
neighborCache->cancelAndDelete(spreadCapTimer);
};

Member Function Documentation

bool GlobalViewBuilder::checkOverlayReady ( )
protected

Definition at line 282 of file GlobalViewBuilder.cc.

Referenced by handleCoordSendTimer().

{
//return UnderlayConfiguratorAccess().get()->isTransitionTimeFinished() && !UnderlayConfiguratorAccess().get()->isInInitPhase();
}
void GlobalViewBuilder::cleanup ( )
const AP* GlobalViewBuilder::getCAP ( )
inline

Definition at line 133 of file GlobalViewBuilder.h.

Referenced by NeighborCache::setCbrNodeId().

{ return &cap; };
void GlobalViewBuilder::handleCapReqRpcCall ( CapReqCall call)

Definition at line 201 of file GlobalViewBuilder.cc.

Referenced by handleRpcCall().

{
AreaDataContainer tmpAreaDataContainer;
tmpAreaDataContainer.CBRAreaPool = cap;
CapReqResponse* response = new CapReqResponse();
response->setAreaData(tmpAreaDataContainer);
neighborCache->sendRpcResponse(call, response);
}
void GlobalViewBuilder::handleCoordinateRpcCall ( GlobalViewBuilderCall globalViewBuilderCall)

Definition at line 93 of file GlobalViewBuilder.cc.

Referenced by handleRpcCall().

{
if (overlay->getThisNode() == msg->getSrcNode()) {
//std::cout << treeManager->getCurrentTreeLevel() << " !!!" << std::endl;
delete msg;
return;
}
// CAP received
if (dynamic_cast<AreaDataCall*>(msg)) {
AreaDataCall* temp = static_cast<AreaDataCall*>(msg);
//treeManager->isParent(msg->getSrcNode())
(msg->getSrcNode() != treeManager->getParentNode())) {
std::cout << neighborCache->getThisNode().getIp()
<< ": " << msg->getSrcNode().getIp() << " is not my parent! Deleting AreaDataCall!" << std::endl;
delete msg;
return;
}
//std::vector<double> tempvec =
// neighborCache->getNcsAccess().getOwnNcsInfo().getCoords();
//for (uint8_t i = 0; i< tempvec.size(); ++i) {
// std::cout << tempvec[i] << std::endl;
//}
//std::cout << overlay->getThisNode().getKey() << " -> "
// << CoordBasedRoutingAccess().get()->getNodeId(tempvec, 4, 160, &cap) << "\n" << std::endl;
neighborCache->getParentModule()->bubble("CAP received!");
capReady = true;
AreaDataCall* newAreaCall = new AreaDataCall("AreaDataCall");
newAreaCall->setAreaData(temp->getAreaData());
newAreaCall->setBitLength(temp->getBitLength());
//std::cout << treeManager->getCurrentTreeLevel() << std::endl;
}
// coordinates received from child
else {
// check if this a child
if (treeManager->isChild(msg->getSrcNode())) {
} else {
//TODO do not delete msg if msg was sent to a key
std::cout << neighborCache->getThisNode().getIp()
<< ": " << msg->getSrcNode().getIp() //<< " (" << msg->getDestKey()
<< ") is no child of mine! Deleting Coordinates!" << std::endl;
delete msg;
return;
}
}
GlobalViewBuilderResponse* gvbResponse = new GlobalViewBuilderResponse("GlobalViewBuilderResponse");
gvbResponse->setBitLength(GLOBALVIEWBUILDERRESPONSE_L(gvbResponse));
neighborCache->sendRpcResponse(msg, gvbResponse);
}
void GlobalViewBuilder::handleCoordSendTimer ( cMessage *  msg)

Definition at line 224 of file GlobalViewBuilder.cc.

Referenced by handleTimerEvent().

{
neighborCache->cancelEvent(msg);
neighborCache->scheduleAt(simTime() + meanCoordSendInterval,
//truncnormal(meanCoordSendInterval, deviation),
msg);
const NodeHandle& thisNode = this->neighborCache->overlay->getThisNode();
if(thisNode.isUnspecified()) {
return;
}
std::stringstream nodeState;
nodeState.str("");
nodeState << "LVL: ";
nodeState << ": ";
if (!treeManager->isRoot() /*neighborCache->getTreeManager()->getParentNode().getKey() !=
neighborCache->overlay->getThisNode().getKey()*/) {
} else {
// this node is root
if(checkOverlayReady() == true) {
EV << "|DD|> GlobalViewBuilder::handleCoordSendTimer ("
<< "Spread GlobaLViewData" << ") <||" << endl;
// wait some seconds before spreading the CAP
neighborCache->scheduleAt(simTime() + 10, spreadCapTimer); //TODO parameter
//spreadGlobalView();
}
}
//std::cout << treeManager->getCurrentTreeLevel() << "\n"
// << sendStrategy->getStrategyDataStatus() << std::endl;
neighborCache->getParentModule()->getDisplayString().setTagArg("t", 0, nodeState.str().c_str());
} else {
std::cout << simTime() << " @ "
<< ": I have no parent :-(" << std::endl;
}
}
bool GlobalViewBuilder::handleRpcCall ( BaseCallMessage msg)
virtual

Implements AbstractTreeMsgClient.

Definition at line 78 of file GlobalViewBuilder.cc.

Referenced by NeighborCache::handleRpcCall().

{
EV << "|DD|> GlobalViewBuilder::handleRpcCall (" << ") <||" << endl;
//delete(msg);
return RPC_HANDLED;
}
void GlobalViewBuilder::handleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)
virtual

This method is called if an RPC response has been received.

Parameters
msgThe response message.
contextPointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcIdThe RPC id.
rttThe Round-Trip-Time of this RPC

Reimplemented from RpcListener.

Definition at line 160 of file GlobalViewBuilder.cc.

{
RPC_ON_RESPONSE(CapReq) {
/*int bitsPerDigit = neighborCache->overlay->getBitsPerDigit();
neighborCache->thisNode.setKey(CoordBasedRoutingAccess().get()->getNodeId(neighborCache->getNcsAccess().getOwnNcsInfo().getCoords(),
bitsPerDigit,
OverlayKey::getLength(),
&_CapReqResponse->getAreaData().CBRAreaPool));
EV << "[GlobalViewBuilder::handleRpcResponse() @ "
<< neighborCache->thisNode.getIp()
<< " (" << neighborCache->thisNode.getKey().toString(16) << ")]"
<< "\n -> nodeID ( 2): "
<< neighborCache->thisNode.getKey().toString(2)
<< "\n -> nodeID (16): "
<< neighborCache->thisNode.getKey().toString(16) << endl;
// returning to BaseOverlay
neighborCache->overlay->join(neighborCache->thisNode.getKey());*/
cap = _CapReqResponse->getAreaData().CBRAreaPool;
//if (cap.size() > 0) //TODO
capReady = true; //TODO
}
}
void GlobalViewBuilder::handleRpcTimeout ( BaseCallMessage msg,
const TransportAddress dest,
cPolymorphic *  context,
int  rpcId,
const OverlayKey destKey 
)
virtual

This method is called if an RPC timeout has been reached.

Parameters
msgThe original RPC message.
destThe destination node
contextPointer to an optional state object. The object has to be handled/deleted by the handleRpcResponse() code
rpcIdThe RPC id.
destKeythe destination OverlayKey

Reimplemented from RpcListener.

Definition at line 191 of file GlobalViewBuilder.cc.

{
std::cout << "THIS SHOULD NOT HAPPEN!!!" << std::endl;
assert(false);
}
void GlobalViewBuilder::handleTimerEvent ( cMessage *  msg)

Definition at line 210 of file GlobalViewBuilder.cc.

Referenced by NeighborCache::handleTimerEvent().

{
if (msg == spreadCapTimer) {
if (treeManager->isRoot()) {
} else {
//std::cout << "msg == spreadCapTimer && !treeManager->isRoot()" << std::endl;
}
} else if (msg == coordSendTimer) {
//neighborCache->cancelEvent(spreadCapTimer);
}
}
void GlobalViewBuilder::initializeViewBuilder ( NeighborCache neighborCache,
BaseOverlay overlay 
)

.cc

Author
Daniel Lienert

Definition at line 33 of file GlobalViewBuilder.cc.

Referenced by NeighborCache::initializeApp().

{
this->neighborCache = neighborCache;
this->overlay = overlay;
this->treeManager = neighborCache->getTreeManager();
meanCoordSendInterval = neighborCache->par("gvbCoordSendInterval");
capReady = false;
onlyAcceptCompleteCCD = neighborCache->par("gvbOnlyAcceptCompleteCCD");
// initialize the send Strategy
activeStrategy = this->neighborCache->par("gvbSendStrategy").stdstringValue();
coordSendTimer = new cMessage("coordSendTimer");
spreadCapTimer = new cMessage("spreadCapTimer");
//start();
}
bool GlobalViewBuilder::isCapReady ( )
inline

Definition at line 131 of file GlobalViewBuilder.h.

Referenced by NeighborCache::prepareOverlay().

{ return capReady; };
bool GlobalViewBuilder::isCapValid ( )
inline

Definition at line 132 of file GlobalViewBuilder.h.

Referenced by NeighborCache::handleTimerEvent(), and NeighborCache::prepareOverlay().

{ return (cap.size() > 0); };
void GlobalViewBuilder::newParent ( )
virtual

Reimplemented from AbstractTreeMsgClient.

Definition at line 276 of file GlobalViewBuilder.cc.

{
//handleCoordSendTimer(coordSendTimer);
}
void GlobalViewBuilder::sendCapRequest ( const TransportAddress node)

Definition at line 152 of file GlobalViewBuilder.cc.

Referenced by NeighborCache::prepareOverlay().

{
assert(!node.isUnspecified());
node,
new CapReqCall("CapRequestCall"),
NULL, DEFAULT_ROUTING, -1, 0, -1, this);
}
void GlobalViewBuilder::spreadGlobalView ( )
protected

Send the calculated global view down the tree to the children.

Definition at line 289 of file GlobalViewBuilder.cc.

Referenced by handleTimerEvent().

{
//std::cout << "CCD: " << ccd.size() << std::endl;
uint32_t tempSize = 0;
if ((oldCcdSize == 0) ||
((ccd.size() < (oldCcdSize * 1.5)) &&
(ccd.size() > (oldCcdSize * 0.5)))) {
tempSize = oldCcdSize;
oldCcdSize = ccd.size();
}
//special case: only accept complete CCD
((int)ccd.size() !=
EV << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CAP.size() " << ccd.size()
<< " != numTerminalCount: no spreading!" << endl;
std::cout << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CCD.size() " << ccd.size()
<< " != numTerminalCount: no spreading!" << std::endl;
return;
} else if (cbr->changeIdLater() &&
(simTime() > cbr->getChangeIdStart()) &&
(simTime() < (cbr->getChangeIdStop() + 3000))) {
EV << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CAP.size() " << ccd.size()
<< " in id change phase, no spreading" << endl;
std::cout << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CAP.size() " << ccd.size()
<< " in id change phase, no spreading" << std::endl;
return;
} else tempSize = oldCcdSize = ccd.size();
//std::cout << "tempSize: " << tempSize << std::endl;
// CCD size check
if ((ccd.size() > (tempSize * 1.2)) ||
(ccd.size() < (tempSize * 0.8))) {
EV << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CAP.size() is too fluctuant: no spreading!" << endl;
std::cout << "[GlobalViewBuilder::spreadGlobalView() @ "
<< " (" << overlay->getThisNode().getKey().toString(16)
<< ")]\n CAP.size() is too fluctuant: no spreading!" << std::endl;
return;
}
/*
for (uint i = 0; i < ccd.size(); ++i) {
std::cout << ccd[i] << ", ";
}
std::cout << std::endl;
uint32_t overlaySize = overlay->estimateOverlaySize();
if ((ccd.size() > (2.0 * overlaySize)) ||
(ccd.size() < (0.5 * overlaySize))) {
//oldCcdSize = ccd.size();
std::cout << "CCD: " << ccd.size()
<< ", overlay->estimateOverlaySize(): " << overlaySize
<< std::endl;
//return;
}
*/
//tmpAreaDataContainer.CBRAreaPool = c2aAdapter->getCBRAreas();
/*
std::cout << "\n\n\nGlobalViewBuilder::spreadGlobalView(): The CCD with size = " << coordsVec.size() << ":" << std::endl;
for (uint32_t i = 0; i < coordsVec.size(); ++i) {
std::cout << coordsVec[i] << " ";
}
std::cout << endl;
*/
const AP* cap =
/*
C2AAdapter* c2aAdapter = C2AAdapter::getInstance();
c2aAdapter->initialize(this, sendStrategy->getStrategyCombinedParams());
c2aAdapter->setCoordinates(coordsVec);
c2aAdapter->createAreas();
const AP cap_test = c2aAdapter->getCBRAreas();
std::cout << " >----- " << cap->size() << std::endl;
//assert (cap_test.size() == cap->size());
std::cout << "#nodes: " << coordsVec.size() << ", #areas: " << cap->size() << std::endl;
for (uint32_t i = 0; i < cap->size(); ++i) {
std::cout << cap->at(i)->prefix << " ("
<< cap->at(i)->min[0] << ", "
<< cap->at(i)->min[1] << ") - ("
<< cap->at(i)->max[0] << ", "
<< cap->at(i)->max[1] << ")"
<< std::endl;
}
std::cout << " ----- " << cap_test.size() << std::endl;
for (uint32_t i = 0; i < cap_test.size(); ++i) {
std::cout << cap_test[i]->prefix << " ("CBRArea
<< cap_test[i]->min[0] << ", "
<< cap_test[i]->min[1] << ") - ("
<< cap_test[i]->max[0] << ", "
<< cap_test[i]->max[1] << ")"
<< std::endl;
}
std::cout << " -----< " << std::endl;
*/
if (cap == NULL) {
EV << "[GlobalViewBuilder::spreadGlobalView() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " No CAP available for spreading!" << endl;
std::cout << "[GlobalViewBuilder::spreadGlobalView() @ " << overlay->getThisNode().getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " No CAP available for spreading!" << std::endl;
return;
}
// measurement of CAP size
/*
std::fstream f;
std::string name("CAP_");
name += simTime().str();
name += ".bin";
f.open(name.c_str(), std::ios::binary|std::ios::out);
for (uint32_t i = 0; i < cap->size(); ++i) {
f.write((char*)&(cap->at(i).prefix), sizeof(cap->at(i).prefix));
f.write((char*)&(cap->at(i).min[0]), sizeof(cap->at(i).min[0]));
f.write((char*)&(cap->at(i).min[1]), sizeof(cap->at(i).min[1]));
f.write((char*)&(cap->at(i).max[0]), sizeof(cap->at(i).max[0]));
f.write((char*)&(cap->at(i).max[1]), sizeof(cap->at(i).max[1]));
}
f.close();
*/
AreaDataCall* msg = new AreaDataCall("AreaDataCall");
AreaDataContainer tmpAreaDataContainer;
tmpAreaDataContainer.CBRAreaPool = *cap;
delete cap;
std::cout << "\n " << simTime() << " CCD @ "
<< ": size = " << ccd.size() << "\n" << std::endl;
msg->setAreaData(tmpAreaDataContainer);
neighborCache->globalStatistics->addStdDev("GlobalViewBuilder: CCD size",
ccd.size());
}
void GlobalViewBuilder::start ( )

Definition at line 59 of file GlobalViewBuilder.cc.

Referenced by NeighborCache::handleReadyMessage().

{
neighborCache->scheduleAt(simTime() +
truncnormal(meanCoordSendInterval / 2.0, //TODO
}

Member Data Documentation

std::string GlobalViewBuilder::activeStrategy
private

Definition at line 66 of file GlobalViewBuilder.h.

Referenced by initializeViewBuilder().

AP GlobalViewBuilder::cap
private
bool GlobalViewBuilder::capReady
private
cMessage* GlobalViewBuilder::coordSendTimer
private
double GlobalViewBuilder::deviation
private

deviation of time interval

Definition at line 61 of file GlobalViewBuilder.h.

Referenced by initializeViewBuilder(), and start().

double GlobalViewBuilder::meanCoordSendInterval
private

mean time interval between sending test messages

Definition at line 60 of file GlobalViewBuilder.h.

Referenced by handleCoordSendTimer(), initializeViewBuilder(), and start().

uint32_t GlobalViewBuilder::oldCcdSize
private

Definition at line 73 of file GlobalViewBuilder.h.

Referenced by initializeViewBuilder(), and spreadGlobalView().

bool GlobalViewBuilder::onlyAcceptCompleteCCD
private

Definition at line 67 of file GlobalViewBuilder.h.

Referenced by initializeViewBuilder(), and spreadGlobalView().

BaseOverlay* GlobalViewBuilder::overlay
protected
SendStrategyFactory GlobalViewBuilder::sendStrategyFactory
private

Definition at line 69 of file GlobalViewBuilder.h.

cMessage* GlobalViewBuilder::spreadCapTimer
private
TreeManagement* GlobalViewBuilder::treeManager
protected

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