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