NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-monitor.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2019 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  *
21  * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
22  * @author Davide Pesavento <davide.pesavento@lip6.fr>
23  */
24 
25 #ifndef NDN_NET_NETWORK_MONITOR_HPP
26 #define NDN_NET_NETWORK_MONITOR_HPP
27 
30 
31 #include <vector>
32 
33 namespace ndn {
34 namespace net {
35 
36 class NetworkMonitorImpl;
37 
50 class NetworkMonitor : noncopyable
51 {
52 public:
53  class Error : public std::runtime_error
54  {
55  public:
56  using std::runtime_error::runtime_error;
57  };
58 
64  explicit
65  NetworkMonitor(boost::asio::io_service& io);
66 
67  enum Capability : uint32_t {
69  CAP_NONE = 0,
71  CAP_ENUM = 1 << 0,
75  CAP_STATE_CHANGE = 1 << 2,
77  CAP_MTU_CHANGE = 1 << 3,
79  CAP_ADDR_ADD_REMOVE = 1 << 4
80  };
81 
83  uint32_t
84  getCapabilities() const;
85 
87  shared_ptr<const NetworkInterface>
88  getNetworkInterface(const std::string& ifname) const;
89 
95  NDN_CXX_NODISCARD std::vector<shared_ptr<const NetworkInterface>>
96  listNetworkInterfaces() const;
97 
98 protected:
99  explicit
100  NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl);
101 
104  {
105  return *m_impl;
106  }
107 
108 private:
109  const unique_ptr<NetworkMonitorImpl> m_impl;
110  // Intentional violation of code-style rule 1.4: m_impl must be assigned before its signals can
111  // be assigned to references below.
112 
113 public: // signals
116 
119 
126 
129 };
130 
131 class NetworkMonitorImpl : noncopyable
132 {
133 public:
135 
136  virtual
137  ~NetworkMonitorImpl() = default;
138 
139  virtual uint32_t
140  getCapabilities() const = 0;
141 
142  virtual shared_ptr<const NetworkInterface>
143  getNetworkInterface(const std::string&) const = 0;
144 
145  virtual std::vector<shared_ptr<const NetworkInterface>>
147 
148 protected:
149  static shared_ptr<NetworkInterface>
151 
152 public:
157 
158 protected:
163 };
164 
165 } // namespace net
166 } // namespace ndn
167 
168 #endif // NDN_NET_NETWORK_MONITOR_HPP
ndn::net::NetworkMonitor::getNetworkInterface
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const
Returns the NetworkInterface with the given name, or nullptr if it does not exist.
Definition: network-monitor.cpp:79
ndn::net::NetworkMonitor::CAP_ADDR_ADD_REMOVE
@ CAP_ADDR_ADD_REMOVE
NetworkInterface onAddressAdded and onAddressRemoved signals are supported.
Definition: network-monitor.hpp:79
ndn::net::NetworkMonitor::CAP_STATE_CHANGE
@ CAP_STATE_CHANGE
NetworkInterface onStateChanged signal is supported.
Definition: network-monitor.hpp:75
ndn::net::NetworkMonitor::getCapabilities
uint32_t getCapabilities() const
Returns a bitwise OR'ed set of Capability flags supported on the current platform.
Definition: network-monitor.cpp:73
ndn::net::NetworkMonitor::getImpl
NetworkMonitorImpl & getImpl()
Definition: network-monitor.hpp:103
ndn::net::NetworkMonitor::CAP_MTU_CHANGE
@ CAP_MTU_CHANGE
NetworkInterface onMtuChanged signal is supported.
Definition: network-monitor.hpp:77
ndn::net::NetworkMonitorImpl
Definition: network-monitor.hpp:132
ndn::net::NetworkMonitorImpl::getNetworkInterface
virtual shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &) const =0
ndn::net::NetworkMonitor::onInterfaceRemoved
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceRemoved
Fires whenever an interface disappears from the system.
Definition: network-monitor.hpp:125
ndn::net::NetworkMonitorImpl::getCapabilities
virtual uint32_t getCapabilities() const =0
ndn::net::NetworkMonitor::listNetworkInterfaces
NDN_CXX_NODISCARD std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const
Lists all network interfaces currently available on the system.
Definition: network-monitor.cpp:85
ndn::net::NetworkMonitor::onEnumerationCompleted
util::Signal< NetworkMonitorImpl > & onEnumerationCompleted
Fires when the enumeration of all network interfaces on the system is complete.
Definition: network-monitor.hpp:115
ndn::util::signal::Signal
provides a lightweight signal / event system
Definition: signal.hpp:52
ndn::net::NetworkMonitor::NetworkMonitor
NetworkMonitor(boost::asio::io_service &io)
Construct instance, request enumeration of all network interfaces, and start monitoring for network s...
Definition: network-monitor.cpp:58
NDN_CXX_NODISCARD
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
ndn::net::NetworkMonitor::CAP_ENUM
@ CAP_ENUM
listNetworkInterfaces() and getNetworkInterface() are supported
Definition: network-monitor.hpp:71
ndn::net::NetworkMonitor
Network interface monitor.
Definition: network-monitor.hpp:51
ndn::net::NetworkMonitorImpl::onInterfaceRemoved
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceRemoved
Definition: network-monitor.hpp:155
ndn::net::NetworkMonitorImpl::onNetworkStateChanged
util::Signal< NetworkMonitorImpl > onNetworkStateChanged
Definition: network-monitor.hpp:156
ndn::net::NetworkMonitorImpl::~NetworkMonitorImpl
virtual ~NetworkMonitorImpl()=default
ndn::net::NetworkMonitorImpl::makeNetworkInterface
static shared_ptr< NetworkInterface > makeNetworkInterface()
Definition: network-monitor.cpp:91
ndn::net::NetworkMonitor::onInterfaceAdded
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
Fires whenever a new interface is detected on the system.
Definition: network-monitor.hpp:118
DECLARE_SIGNAL_EMIT
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a 'emit_signalName' method
Definition: emit.hpp:59
ndn::net::NetworkMonitorImpl::onEnumerationCompleted
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
Definition: network-monitor.hpp:153
ndn::net::NetworkMonitor::CAP_NONE
@ CAP_NONE
NetworkMonitor is not supported and is a no-op.
Definition: network-monitor.hpp:69
ndn::net
Definition: link-type-helper.cpp:30
network-interface.hpp
ndn::net::NetworkMonitorImpl::listNetworkInterfaces
virtual std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const =0
ndn::net::NetworkMonitor::Capability
Capability
Definition: network-monitor.hpp:67
ndn::net::NetworkMonitor::CAP_IF_ADD_REMOVE
@ CAP_IF_ADD_REMOVE
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.
Definition: network-monitor.hpp:73
ndn::net::NetworkMonitorImpl::onInterfaceAdded
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
Definition: network-monitor.hpp:154
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
asio-fwd.hpp
ndn::net::NetworkMonitor::onNetworkStateChanged
util::Signal< NetworkMonitorImpl > & onNetworkStateChanged
Definition: network-monitor.hpp:128
ndn::net::NetworkMonitor::Error
Definition: network-monitor.hpp:54