NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
network-interface-predicate.cpp
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26
#include "
network-interface-predicate.hpp
"
27
28
#include "
config-file.hpp
"
29
#include "
network-interface.hpp
"
30
#include "
network.hpp
"
31
32
namespace
nfd
{
33
34
NetworkInterfacePredicate::NetworkInterfacePredicate
()
35
{
36
this->
clear
();
37
}
38
39
void
40
NetworkInterfacePredicate::clear
()
41
{
42
m_whitelist = std::set<std::string>{
"*"
};
43
m_blacklist.clear();
44
}
45
46
static
void
47
parseList
(std::set<std::string>&
set
,
const
boost::property_tree::ptree& list,
const
std::string& section)
48
{
49
set
.clear();
50
51
for
(
const
auto
& item : list) {
52
if
(item.first ==
"*"
) {
53
// insert wildcard
54
set
.insert(item.first);
55
}
56
else
if
(item.first ==
"ifname"
) {
57
// very basic sanity check for interface names
58
auto
name
= item.second.get_value<std::string>();
59
if
(
name
.empty()) {
60
BOOST_THROW_EXCEPTION(
ConfigFile::Error
(
"Empty interface name in \""
+ section +
"\" section"
));
61
}
62
set
.insert(
name
);
63
}
64
else
if
(item.first ==
"ether"
) {
65
// validate ethernet address
66
auto
addr = item.second.get_value<std::string>();
67
if
(
ethernet::Address::fromString
(addr).
isNull
()) {
68
BOOST_THROW_EXCEPTION(
ConfigFile::Error
(
"Malformed ether address \""
+ addr +
69
"\" in \""
+ section +
"\" section"
));
70
}
71
set
.insert(addr);
72
}
73
else
if
(item.first ==
"subnet"
) {
74
// example subnet: 10.0.0.0/8
75
auto
cidr = item.second.get_value<std::string>();
76
if
(!
Network::isValidCidr
(cidr)) {
77
BOOST_THROW_EXCEPTION(
ConfigFile::Error
(
"Malformed subnet declaration \""
+ cidr +
78
"\" in \""
+ section +
"\" section"
));
79
}
80
set
.insert(cidr);
81
}
82
}
83
}
84
85
void
86
NetworkInterfacePredicate::parseWhitelist
(
const
boost::property_tree::ptree& list)
87
{
88
parseList
(m_whitelist, list,
"whitelist"
);
89
}
90
91
void
92
NetworkInterfacePredicate::parseBlacklist
(
const
boost::property_tree::ptree& list)
93
{
94
parseList
(m_blacklist, list,
"blacklist"
);
95
}
96
97
static
bool
98
doesMatchRule
(
const
NetworkInterfaceInfo
& nic,
const
std::string& rule)
99
{
100
// if '/' is in rule, this is a subnet, check if IP in subnet
101
if
(rule.find(
'/'
) != std::string::npos) {
102
Network
n = boost::lexical_cast<
Network
>(rule);
103
for
(
const
auto
& addr : nic.
ipv4Addresses
) {
104
if
(n.
doesContain
(addr)) {
105
return
true
;
106
}
107
}
108
}
109
110
return
rule ==
"*"
||
111
nic.
name
== rule ||
112
nic.
etherAddress
.
toString
() == rule;
113
}
114
115
bool
116
NetworkInterfacePredicate::operator()
(
const
NetworkInterfaceInfo
& nic)
const
117
{
118
return
std::any_of(m_whitelist.begin(), m_whitelist.end(), bind(&
doesMatchRule
, nic, _1)) &&
119
std::none_of(m_blacklist.begin(), m_blacklist.end(), bind(&
doesMatchRule
, nic, _1));
120
}
121
122
}
// namespace nfd
network-interface.hpp
ndn::util::ethernet::Address::fromString
static Address fromString(const std::string &str)
Creates an Address from a string containing an Ethernet address in hexadecimal notation, with colons or hyphens as separators.
Definition:
ethernet.cpp:86
network-interface-predicate.hpp
nfd::NetworkInterfaceInfo
contains information about a network interface
Definition:
network-interface.hpp:41
nfd::doesMatchRule
static bool doesMatchRule(const NetworkInterfaceInfo &nic, const std::string &rule)
Definition:
network-interface-predicate.cpp:98
nfd::NetworkInterfacePredicate::NetworkInterfacePredicate
NetworkInterfacePredicate()
Definition:
network-interface-predicate.cpp:34
nfd::NetworkInterfaceInfo::etherAddress
ethernet::Address etherAddress
Definition:
network-interface.hpp:47
nfd::parseList
static void parseList(std::set< std::string > &set, const boost::property_tree::ptree &list, const std::string §ion)
Definition:
network-interface-predicate.cpp:47
nfd::NetworkInterfacePredicate::parseWhitelist
void parseWhitelist(const boost::property_tree::ptree &list)
Definition:
network-interface-predicate.cpp:86
config-file.hpp
nfd::NetworkInterfacePredicate::clear
void clear()
Set the whitelist to "*" and clear the blacklist.
Definition:
network-interface-predicate.cpp:40
nfd
Copyright (c) 2011-2015 Regents of the University of California.
Definition:
ndn-common.hpp:40
nfd::NetworkInterfacePredicate::operator()
bool operator()(const NetworkInterfaceInfo &nic) const
Definition:
network-interface-predicate.cpp:116
network.hpp
nfd::NetworkInterfaceInfo::ipv4Addresses
std::vector< boost::asio::ip::address_v4 > ipv4Addresses
Definition:
network-interface.hpp:48
nfd::Network::isValidCidr
static bool isValidCidr(const std::string &cidr)
Definition:
network.cpp:61
nfd::Network
Definition:
network.hpp:33
nfd::ConfigFile::Error
Definition:
config-file.hpp:53
nfd::NetworkInterfacePredicate::parseBlacklist
void parseBlacklist(const boost::property_tree::ptree &list)
Definition:
network-interface-predicate.cpp:92
nfd::NetworkInterfaceInfo::name
std::string name
Definition:
network-interface.hpp:46
ndn::util::ethernet::Address::isNull
bool isNull() const
True if this is a null address (00:00:00:00:00:00)
Definition:
ethernet.cpp:66
nfd::Network::doesContain
bool doesContain(const boost::asio::ip::address &address) const
Definition:
network.hpp:42
ndn::util::ethernet::Address::toString
std::string toString(char sep=':') const
Converts the address to a human-readable string.
Definition:
ethernet.cpp:72
ndn::name
Definition:
name-component.cpp:36
ndnSIM
NFD
core
network-interface-predicate.cpp
Generated on Wed Jan 11 2017 18:17:15 for ndnSIM by
1.8.13