IBR-DTN  1.0.0
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"
32 #include "core/TimeEvent.h"
33 #include "core/BundlePurgeEvent.h"
34 
35 #include <ibrcommon/thread/Mutex.h>
36 #include <ibrcommon/thread/Queue.h>
37 #include <ibrcommon/thread/ThreadsafeReference.h>
38 
39 #include <map>
40 #include <list>
41 
42 namespace dtn
43 {
44  namespace routing
45  {
56  class ProphetRoutingExtension : public RoutingExtension, public ibrcommon::JoinableThread,
57  public dtn::core::EventReceiver<dtn::routing::NodeHandshakeEvent>,
58  public dtn::core::EventReceiver<dtn::core::TimeEvent>,
59  public dtn::core::EventReceiver<dtn::core::BundlePurgeEvent>
60  {
61  friend class ForwardingStrategy;
62  static const std::string TAG;
63 
64  public:
65  ProphetRoutingExtension(ForwardingStrategy *strategy, float p_encounter_max, float p_encounter_first,
66  float p_first_threshold, float beta, float gamma, float delta,
67  size_t time_unit, size_t i_typ,
68  dtn::data::Timestamp next_exchange_timeout);
69  virtual ~ProphetRoutingExtension();
70 
71  virtual const std::string getTag() const throw ();
72 
73  /* virtual methods from BaseRouter::Extension */
74  virtual void requestHandshake(const dtn::data::EID&, NodeHandshake&) const;
75  virtual void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&);
76  virtual void processHandshake(const dtn::data::EID&, NodeHandshake&);
77  virtual void componentUp() throw ();
78  virtual void componentDown() throw ();
79 
80  virtual void raiseEvent(const dtn::routing::NodeHandshakeEvent &evt) throw ();
81  virtual void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
82  virtual void raiseEvent(const dtn::core::BundlePurgeEvent &evt) throw ();
83 
84  virtual void eventDataChanged(const dtn::data::EID &peer) throw ();
85 
86  virtual void eventTransferCompleted(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
87 
88  virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
89 
95  ibrcommon::ThreadsafeReference<DeliveryPredictabilityMap> getDeliveryPredictabilityMap();
101  ibrcommon::ThreadsafeReference<const DeliveryPredictabilityMap> getDeliveryPredictabilityMap() const;
102 
107  ibrcommon::ThreadsafeReference<const AcknowledgementSet> getAcknowledgementSet() const;
108  protected:
109  virtual void run() throw ();
110  void __cancellation() throw ();
111  private:
116  void updateNeighbor(const dtn::data::EID& neighbor, const DeliveryPredictabilityMap& neighbor_dp_map);
117 
122  void age();
123 
127  void store(const ibrcommon::File &target);
128 
132  void restore(const ibrcommon::File &source);
133 
134  DeliveryPredictabilityMap _deliveryPredictabilityMap;
135  ForwardingStrategy *_forwardingStrategy;
136  AcknowledgementSet _acknowledgementSet;
137 
138  ibrcommon::Mutex _next_exchange_mutex;
139  dtn::data::Timestamp _next_exchange_timeout;
140  dtn::data::Timestamp _next_exchange_timestamp;
141 
145  float p_encounter(const dtn::data::EID &neighbor) const;
146 
147  float _p_encounter_max;
148  float _p_encounter_first;
149  float _p_first_threshold;
150  float _delta;
151  size_t _i_typ;
152 
153  typedef std::map<dtn::data::EID, dtn::data::Timestamp> age_map;
154  age_map _ageMap;
155 
156  ibrcommon::File _persistent_file;
157 
158  class Task
159  {
160  public:
161  virtual ~Task() {};
162  virtual std::string toString() const = 0;
163  };
164 
165  class SearchNextBundleTask : public Task
166  {
167  public:
168  SearchNextBundleTask(const dtn::data::EID &eid);
169  virtual ~SearchNextBundleTask();
170 
171  virtual std::string toString() const;
172 
173  const dtn::data::EID eid;
174  };
175 
176  class NextExchangeTask : public Task
177  {
178  public:
179  NextExchangeTask();
180  virtual ~NextExchangeTask();
181 
182  virtual std::string toString() const;
183  };
184 
185  ibrcommon::Queue<Task* > _taskqueue;
186 
187  public:
194  {
195  public:
196  explicit GRTR_Strategy();
197  virtual ~GRTR_Strategy();
198  virtual bool shallForward(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::MetaBundle& bundle) const;
199  };
200 
208  {
209  public:
210  explicit GTMX_Strategy(unsigned int NF_max);
211  virtual ~GTMX_Strategy();
212  virtual bool shallForward(const DeliveryPredictabilityMap& neighbor_dpm, const dtn::data::MetaBundle& bundle) const;
213 
214  void addForward(const dtn::data::BundleID &id);
215 
216  private:
217  unsigned int _NF_max;
218 
219  typedef std::map<dtn::data::BundleID, unsigned int> nf_map;
220  nf_map _NF_map;
221  };
222  };
223  } // namespace routing
224 } // namespace dtn
225 
226 #endif // PROPHETROUTINGEXTENSION_H_
virtual void eventDataChanged(const dtn::data::EID &peer)
The GRTR forwarding strategy. Using this strategy, packets are forwarding, if the neighbor has a high...
virtual void processHandshake(const dtn::data::EID &, NodeHandshake &)
This class keeps track of the predictablities to see a specific EID.
virtual void eventTransferCompleted(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta)
This class is a abstract base class for all prophet forwarding strategies.
const std::string TAG
Definition: dtnoutbox.cpp:62
virtual bool shallForward(const DeliveryPredictabilityMap &neighbor_dpm, const dtn::data::MetaBundle &bundle) const
Set of Acknowledgements, that can be serialized in node handshakes.
virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta)
ibrcommon::ThreadsafeReference< const AcknowledgementSet > getAcknowledgementSet() const
The GTMX forwarding strategy. Using this strategy, packets are forwarding, if the neighbor has a high...
ProphetRoutingExtension(ForwardingStrategy *strategy, float p_encounter_max, float p_encounter_first, float p_first_threshold, float beta, float gamma, float delta, size_t time_unit, size_t i_typ, dtn::data::Timestamp next_exchange_timeout)
virtual void responseHandshake(const dtn::data::EID &, const NodeHandshake &, NodeHandshake &)
virtual void requestHandshake(const dtn::data::EID &, NodeHandshake &) const
virtual const std::string getTag() const
virtual void raiseEvent(const dtn::routing::NodeHandshakeEvent &evt)
ibrcommon::ThreadsafeReference< DeliveryPredictabilityMap > getDeliveryPredictabilityMap()
virtual bool shallForward(const DeliveryPredictabilityMap &neighbor_dpm, const dtn::data::MetaBundle &bundle) const
Routing extension for PRoPHET routing.
dtn::data::SDNV< Size > Timestamp
Definition: Number.h:41