IBR-DTN  1.0.0
BundleCore.h
Go to the documentation of this file.
1 /*
2  * BundleCore.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 BUNDLECORE_H_
23 #define BUNDLECORE_H_
24 
25 #include "Component.h"
26 #include "Configuration.h"
27 
28 #include "core/EventReceiver.h"
30 #include "storage/BundleStorage.h"
31 #include "core/WallClock.h"
32 #include "routing/BaseRouter.h"
33 #include "core/BundleFilter.h"
34 
35 #include "net/ConnectionManager.h"
36 #include "net/ConvergenceLayer.h"
37 #include "net/DiscoveryAgent.h"
38 
40 #include "core/BundlePurgeEvent.h"
43 
44 #include <ibrdtn/data/Serializer.h>
45 #include <ibrdtn/data/EID.h>
46 
47 #include <ibrcommon/thread/RWMutex.h>
48 #include <ibrcommon/link/LinkManager.h>
49 
50 #include <vector>
51 #include <set>
52 #include <map>
53 #include "BundleFilterTable.h"
54 
55 using namespace dtn::data;
56 
57 namespace dtn
58 {
59  namespace core
60  {
61  class P2PDialupException : public ibrcommon::Exception
62  {
63  public:
64  P2PDialupException(string what = "No path known except of dial-up connections.") throw() : Exception(what)
65  {
66  };
67  };
68 
72  class BundleCore
73  : public dtn::daemon::IntegratedComponent, public dtn::data::Validator, public ibrcommon::LinkManager::EventCallback, public dtn::daemon::Configuration::OnChangeListener,
74  public dtn::core::EventReceiver<dtn::routing::QueueBundleEvent>, public dtn::core::EventReceiver<dtn::core::BundlePurgeEvent>, public dtn::core::EventReceiver<dtn::net::TransferCompletedEvent>, public dtn::core::EventReceiver<dtn::net::TransferAbortedEvent>
75  {
76  static const std::string TAG;
77 
78  public:
80 
81  static BundleCore& getInstance();
82 
83  WallClock& getClock();
84 
85  virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf) throw ();
86 
87  void setStorage(dtn::storage::BundleStorage *storage);
88  dtn::storage::BundleStorage& getStorage();
89 
90  void setSeeker(dtn::storage::BundleSeeker *seeker);
91  dtn::storage::BundleSeeker& getSeeker();
92 
93  void setRouter(dtn::routing::BaseRouter *router);
94  dtn::routing::BaseRouter& getRouter() const;
95 
100  dtn::net::ConnectionManager& getConnectionManager();
101 
105  dtn::net::DiscoveryAgent& getDiscoveryAgent();
106 
113  void addRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop, const dtn::data::Timeout timeout = 0);
114 
120  void removeRoute(const dtn::data::EID &destination, const dtn::data::EID &nexthop);
121 
126  bool isGloballyConnected() const;
127 
128  void raiseEvent(const dtn::routing::QueueBundleEvent &evt) throw ();
129  void raiseEvent(const dtn::core::BundlePurgeEvent &evt) throw ();
130  void raiseEvent(const dtn::net::TransferCompletedEvent &evt) throw ();
131  void raiseEvent(const dtn::net::TransferAbortedEvent &evt) throw ();
132 
133  virtual void validate(const dtn::data::PrimaryBlock &obj) const throw (RejectedException);
134  virtual void validate(const dtn::data::Block &obj, const dtn::data::Number&) const throw (RejectedException);
135  virtual void validate(const dtn::data::PrimaryBlock &bundle, const dtn::data::Block &obj, const dtn::data::Number&) const throw (RejectedException);
136  virtual void validate(const dtn::data::Bundle &obj) const throw (RejectedException);
137  virtual void validate(const dtn::data::MetaBundle &obj) const throw (RejectedException);
138 
143  BundleFilter::ACTION filter(BundleFilter::TABLE table, const FilterContext &context, dtn::data::Bundle &bundle) const;
144 
148  BundleFilter::ACTION evaluate(BundleFilter::TABLE table, const FilterContext &context) const;
149 
153  static dtn::data::Length blocksizelimit;
154 
159  static dtn::data::Length foreign_blocksizelimit;
160 
164  static dtn::data::Length max_lifetime;
165 
169  static dtn::data::Length max_timestamp_future;
170 
174  static bool forwarding;
175 
179  static dtn::data::Size max_bundles_in_transit;
180 
184  virtual const std::string getName() const;
185 
186  static void processBlocks(dtn::data::Bundle &b);
187 
188  void setGloballyConnected(bool val);
189 
190  void eventNotify(const ibrcommon::LinkEvent &evt);
191 
195  static void inject(const dtn::data::EID &source, dtn::data::Bundle &bundle);
196 
197  protected:
198  virtual void componentUp() throw ();
199  virtual void componentDown() throw ();
200 
201  private:
205  BundleCore();
206 
210  virtual ~BundleCore();
211 
215  void check_connection_state() throw ();
216 
220  void reload_filter_tables() throw ();
221 
225  BundleCore operator=(const BundleCore &k)
226  { return k; };
227 
231  WallClock _clock;
232 
233  dtn::storage::BundleStorage *_storage;
235  dtn::routing::BaseRouter *_router;
236 
237  // generator for statusreports
238  StatusReportGenerator _statusreportgen;
239 
240  // manager class for connections
241  dtn::net::ConnectionManager _connectionmanager;
242 
243  // discovery agent handling all the discovery stuff
244  dtn::net::DiscoveryAgent _disco_agent;
245 
250  bool _globally_connected;
251 
252  BundleFilterTable _table_validation;
253  BundleFilterTable _table_input;
254  BundleFilterTable _table_output;
255  BundleFilterTable _table_routing;
256 
257  mutable ibrcommon::RWMutex _filter_mutex;
258  };
259  }
260 }
261 
262 #endif /*BUNDLECORE_H_*/
263 
static dtn::data::EID local
Definition: BundleCore.h:79
size_t Length
Definition: Number.h:33
P2PDialupException(string what="No path known except of dial-up connections.")
Definition: BundleCore.h:64
const std::string TAG
Definition: dtnoutbox.cpp:62
size_t Timeout
Definition: Number.h:35
size_t Size
Definition: Number.h:34