OverSim
BaseRpc.h
Go to the documentation of this file.
1 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 
26 #ifndef __BASERPC_H_
27 #define __BASERPC_H_
28 
29 #include <oversim_mapset.h>
30 
31 #include <omnetpp.h>
32 
33 #include <RpcState.h>
34 #include <RpcListener.h>
35 #include <RpcMacros.h>
36 
37 #include <ProxNodeHandle.h>
38 
40 class GlobalStatistics;
41 class GlobalParameters;
42 class NeighborCache;
43 class CryptoModule;
44 class WaitingContexts;
45 class BaseOverlay;
46 
47 class ProxListener;
48 
59 class BaseRpc : public RpcListener,
60  public cSimpleModule
61 {
62 public:
63 
64  BaseRpc();
65 
71  const NodeHandle& getThisNode() { return thisNode; };
72 
73  simtime_t getUdpTimeout() { return rpcUdpTimeout; };
74 
75 protected:
76 
77  // overlay identity
81 
82  // overlay common parameters
83  bool debugOutput;
85  // references to global modules
97  virtual bool internalHandleRpcCall(BaseCallMessage* msg);
98 
113  cPolymorphic* context, int rpcId,
114  simtime_t rtt);
115 
132  virtual void internalHandleRpcTimeout(BaseCallMessage* msg,
133  const TransportAddress& dest,
134  cPolymorphic* context,
135  int rpcId, const OverlayKey& destKey);
139  void initRpcs();
140 
144  void finishRpcs();
145 
152  virtual void internalHandleRpcMessage(BaseRpcMessage* msg);
153 
178  inline uint32_t sendRouteRpcCall(CompType destComp,
179  const TransportAddress& dest,
180  const OverlayKey& destKey,
181  BaseCallMessage* msg,
182  cPolymorphic* context = NULL,
183  RoutingType routingType = DEFAULT_ROUTING,
184  simtime_t timeout = -1,
185  int retries = 0,
186  int rpcId = -1,
187  RpcListener* rpcListener = NULL)
188  {
189  if (dest.isUnspecified() && destKey.isUnspecified())
190  opp_error("BaseRpc::sendRouteRpcCall() with both key and "
191  "transportAddress unspecified!");
192  return sendRpcCall(ROUTE_TRANSPORT, destComp, dest, destKey, msg,
193  context, routingType, timeout, retries,
194  rpcId, rpcListener);
195  }
196 
219  inline uint32_t sendRouteRpcCall(CompType destComp,
220  const OverlayKey& destKey,
221  BaseCallMessage* msg,
222  cPolymorphic* context = NULL,
223  RoutingType routingType = DEFAULT_ROUTING,
224  simtime_t timeout = -1,
225  int retries = 0,
226  int rpcId = -1,
227  RpcListener* rpcListener = NULL)
228  {
229  return sendRpcCall(ROUTE_TRANSPORT, destComp,
231  destKey, msg, context, routingType, timeout,
232  retries, rpcId, rpcListener);
233  }
234 
258  inline uint32_t sendRouteRpcCall(CompType destComp,
259  const TransportAddress& dest,
260  BaseCallMessage* msg,
261  cPolymorphic* context = NULL,
262  RoutingType routingType = DEFAULT_ROUTING,
263  simtime_t timeout = -1,
264  int retries = 0,
265  int rpcId = -1,
266  RpcListener* rpcListener = NULL)
267  {
268  return sendRpcCall(ROUTE_TRANSPORT, destComp, dest,
269  OverlayKey::UNSPECIFIED_KEY, msg, context,
270  routingType, timeout, retries, rpcId, rpcListener);
271  }
272 
293  inline uint32_t sendUdpRpcCall(const TransportAddress& dest,
294  BaseCallMessage* msg,
295  cPolymorphic* context = NULL,
296  simtime_t timeout = -1,
297  int retries = 0, int rpcId = -1,
298  RpcListener* rpcListener = NULL)
299  {
300  return sendRpcCall(UDP_TRANSPORT, INVALID_COMP, dest,
301  OverlayKey::UNSPECIFIED_KEY, msg, context,
302  NO_OVERLAY_ROUTING, timeout, retries, rpcId,
303  rpcListener);
304  }
305 
326  inline uint32_t sendInternalRpcCall(CompType destComp,
327  BaseCallMessage* msg,
328  cPolymorphic* context = NULL,
329  simtime_t timeout = -1,
330  int retries = 0,
331  int rpcId = -1,
332  RpcListener* rpcListener = NULL)
333  {
334  return sendRpcCall(INTERNAL_TRANSPORT, destComp,
336  OverlayKey::UNSPECIFIED_KEY, msg, context,
337  NO_OVERLAY_ROUTING, timeout, retries, rpcId,
338  rpcListener);
339  }
340 
346  void cancelRpcMessage(uint32_t nonce);
347 
351  void cancelAllRpcs();
352 
365  void sendRpcResponse(TransportType transportType,
366  CompType destComp,
367  const TransportAddress &dest,
368  const OverlayKey &destKey,
369  BaseCallMessage* call,
370  BaseResponseMessage* response);
371 
379  void sendRpcResponse(BaseCallMessage* call,
380  BaseResponseMessage* response);
381 
398  int pingNode(const TransportAddress& dest,
399  simtime_t timeout = -1,
400  int retries = 0,
401  cPolymorphic* context = NULL,
402  const char* caption = "PING",
403  RpcListener* rpcListener = NULL,
404  int rpcId = -1,
405  TransportType transportType = INVALID_TRANSPORT);
406 
415  virtual bool handleRpcCall(BaseCallMessage* msg);
416 
425  virtual CompType getThisCompType() = 0;
426 
428 
429  virtual void sendMessageToUDP(const TransportAddress& addr,
430  cPacket* message,
431  simtime_t delay = SIMTIME_ZERO)
432  {
433  throw cRuntimeError("sendMessageToUDP() not implemented");
434  };
435 
436  virtual void pingResponse(PingResponse* pingResponse,
437  cPolymorphic* context, int rpcId,
438  simtime_t rtt);
439 
440  virtual void pingTimeout(PingCall* pingCall,
441  const TransportAddress& dest,
442  cPolymorphic* context,
443  int rpcId);
444 
452 
453  bool internalHandleMessage(cMessage* msg);
454 
455 
456 private:
457 
458  virtual void handleTimerEvent(cMessage* msg);
459 
488  uint32_t sendRpcCall(TransportType transportType,
489  CompType destComp,
490  const TransportAddress& dest,
491  const OverlayKey& destKey,
492  BaseCallMessage* msg,
493  cPolymorphic* context,
494  RoutingType routingType,
495  simtime_t timeout, int retries,
496  int rpcId, RpcListener* rpcListener);
497 
498  void sendRpcMessageWithTransport(TransportType transportType,
499  CompType destComp,
500  RoutingType routingType,
501  const std::vector<TransportAddress>& sourceRoute,
502  const OverlayKey& destKey,
503  BaseRpcMessage* message);
504 
505  virtual void internalSendRouteRpc(BaseRpcMessage* message,
506  const OverlayKey& destKey,
507  const std::vector<TransportAddress>&
508  sourceRoute,
509  RoutingType routingType) = 0;
510 
511  virtual void internalSendRpcResponse(BaseCallMessage* call,
512  BaseResponseMessage* response) = 0;
513 
514  void pingRpcCall(PingCall* call);
515  void pingRpcResponse(PingResponse* response, cPolymorphic* context,
516  int rpcId, simtime_t rtt);
517  void pingRpcTimeout(PingCall* pingCall, const TransportAddress& dest,
518  cPolymorphic* context, int rpcId);
519 
520  typedef UNORDERED_MAP<int,RpcState> RpcStates;
521 
528 };
529 
530 #endif