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-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 
22 #ifndef NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
23 #define NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
24 
25 #include "ndn-cxx-config.hpp"
26 #include "../network-monitor.hpp"
27 
28 #ifndef NDN_CXX_HAVE_OSX_FRAMEWORKS
29 #error "This file should not be compiled ..."
30 #endif
31 
32 #include "../../util/cf-releaser-osx.hpp"
33 #include "../../util/scheduler.hpp"
34 #include "../../util/scheduler-scoped-event-id.hpp"
35 
36 #include <CoreFoundation/CoreFoundation.h>
37 #include <SystemConfiguration/SystemConfiguration.h>
38 
39 #include <boost/asio/ip/udp.hpp>
40 #include <map>
41 
42 namespace ndn {
43 namespace net {
44 
45 class IfAddrs;
46 
48 {
49 public:
51 
52  NetworkMonitorImplOsx(boost::asio::io_service& io);
53 
55 
56  uint32_t
57  getCapabilities() const final
58  {
63  }
64 
65  shared_ptr<const NetworkInterface>
66  getNetworkInterface(const std::string& ifname) const final;
67 
68  std::vector<shared_ptr<const NetworkInterface>>
69  listNetworkInterfaces() const final;
70 
71 private:
72  static void
73  afterNotificationCenterEvent(CFNotificationCenterRef center, void* observer,
74  CFStringRef name, const void* object,
75  CFDictionaryRef userInfo);
76 
77  void
78  scheduleCfLoop();
79 
80  void
81  enumerateInterfaces();
82 
83  std::set<std::string>
84  getInterfaceNames() const;
85 
86  void
87  addNewInterface(const std::string& ifName, const IfAddrs& ifaList);
88 
90  getInterfaceState(const NetworkInterface& netif) const;
91 
92  size_t
93  getInterfaceMtu(const NetworkInterface& netif);
94 
95  void
96  updateInterfaceInfo(NetworkInterface& netif, const IfAddrs& ifaList);
97 
98  static void
99  onConfigChanged(SCDynamicStoreRef store, CFArrayRef changedKeys, void* context);
100 
101  void
102  onConfigChanged(CFArrayRef changedKeys);
103 
104 private:
105  std::map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
106 
107  util::Scheduler m_scheduler;
108  util::scheduler::ScopedEventId m_cfLoopEvent;
109 
110  SCDynamicStoreContext m_context;
111  util::CFReleaser<SCDynamicStoreRef> m_scStore;
112  util::CFReleaser<CFRunLoopSourceRef> m_loopSource;
113 
114  boost::asio::ip::udp::socket m_ioctlSocket;
115 };
116 
117 } // namespace net
118 } // namespace ndn
119 
120 #endif // NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP
Copyright (c) 2011-2015 Regents of the University of California.
listNetworkInterfaces() and getNetworkInterface() are supported
NetworkInterface onAddressAdded and onAddressRemoved signals are supported.
NetworkMonitorImplOsx(boost::asio::io_service &io)
NetworkInterface onStateChanged signal is supported.
InterfaceState
Indicates the state of a network interface.
STL namespace.
Represents one network interface attached to the host.
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const final
Helper class to wrap CoreFoundation object pointers.
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const final
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.