blob: 1770582c0bd10b356dac3ba3ad6b0fe4a2309820 [file] [log] [blame]
Alexander Afanasyev689f0e92014-11-09 12:09:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
susmit91e1d7c2016-10-03 16:16:57 -06003 * 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 Afanasyev689f0e92014-11-09 12:09:00 -080010 *
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 Pesavento89567d32016-11-19 16:39:45 +010029#include "common.hpp"
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080030
31namespace nfd {
32
33class Network
34{
35public:
Davide Pesavento89567d32016-11-19 16:39:45 +010036 Network();
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080037
38 Network(const boost::asio::ip::address& minAddress,
Davide Pesavento89567d32016-11-19 16:39:45 +010039 const boost::asio::ip::address& maxAddress);
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080040
41 bool
42 doesContain(const boost::asio::ip::address& address) const
43 {
Davide Pesavento89567d32016-11-19 16:39:45 +010044 return m_minAddress <= address && address <= m_maxAddress;
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080045 }
46
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080047 static const Network&
48 getMaxRangeV4();
49
50 static const Network&
51 getMaxRangeV6();
52
Davide Pesavento89567d32016-11-19 16:39:45 +010053 static bool
54 isValidCidr(const std::string& cidr);
55
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080056 bool
57 operator==(const Network& rhs) const
58 {
59 return m_minAddress == rhs.m_minAddress && m_maxAddress == rhs.m_maxAddress;
60 }
61
62 bool
63 operator!=(const Network& rhs) const
64 {
65 return !(*this == rhs);
66 }
67
68private:
69 boost::asio::ip::address m_minAddress;
70 boost::asio::ip::address m_maxAddress;
71
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080072 friend std::ostream&
73 operator<<(std::ostream& os, const Network& network);
Davide Pesavento89567d32016-11-19 16:39:45 +010074
75 friend std::istream&
76 operator>>(std::istream& is, Network& network);
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080077};
78
79std::ostream&
80operator<<(std::ostream& os, const Network& network);
81
82std::istream&
83operator>>(std::istream& is, Network& network);
84
85} // namespace nfd
86
87#endif // NFD_CORE_NETWORK_HPP