IBR-DTNSuite  0.10
IPNDAgent.h
Go to the documentation of this file.
1 /*
2  * IPNDAgent.h
3  *
4  * IPND is based on the Internet-Draft for DTN-IPND.
5  *
6  *
7  * Copyright (C) 2011 IBR, TU Braunschweig
8  *
9  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  */
24 
25 #ifndef IPNDAGENT_H_
26 #define IPNDAGENT_H_
27 
28 #include "Component.h"
29 #include "net/DiscoveryAgent.h"
31 #include "core/EventReceiver.h"
33 #include <ibrcommon/net/vsocket.h>
35 #include <ibrcommon/thread/Mutex.h>
36 #include <list>
37 #include <map>
38 
39 using namespace dtn::data;
40 
41 namespace dtn
42 {
43  namespace net
44  {
46  {
47  public:
48  static const std::string TAG;
49 
50  IPNDAgent(int port);
51  virtual ~IPNDAgent();
52 
53  void add(const ibrcommon::vaddress &address);
54  void bind(const ibrcommon::vinterface &net);
55 
59  virtual const std::string getName() const;
60 
61  void eventNotify(const ibrcommon::LinkEvent &evt);
62 
66  void raiseEvent(const Event *evt) throw ();
67 
68  protected:
69  void sendAnnoucement(const uint16_t &sn, std::list<dtn::net::DiscoveryServiceProvider*> &provider);
70  virtual void componentRun() throw ();
71  virtual void componentUp() throw ();
72  virtual void componentDown() throw ();
73  void __cancellation() throw ();
74 
75  private:
76  void leave_interface(const ibrcommon::vinterface &iface) throw ();
77  void join_interface(const ibrcommon::vinterface &iface) throw ();
78  void send(const DiscoveryAnnouncement &a, const ibrcommon::vinterface &iface, const ibrcommon::vaddress &addr);
79 
80  void listen(const ibrcommon::vinterface &iface) throw ();
81  void unlisten(const ibrcommon::vinterface &iface) throw ();
82 
83  DiscoveryAnnouncement::DiscoveryVersion _version;
84  ibrcommon::vsocket _recv_socket;
85  ibrcommon::vsocket _send_socket;
86  bool _send_socket_state;
87 
88  std::set<ibrcommon::vaddress> _destinations;
89 
90  ibrcommon::Mutex _interface_lock;
91  std::set<ibrcommon::vinterface> _interfaces;
92  };
93  }
94 }
95 
96 #endif /* IPNDAGENT_H_ */