NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-monitor-stub.cpp
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
#include "
ndn-cxx/net/network-monitor-stub.hpp
"
26
27
#include <unordered_map>
28
29
#include <boost/range/adaptor/map.hpp>
30
#include <boost/range/algorithm/copy.hpp>
31
32
namespace
ndn
{
33
namespace
net
{
34
35
class
NetworkMonitorImplStub
:
public
NetworkMonitorImpl
36
{
37
public
:
38
explicit
39
NetworkMonitorImplStub
(uint32_t capabilities)
40
: m_capabilities(capabilities)
41
{
42
}
43
44
uint32_t
45
getCapabilities
() const final
46
{
47
return
m_capabilities;
48
}
49
50
shared_ptr<const NetworkInterface>
51
getNetworkInterface
(
const
std::string& ifname)
const
final
52
{
53
auto
i = m_interfaces.find(ifname);
54
return
i == m_interfaces.end() ? nullptr : i->second;
55
}
56
57
std::vector<shared_ptr<const NetworkInterface>>
58
listNetworkInterfaces
() const final
59
{
60
std::vector<shared_ptr<const NetworkInterface>> v;
61
boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
62
return
v;
63
}
64
65
public
:
// internal
66
using
NetworkMonitorImpl::makeNetworkInterface
;
67
68
void
69
addInterface
(shared_ptr<NetworkInterface> netif)
70
{
71
BOOST_ASSERT(netif !=
nullptr
);
72
bool
isNew = m_interfaces.emplace(netif->getName(), netif).second;
73
if
(!isNew) {
74
NDN_THROW
(std::invalid_argument(
"duplicate ifname"
));
75
}
76
this->
emitSignal
(
onInterfaceAdded
, netif);
77
}
78
79
void
80
removeInterface
(
const
std::string& ifname)
81
{
82
auto
i = m_interfaces.find(ifname);
83
if
(i == m_interfaces.end()) {
84
return
;
85
}
86
shared_ptr<NetworkInterface> netif = i->second;
87
m_interfaces.erase(i);
88
this->
emitSignal
(
onInterfaceRemoved
, netif);
89
}
90
91
void
92
emitEnumerationCompleted
()
93
{
94
this->
emitSignal
(
onEnumerationCompleted
);
95
}
96
97
private
:
98
uint32_t m_capabilities;
99
std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
100
};
101
102
NetworkMonitorStub::NetworkMonitorStub
(uint32_t capabilities)
103
:
NetworkMonitor
(make_unique<
NetworkMonitorImplStub
>(capabilities))
104
{
105
}
106
107
NetworkMonitorImplStub
&
108
NetworkMonitorStub::getImpl()
109
{
110
return
static_cast<
NetworkMonitorImplStub
&
>
(this->
NetworkMonitor::getImpl
());
111
}
112
113
shared_ptr<NetworkInterface>
114
NetworkMonitorStub::makeNetworkInterface
()
115
{
116
return
NetworkMonitorImplStub::makeNetworkInterface
();
117
}
118
119
void
120
NetworkMonitorStub::addInterface
(shared_ptr<NetworkInterface> netif)
121
{
122
this->getImpl().
addInterface
(
std::move
(netif));
123
}
124
125
void
126
NetworkMonitorStub::removeInterface
(
const
std::string& ifname)
127
{
128
this->getImpl().
removeInterface
(ifname);
129
}
130
131
void
132
NetworkMonitorStub::emitEnumerationCompleted
()
133
{
134
this->getImpl().
emitEnumerationCompleted
();
135
}
136
137
}
// namespace net
138
}
// namespace ndn
ndn::net::NetworkMonitorImplStub::listNetworkInterfaces
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const final
Definition:
network-monitor-stub.cpp:58
ndn::net::NetworkMonitorStub::emitEnumerationCompleted
void emitEnumerationCompleted()
emit the onEnumerationCompleted signal
Definition:
network-monitor-stub.cpp:132
ndn::net::NetworkMonitor::getImpl
NetworkMonitorImpl & getImpl()
Definition:
network-monitor.hpp:103
nonstd::optional_lite::std11::move
T & move(T &t)
Definition:
optional.hpp:421
ndn::net::NetworkMonitorImpl
Definition:
network-monitor.hpp:132
network-monitor-stub.hpp
ndn::net::NetworkMonitorImplStub::addInterface
void addInterface(shared_ptr< NetworkInterface > netif)
Definition:
network-monitor-stub.cpp:69
ndn::net::NetworkMonitorStub::addInterface
void addInterface(shared_ptr< NetworkInterface > netif)
emit the onInterfaceAdded signal and add netif internally
Definition:
network-monitor-stub.cpp:120
ndn::net::NetworkMonitorStub::makeNetworkInterface
static shared_ptr< NetworkInterface > makeNetworkInterface()
create a NetworkInterface instance
Definition:
network-monitor-stub.cpp:114
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::makeNetworkInterface
static shared_ptr< NetworkInterface > makeNetworkInterface()
Definition:
network-monitor.cpp:91
ndn::net::NetworkMonitorStub::removeInterface
void removeInterface(const std::string &ifname)
emit the onInterfaceRemoved signal and remove netif internally
Definition:
network-monitor-stub.cpp:126
ndn::net::NetworkMonitorImplStub::getNetworkInterface
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const final
Definition:
network-monitor-stub.cpp:51
NDN_THROW
#define NDN_THROW(e)
Definition:
exception.hpp:61
ndn::net::NetworkMonitorImplStub
Definition:
network-monitor-stub.cpp:36
ndn::net::NetworkMonitorStub::NetworkMonitorStub
NetworkMonitorStub(uint32_t capabilities)
constructor
Definition:
network-monitor-stub.cpp:102
ndn::net::NetworkMonitorImplStub::NetworkMonitorImplStub
NetworkMonitorImplStub(uint32_t capabilities)
Definition:
network-monitor-stub.cpp:39
ndn::net::NetworkMonitorImpl::onEnumerationCompleted
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
Definition:
network-monitor.hpp:153
ndn::net::NetworkMonitorImplStub::emitEnumerationCompleted
void emitEnumerationCompleted()
Definition:
network-monitor-stub.cpp:92
ndn::net
Definition:
link-type-helper.cpp:30
emitSignal
#define emitSignal(...)
(implementation detail)
Definition:
emit.hpp:76
ndn::net::NetworkMonitorImpl::onInterfaceAdded
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
Definition:
network-monitor.hpp:154
ndn::net::NetworkMonitorImplStub::removeInterface
void removeInterface(const std::string &ifname)
Definition:
network-monitor-stub.cpp:80
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-strategy-choice-helper.hpp:34
ndn::net::NetworkMonitorImplStub::getCapabilities
uint32_t getCapabilities() const final
Definition:
network-monitor-stub.cpp:45
ndnSIM
ndn-cxx
ndn-cxx
net
network-monitor-stub.cpp
Generated on Mon Jun 1 2020 22:32:14 for ndnSIM by
1.8.18