NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-monitor-impl-osx.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 
22 #ifndef NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
23 #define NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
24 
25 #include "ndn-cxx/detail/config.hpp"
27 
28 #ifndef NDN_CXX_HAVE_OSX_FRAMEWORKS
29 #error "This file should not be included ..."
30 #endif
31 
34 
35 #include <CoreFoundation/CoreFoundation.h>
36 #include <SystemConfiguration/SystemConfiguration.h>
37 
38 #include <boost/asio/ip/udp.hpp>
39 #include <map>
40 
41 namespace ndn {
42 namespace net {
43 
44 class IfAddrs;
45 
47 {
48 public:
49  NetworkMonitorImplOsx(boost::asio::io_service& io);
50 
52 
53  uint32_t
54  getCapabilities() const final
55  {
60  }
61 
62  shared_ptr<const NetworkInterface>
63  getNetworkInterface(const std::string& ifname) const final;
64 
65  std::vector<shared_ptr<const NetworkInterface>>
66  listNetworkInterfaces() const final;
67 
68 private:
69  static void
70  afterNotificationCenterEvent(CFNotificationCenterRef center, void* observer,
71  CFStringRef name, const void* object,
72  CFDictionaryRef userInfo);
73 
74  void
75  scheduleCfLoop();
76 
77  void
78  enumerateInterfaces();
79 
80  std::set<std::string>
81  getInterfaceNames() const;
82 
83  void
84  addNewInterface(const std::string& ifName, const IfAddrs& ifaList);
85 
87  getInterfaceState(const NetworkInterface& netif) const;
88 
89  size_t
90  getInterfaceMtu(const NetworkInterface& netif);
91 
92  void
93  updateInterfaceInfo(NetworkInterface& netif, const IfAddrs& ifaList);
94 
95  static void
96  onConfigChanged(SCDynamicStoreRef store, CFArrayRef changedKeys, void* context);
97 
98  void
99  onConfigChanged(CFArrayRef changedKeys);
100 
101 private:
102  std::map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
103 
104  Scheduler m_scheduler;
105  scheduler::ScopedEventId m_cfLoopEvent;
106 
107  SCDynamicStoreContext m_context;
108  detail::CFReleaser<SCDynamicStoreRef> m_scStore;
109  detail::CFReleaser<CFRunLoopSourceRef> m_loopSource;
110 
111  boost::asio::ip::udp::socket m_ioctlSocket;
112 };
113 
114 } // namespace net
115 } // namespace ndn
116 
117 #endif // NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
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::NetworkMonitorImplOsx::getCapabilities
uint32_t getCapabilities() const final
Definition: network-monitor-impl-osx.hpp:54
ndn::net::NetworkMonitorImpl
Definition: network-monitor.hpp:132
ndn::net::NetworkInterface
Represents one network interface attached to the host.
Definition: network-interface.hpp:70
ndn::net::NetworkMonitorImplOsx::~NetworkMonitorImplOsx
~NetworkMonitorImplOsx()
Definition: network-monitor-impl-osx.cpp:149
boost
Definition: block.hpp:31
ndn::net::NetworkMonitorImplOsx
Definition: network-monitor-impl-osx.hpp:47
scheduler.hpp
ndn::net::NetworkMonitorImplOsx::NetworkMonitorImplOsx
NetworkMonitorImplOsx(boost::asio::io_service &io)
Definition: network-monitor-impl-osx.cpp:105
ndn::detail::CFReleaser
Helper class to wrap CoreFoundation object pointers.
Definition: cf-releaser-osx.hpp:50
ndn::scheduler::ScopedEventId
detail::ScopedCancelHandle< EventId > ScopedEventId
A scoped handle for a scheduled event.
Definition: scheduler.hpp:128
ndn::net::NetworkMonitor::CAP_ENUM
@ CAP_ENUM
listNetworkInterfaces() and getNetworkInterface() are supported
Definition: network-monitor.hpp:71
ndn::net::NetworkMonitorImplOsx::listNetworkInterfaces
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const final
Definition: network-monitor-impl-osx.cpp:165
ndn::net::IfAddrs
Definition: network-monitor-impl-osx.cpp:79
ndn::net::InterfaceState
InterfaceState
Indicates the state of a network interface.
Definition: network-interface.hpp:50
cf-releaser-osx.hpp
ndn::scheduler
Definition: scheduler.cpp:27
ndn::scheduler::Scheduler
Generic time-based scheduler.
Definition: scheduler.hpp:133
ndn::net::NetworkMonitorImplOsx::getNetworkInterface
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const final
Definition: network-monitor-impl-osx.cpp:158
ndn::name
Definition: name-component-types.hpp:33
ndn::net
Definition: link-type-helper.cpp:30
network-monitor.hpp
ndn::net::NetworkMonitor::CAP_IF_ADD_REMOVE
@ CAP_IF_ADD_REMOVE
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.
Definition: network-monitor.hpp:73
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34