Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 3 | * Copyright (c) 2014-2016, 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 |
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 | |
| 29 | #include <boost/asio.hpp> |
| 30 | #include <boost/utility/value_init.hpp> |
| 31 | #include <boost/lexical_cast.hpp> |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 32 | #include <boost/algorithm/string.hpp> |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | |
| 36 | class Network |
| 37 | { |
| 38 | public: |
| 39 | Network() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | Network(const boost::asio::ip::address& minAddress, |
| 44 | const boost::asio::ip::address& maxAddress) |
| 45 | : m_minAddress(minAddress) |
| 46 | , m_maxAddress(maxAddress) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | print(std::ostream& os) const; |
| 52 | |
| 53 | bool |
| 54 | doesContain(const boost::asio::ip::address& address) const |
| 55 | { |
| 56 | return (m_minAddress <= address && address <= m_maxAddress); |
| 57 | } |
| 58 | |
susmit | 91e1d7c | 2016-10-03 16:16:57 -0600 | [diff] [blame] | 59 | static bool |
| 60 | isValidCidr(const std::string& cidr); |
| 61 | |
Alexander Afanasyev | 689f0e9 | 2014-11-09 12:09:00 -0800 | [diff] [blame] | 62 | static const Network& |
| 63 | getMaxRangeV4(); |
| 64 | |
| 65 | static const Network& |
| 66 | getMaxRangeV6(); |
| 67 | |
| 68 | bool |
| 69 | operator==(const Network& rhs) const |
| 70 | { |
| 71 | return m_minAddress == rhs.m_minAddress && m_maxAddress == rhs.m_maxAddress; |
| 72 | } |
| 73 | |
| 74 | bool |
| 75 | operator!=(const Network& rhs) const |
| 76 | { |
| 77 | return !(*this == rhs); |
| 78 | } |
| 79 | |
| 80 | private: |
| 81 | boost::asio::ip::address m_minAddress; |
| 82 | boost::asio::ip::address m_maxAddress; |
| 83 | |
| 84 | friend std::istream& |
| 85 | operator>>(std::istream& is, Network& network); |
| 86 | |
| 87 | friend std::ostream& |
| 88 | operator<<(std::ostream& os, const Network& network); |
| 89 | }; |
| 90 | |
| 91 | std::ostream& |
| 92 | operator<<(std::ostream& os, const Network& network); |
| 93 | |
| 94 | std::istream& |
| 95 | operator>>(std::istream& is, Network& network); |
| 96 | |
| 97 | } // namespace nfd |
| 98 | |
| 99 | #endif // NFD_CORE_NETWORK_HPP |