blob: 2aa62037e0ea759cd7f599c55710be88a8de5eee [file] [log] [blame]
Davide Pesaventoeee53aa2016-04-11 17:20:21 +02001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
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.
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_TESTS_DAEMON_FACE_TEST_IP_HPP
27#define NFD_TESTS_DAEMON_FACE_TEST_IP_HPP
28
29#include <boost/asio/ip/address_v4.hpp>
30#include <boost/asio/ip/address_v6.hpp>
31
32#define SKIP_IF_IP_UNAVAILABLE(address) \
33 do { \
34 if ((address).is_unspecified()) { \
35 BOOST_WARN_MESSAGE(false, "skipping assertions that require a valid IP address"); \
36 return; \
37 } \
38 } while (false)
39
40namespace nfd {
41namespace tests {
42
43enum class LoopbackAddress {
44 No,
45 Yes,
46 DontCare,
47 Default = Yes
48};
49
50enum class MulticastInterface {
51 No,
52 Yes,
53 DontCare,
54 Default = DontCare
55};
56
57/** \brief get an IP address for test purposes from any available network interface
58 * \tparam A the address type, either boost::asio::ip::address_v4 or boost::asio::ip::address_v6
59 * \param loopback specifies if the address can, must, or must not be a loopback address
60 * \param mcast specifies if the address can, must, or must not be chosen from a multicast-capable interface
61 * \return an IP address
62 * \retval default-constructed A, if no appropriate address is available
63 */
64template<typename A>
65A
66getTestIp(LoopbackAddress loopback = LoopbackAddress::Default,
67 MulticastInterface mcast = MulticastInterface::Default);
68
69template<>
70boost::asio::ip::address_v4
71getTestIp(LoopbackAddress loopback, MulticastInterface mcast);
72
73template<>
74boost::asio::ip::address_v6
75getTestIp(LoopbackAddress loopback, MulticastInterface mcast);
76
77} // namespace tests
78} // namespace nfd
79
80#endif // NFD_TESTS_DAEMON_FACE_TEST_IP_HPP