IBR-DTNSuite  0.12
ProphetRoutingExtension.h
Go to the documentation of this file.
1 /*
2  * ProphetRoutingExtension.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef PROPHETROUTINGEXTENSION_H_
23 #define PROPHETROUTINGEXTENSION_H_
24 
28 
30 #include "core/EventReceiver.h"
31 
32 #include <ibrcommon/thread/Mutex.h>
33 #include <ibrcommon/thread/Queue.h>
35 
36 #include <map>
37 #include <list>
38 
39 namespace dtn
40 {
41  namespace routing
42  {
54  {
55  friend class ForwardingStrategy;
56  static const std::string TAG;
57 
58  public:
59  ProphetRoutingExtension(ForwardingStrategy *strategy, float p_encounter_max, float p_encounter_first,
60  float p_first_threshold, float beta, float gamma, float delta,
61  size_t time_unit, size_t i_typ,
62  dtn::data::Timestamp next_exchange_timeout);
63  virtual ~ProphetRoutingExtension();
64 
65  /* virtual methods from BaseRouter::Extension */
66  virtual void requestHandshake(const dtn::data::EID&, NodeHandshake&) const;
67  virtual void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&);
68  virtual void processHandshake(const dtn::data::EID&, NodeHandshake&);
69  virtual void componentUp() throw ();
70  virtual void componentDown() throw ();
71 
72  virtual void raiseEvent(const dtn::core::Event *evt) throw ();
73 
74  virtual void eventDataChanged(const dtn::data::EID &peer) throw ();
75 
76  virtual void eventTransferCompleted(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
77 
78  virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
79 
85  ibrcommon::ThreadsafeReference<DeliveryPredictabilityMap> getDeliveryPredictabilityMap();
91  ibrcommon::ThreadsafeReference<const DeliveryPredictabilityMap> getDeliveryPredictabilityMap() const;
92 
97  ibrcommon::ThreadsafeReference<const AcknowledgementSet> getAcknowledgementSet() const;
98  protected:
99  virtual void run() throw ();
100  void __cancellation() throw ();
101  private:
106  void updateNeighbor(const dtn::data::EID& neighbor, const DeliveryPredictabilityMap& neighbor_dp_map);
107 
112  void age();
113 
114  DeliveryPredictabilityMap _deliveryPredictabilityMap;
115  ForwardingStrategy *_forwardingStrategy;
116  AcknowledgementSet _acknowledgementSet;
117 
118  ibrcommon::Mutex _next_exchange_mutex;
119  dtn::data::Timestamp _next_exchange_timeout;
120  dtn::data::Timestamp _next_exchange_timestamp;
121 
125  float p_encounter(const dtn::data::EID &neighbor) const;
126 
127  float _p_encounter_max;
128  float _p_encounter_first;
129  float _p_first_threshold;
130  float _delta;
131  size_t _i_typ;
132 
133  typedef std::map<dtn::data::EID, dtn::data::Timestamp> age_map;
134  age_map _ageMap;
135 
136  class Task
137  {
138  public:
139  virtual ~Task() {};
140  virtual std::string toString() const = 0;
141  };
142 
143  class SearchNextBundleTask : public Task
144  {
145  public:
146  SearchNextBundleTask(const dtn::data::EID &eid);
147  virtual ~SearchNextBundleTask();
148 
149  virtual std::string toString() const;
150 
151  const dtn::data::EID eid;
152  };
153 
154  class NextExchangeTask : public Task
155  {
156  public:
157  NextExchangeTask();
158  virtual ~NextExchangeTask();
159 
160  virtual std::string toString() const;
161  };
162 
163  ibrcommon::Queue<Task* > _taskqueue;
164 
165  public:
172  {
173  public:
174  explicit GRTR_Strategy();
175  virtual ~GRTR_Strategy();
176  virtual bool shallForward(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::MetaBundle& bundle) const;
177  };
178 
186  {
187  public:
188  explicit GTMX_Strategy(unsigned int NF_max);
189  virtual ~GTMX_Strategy();
190  virtual bool shallForward(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::MetaBundle& bundle) const;
191 
192  void addForward(const dtn::data::BundleID &id);
193 
194  private:
195  unsigned int _NF_max;
196 
197  typedef std::map<dtn::data::BundleID, unsigned int> nf_map;
198  nf_map _NF_map;
199  };
200  };
201  } // namespace routing
202 } // namespace dtn
203 
204 #endif // PROPHETROUTINGEXTENSION_H_