IBR-DTNSuite  0.10
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"
32 #include "net/DiscoveryService.h"
34 
36 #include <ibrcommon/net/vsocket.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  {
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 update(const ibrcommon::vinterface &iface, DiscoveryAnnouncement &announcement)
106 
107  void eventNotify(const ibrcommon::LinkEvent &evt);
108 
112  void raiseEvent(const Event *evt) throw ();
113 
114  virtual void resetStats();
115  virtual const stats_map& getStats();
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 
153  static const int DEFAULT_PORT;
154 
155  ibrcommon::vsocket _vsocket;
156  bool _vsocket_state;
157 
158  ibrcommon::Conditional _connections_cond;
159  std::list<TCPConnection*> _connections;
160 
161  ibrcommon::Mutex _interface_lock;
162  std::set<ibrcommon::vinterface> _interfaces;
163 
164  ibrcommon::Mutex _portmap_lock;
165  std::map<ibrcommon::vinterface, unsigned int> _portmap;
166  unsigned int _any_port;
167  };
168  }
169 }
170 
171 #endif /* TCPCONVERGENCELAYER_H_ */