NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-monitor.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2018 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 
26 #include "ndn-cxx/util/logger.hpp"
27 
28 #include "ndn-cxx/detail/config.hpp"
30 #if defined(NDN_CXX_HAVE_OSX_FRAMEWORKS)
32 #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplOsx
33 #elif defined(NDN_CXX_HAVE_NETLINK)
35 #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplNetlink
36 #else
37 #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplNoop
38 #endif
39 
40 NDN_LOG_INIT(ndn.NetworkMonitor);
41 
42 namespace ndn {
43 namespace net {
44 
45 static unique_ptr<NetworkMonitorImpl>
46 makeNetworkMonitorImpl(boost::asio::io_service& io)
47 {
48  try {
49  return make_unique<NETWORK_MONITOR_IMPL_TYPE>(io);
50  }
51  catch (const std::runtime_error& e) {
52  NDN_LOG_WARN("failed to initialize " BOOST_STRINGIZE(NETWORK_MONITOR_IMPL_TYPE) ": " << e.what());
53  // fallback to dummy implementation
54  return make_unique<NetworkMonitorImplNoop>(io);
55  }
56 }
57 
58 NetworkMonitor::NetworkMonitor(boost::asio::io_service& io)
60 {
61 }
62 
63 NetworkMonitor::NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl)
64  : m_impl(std::move(impl))
65  , onEnumerationCompleted(m_impl->onEnumerationCompleted)
66  , onInterfaceAdded(m_impl->onInterfaceAdded)
67  , onInterfaceRemoved(m_impl->onInterfaceRemoved)
68  , onNetworkStateChanged(m_impl->onNetworkStateChanged)
69 {
70 }
71 
72 uint32_t
74 {
75  return m_impl->getCapabilities();
76 }
77 
78 shared_ptr<const NetworkInterface>
79 NetworkMonitor::getNetworkInterface(const std::string& ifname) const
80 {
81  return m_impl->getNetworkInterface(ifname);
82 }
83 
84 std::vector<shared_ptr<const NetworkInterface>>
86 {
87  return m_impl->listNetworkInterfaces();
88 }
89 
90 shared_ptr<NetworkInterface>
92 {
93  // cannot use make_shared because NetworkInterface constructor is private
94  return shared_ptr<NetworkInterface>(new NetworkInterface);
95 }
96 
97 } // namespace net
98 } // namespace ndn
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_LOG_INIT
#define NDN_LOG_INIT(name)
declare a log module
Definition: logger.hpp:81
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
nonstd::optional_lite::std11::move
T & move(T &t)
Definition: optional.hpp:421
ndn::net::NetworkInterface
Represents one network interface attached to the host.
Definition: network-interface.hpp:70
NETWORK_MONITOR_IMPL_TYPE
#define NETWORK_MONITOR_IMPL_TYPE
Definition: network-monitor.cpp:37
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::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
network-monitor-impl-noop.hpp
ndn::net::NetworkMonitor
Network interface monitor.
Definition: network-monitor.hpp:51
ndn::net::NetworkMonitorImpl::makeNetworkInterface
static shared_ptr< NetworkInterface > makeNetworkInterface()
Definition: network-monitor.cpp:91
logger.hpp
NDN_LOG_WARN
#define NDN_LOG_WARN(expression)
Definition: logger.hpp:101
ndn::net
Definition: link-type-helper.cpp:30
network-monitor.hpp
network-monitor-impl-osx.hpp
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ndn::net::makeNetworkMonitorImpl
static unique_ptr< NetworkMonitorImpl > makeNetworkMonitorImpl(boost::asio::io_service &io)
Definition: network-monitor.cpp:46