IBR-DTNSuite  0.10
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 
88  void queue(const dtn::net::BundleTransfer &job);
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 
140  typedef std::pair<dtn::core::Node::Protocol, ConvergenceLayer::stats_map> stats_pair;
141  typedef std::list<stats_pair> stats_list;
142 
144  void resetStats();
145 
146  protected:
151  void discovered(const dtn::core::Node &node);
152 
153  virtual void componentUp() throw ();
154  virtual void componentDown() throw ();
155 
156  private:
160  void dialup(const dtn::core::Node &n);
161 
165  void queue(const dtn::core::Node &node, const dtn::net::BundleTransfer &job);
166 
170  void check_unavailable();
171 
175  void check_available();
176 
180  void check_autoconnect();
181 
185  dtn::core::Node& getNode(const dtn::data::EID &eid) throw (NeighborNotAvailableException);
186 
187  // mutex for the list of convergence layers
188  ibrcommon::Mutex _cl_lock;
189 
190  // contains all configured convergence layers
191  std::set<ConvergenceLayer*> _cl;
192 
193  // dial-up extensions
194  ibrcommon::Mutex _dialup_lock;
195  std::set<P2PDialupExtension*> _dialups;
196 
197  // mutex for the lists of nodes
198  ibrcommon::Mutex _node_lock;
199 
200  // contains all nodes
201  typedef std::map<dtn::data::EID, dtn::core::Node> nodemap;
202  nodemap _nodes;
203 
204  // next timestamp for autoconnect check
205  dtn::data::Timestamp _next_autoconnect;
206  };
207  }
208 }
209 
210 #endif /* CONNECTIONMANAGER_H_ */