Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 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 |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 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_HPP |
| 27 | #define NFD_CORE_NETWORK_HPP |
| 28 | |
Davide Pesavento | a9b09b6 | 2022-06-04 14:07:25 -0400 | [diff] [blame^] | 29 | #include <boost/asio/ip/address.hpp> |
| 30 | #include <string_view> |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 31 | |
| 32 | namespace nfd { |
| 33 | |
| 34 | class Network |
| 35 | { |
| 36 | public: |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 37 | Network(); |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 38 | |
| 39 | Network(const boost::asio::ip::address& minAddress, |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 40 | const boost::asio::ip::address& maxAddress); |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 41 | |
| 42 | bool |
| 43 | doesContain(const boost::asio::ip::address& address) const |
| 44 | { |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 45 | return m_minAddress <= address && address <= m_maxAddress; |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 48 | static const Network& |
| 49 | getMaxRangeV4(); |
| 50 | |
| 51 | static const Network& |
| 52 | getMaxRangeV6(); |
| 53 | |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 54 | static bool |
Davide Pesavento | a3a7a4e | 2022-05-29 16:06:22 -0400 | [diff] [blame] | 55 | isValidCidr(std::string_view cidr); |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 56 | |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 57 | bool |
| 58 | operator==(const Network& rhs) const |
| 59 | { |
| 60 | return m_minAddress == rhs.m_minAddress && m_maxAddress == rhs.m_maxAddress; |
| 61 | } |
| 62 | |
| 63 | bool |
| 64 | operator!=(const Network& rhs) const |
| 65 | { |
| 66 | return !(*this == rhs); |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | boost::asio::ip::address m_minAddress; |
| 71 | boost::asio::ip::address m_maxAddress; |
| 72 | |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 73 | friend std::ostream& |
| 74 | operator<<(std::ostream& os, const Network& network); |
Davide Pesavento | 89567d3 | 2016-11-19 16:39:45 +0100 | [diff] [blame] | 75 | |
| 76 | friend std::istream& |
| 77 | operator>>(std::istream& is, Network& network); |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | std::ostream& |
| 81 | operator<<(std::ostream& os, const Network& network); |
| 82 | |
| 83 | std::istream& |
| 84 | operator>>(std::istream& is, Network& network); |
| 85 | |
| 86 | } // namespace nfd |
| 87 | |
| 88 | #endif // NFD_CORE_NETWORK_HPP |