NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
network-predicate.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef NFD_CORE_NETWORK_PREDICATE_HPP
27 #define NFD_CORE_NETWORK_PREDICATE_HPP
28 
29 #include "common.hpp"
30 #include <ndn-cxx/net/network-interface.hpp>
31 
32 namespace nfd {
33 
35 {
36 public:
38 
39  virtual
41 
45  void
46  clear();
47 
48  void
49  parseWhitelist(const boost::property_tree::ptree& list);
50 
51  void
52  parseBlacklist(const boost::property_tree::ptree& list);
53 
54  void
55  assign(std::initializer_list<std::pair<std::string, std::string>> whitelist,
56  std::initializer_list<std::pair<std::string, std::string>> blacklist);
57 
58  bool
59  operator==(const NetworkPredicateBase& other) const;
60 
61  bool
62  operator!=(const NetworkPredicateBase& other) const
63  {
64  return !this->operator==(other);
65  }
66 
67 private:
68  virtual bool
69  isRuleSupported(const std::string& key) = 0;
70 
71  virtual bool
72  isRuleValid(const std::string& key, const std::string& value) = 0;
73 
74  void
75  parseList(std::set<std::string>& set, const boost::property_tree::ptree& list, const std::string& section);
76 
77  void
78  parseList(std::set<std::string>& set, std::initializer_list<std::pair<std::string, std::string>> list);
79 
81  std::set<std::string> m_whitelist;
82  std::set<std::string> m_blacklist;
83 };
84 
96 {
97 public:
98  bool
99  operator()(const ndn::net::NetworkInterface& netif) const;
100 
101 private:
102  bool
103  isRuleSupported(const std::string& key) final;
104 
105  bool
106  isRuleValid(const std::string& key, const std::string& value) final;
107 };
108 
118 {
119 public:
120  bool
121  operator()(const boost::asio::ip::address& address) const;
122 
123 private:
124  bool
125  isRuleSupported(const std::string& key) final;
126 
127  bool
128  isRuleValid(const std::string& key, const std::string& value) final;
129 };
130 
131 } // namespace nfd
132 
133 #endif // NFD_CORE_NETWORK_PREDICATE_HPP
void assign(std::initializer_list< std::pair< std::string, std::string >> whitelist, std::initializer_list< std::pair< std::string, std::string >> blacklist)
bool operator()(const boost::asio::ip::address &address) const
void parseWhitelist(const boost::property_tree::ptree &list)
std::set< std::string > m_whitelist
Represents one network interface attached to the host.
Represents a predicate to accept or reject a ndn::net::NetworkInterface.
void parseBlacklist(const boost::property_tree::ptree &list)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool operator==(const NetworkPredicateBase &other) const
bool operator()(const ndn::net::NetworkInterface &netif) const
void clear()
Set the whitelist to "*" and clear the blacklist.
std::set< std::string > m_blacklist
bool operator!=(const NetworkPredicateBase &other) const
Represents a predicate to accept or reject an IP address.
#define PUBLIC_WITH_TESTS_ELSE_PROTECTED
Definition: common.hpp:39