IBR-DTNSuite  0.12
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"
27 #include "core/EventReceiver.h"
28 #include <ibrdtn/data/MetaBundle.h>
29 #include <ibrcommon/thread/Queue.h>
30 #include <ibrcommon/thread/Mutex.h>
31 
32 namespace dtn
33 {
34  namespace routing
35  {
37  {
38  static const std::string TAG;
39 
40  public:
42  virtual ~StaticRoutingExtension();
43 
48  virtual void eventDataChanged(const dtn::data::EID &peer) throw ();
49 
53  virtual void eventBundleQueued(const dtn::data::EID &peer, const dtn::data::MetaBundle &meta) throw ();
54 
55  void raiseEvent(const dtn::core::Event *evt) throw ();
56  void componentUp() throw ();
57  void componentDown() throw ();
58 
59  protected:
60  void run() throw ();
61  void __cancellation() throw ();
62 
63  private:
64  class EIDRoute : public StaticRoute
65  {
66  public:
67  EIDRoute(const dtn::data::EID &match, const dtn::data::EID &nexthop, const dtn::data::Timestamp &expiretime = 0);
68  virtual ~EIDRoute();
69 
70  bool match(const dtn::data::EID &eid) const;
71  const dtn::data::EID& getDestination() const;
72 
77  const std::string toString() const;
78 
79  const dtn::data::Timestamp& getExpiration() const;
80 
84  void raiseExpired() const;
85 
89  bool equals(const StaticRoute &route) const;
90 
91  private:
92  const dtn::data::EID _nexthop;
93  const dtn::data::EID _match;
94  const dtn::data::Timestamp expiretime;
95  };
96 
97  class Task
98  {
99  public:
100  virtual ~Task() {};
101  virtual std::string toString() = 0;
102  };
103 
104  class SearchNextBundleTask : public Task
105  {
106  public:
107  SearchNextBundleTask(const dtn::data::EID &eid);
108  virtual ~SearchNextBundleTask();
109 
110  virtual std::string toString();
111 
112  const dtn::data::EID eid;
113  };
114 
115  class ProcessBundleTask : public Task
116  {
117  public:
118  ProcessBundleTask(const dtn::data::MetaBundle &meta, const dtn::data::EID &origin);
119  virtual ~ProcessBundleTask();
120 
121  virtual std::string toString();
122 
123  const dtn::data::MetaBundle bundle;
124  const dtn::data::EID origin;
125  };
126 
127  class ClearRoutesTask : public Task
128  {
129  public:
130  ClearRoutesTask();
131  virtual ~ClearRoutesTask();
132  virtual std::string toString();
133  };
134 
135  class RouteChangeTask : public Task
136  {
137  public:
138  enum CHANGE_TYPE
139  {
140  ROUTE_ADD = 0,
141  ROUTE_DEL = 1
142  };
143 
144  RouteChangeTask(CHANGE_TYPE type, StaticRoute *route);
145  virtual ~RouteChangeTask();
146 
147  virtual std::string toString();
148 
149  CHANGE_TYPE type;
150  StaticRoute *route;
151  };
152 
153  class ExpireTask : public Task
154  {
155  public:
156  ExpireTask(dtn::data::Timestamp timestamp);
157  virtual ~ExpireTask();
158 
159  virtual std::string toString();
160 
161  dtn::data::Timestamp timestamp;
162  };
163 
168 
172  std::list<StaticRoute*> _routes;
173  ibrcommon::Mutex _expire_lock;
174  dtn::data::Timestamp next_expire;
175  };
176  }
177 }
178 
179 #endif /* STATICROUTINGEXTENSION_H_ */