IBR-DTN  1.0.0
StaticRoutingExtension.h
Go to the documentation of this file.
1 /*
2  * StaticRoutingExension.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 STATICROUTINGEXTENSION_H_
23 #define STATICROUTINGEXTENSION_H_
24 
25 #include "routing/StaticRoute.h"
28 #include "core/TimeEvent.h"
29 #include "core/EventReceiver.h"
30 #include <ibrdtn/data/MetaBundle.h>
31 #include <ibrcommon/thread/Queue.h>
32 #include <ibrcommon/thread/Mutex.h>
33 
34 namespace dtn
35 {
36  namespace routing
37  {
38  class StaticRoutingExtension : public RoutingExtension, public ibrcommon::JoinableThread,
39  public dtn::core::EventReceiver<dtn::core::TimeEvent>,
40  public dtn::core::EventReceiver<dtn::routing::StaticRouteChangeEvent>
41  {
42  static const std::string TAG;
43 
44  public:
46  virtual ~StaticRoutingExtension();
47 
48  virtual const std::string getTag() const throw ();
49 
54  virtual void eventDataChanged(const dtn::data::EID &peer) throw ();
55 
59  virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
60 
61  void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
62  void raiseEvent(const dtn::routing::StaticRouteChangeEvent &evt) throw ();
63  void componentUp() throw ();
64  void componentDown() throw ();
65 
66  protected:
67  void run() throw ();
68  void __cancellation() throw ();
69 
70  private:
71  class EIDRoute : public StaticRoute
72  {
73  public:
74  EIDRoute(const dtn::data::EID &match, const dtn::data::EID &nexthop, const dtn::data::Timestamp &expiretime = 0);
75  virtual ~EIDRoute();
76 
77  bool match(const dtn::data::EID &eid) const;
78  const dtn::data::EID& getDestination() const;
79 
84  const std::string toString() const;
85 
86  const dtn::data::Timestamp& getExpiration() const;
87 
91  void raiseExpired() const;
92 
96  bool equals(const StaticRoute &route) const;
97 
98  private:
99  const dtn::data::EID _nexthop;
100  const dtn::data::EID _match;
101  const dtn::data::Timestamp expiretime;
102  };
103 
104  class Task
105  {
106  public:
107  virtual ~Task() {};
108  virtual std::string toString() = 0;
109  };
110 
111  class SearchNextBundleTask : public Task
112  {
113  public:
114  SearchNextBundleTask(const dtn::data::EID &eid);
115  virtual ~SearchNextBundleTask();
116 
117  virtual std::string toString();
118 
119  const dtn::data::EID eid;
120  };
121 
122  class ProcessBundleTask : public Task
123  {
124  public:
125  ProcessBundleTask(const dtn::data::MetaBundle &meta, const dtn::data::EID &origin);
126  virtual ~ProcessBundleTask();
127 
128  virtual std::string toString();
129 
130  const dtn::data::MetaBundle bundle;
131  const dtn::data::EID origin;
132  };
133 
134  class ClearRoutesTask : public Task
135  {
136  public:
137  ClearRoutesTask();
138  virtual ~ClearRoutesTask();
139  virtual std::string toString();
140  };
141 
142  class RouteChangeTask : public Task
143  {
144  public:
145  enum CHANGE_TYPE
146  {
147  ROUTE_ADD = 0,
148  ROUTE_DEL = 1
149  };
150 
151  RouteChangeTask(CHANGE_TYPE type, StaticRoute *route);
152  virtual ~RouteChangeTask();
153 
154  virtual std::string toString();
155 
156  CHANGE_TYPE type;
157  StaticRoute *route;
158  };
159 
160  class ExpireTask : public Task
161  {
162  public:
163  ExpireTask(dtn::data::Timestamp timestamp);
164  virtual ~ExpireTask();
165 
166  virtual std::string toString();
167 
168  dtn::data::Timestamp timestamp;
169  };
170 
174  ibrcommon::Queue<StaticRoutingExtension::Task* > _taskqueue;
175 
179  std::list<StaticRoute*> _routes;
180  ibrcommon::Mutex _expire_lock;
181  dtn::data::Timestamp next_expire;
182  };
183  }
184 }
185 
186 #endif /* STATICROUTINGEXTENSION_H_ */
virtual void eventDataChanged(const dtn::data::EID &peer)
virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta)
void raiseEvent(const dtn::core::TimeEvent &evt)
virtual const std::string getTag() const