IBR-DTNSuite  0.12
NetLinkManager.h
Go to the documentation of this file.
1 /*
2  * NetLinkManager.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 NETLINKMANAGER_H_
23 #define NETLINKMANAGER_H_
24 
26 #include "ibrcommon/net/socket.h"
27 #include "ibrcommon/net/vsocket.h"
29 #include "ibrcommon/thread/Mutex.h"
32 
33 #include <netlink/cache.h>
34 #include <map>
35 
36 namespace ibrcommon
37 {
39  {
40  friend class LinkManager;
41 
42  public:
43  virtual ~NetLinkManager();
44 
45  void up() throw ();
46  void down() throw ();
47 
48  const vinterface getInterface(int index) const;
49  const std::list<vaddress> getAddressList(const vinterface &iface, const std::string &scope = "");
50 
51  class parse_exception : public Exception
52  {
53  public:
54  parse_exception(string error) : Exception(error)
55  {};
56  };
57 
58  protected:
59  void run() throw ();
60  void __cancellation() throw ();
61 
62  private:
64 
65  class netlinkcache : public basesocket
66  {
67  public:
68  netlinkcache(int protocol);
69  virtual ~netlinkcache();
70 
71  virtual void up() throw (socket_exception);
72  virtual void down() throw (socket_exception);
73 
74  virtual int fd() const throw (socket_exception);
75 
76  void add(const std::string &cachename) throw (socket_exception);
77  struct nl_cache* get(const std::string &cachename) const throw (socket_exception);
78 
79  void receive() throw (socket_exception);
80 
81  private:
82  const int _protocol;
83 
84  void *_nl_handle;
85  struct nl_cache_mngr *_mngr;
86 
87  std::map<std::string, struct nl_cache*> _caches;
88  };
89 
90  ibrcommon::Mutex _cache_mutex;
91  netlinkcache _route_cache;
92 
93  bool _running;
94 
95  ibrcommon::vsocket _sock;
96  };
97 }
98 
99 #endif /* NETLINKMANAGER_H_ */