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