IBR-DTN  1.0.0
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 
40 #include <ibrcommon/thread/Thread.h>
41 #include <ibrcommon/thread/Mutex.h>
42 #include <ibrcommon/thread/RWMutex.h>
43 #include <ibrcommon/thread/Conditional.h>
44 
49 #include "core/NodeEvent.h"
50 #include "core/TimeEvent.h"
51 #include "net/ConnectionEvent.h"
52 #include "core/BundlePurgeEvent.h"
53 
54 
55 
56 
57 namespace dtn
58 {
59  namespace routing
60  {
62  public dtn::core::EventReceiver<dtn::net::TransferAbortedEvent>,
63  public dtn::core::EventReceiver<dtn::net::TransferCompletedEvent>,
64  public dtn::core::EventReceiver<dtn::net::BundleReceivedEvent>,
65  public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>,
66  public dtn::core::EventReceiver<dtn::core::NodeEvent>,
67  public dtn::core::EventReceiver<dtn::core::TimeEvent>,
68  public dtn::core::EventReceiver<dtn::net::ConnectionEvent>,
69  public dtn::core::EventReceiver<dtn::core::BundlePurgeEvent>
70  {
71  static const std::string TAG;
72 
73  public:
74  class RoutingException : public ibrcommon::Exception
75  {
76  public:
77  RoutingException(string what = "An error occured during routing.") throw() : Exception(what)
78  {
79  };
80  };
81 
86  {
87  public:
88  NoNeighbourFoundException(string what = "No neighbour was found.") throw() : RoutingException(what)
89  {
90  };
91  };
92 
97  {
98  public:
99  NoRouteFoundException(string what = "No route found.") throw() : RoutingException(what)
100  {
101  };
102  };
103 
104  typedef std::set<RoutingExtension*> extension_list;
105 
106  BaseRouter();
107  ~BaseRouter();
108 
113  void add(RoutingExtension *extension);
114 
118  void remove(RoutingExtension *extension);
119 
124  const extension_list& getExtensions() const;
125 
129  ibrcommon::RWMutex& getExtensionMutex() throw ();
130 
134  void clearExtensions();
135 
139  void raiseEvent(const dtn::net::TransferAbortedEvent &evt) throw ();
140  void raiseEvent(const dtn::net::TransferCompletedEvent &evt) throw ();
141  void raiseEvent(const dtn::net::BundleReceivedEvent &evt) throw ();
142  void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
143  void raiseEvent(const dtn::core::NodeEvent &evt) throw ();
144  void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
145  void raiseEvent(const dtn::net::ConnectionEvent &evt) throw ();
146  void raiseEvent(const dtn::core::BundlePurgeEvent &evt) throw ();
147 
151  dtn::storage::BundleStorage &getStorage();
152 
156  dtn::storage::BundleSeeker &getSeeker();
157 
162  void doHandshake(const dtn::data::EID &eid);
163 
167  void pushHandshakeUpdated(const NodeHandshakeItem::IDENTIFIER id);
168 
174  bool isKnown(const dtn::data::BundleID &id);
175 
182  bool filterKnown(const dtn::data::MetaBundle &meta);
183 
188  void setKnown(const dtn::data::MetaBundle &meta);
189 
194  const dtn::data::BundleSet getKnownBundles();
195 
200  const dtn::data::BundleSet getPurgedBundles();
201 
206  void setPurged(const dtn::data::MetaBundle &meta);
207 
213  bool isPurged(const dtn::data::BundleID &id);
214 
218  virtual const std::string getName() const;
219 
225 
229  void extensionsUp() throw ();
230 
234  void extensionsDown() throw ();
235 
241  void processHandshake(const dtn::data::EID &source, NodeHandshake &answer);
242 
248  void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&);
249 
255  void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request);
256 
257 
258  protected:
259  virtual void componentUp() throw ();
260  virtual void componentDown() throw ();
261 
262  private:
263  void __eventDataChanged(const dtn::data::EID &peer) throw ();
264  void __eventTransferCompleted(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
265  void __eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
266 
267  ibrcommon::Mutex _known_bundles_lock;
268  dtn::data::BundleSet _known_bundles;
269 
270  ibrcommon::Mutex _purged_bundles_lock;
271  dtn::data::BundleSet _purged_bundles;
272 
273  ibrcommon::RWMutex _extensions_mutex;
274  extension_list _extensions;
275 
276  // this is true if the extensions are up
277  bool _extension_state;
278 
279  NeighborDatabase _neighbor_database;
280  NodeHandshakeExtension _nh_extension;
281  RetransmissionExtension _retransmission_extension;
282 
283  dtn::data::Timestamp _next_expiration;
284  };
285  }
286 }
287 
288 
289 #endif /* BASEROUTER_H_ */
void add(RoutingExtension *extension)
Definition: BaseRouter.cpp:73
const extension_list & getExtensions() const
Definition: BaseRouter.cpp:90
void processHandshake(const dtn::data::EID &source, NodeHandshake &answer)
Definition: BaseRouter.cpp:152
ibrcommon::RWMutex & getExtensionMutex()
Definition: BaseRouter.cpp:85
std::set< RoutingExtension * > extension_list
Definition: BaseRouter.h:104
NoRouteFoundException(string what="No route found.")
Definition: BaseRouter.h:99
void doHandshake(const dtn::data::EID &eid)
Definition: BaseRouter.cpp:543
void pushHandshakeUpdated(const NodeHandshakeItem::IDENTIFIER id)
Definition: BaseRouter.cpp:548
void setKnown(const dtn::data::MetaBundle &meta)
Definition: BaseRouter.cpp:563
void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request)
Definition: BaseRouter.cpp:192
const dtn::data::BundleSet getPurgedBundles()
Definition: BaseRouter.cpp:607
virtual void componentDown()
Definition: BaseRouter.cpp:225
bool isPurged(const dtn::data::BundleID &id)
Definition: BaseRouter.cpp:595
RoutingException(string what="An error occured during routing.")
Definition: BaseRouter.h:77
NoNeighbourFoundException(string what="No neighbour was found.")
Definition: BaseRouter.h:88
bool isKnown(const dtn::data::BundleID &id)
Definition: BaseRouter.cpp:570
dtn::storage::BundleStorage & getStorage()
Definition: BaseRouter.cpp:553
void setPurged(const dtn::data::MetaBundle &meta)
Definition: BaseRouter.cpp:601
const dtn::data::BundleSet getKnownBundles()
Definition: BaseRouter.cpp:588
NeighborDatabase & getNeighborDB()
Definition: BaseRouter.cpp:618
dtn::storage::BundleSeeker & getSeeker()
Definition: BaseRouter.cpp:558
virtual void componentUp()
Definition: BaseRouter.cpp:212
bool filterKnown(const dtn::data::MetaBundle &meta)
Definition: BaseRouter.cpp:579
void raiseEvent(const dtn::net::TransferAbortedEvent &evt)
Definition: BaseRouter.cpp:356
virtual const std::string getName() const
Definition: BaseRouter.cpp:613
void responseHandshake(const dtn::data::EID &, const NodeHandshake &, NodeHandshake &)
Definition: BaseRouter.cpp:172