IBR-DTNSuite  0.12
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 <set>
35 
36 namespace dtn
37 {
38  namespace net
39  {
41  {
42  public:
43  NeighborNotAvailableException(string what = "The requested connection is not available.") throw() : ibrcommon::Exception(what)
44  {
45  };
46  };
47 
49  {
50  public:
51  ConnectionNotAvailableException(string what = "The requested connection is not available.") throw() : ibrcommon::Exception(what)
52  {
53  };
54  };
55 
57  {
58  public:
60  virtual ~ConnectionManager();
61 
62  void add(const dtn::core::Node &n);
63  void remove(const dtn::core::Node &n);
64 
68  void add(ConvergenceLayer *cl);
69 
73  void remove(ConvergenceLayer *cl);
74 
78  void add(P2PDialupExtension *ext);
79 
83  void remove(P2PDialupExtension *ext);
84 
89 
93  void raiseEvent(const dtn::core::Event *evt) throw ();
94 
96  {
97  public:
98  ShutdownException(string what = "System shutdown") throw() : ibrcommon::Exception(what)
99  {
100  };
101  };
102 
103  void open(const dtn::core::Node &node) throw (ibrcommon::Exception);
104 
109  const std::set<dtn::core::Node> getNeighbors();
110 
116  bool isNeighbor(const dtn::core::Node&);
117 
125 
130  void updateNeighbor(const dtn::core::Node &n);
131 
135  virtual const std::string getName() const;
136 
141  void resetStats();
142 
143  protected:
148  void discovered(const dtn::core::Node &node);
149 
150  virtual void componentUp() throw ();
151  virtual void componentDown() throw ();
152 
153  private:
157  void dialup(const dtn::core::Node &n);
158 
162  void queue(const dtn::core::Node &node, const dtn::net::BundleTransfer &job);
163 
167  void check_unavailable();
168 
172  void check_available();
173 
177  void check_autoconnect();
178 
182  dtn::core::Node& getNode(const dtn::data::EID &eid) throw (NeighborNotAvailableException);
183 
184  // mutex for the list of convergence layers
185  ibrcommon::Mutex _cl_lock;
186 
187  // contains all configured convergence layers
188  std::set<ConvergenceLayer*> _cl;
189 
190  // dial-up extensions
191  ibrcommon::Mutex _dialup_lock;
192  std::set<P2PDialupExtension*> _dialups;
193 
194  // mutex for the lists of nodes
195  ibrcommon::Mutex _node_lock;
196 
197  // contains all nodes
198  typedef std::map<dtn::data::EID, dtn::core::Node> nodemap;
199  nodemap _nodes;
200 
201  // next timestamp for autoconnect check
202  dtn::data::Timestamp _next_autoconnect;
203  };
204  }
205 }
206 
207 #endif /* CONNECTIONMANAGER_H_ */