IBR-DTNSuite  0.12
BaseRouter.h
Go to the documentation of this file.
1 /*
2  * BaseRouter.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 BASEROUTER_H_
23 #define BASEROUTER_H_
24 
25 #include "Component.h"
27 #include "routing/NodeHandshake.h"
28 #include "core/EventReceiver.h"
29 #include "storage/BundleStorage.h"
30 #include "storage/BundleSeeker.h"
31 
35 
36 #include <ibrdtn/data/BundleSet.h>
37 #include <ibrdtn/data/BundleID.h>
38 #include <ibrdtn/data/MetaBundle.h>
39 
41 #include <ibrcommon/thread/Mutex.h>
44 
45 
46 namespace dtn
47 {
48  namespace routing
49  {
51  {
52  static const std::string TAG;
53 
54  public:
56  {
57  public:
58  RoutingException(string what = "An error occured during routing.") throw() : Exception(what)
59  {
60  };
61  };
62 
67  {
68  public:
69  NoNeighbourFoundException(string what = "No neighbour was found.") throw() : RoutingException(what)
70  {
71  };
72  };
73 
78  {
79  public:
80  NoRouteFoundException(string what = "No route found.") throw() : RoutingException(what)
81  {
82  };
83  };
84 
85  typedef std::set<RoutingExtension*> extension_list;
86 
87  BaseRouter();
88  ~BaseRouter();
89 
94  void add(RoutingExtension *extension);
95 
99  void remove(RoutingExtension *extension);
100 
105  const extension_list& getExtensions() const;
106 
111 
115  void clearExtensions();
116 
120  void raiseEvent(const dtn::core::Event *evt) throw ();
121 
125  dtn::storage::BundleStorage &getStorage();
126 
130  dtn::storage::BundleSeeker &getSeeker();
131 
136  void doHandshake(const dtn::data::EID &eid);
137 
143  bool isKnown(const dtn::data::BundleID &id);
144 
151  bool filterKnown(const dtn::data::MetaBundle &meta);
152 
157  void setKnown(const dtn::data::MetaBundle &meta);
158 
163  const dtn::data::BundleSet getKnownBundles();
164 
169  const dtn::data::BundleSet getPurgedBundles();
170 
175  void setPurged(const dtn::data::MetaBundle &meta);
176 
182  bool isPurged(const dtn::data::BundleID &id);
183 
187  virtual const std::string getName() const;
188 
194 
198  void extensionsUp() throw ();
199 
203  void extensionsDown() throw ();
204 
210  void processHandshake(const dtn::data::EID &source, NodeHandshake &answer);
211 
217  void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&);
218 
224  void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request);
225 
226 
227  protected:
228  virtual void componentUp() throw ();
229  virtual void componentDown() throw ();
230 
231  private:
232  void __eventDataChanged(const dtn::data::EID &peer) throw ();
233  void __eventTransferCompleted(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
234  void __eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
235 
236  ibrcommon::Mutex _known_bundles_lock;
237  dtn::data::BundleSet _known_bundles;
238 
239  ibrcommon::Mutex _purged_bundles_lock;
240  dtn::data::BundleSet _purged_bundles;
241 
242  ibrcommon::RWMutex _extensions_mutex;
243  extension_list _extensions;
244 
245  // this is true if the extensions are up
246  bool _extension_state;
247 
248  NeighborDatabase _neighbor_database;
249  NodeHandshakeExtension _nh_extension;
250  RetransmissionExtension _retransmission_extension;
251 
252  dtn::data::Timestamp _next_expiration;
253  };
254  }
255 }
256 
257 
258 #endif /* BASEROUTER_H_ */