blob: 29493241e2c7503497adf09d083b28c0e8e94530 [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
29#include <boost/asio.hpp>
30#include <boost/utility/value_init.hpp>
31#include <boost/lexical_cast.hpp>
susmit91e1d7c2016-10-03 16:16:57 -060032#include <boost/algorithm/string.hpp>
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080033
34namespace nfd {
35
36class Network
37{
38public:
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
susmit91e1d7c2016-10-03 16:16:57 -060059 static bool
60 isValidCidr(const std::string& cidr);
61
Alexander Afanasyev689f0e92014-11-09 12:09:00 -080062 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
80private:
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
91std::ostream&
92operator<<(std::ostream& os, const Network& network);
93
94std::istream&
95operator>>(std::istream& is, Network& network);
96
97} // namespace nfd
98
99#endif // NFD_CORE_NETWORK_HPP