NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-monitor-impl-rtnl.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_NET_NETWORK_MONITOR_IMPL_RTNL_HPP
25 #define NDN_NET_NETWORK_MONITOR_IMPL_RTNL_HPP
26 
27 #include "ndn-cxx-config.hpp"
28 #include "../network-monitor.hpp"
29 
30 #ifndef NDN_CXX_HAVE_RTNETLINK
31 #error "This file should not be compiled ..."
32 #endif
33 
34 #include <boost/asio/posix/stream_descriptor.hpp>
35 
36 #include <array>
37 #include <map>
38 
39 #include <linux/netlink.h>
40 #include <linux/rtnetlink.h>
41 #include <linux/if_addr.h>
42 #include <linux/if_link.h>
43 
44 namespace ndn {
45 namespace net {
46 
48 {
49 public:
51 
54  explicit
55  NetworkMonitorImplRtnl(boost::asio::io_service& io);
56 
58 
59  uint32_t
60  getCapabilities() const final
61  {
67  }
68 
69  shared_ptr<const NetworkInterface>
70  getNetworkInterface(const std::string& ifname) const final;
71 
72  std::vector<shared_ptr<const NetworkInterface>>
73  listNetworkInterfaces() const final;
74 
75 private:
76  struct RtnlRequest
77  {
78  nlmsghdr nlh;
79  ifinfomsg ifi;
80  rtattr rta __attribute__((aligned(NLMSG_ALIGNTO))); // rtattr has to be aligned
81  uint32_t rtext; // space for IFLA_EXT_MASK
82  };
83 
84  bool
85  isEnumerating() const;
86 
87  void
88  initSocket();
89 
90  void
91  sendDumpRequest(uint16_t nlmsgType);
92 
93  void
94  asyncRead();
95 
96  void
97  handleRead(const boost::system::error_code& error, size_t nBytesReceived,
98  const shared_ptr<boost::asio::posix::stream_descriptor>& socket);
99 
100  void
101  parseNetlinkMessage(const nlmsghdr* nlh, size_t len);
102 
103  void
104  parseLinkMessage(const nlmsghdr* nlh, const ifinfomsg* ifi);
105 
106  void
107  parseAddressMessage(const nlmsghdr* nlh, const ifaddrmsg* ifa);
108 
109  void
110  parseRouteMessage(const nlmsghdr* nlh, const rtmsg* rtm);
111 
112  static void
113  updateInterfaceState(NetworkInterface& interface, uint8_t operState);
114 
115 private:
116  std::map<int, shared_ptr<NetworkInterface>> m_interfaces;
117  std::array<uint8_t, 16384> m_buffer;
118  shared_ptr<boost::asio::posix::stream_descriptor> m_socket;
119  uint32_t m_pid;
120  uint32_t m_sequenceNo;
121  bool m_isEnumeratingLinks;
122  bool m_isEnumeratingAddresses;
123 };
124 
125 } // namespace net
126 } // namespace ndn
127 
128 #endif // NDN_NET_NETWORK_MONITOR_IMPL_RTNL_HPP
Copyright (c) 2011-2015 Regents of the University of California.
listNetworkInterfaces() and getNetworkInterface() are supported
NetworkInterface onAddressAdded and onAddressRemoved signals are supported.
NetworkInterface onMtuChanged signal is supported.
NetworkInterface onStateChanged signal is supported.
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const final
NetworkMonitorImplRtnl(boost::asio::io_service &io)
initialize netlink socket and start enumerating interfaces
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const final