IBR-DTNSuite  0.8
daemon/src/routing/StaticRoutingExtension.h
Go to the documentation of this file.
00001 /*
00002  * StaticRoutingExension.h
00003  *
00004  *  Created on: 15.02.2010
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef STATICROUTINGEXTENSION_H_
00009 #define STATICROUTINGEXTENSION_H_
00010 
00011 #include "routing/BaseRouter.h"
00012 #include <ibrdtn/data/MetaBundle.h>
00013 #include <ibrcommon/thread/Queue.h>
00014 #include <ibrcommon/thread/Mutex.h>
00015 #include <regex.h>
00016 
00017 namespace dtn
00018 {
00019         namespace routing
00020         {
00021                 class StaticRoutingExtension : public BaseRouter::ThreadedExtension
00022                 {
00023                 public:
00024                         StaticRoutingExtension();
00025                         virtual ~StaticRoutingExtension();
00026 
00027                         void notify(const dtn::core::Event *evt);
00028 
00029                         class StaticRoute
00030                         {
00031                         public:
00032                                 virtual ~StaticRoute() = 0;
00033                                 virtual bool match(const dtn::data::EID &eid) const = 0;
00034                                 virtual const dtn::data::EID& getDestination() const = 0;
00035                                 virtual const std::string toString() const = 0;
00036                                 virtual size_t getExpiration() const { return 0; };
00037                         };
00038 
00039                 protected:
00040                         void run();
00041                         void __cancellation();
00042 
00043                 private:
00044                         class RegexRoute : public StaticRoute
00045                         {
00046                         public:
00047                                 RegexRoute(const std::string &regex, const dtn::data::EID &dest);
00048                                 virtual ~RegexRoute();
00049 
00050                                 bool match(const dtn::data::EID &eid) const;
00051                                 const dtn::data::EID& getDestination() const;
00052 
00058                                 RegexRoute(const RegexRoute &obj);
00059                                 RegexRoute& operator=(const RegexRoute &obj);
00060 
00065                                 const std::string toString() const;
00066 
00067                         private:
00068                                 dtn::data::EID _dest;
00069                                 std::string _regex_str;
00070                                 regex_t _regex;
00071                                 bool _invalid;
00072                         };
00073 
00074                         class EIDRoute : public StaticRoute
00075                         {
00076                         public:
00077                                 EIDRoute(const dtn::data::EID &match, const dtn::data::EID &nexthop, size_t expiretime = 0);
00078                                 virtual ~EIDRoute();
00079 
00080                                 bool match(const dtn::data::EID &eid) const;
00081                                 const dtn::data::EID& getDestination() const;
00082 
00087                                 const std::string toString() const;
00088 
00089                                 size_t getExpiration() const;
00090 
00091                         private:
00092                                 const dtn::data::EID _nexthop;
00093                                 const dtn::data::EID _match;
00094                                 const size_t expiretime;
00095                         };
00096 
00097                         class Task
00098                         {
00099                         public:
00100                                 virtual ~Task() {};
00101                                 virtual std::string toString() = 0;
00102                         };
00103 
00104                         class SearchNextBundleTask : public Task
00105                         {
00106                         public:
00107                                 SearchNextBundleTask(const dtn::data::EID &eid);
00108                                 virtual ~SearchNextBundleTask();
00109 
00110                                 virtual std::string toString();
00111 
00112                                 const dtn::data::EID eid;
00113                         };
00114 
00115                         class ProcessBundleTask : public Task
00116                         {
00117                         public:
00118                                 ProcessBundleTask(const dtn::data::MetaBundle &meta, const dtn::data::EID &origin);
00119                                 virtual ~ProcessBundleTask();
00120 
00121                                 virtual std::string toString();
00122 
00123                                 const dtn::data::MetaBundle bundle;
00124                                 const dtn::data::EID origin;
00125                         };
00126 
00127                         class ClearRoutesTask : public Task
00128                         {
00129                         public:
00130                                 ClearRoutesTask();
00131                                 virtual ~ClearRoutesTask();
00132                                 virtual std::string toString();
00133                         };
00134 
00135                         class RouteChangeTask : public Task
00136                         {
00137                         public:
00138                                 enum CHANGE_TYPE
00139                                 {
00140                                         ROUTE_ADD = 0,
00141                                         ROUTE_DEL = 1
00142                                 };
00143 
00144                                 RouteChangeTask(CHANGE_TYPE type, StaticRoute *route);
00145                                 virtual ~RouteChangeTask();
00146 
00147                                 virtual std::string toString();
00148 
00149                                 CHANGE_TYPE type;
00150                                 StaticRoute *route;
00151                         };
00152 
00153                         class ExpireTask : public Task
00154                         {
00155                         public:
00156                                 ExpireTask(size_t timestamp);
00157                                 virtual ~ExpireTask();
00158 
00159                                 virtual std::string toString();
00160 
00161                                 size_t timestamp;
00162                         };
00163 
00167                         ibrcommon::Queue<StaticRoutingExtension::Task* > _taskqueue;
00168 
00172                         std::list<StaticRoutingExtension::StaticRoute*> _routes;
00173                         ibrcommon::Mutex _expire_lock;
00174                         size_t next_expire;
00175                 };
00176         }
00177 }
00178 
00179 #endif /* STATICROUTINGEXTENSION_H_ */