IBR-DTN  1.0.0
ConnectionManager.h
Go to the documentation of this file.
1 /*
2  * ConnectionManager.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 CONNECTIONMANAGER_H_
23 #define CONNECTIONMANAGER_H_
24 
25 #include "Component.h"
26 #include "net/ConvergenceLayer.h"
27 #include "net/P2PDialupExtension.h"
28 #include "net/BundleReceiver.h"
29 #include "core/EventReceiver.h"
30 #include <ibrdtn/data/EID.h>
31 #include "core/Node.h"
32 #include <ibrcommon/Exceptions.h>
33 
34 #include "core/NodeEvent.h"
35 #include "core/TimeEvent.h"
36 #include "core/GlobalEvent.h"
37 #include "net/ConnectionEvent.h"
38 
39 #include <set>
40 #include <list>
41 
42 namespace dtn
43 {
44  namespace net
45  {
46  class NodeNotAvailableException : public ibrcommon::Exception
47  {
48  public:
49  NodeNotAvailableException(string what = "The requested node is not a neighbor.") throw() : ibrcommon::Exception(what)
50  {
51  };
52  };
53 
54  class ConnectionNotAvailableException : public ibrcommon::Exception
55  {
56  public:
57  ConnectionNotAvailableException(string what = "The requested connection is not available.") throw() : ibrcommon::Exception(what)
58  {
59  };
60  };
61 
63  : public dtn::core::EventReceiver<dtn::core::TimeEvent>, public dtn::daemon::IntegratedComponent,
64  public dtn::core::EventReceiver<dtn::core::GlobalEvent>, public dtn::core::EventReceiver<dtn::core::NodeEvent>, public dtn::core::EventReceiver<dtn::net::ConnectionEvent>
65  {
66  public:
68  virtual ~ConnectionManager();
69 
70  void add(const dtn::core::Node &n) throw ();
71  void remove(const dtn::core::Node &n) throw ();
72 
76  void add(ConvergenceLayer *cl);
77 
81  void remove(ConvergenceLayer *cl);
82 
86  void add(P2PDialupExtension *ext);
87 
91  void remove(P2PDialupExtension *ext);
92 
97 
101  void raiseEvent(const dtn::core::TimeEvent &evt) throw ();
102  void raiseEvent(const dtn::core::NodeEvent &evt) throw ();
103  void raiseEvent(const dtn::net::ConnectionEvent &evt) throw ();
104  void raiseEvent(const dtn::core::GlobalEvent &evt) throw ();
105 
106  class ShutdownException : public ibrcommon::Exception
107  {
108  public:
109  ShutdownException(string what = "System shutdown") throw() : ibrcommon::Exception(what)
110  {
111  };
112  };
113 
114  void open(const dtn::core::Node &node) throw (ibrcommon::Exception);
115 
116 
117  typedef std::set<dtn::core::Node::Protocol> protocol_set;
118  typedef std::list<dtn::core::Node::Protocol> protocol_list;
119 
123  const protocol_set getSupportedProtocols() throw ();
124 
128  const protocol_list getSupportedProtocols(const dtn::data::EID &eid) throw (NodeNotAvailableException);
129 
134  const std::set<dtn::core::Node> getNeighbors();
135 
141  bool isNeighbor(const dtn::core::Node&) throw ();
142 
149  const dtn::core::Node getNeighbor(const dtn::data::EID &eid) throw (NodeNotAvailableException);
150 
155  void updateNeighbor(const dtn::core::Node &n);
156 
160  virtual const std::string getName() const;
161 
165  void getStats(dtn::net::ConvergenceLayer::stats_data &data);
166  void resetStats();
167 
168  protected:
173  void discovered(const dtn::core::Node &node);
174 
175  virtual void componentUp() throw ();
176  virtual void componentDown() throw ();
177 
178  private:
182  void check_unavailable();
183 
187  void check_available();
188 
192  void check_autoconnect();
193 
197  bool isReachable(const dtn::core::Node &node) throw ();
198 
202  dtn::core::Node& getNode(const dtn::data::EID &eid) throw (NodeNotAvailableException);
203 
204  // mutex for the list of convergence layers
205  ibrcommon::Mutex _cl_lock;
206 
207  // contains all configured convergence layers
208  std::set<ConvergenceLayer*> _cl;
209  std::set<Node::Protocol> _cl_protocols;
210 
211  // dial-up extensions
212  ibrcommon::Mutex _dialup_lock;
213  std::set<P2PDialupExtension*> _dialups;
214 
215  // mutex for the lists of nodes
216  ibrcommon::Mutex _node_lock;
217 
218  // contains all nodes
219  typedef std::map<dtn::data::EID, dtn::core::Node> nodemap;
220  nodemap _nodes;
221 
222  // next timestamp for autoconnect check
223  dtn::data::Timestamp _next_autoconnect;
224  };
225  }
226 }
227 
228 #endif /* CONNECTIONMANAGER_H_ */
const std::set< dtn::core::Node > getNeighbors()
ShutdownException(string what="System shutdown")
bool isNeighbor(const dtn::core::Node &)
std::list< dtn::core::Node::Protocol > protocol_list
void getStats(dtn::net::ConvergenceLayer::stats_data &data)
void add(const dtn::core::Node &n)
void discovered(const dtn::core::Node &node)
std::set< dtn::core::Node::Protocol > protocol_set
void queue(dtn::net::BundleTransfer &job)
const protocol_set getSupportedProtocols()
virtual const std::string getName() const
void raiseEvent(const dtn::core::TimeEvent &evt)
void updateNeighbor(const dtn::core::Node &n)
const dtn::core::Node getNeighbor(const dtn::data::EID &eid)
void open(const dtn::core::Node &node)
NodeNotAvailableException(string what="The requested node is not a neighbor.")
ConnectionNotAvailableException(string what="The requested connection is not available.")