IBR-DTNSuite  0.12
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 
35 #include <ibrcommon/net/vsocket.h>
37 #include <ibrcommon/thread/Mutex.h>
38 
39 #include <set>
40 #include <list>
41 #include <map>
42 
43 namespace dtn
44 {
45  namespace net
46  {
52  {
53  friend class TCPConnection;
54 
55  const static std::string TAG;
56  public:
63 
67  virtual ~TCPConvergenceLayer();
68 
74  void add(const ibrcommon::vinterface &net, int port) throw ();
75 
80  void queue(const dtn::core::Node &n, const dtn::net::BundleTransfer &job);
81 
87  void open(const dtn::core::Node &n);
88 
92  virtual const std::string getName() const;
93 
99 
104 
105  void eventNotify(const ibrcommon::LinkEvent &evt);
106 
110  void raiseEvent(const dtn::core::Event *evt) throw ();
111 
112  virtual void resetStats();
113 
114  virtual void getStats(ConvergenceLayer::stats_data &data) const;
115 
116  protected:
117  void __cancellation() throw ();
118 
119  void componentUp() throw ();
120  void componentRun() throw ();
121  void componentDown() throw ();
122 
123  private:
127  void listen(const ibrcommon::vinterface &iface, int port) throw ();
128 
132  void unlisten(const ibrcommon::vinterface &iface) throw ();
133 
137  void closeAll();
138 
143  void connectionUp(TCPConnection *conn);
144 
150  void connectionDown(TCPConnection *conn);
151 
155  void addTrafficIn(size_t) throw ();
156 
160  void addTrafficOut(size_t) throw ();
161 
162  static const int DEFAULT_PORT;
163 
164  ibrcommon::vsocket _vsocket;
165  bool _vsocket_state;
166 
167  ibrcommon::Conditional _connections_cond;
168  std::list<TCPConnection*> _connections;
169 
170  ibrcommon::Mutex _interface_lock;
171  std::set<ibrcommon::vinterface> _interfaces;
172 
173  ibrcommon::Mutex _portmap_lock;
174  std::map<ibrcommon::vinterface, unsigned int> _portmap;
175  unsigned int _any_port;
176 
177  // stats variables
178  ibrcommon::Mutex _stats_lock;
179  size_t _stats_in;
180  size_t _stats_out;
181  };
182  }
183 }
184 
185 #endif /* TCPCONVERGENCELAYER_H_ */