OverSim
RecursiveLookup.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2008 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include <CommonMessages_m.h>
25 
26 #include <BaseOverlay.h>
27 #include <LookupListener.h>
28 
29 #include <RecursiveLookup.h>
30 
32  RoutingType routingType,
33  const RecursiveLookupConfiguration& config,
34  bool appLookup) :
35  overlay(overlay),
36  routingType(routingType),
37  redundantNodes(config.redundantNodes),
38  numRetries(config.numRetries),
39  appLookup(appLookup)
40 {
41  valid = false;
42 }
43 
45 {
46  if (listener != NULL) {
47  delete listener;
48  listener = NULL;
49  }
50 
51  overlay->removeLookup(this);
52 }
53 
54 void RecursiveLookup::lookup(const OverlayKey& key, int numSiblings,
55  int hopCountMax, int retries,
56  LookupListener* listener)
57 {
58  this->listener = listener;
59 
60  FindNodeCall* call = new FindNodeCall("FindNodeCall");
62  else call->setStatType(MAINTENANCE_STAT);
63  call->setLookupKey(key);
65  call->setNumSiblings(numSiblings);
66  call->setBitLength(FINDNODECALL_L(call));
67 
68  nonce = overlay->sendRouteRpcCall(OVERLAY_COMP, key, call, NULL,
69  routingType, -1, retries, -1, this);
70 }
71 
73 {
74  return siblings;
75 }
76 
78 {
79  return valid;
80 }
81 
83 {
85 
86  delete this;
87 }
88 
90 {
91  //throw new cRuntimeError("RecursiveLookup is asked for # accumulated hops!");
92  return 0; //TODO hopCount in findNodeCall/Response ?
93 }
94 
96  const TransportAddress& dest,
97  cPolymorphic* context, int rpcId,
98  const OverlayKey& destKey)
99 {
100  //TODO retry
101  valid = false;
102 
103  // inform listener
104  if (listener != NULL) {
105  listener->lookupFinished(this);
106  listener = NULL;
107  }
108 
109  delete this;
110 }
111 
113  cPolymorphic* context, int rpcId,
114  simtime_t rtt)
115 {
116  FindNodeResponse* findNodeResponse = check_and_cast<FindNodeResponse*>(msg);
117 
118  if (findNodeResponse->getSiblings() &&
119  findNodeResponse->getClosestNodesArraySize() > 0) {
120  valid = true;
121  for (uint32_t i = 0; i < findNodeResponse->getClosestNodesArraySize();
122  i++) {
123  siblings.push_back(findNodeResponse->getClosestNodes(i));
124  }
125  }
126 
127 // std::cout << "RecursiveLookup::handleRpcResponse() "
128 // << findNodeResponse->getClosestNodesArraySize() << std::endl;
129 
130  // inform listener
131  if (listener != NULL) {
132  listener->lookupFinished(this);
133  listener = NULL;
134  }
135  delete this;
136 }