IBR-DTNSuite  0.10
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/DTNTime.h>
38 #include <ibrdtn/data/BundleID.h>
39 #include <ibrdtn/data/MetaBundle.h>
40 
42 #include <ibrcommon/thread/Mutex.h>
45 
46 
47 namespace dtn
48 {
49  namespace routing
50  {
52  {
53  static const std::string TAG;
54 
55  public:
57  {
58  public:
59  RoutingException(string what = "An error occured during routing.") throw() : Exception(what)
60  {
61  };
62  };
63 
68  {
69  public:
70  NoNeighbourFoundException(string what = "No neighbour was found.") throw() : RoutingException(what)
71  {
72  };
73  };
74 
79  {
80  public:
81  NoRouteFoundException(string what = "No route found.") throw() : RoutingException(what)
82  {
83  };
84  };
85 
86  typedef std::set<RoutingExtension*> extension_list;
87 
88  BaseRouter();
89  ~BaseRouter();
90 
95  void add(RoutingExtension *extension);
96 
100  void remove(RoutingExtension *extension);
101 
106  const extension_list& getExtensions() const;
107 
112 
116  void clearExtensions();
117 
121  void raiseEvent(const dtn::core::Event *evt) throw ();
122 
126  dtn::storage::BundleStorage &getStorage();
127 
131  dtn::storage::BundleSeeker &getSeeker();
132 
137  void doHandshake(const dtn::data::EID &eid);
138 
144  bool isKnown(const dtn::data::BundleID &id);
145 
152  bool filterKnown(const dtn::data::MetaBundle &meta);
153 
158  void setKnown(const dtn::data::MetaBundle &meta);
159 
164  const dtn::data::BundleSet getKnownBundles();
165 
170  const dtn::data::BundleSet getPurgedBundles();
171 
176  void setPurged(const dtn::data::MetaBundle &meta);
177 
183  bool isPurged(const dtn::data::BundleID &id);
184 
188  virtual const std::string getName() const;
189 
195 
199  void extensionsUp() throw ();
200 
204  void extensionsDown() throw ();
205 
211  void processHandshake(const dtn::data::EID &source, NodeHandshake &answer);
212 
218  void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&);
219 
225  void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request);
226 
227 
228  protected:
229  virtual void componentUp() throw ();
230  virtual void componentDown() throw ();
231 
232  private:
233  void __forward_event(const dtn::core::Event *evt) throw ();
234 
235  ibrcommon::Mutex _known_bundles_lock;
236  dtn::data::BundleSet _known_bundles;
237 
238  ibrcommon::Mutex _purged_bundles_lock;
239  dtn::data::BundleSet _purged_bundles;
240 
241  ibrcommon::RWMutex _extensions_mutex;
242  extension_list _extensions;
243 
244  // this is true if the extensions are up
245  bool _extension_state;
246 
247  NeighborDatabase _neighbor_database;
248  NodeHandshakeExtension _nh_extension;
249  RetransmissionExtension _retransmission_extension;
250 
251  dtn::data::Timestamp _next_expiration;
252  };
253  }
254 }
255 
256 
257 #endif /* BASEROUTER_H_ */