#include <IterativeLookup.h>
Definition at line 260 of file IterativeLookup.h.
Protected Member Functions | |
| bool | accepts (int rpcId) |
| void | handleResponse (FindNodeResponse *msg) |
| void | handleTimeout (BaseCallMessage *msg, const TransportAddress &dest, int rpcId) |
| void | handleFailedNodeResponse (const NodeHandle &src, cPacket *findNodeExt, bool retry) |
| IterativePathLookup (IterativeLookup *lookup) | |
| virtual | ~IterativePathLookup () |
| virtual FindNodeCall * | createRpcMessage (cPacket *findNodeExt=NULL) |
| Creates a find node call message. | |
| int | add (const NodeHandle &handle, const NodeHandle &source=NodeHandle::UNSPECIFIED_NODE) |
| Adds a NodeHandle to next hops. | |
Protected Attributes | |
| IterativeLookup * | lookup |
| int | hops |
| int | step |
| int | pendingRpcs |
| bool | finished |
| bool | success |
| LookupVector | nextHops |
| std::map< TransportAddress, NodeHandle > | oldNextHops |
Private Member Functions | |
| void | sendRpc (int num, cPacket *FindNodeExt=NULL) |
| void | sendNewRpcAfterTimeout (cPacket *findNodeExt) |
Friends | |
| class | IterativeLookup |
| IterativePathLookup::IterativePathLookup | ( | IterativeLookup * | lookup | ) | [protected] |
Definition at line 617 of file IterativeLookup.cc.
00618 { 00619 this->lookup = lookup; 00620 this->hops = 0; 00621 this->step = 0; 00622 this->pendingRpcs = 0; 00623 this->finished = false; 00624 this->success = false; 00625 00626 if (lookup->routingType == EXHAUSTIVE_ITERATIVE_ROUTING) { 00627 // need to add some extra space for backup nodes, if we have to 00628 // remove failed nodes from the nextHops vector 00629 this->nextHops = LookupVector(2*(lookup->config.redundantNodes), 00630 lookup); 00631 } else { 00632 this->nextHops = LookupVector((lookup->config.redundantNodes), 00633 lookup); 00634 } 00635 }
| IterativePathLookup::~IterativePathLookup | ( | ) | [protected, virtual] |
| bool IterativePathLookup::accepts | ( | int | rpcId | ) | [protected] |
Definition at line 640 of file IterativeLookup.cc.
Referenced by IterativeLookup::handleRpcResponse().
00641 { 00642 if (finished) { 00643 return false; 00644 } 00645 00646 // shall we use all responses, or only 00647 // the first one (rpcId == step)? 00648 if (lookup->config.useAllParallelResponses 00649 && lookup->config.merge) { 00650 00651 return true; 00652 } 00653 00654 return (rpcId == step); 00655 }
| void IterativePathLookup::handleResponse | ( | FindNodeResponse * | msg | ) | [protected] |
Definition at line 657 of file IterativeLookup.cc.
Referenced by IterativeLookup::handleRpcResponse().
00658 { 00659 if (finished) 00660 return; 00661 00662 const NodeHandle& source = msg->getSrcNode(); 00663 std::map<TransportAddress, NodeHandle>::iterator oldPos; 00664 oldPos = oldNextHops.find(source); 00665 if (oldPos != oldNextHops.end()) oldNextHops.erase(oldPos); 00666 00667 // don't count local hops 00668 if (lookup->overlay->getThisNode() != source) { 00669 hops++; 00670 } 00671 00672 lookup->setVisited(source); 00673 00674 if (source.key == lookup->key) { 00675 00676 // cout << "received response from destination for key " << lookup->key 00677 // << " with isSibling = " << msg->getSiblings() << endl; 00678 } 00679 00680 step++; 00681 00682 // decrease pending rpcs 00683 pendingRpcs--; 00684 00685 if (msg->getClosestNodesArraySize() != 0) { 00686 // mode: merge or replace 00687 if (!lookup->config.merge) { 00688 nextHops.clear(); 00689 } 00690 } else { 00691 //cout << "findNode() returned 0 nodes!" << endl; 00692 } 00693 00694 int numNewRpcs = 0; 00695 00696 // add new next hops 00697 for (uint32_t i=0; i < msg->getClosestNodesArraySize(); i++) { 00698 const NodeHandle& handle = msg->getClosestNodes(i); 00699 00700 // add NodeHandle to next hops and siblings 00701 int pos = add(handle, source); 00702 00703 // only send new rpcs if we've learned about new nodes 00704 if ((pos >= 0) && (pos < lookup->config.redundantNodes)) { 00705 numNewRpcs++; 00706 } 00707 00708 // check if node was found 00709 if ((lookup->numSiblings == 0) && (handle.key == lookup->key) 00710 && (!lookup->config.secure)) { 00711 00712 lookup->addSibling(handle); 00713 00714 finished = true; 00715 success = true; 00716 return; 00717 } else { 00718 if (lookup->numSiblings != 0 && !lookup->config.secure 00719 && (lookup->routingType != EXHAUSTIVE_ITERATIVE_ROUTING) 00720 && msg->getSiblings()) { 00721 00722 //cout << "adding sibling " << handle << endl; 00723 lookup->addSibling(handle); 00724 } 00725 } 00726 } 00727 00728 #if 0 00729 cout << "nextHops.size " << nextHops.size() 00730 << " find node response " << msg->getClosestNodesArraySize() 00731 << " config " << lookup->config.redundantNodes << endl; 00732 00733 cout << "looking for " << lookup->key << endl; 00734 00735 for (uint32_t i=0; i < msg->getClosestNodesArraySize(); i++) { 00736 cout << "find node " << msg->getClosestNodes(i) << endl; 00737 } 00738 00739 cout << "next Hops " << nextHops << endl; 00740 #endif 00741 00742 // check if sibling lookup is finished 00743 if ((lookup->routingType != EXHAUSTIVE_ITERATIVE_ROUTING) 00744 && msg->getSiblings() 00745 && msg->getClosestNodesArraySize() != 0 && 00746 lookup->numSiblings != 0 && !lookup->config.secure) { 00747 00748 finished = true; 00749 success = true; 00750 return; 00751 } 00752 00753 // extract find node extension object 00754 cPacket* findNodeExt = NULL; 00755 if (msg->hasObject("findNodeExt")) { 00756 findNodeExt = (cPacket*)msg->removeObject("findNodeExt"); 00757 } 00758 00759 // If config.newRpcOnEveryResponse is true, send a new RPC 00760 // even if there was no lookup progress 00761 if ((numNewRpcs == 0) && lookup->config.newRpcOnEveryResponse) { 00762 numNewRpcs = 1; 00763 } 00764 00765 // send next rpcs 00766 sendRpc(min(numNewRpcs, lookup->config.parallelRpcs), findNodeExt); 00767 00768 delete findNodeExt; 00769 }
| void IterativePathLookup::handleTimeout | ( | BaseCallMessage * | msg, | |
| const TransportAddress & | dest, | |||
| int | rpcId | |||
| ) | [protected] |
Definition at line 783 of file IterativeLookup.cc.
Referenced by IterativeLookup::handleRpcResponse(), and IterativeLookup::handleRpcTimeout().
00785 { 00786 if (finished) 00787 return; 00788 00789 EV << "[IterativePathLookup::handleTimeout()]\n" 00790 << " Timeout of RPC " << rpcId 00791 << endl; 00792 00793 //std::cout << lookup->overlay->getThisNode() << ": Path timeout for node" 00794 // << dest << endl; 00795 00796 if ((lookup->routingType == EXHAUSTIVE_ITERATIVE_ROUTING) 00797 && lookup->getDead(dest)) { 00798 nextHops.erase(nextHops.findIterator(( 00799 dynamic_cast<const NodeHandle&>(dest)).key)); 00800 } 00801 00802 std::map<TransportAddress, NodeHandle>::iterator oldPos; 00803 oldPos = oldNextHops.find(dest); 00804 00805 // decrease pending rpcs 00806 pendingRpcs--; 00807 00808 cPacket* findNodeExt = NULL; 00809 if (msg && msg->hasObject("findNodeExt")) { 00810 findNodeExt = static_cast<cPacket*>( 00811 msg->removeObject("findNodeExt")); 00812 } 00813 00814 if (oldPos == oldNextHops.end() || (!lookup->config.failedNodeRpcs)) { 00815 sendNewRpcAfterTimeout(findNodeExt); 00816 delete findNodeExt; 00817 } else { 00818 if (oldPos->second.isUnspecified()) { 00819 FindNodeCall* findNodeCall = dynamic_cast<FindNodeCall*>(msg); 00820 // answer was from local findNode() 00821 00822 if (findNodeCall && lookup->overlay->handleFailedNode(dest)) { 00823 NodeVector* retry = lookup->overlay->findNode( 00824 findNodeCall->getLookupKey(), -1, lookup->numSiblings, msg); 00825 00826 for (NodeVector::iterator i = retry->begin(); i != retry->end(); i++) { 00827 nextHops.add(LookupEntry(*i, NodeHandle::UNSPECIFIED_NODE, false)); 00828 } 00829 00830 delete retry; 00831 } 00832 00833 sendNewRpcAfterTimeout(findNodeExt); 00834 delete findNodeExt; 00835 00836 } else { 00837 FailedNodeCall* call = new FailedNodeCall("FailedNodeCall"); 00838 call->setFailedNode(dest); 00839 call->setBitLength(FAILEDNODECALL_L(call)); 00840 if (findNodeExt) { 00841 call->addObject(findNodeExt); 00842 call->addBitLength(findNodeExt->getBitLength()); 00843 } 00844 lookup->overlay->countFailedNodeCall(call); 00845 lookup->overlay->sendUdpRpcCall(oldPos->second, call, NULL, 00846 -1, 0, -1, lookup); 00847 } 00848 } 00849 }
| void IterativePathLookup::handleFailedNodeResponse | ( | const NodeHandle & | src, | |
| cPacket * | findNodeExt, | |||
| bool | retry | |||
| ) | [protected] |
Definition at line 851 of file IterativeLookup.cc.
00853 { 00854 if (finished) { 00855 return; 00856 } 00857 00858 std::map<TransportAddress, NodeHandle>::iterator oldPos; 00859 for (oldPos = oldNextHops.begin(); oldPos != oldNextHops.end(); oldPos++) { 00860 if ((! oldPos->second.isUnspecified()) && 00861 (oldPos->second == src)) break; 00862 } 00863 00864 if (oldPos == oldNextHops.end()) { 00865 return; 00866 } 00867 00868 std::map<TransportAddress, NodeHandle>::iterator oldSrcPos = 00869 oldNextHops.find(src); 00870 const NodeHandle* oldSrc = &NodeHandle::UNSPECIFIED_NODE; 00871 00872 if (oldSrcPos != oldNextHops.end()) { 00873 oldSrc = &(oldSrcPos->second); 00874 } 00875 00876 if (retry) { 00877 // FIXME: This is needed for a node to be asked again when detecting 00878 // a failed node. It could pose problems when parallel lookups and 00879 // failed node recovery are both needed at the same time! 00880 lookup->setVisited(src, false); 00881 00882 nextHops.add(LookupEntry(src, *oldSrc, false)); 00883 } 00884 00885 oldNextHops.erase(oldPos); 00886 00887 sendNewRpcAfterTimeout(findNodeExt); 00888 }
| void IterativePathLookup::sendRpc | ( | int | num, | |
| cPacket * | FindNodeExt = NULL | |||
| ) | [private] |
Definition at line 890 of file IterativeLookup.cc.
Referenced by handleResponse(), sendNewRpcAfterTimeout(), and IterativeLookup::start().
00891 { 00892 // path finished? yes -> quit 00893 if (finished) 00894 return; 00895 00896 // check for maximum hop count 00897 if (lookup->hopCountMax && (hops >= lookup->hopCountMax)) { 00898 EV << "[IterativePathLookup::sendRpc()]\n" 00899 << " Max hop count exceeded - lookup failed!" 00900 << endl; 00901 //cout << "[IterativePathLookup::sendRpc()]\n" 00902 // << " Max hop count exceeded - lookup failed!" 00903 // << endl; 00904 00905 finished = true; 00906 success = false; 00907 00908 return; 00909 } 00910 00911 // if strictParallelRpcs is true, limit concurrent in-flight requests 00912 // to config.parallelRpcs 00913 if (lookup->config.strictParallelRpcs) { 00914 num = min(num, lookup->config.parallelRpcs - pendingRpcs); 00915 } 00916 00917 // try all remaining nodes 00918 if ((num == 0) && (pendingRpcs == 0) 00919 && !lookup->config.finishOnFirstUnchanged) { 00920 num = lookup->config.parallelRpcs; 00921 //cout << "trying all remaining nodes (" 00922 // << lookup->numSiblings << ")" << endl; 00923 } 00924 00925 // send rpc messages 00926 LookupVector::iterator it = nextHops.begin(); 00927 int i = 0; 00928 for (LookupVector::iterator it = nextHops.begin(); 00929 ((num > 0) && (i < lookup->config.redundantNodes) 00930 && (it != nextHops.end())); it++, i++) { 00931 00932 // ignore nodes to which we've already sent an RPC 00933 if (it->alreadyUsed || lookup->getDead(it->handle)) continue; 00934 00935 // check if node has already been visited? no -> 00936 // TODO: doesn't work with Broose 00937 if (!lookup->getVisited(it->handle)) { 00938 // send rpc to node increase pending rpcs 00939 pendingRpcs++; 00940 num--; 00941 FindNodeCall* call = createRpcMessage(findNodeExt); 00942 lookup->sendRpc(it->handle, call, this, step); 00943 oldNextHops[it->handle] = it->source; 00944 00945 //cout << "Sending RPC to " << it->handle 00946 // << " ( " << num << " more )" 00947 // << " thisNode = " << lookup->overlay->getThisNode().key << endl; 00948 00949 // mark node as already used 00950 it->alreadyUsed = true; 00951 } else { 00952 //EV << "[IterativePathLookup::sendRpc()]\n" 00953 // << " Last next hop (" 00954 // << it->handle 00955 // << ") already visited." 00956 // << endl; 00957 00958 // std::cout << "visited:" << std::endl; 00959 // for (TransportAddress::Set::iterator it = lookup->visited.begin(); 00960 // it != lookup->visited.end(); it++) 00961 // std::cout << *it << std::endl; 00962 // 00963 // std::cout << "nextHops:" << std::endl; 00964 // for (NodePairVector::iterator it = nextHops.begin(); 00965 // it != nextHops.end(); it++) 00966 // std::cout << it->first << std::endl; 00967 } 00968 } 00969 00970 // no rpc sent, no pending rpcs? 00971 // -> failed for normal lookups 00972 // -> exhaustive lookups are always successful 00973 if (pendingRpcs == 0) { 00974 if (lookup->routingType == EXHAUSTIVE_ITERATIVE_ROUTING) { 00975 int i = 0; 00976 for (LookupVector::iterator it = nextHops.begin(); 00977 ((i < lookup->config.redundantNodes) 00978 && (it != nextHops.end())); it++, i++) { 00979 lookup->addSibling(it->handle); 00980 } 00981 00982 success = true; 00983 } else { 00984 success = false; 00985 //cout << "failed nextHops for key " << lookup->key << endl; 00986 //cout << nextHops << endl; 00987 } 00988 00989 finished = true; 00990 } 00991 //cout << endl; 00992 }
| void IterativePathLookup::sendNewRpcAfterTimeout | ( | cPacket * | findNodeExt | ) | [private] |
Definition at line 771 of file IterativeLookup.cc.
Referenced by handleFailedNodeResponse(), and handleTimeout().
00772 { 00773 // two alternatives to react on a timeout 00774 if (lookup->config.newRpcOnEveryTimeout) { 00775 // always send one new RPC for every timeout 00776 sendRpc(1, findNodeExt); 00777 } else if (pendingRpcs == 0) { 00778 // wait until all RPCs have timed out and then send alpha new RPCs 00779 sendRpc(lookup->config.parallelRpcs, findNodeExt); 00780 } 00781 }
| FindNodeCall * IterativePathLookup::createRpcMessage | ( | cPacket * | findNodeExt = NULL |
) | [protected, virtual] |
Creates a find node call message.
This method can be overridden to add some additional state information to the FindNodeCall message.
| findNodeExt | Pointer to a optional cMessage, that may contain overlay specific data to be attached to FindNode RPCs and BaseRouteMessages |
Definition at line 994 of file IterativeLookup.cc.
Referenced by sendRpc().
00995 { 00996 // create default find node call message 00997 FindNodeCall* call = new FindNodeCall( "FindNodeCall" ); 00998 00999 if (lookup->appLookup) { 01000 call->setStatType(APP_LOOKUP_STAT); 01001 } else { 01002 call->setStatType(MAINTENANCE_STAT); 01003 } 01004 01005 call->setLookupKey(lookup->key); 01006 call->setNumRedundantNodes(lookup->config.redundantNodes); 01007 call->setNumSiblings(lookup->numSiblings); 01008 call->setBitLength(FINDNODECALL_L(call)); 01009 01010 // duplicate extension object 01011 if (findNodeExt != NULL) { 01012 call->addObject((cObject*)findNodeExt->dup()); 01013 call->addBitLength(findNodeExt->getBitLength()); 01014 } 01015 01016 return call; 01017 }
| int IterativePathLookup::add | ( | const NodeHandle & | handle, | |
| const NodeHandle & | source = NodeHandle::UNSPECIFIED_NODE | |||
| ) | [protected] |
Adds a NodeHandle to next hops.
Definition at line 1019 of file IterativeLookup.cc.
Referenced by IterativeLookup::start().
01020 { 01021 if (lookup->config.merge) { 01022 return nextHops.add(LookupEntry(handle, source, false)); 01023 } else { 01024 nextHops.push_back(LookupEntry(handle, source, false)); 01025 return (nextHops.size() - 1); 01026 } 01027 }
friend class IterativeLookup [friend] |
Definition at line 262 of file IterativeLookup.h.
IterativeLookup* IterativePathLookup::lookup [protected] |
Definition at line 265 of file IterativeLookup.h.
Referenced by accepts(), add(), createRpcMessage(), handleFailedNodeResponse(), handleResponse(), handleTimeout(), sendNewRpcAfterTimeout(), and sendRpc().
int IterativePathLookup::hops [protected] |
Definition at line 268 of file IterativeLookup.h.
Referenced by handleResponse(), IterativeLookup::handleRpcResponse(), IterativeLookup::handleRpcTimeout(), IterativePathLookup(), and sendRpc().
int IterativePathLookup::step [protected] |
Definition at line 269 of file IterativeLookup.h.
Referenced by accepts(), handleResponse(), IterativePathLookup(), and sendRpc().
int IterativePathLookup::pendingRpcs [protected] |
Definition at line 270 of file IterativeLookup.h.
Referenced by handleResponse(), handleTimeout(), IterativePathLookup(), sendNewRpcAfterTimeout(), and sendRpc().
bool IterativePathLookup::finished [protected] |
Definition at line 271 of file IterativeLookup.h.
Referenced by accepts(), handleFailedNodeResponse(), handleResponse(), IterativeLookup::handleRpcResponse(), IterativeLookup::handleRpcTimeout(), handleTimeout(), IterativePathLookup(), and sendRpc().
bool IterativePathLookup::success [protected] |
Definition at line 272 of file IterativeLookup.h.
Referenced by handleResponse(), IterativeLookup::handleRpcResponse(), IterativeLookup::handleRpcTimeout(), IterativePathLookup(), and sendRpc().
LookupVector IterativePathLookup::nextHops [protected] |
Definition at line 273 of file IterativeLookup.h.
Referenced by add(), handleFailedNodeResponse(), handleResponse(), handleTimeout(), IterativePathLookup(), and sendRpc().
std::map<TransportAddress, NodeHandle> IterativePathLookup::oldNextHops [protected] |
Definition at line 274 of file IterativeLookup.h.
Referenced by handleFailedNodeResponse(), handleResponse(), handleTimeout(), and sendRpc().
1.5.5