IBR-DTNSuite  0.10
DatagramConvergenceLayer.h
Go to the documentation of this file.
1 /*
2  * DatagramConvergenceLayer.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 DATAGRAMCONVERGENCELAYER_H_
23 #define DATAGRAMCONVERGENCELAYER_H_
24 
25 #include "Component.h"
26 #include "core/EventReceiver.h"
27 #include "net/DatagramService.h"
28 #include "net/DatagramConnection.h"
29 #include "net/ConvergenceLayer.h"
30 #include "net/DiscoveryAgent.h"
32 
34 
35 #include <list>
36 
37 namespace dtn
38 {
39  namespace net
40  {
43  {
44  public:
45  static const std::string TAG;
46 
48  {
54  };
55 
57  virtual ~DatagramConvergenceLayer();
58 
64 
71  void queue(const dtn::core::Node &n, const dtn::net::BundleTransfer &job);
72 
76  virtual const std::string getName() const;
77 
82  virtual void raiseEvent(const dtn::core::Event *evt) throw ();
83 
84  protected:
85  virtual void componentUp() throw ();
86  virtual void componentRun() throw ();
87  virtual void componentDown() throw ();
88  void __cancellation() throw ();
89 
90  void sendAnnoucement();
91 
99  void callback_send(DatagramConnection &connection, const char &flags, const unsigned int &seqno, const std::string &destination, const char *buf, const dtn::data::Length &len) throw (DatagramException);
100 
101  void callback_ack(DatagramConnection &connection, const unsigned int &seqno, const std::string &destination) throw (DatagramException);
102 
103  void connectionUp(const DatagramConnection *conn);
104  void connectionDown(const DatagramConnection *conn);
105 
106  private:
107  DatagramConnection& getConnection(const std::string &identifier);
108 
109  DatagramService *_service;
110 
111  ibrcommon::Mutex _send_lock;
112 
113  // this conditional must be locked when iterating over the
114  // list of connections
115  ibrcommon::Conditional _cond_connections;
116 
117  // this lock is used to protect a connection reference from
118  // being deleted while using it
119  ibrcommon::RWMutex _mutex_connection;
120 
121  typedef std::list<DatagramConnection*> connection_list;
122  connection_list _connections;
123 
124  bool _running;
125 
126  uint16_t _discovery_sn;
127  };
128  } /* namespace data */
129 } /* namespace dtn */
130 #endif /* DATAGRAMCONVERGENCELAYER_H_ */