IBR-DTNSuite 0.6

daemon/src/routing/BaseRouter.h

Go to the documentation of this file.
00001 /*
00002  * BaseRouter.h
00003  *
00004  *  Created on: 15.02.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef BASEROUTER_H_
00009 #define BASEROUTER_H_
00010 
00011 #include "Component.h"
00012 #include "routing/NeighborDatabase.h"
00013 #include "routing/BundleSummary.h"
00014 #include "core/EventReceiver.h"
00015 #include "core/BundleStorage.h"
00016 
00017 #include <ibrdtn/data/DTNTime.h>
00018 #include <ibrdtn/data/BundleID.h>
00019 #include <ibrdtn/data/MetaBundle.h>
00020 
00021 #include <ibrcommon/thread/Thread.h>
00022 #include <ibrcommon/thread/Conditional.h>
00023 
00024 
00025 namespace dtn
00026 {
00027         namespace routing
00028         {
00029                 class BaseRouter : public dtn::core::EventReceiver, public dtn::daemon::IntegratedComponent
00030                 {
00031                 public:
00032                         class RoutingException : public ibrcommon::Exception
00033                         {
00034                                 public:
00035                                         RoutingException(string what = "An error occured during routing.") throw() : Exception(what)
00036                                         {
00037                                         };
00038                         };
00039 
00043                         class NoNeighbourFoundException : public RoutingException
00044                         {
00045                                 public:
00046                                         NoNeighbourFoundException(string what = "No neighbour was found.") throw() : RoutingException(what)
00047                                         {
00048                                         };
00049                         };
00050 
00054                         class NoRouteFoundException : public RoutingException
00055                         {
00056                                 public:
00057                                         NoRouteFoundException(string what = "No route found.") throw() : RoutingException(what)
00058                                         {
00059                                         };
00060                         };
00061 
00062                         class Extension
00063                         {
00064                         public:
00065                                 Extension();
00066                                 virtual ~Extension() = 0;
00067 
00068                                 virtual void notify(const dtn::core::Event *evt) = 0;
00069 
00070                                 enum CALLBACK_ACTION
00071                                 {
00072                                         ROUTE_CALLBACK_FORWARDED = 0,
00073                                         ROUTE_CALLBACK_ABORTED = 1,
00074                                         ROUTE_CALLBACK_REJECTED = 2,
00075                                         ROUTE_CALLBACK_DELETED = 3
00076                                 };
00077 
00084                                 void transferTo(const dtn::data::EID &destination, const dtn::data::BundleID &id);
00085                                 void transferTo(NeighborDatabase::NeighborEntry &entry, const dtn::data::BundleID &id);
00086 
00087                         protected:
00088                                 BaseRouter& operator*();
00089 
00090                         private:
00091                                 friend class BaseRouter;
00092                                 static BaseRouter *_router;
00093                         };
00094 
00095                         class ThreadedExtension : public Extension, public ibrcommon::JoinableThread
00096                         {
00097                         public:
00098                                 ThreadedExtension();
00099                                 virtual ~ThreadedExtension() = 0;
00100 
00101                                 virtual void notify(const dtn::core::Event *evt) = 0;
00102 
00103                         protected:
00104                                 virtual void stopExtension() = 0;
00105                         };
00106 
00107                         class Endpoint
00108                         {
00109                         public:
00110                                 Endpoint();
00111                                 virtual ~Endpoint() = 0;
00112                         };
00113 
00114                 private:
00115                         class VirtualEndpoint
00116                         {
00117                         public:
00118                                 VirtualEndpoint(dtn::data::EID name);
00119                                 virtual ~VirtualEndpoint();
00120 
00121                                 ibrcommon::Mutex _clientlock;
00122                                 Endpoint *_client;
00123 
00124                                 dtn::data::EID _name;
00125                                 dtn::data::DTNTime _lastseen;
00126                                 dtn::data::DTNTime _expire;
00127                         };
00128 
00129                 public:
00130                         BaseRouter(dtn::core::BundleStorage &storage);
00131                         ~BaseRouter();
00132 
00137                         void addExtension(BaseRouter::Extension *extension);
00138 
00142                         void raiseEvent(const dtn::core::Event *evt);
00143 
00149                         dtn::data::Bundle getBundle(const dtn::data::BundleID &id);
00150 
00151                         dtn::core::BundleStorage &getStorage();
00152 
00158                         bool isKnown(const dtn::data::BundleID &id);
00159 
00164                         void setKnown(const dtn::data::MetaBundle &meta);
00165 
00166                         const SummaryVector getSummaryVector();
00167 
00171                         virtual const std::string getName() const;
00172 
00173                         NeighborDatabase& getNeighborDB();
00174 
00175                 protected:
00176                         virtual void componentUp();
00177                         virtual void componentDown();
00178 
00179                 private:
00180                         ibrcommon::Mutex _known_bundles_lock;
00181                         BundleSummary _known_bundles;
00182 
00183                         dtn::core::BundleStorage &_storage;
00184                         std::list<BaseRouter::Extension*> _extensions;
00185 
00186                         NeighborDatabase _neighbor_database;
00187                 };
00188         }
00189 }
00190 
00191 
00192 #endif /* BASEROUTER_H_ */