IBR-DTNSuite
0.8
|
00001 /* 00002 * NetLink3Manager.h 00003 * 00004 * Created on: 17.10.2011 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef NETLINK3MANAGER_H_ 00009 #define NETLINK3MANAGER_H_ 00010 00011 #include "ibrcommon/net/LinkManager.h" 00012 #include "ibrcommon/thread/Mutex.h" 00013 #include "ibrcommon/thread/Thread.h" 00014 #include "ibrcommon/net/vsocket.h" 00015 00016 #include <netlink/netlink.h> 00017 #include <netlink/socket.h> 00018 #include <netlink/route/link.h> 00019 #include <netlink/msg.h> 00020 00021 namespace ibrcommon 00022 { 00023 class NetLink3ManagerEvent : public LinkManagerEvent 00024 { 00025 public: 00026 NetLink3ManagerEvent(struct nl_msg *msg); 00027 virtual ~NetLink3ManagerEvent(); 00028 00029 virtual const ibrcommon::vinterface& getInterface() const; 00030 virtual const ibrcommon::vaddress& getAddress() const; 00031 virtual unsigned int getState() const; 00032 virtual EventType getType() const; 00033 00034 virtual bool isWirelessExtension() const; 00035 00036 void debug() const; 00037 const std::string toString() const; 00038 00039 private: 00040 EventType _type; 00041 unsigned int _state; 00042 bool _wireless; 00043 ibrcommon::vinterface _interface; 00044 ibrcommon::vaddress _address; 00045 std::map<int, std::string> _attributes; 00046 }; 00047 00048 class NetLink3Manager : public ibrcommon::LinkManager, public ibrcommon::JoinableThread 00049 { 00050 friend class LinkManager; 00051 00052 public: 00053 virtual ~NetLink3Manager(); 00054 00055 const std::string getInterface(int index) const; 00056 const std::list<vaddress> getAddressList(const vinterface &iface, const vaddress::Family f); 00057 00058 class parse_exception : public Exception 00059 { 00060 public: 00061 parse_exception(string error) : Exception(error) 00062 {}; 00063 }; 00064 00065 void callback(const NetLink3ManagerEvent &evt); 00066 00067 protected: 00068 void run(); 00069 void __cancellation(); 00070 00071 private: 00072 NetLink3Manager(); 00073 00074 struct nl_sock *_nl_notify_sock; 00075 struct nl_sock *_nl_query_sock; 00076 00077 // local link cache 00078 struct nl_cache *_link_cache; 00079 struct nl_cache *_addr_cache; 00080 00081 // mutex for the link cache 00082 ibrcommon::Mutex _call_mutex; 00083 00084 bool _refresh_cache; 00085 bool _running; 00086 00087 ibrcommon::vsocket *_sock; 00088 }; 00089 } /* namespace ibrcommon */ 00090 #endif /* NETLINK3MANAGER_H_ */