IBR-DTN  1.0.0
TCPConvergenceLayer.h
Go to the documentation of this file.
1 /*
2  * TCPConvergenceLayer.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 TCPCONVERGENCELAYER_H_
23 #define TCPCONVERGENCELAYER_H_
24 
25 #include "config.h"
26 #include "Component.h"
27 
28 #include "core/Node.h"
29 #include "core/EventReceiver.h"
30 #include "net/ConvergenceLayer.h"
31 #include "net/TCPConnection.h"
33 #include "net/P2PDialupEvent.h"
34 
35 #include <ibrcommon/link/LinkManager.h>
36 #include <ibrcommon/net/vsocket.h>
37 #include <ibrcommon/net/vinterface.h>
38 #include <ibrcommon/thread/Mutex.h>
39 
40 #include <set>
41 #include <list>
42 #include <map>
43 
44 namespace dtn
45 {
46  namespace net
47  {
52  class TCPConvergenceLayer : public dtn::daemon::IndependentComponent, public dtn::core::EventReceiver<dtn::net::P2PDialupEvent>, public ConvergenceLayer, public DiscoveryBeaconHandler, public ibrcommon::LinkManager::EventCallback
53  {
54  friend class TCPConnection;
55 
56  const static std::string TAG;
57  public:
64 
68  virtual ~TCPConvergenceLayer();
69 
75  void add(const ibrcommon::vinterface &net, int port) throw ();
76 
81  void queue(const dtn::core::Node &n, const dtn::net::BundleTransfer &job);
82 
88  void open(const dtn::core::Node &n);
89 
93  virtual const std::string getName() const;
94 
100 
104  void onUpdateBeacon(const ibrcommon::vinterface &iface, DiscoveryBeacon &beacon) throw (NoServiceHereException);
105 
106  void eventNotify(const ibrcommon::LinkEvent &evt);
107 
111  void raiseEvent(const dtn::net::P2PDialupEvent &evt) throw ();
112 
113  virtual void resetStats();
114 
115  virtual void getStats(ConvergenceLayer::stats_data &data) const;
116 
117  protected:
118  void __cancellation() throw ();
119 
120  void componentUp() throw ();
121  void componentRun() throw ();
122  void componentDown() throw ();
123 
124  private:
128  void listen(const ibrcommon::vinterface &iface, int port) throw ();
129 
133  void unlisten(const ibrcommon::vinterface &iface) throw ();
134 
138  void closeAll();
139 
144  void connectionUp(TCPConnection *conn);
145 
151  void connectionDown(TCPConnection *conn);
152 
156  void addTrafficIn(size_t) throw ();
157 
161  void addTrafficOut(size_t) throw ();
162 
163  static const int DEFAULT_PORT;
164 
165  ibrcommon::vsocket _vsocket;
166  bool _vsocket_state;
167 
168  ibrcommon::Conditional _connections_cond;
169  std::list<TCPConnection*> _connections;
170 
171  ibrcommon::Mutex _interface_lock;
172  std::set<ibrcommon::vinterface> _interfaces;
173 
174  ibrcommon::Mutex _portmap_lock;
175  std::map<ibrcommon::vinterface, unsigned int> _portmap;
176  unsigned int _any_port;
177 
178  // stats variables
179  ibrcommon::Mutex _stats_lock;
180  size_t _stats_in;
181  size_t _stats_out;
182 
183  const size_t _keepalive_timeout;
184  };
185  }
186 }
187 
188 #endif /* TCPCONVERGENCELAYER_H_ */
dtn::core::Node::Protocol getDiscoveryProtocol() const
void open(const dtn::core::Node &n)
const std::string TAG
Definition: dtnoutbox.cpp:62
void onUpdateBeacon(const ibrcommon::vinterface &iface, DiscoveryBeacon &beacon)
void add(const ibrcommon::vinterface &net, int port)
std::map< string, string > stats_data
void queue(const dtn::core::Node &n, const dtn::net::BundleTransfer &job)
void raiseEvent(const dtn::net::P2PDialupEvent &evt)
void eventNotify(const ibrcommon::LinkEvent &evt)
virtual const std::string getName() const
virtual void getStats(ConvergenceLayer::stats_data &data) const