Ratan Gupta | c9645fe | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 1 | #include "config_parser.hpp" |
Ratan Gupta | 5978dd1 | 2017-07-25 13:47:13 +0530 | [diff] [blame] | 2 | #include "ipaddress.hpp" |
Ratan Gupta | 3529717 | 2018-11-28 18:40:16 +0530 | [diff] [blame] | 3 | #include "mock_network_manager.hpp" |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 4 | #include "mock_syscall.hpp" |
William A. Kennington III | cb64b99 | 2019-04-21 18:45:07 -0700 | [diff] [blame] | 5 | #include "util.hpp" |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 6 | |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 7 | #include <arpa/inet.h> |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 8 | #include <net/if.h> |
| 9 | #include <netinet/in.h> |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 10 | #include <stdlib.h> |
| 11 | |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 12 | #include <charconv> |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 13 | #include <exception> |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 14 | #include <sdbusplus/bus.hpp> |
William A. Kennington III | 84bfe67 | 2022-07-13 14:15:30 -0700 | [diff] [blame] | 15 | #include <stdplus/gtest/tmp.hpp> |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 16 | #include <string_view> |
Asmitha Karunanithi | 003b8b7 | 2022-01-06 04:17:59 -0600 | [diff] [blame] | 17 | #include <xyz/openbmc_project/Common/error.hpp> |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 18 | |
| 19 | #include <gtest/gtest.h> |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 20 | |
| 21 | namespace phosphor |
| 22 | { |
| 23 | namespace network |
| 24 | { |
| 25 | |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 26 | using std::literals::string_view_literals::operator""sv; |
| 27 | |
William A. Kennington III | 84bfe67 | 2022-07-13 14:15:30 -0700 | [diff] [blame] | 28 | class TestEthernetInterface : public stdplus::gtest::TestWithTmp |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 29 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 30 | public: |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 31 | sdbusplus::bus_t bus; |
William A. Kennington III | 84bfe67 | 2022-07-13 14:15:30 -0700 | [diff] [blame] | 32 | std::string confDir; |
Ratan Gupta | 3529717 | 2018-11-28 18:40:16 +0530 | [diff] [blame] | 33 | MockManager manager; |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 34 | MockEthernetInterface interface; |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 35 | TestEthernetInterface() : |
William A. Kennington III | 84bfe67 | 2022-07-13 14:15:30 -0700 | [diff] [blame] | 36 | bus(sdbusplus::bus::new_default()), confDir(CaseTmpDir()), |
| 37 | manager(bus, "/xyz/openbmc_test/network", confDir), |
William A. Kennington III | ebb1ad0 | 2019-04-21 18:02:49 -0700 | [diff] [blame] | 38 | interface(makeInterface(bus, manager)) |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 39 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 40 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 41 | } |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 42 | |
Patrick Williams | c38b071 | 2022-07-22 19:26:54 -0500 | [diff] [blame] | 43 | static MockEthernetInterface makeInterface(sdbusplus::bus_t& bus, |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 44 | MockManager& manager) |
William A. Kennington III | ebb1ad0 | 2019-04-21 18:02:49 -0700 | [diff] [blame] | 45 | { |
William A. Kennington III | 862275a | 2019-04-22 20:37:08 -0700 | [diff] [blame] | 46 | mock_clear(); |
William A. Kennington III | 9ecb90e | 2022-10-14 03:12:43 -0700 | [diff] [blame] | 47 | mock_addIF("test0", /*idx=*/1); |
William A. Kennington III | d298f93 | 2022-10-17 14:31:38 -0700 | [diff] [blame^] | 48 | return {bus, manager, getInterfaceInfo("test0"), |
| 49 | "/xyz/openbmc_test/network"sv, config::Parser()}; |
William A. Kennington III | ebb1ad0 | 2019-04-21 18:02:49 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 52 | int countIPObjects() |
| 53 | { |
| 54 | return interface.getAddresses().size(); |
| 55 | } |
| 56 | |
| 57 | bool isIPObjectExist(const std::string& ipaddress) |
| 58 | { |
| 59 | auto address = interface.getAddresses().find(ipaddress); |
| 60 | if (address == interface.getAddresses().end()) |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 61 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 62 | return false; |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 63 | } |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 64 | return true; |
| 65 | } |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 66 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 67 | bool deleteIPObject(const std::string& ipaddress) |
| 68 | { |
| 69 | auto address = interface.getAddresses().find(ipaddress); |
| 70 | if (address == interface.getAddresses().end()) |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 71 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 72 | return false; |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 73 | } |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 74 | address->second->delete_(); |
| 75 | return true; |
| 76 | } |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 77 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 78 | std::string getObjectPath(const std::string& ipaddress, uint8_t subnetMask, |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 79 | IP::AddressOrigin origin) |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 80 | { |
| 81 | IP::Protocol addressType = IP::Protocol::IPv4; |
Ratan Gupta | 255d514 | 2017-08-10 09:02:08 +0530 | [diff] [blame] | 82 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 83 | return interface.generateObjectPath(addressType, ipaddress, subnetMask, |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 84 | origin); |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void createIPObject(IP::Protocol addressType, const std::string& ipaddress, |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 88 | uint8_t subnetMask) |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 89 | { |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 90 | interface.ip(addressType, ipaddress, subnetMask, ""); |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 91 | } |
Asmitha Karunanithi | 003b8b7 | 2022-01-06 04:17:59 -0600 | [diff] [blame] | 92 | |
| 93 | void setNtpServers() |
| 94 | { |
| 95 | ServerList ntpServers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"}; |
| 96 | interface.EthernetInterfaceIntf::ntpServers(ntpServers); |
| 97 | } |
| 98 | |
| 99 | ServerList getNtpServers() |
| 100 | { |
| 101 | return interface.EthernetInterfaceIntf::ntpServers(); |
| 102 | } |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 103 | }; |
| 104 | |
William A. Kennington III | 9ecb90e | 2022-10-14 03:12:43 -0700 | [diff] [blame] | 105 | TEST_F(TestEthernetInterface, Fields) |
| 106 | { |
| 107 | EXPECT_EQ(0, interface.mtu()); |
| 108 | EXPECT_EQ("", interface.macAddress()); |
| 109 | EXPECT_FALSE(interface.linkUp()); |
| 110 | |
| 111 | constexpr unsigned idx = 2; |
| 112 | constexpr ether_addr mac{0x11, 0x22, 0x33, 0x44, 0x55, 0x66}; |
| 113 | constexpr unsigned mtu = 150; |
| 114 | |
| 115 | mock_addIF("test1", idx, IFF_RUNNING, mac, mtu); |
William A. Kennington III | d298f93 | 2022-10-17 14:31:38 -0700 | [diff] [blame^] | 116 | MockEthernetInterface intf(bus, manager, getInterfaceInfo("test1"), |
| 117 | "/xyz/openbmc_test/network"sv, config::Parser()); |
William A. Kennington III | 9ecb90e | 2022-10-14 03:12:43 -0700 | [diff] [blame] | 118 | |
| 119 | EXPECT_EQ(mtu, intf.mtu()); |
| 120 | EXPECT_EQ(mac_address::toString(mac), intf.macAddress()); |
| 121 | EXPECT_TRUE(intf.linkUp()); |
| 122 | } |
| 123 | |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 124 | TEST_F(TestEthernetInterface, NoIPaddress) |
| 125 | { |
| 126 | EXPECT_EQ(countIPObjects(), 0); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | TEST_F(TestEthernetInterface, AddIPAddress) |
| 130 | { |
| 131 | IP::Protocol addressType = IP::Protocol::IPv4; |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 132 | createIPObject(addressType, "10.10.10.10", 16); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 133 | EXPECT_EQ(true, isIPObjectExist("10.10.10.10")); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | TEST_F(TestEthernetInterface, AddMultipleAddress) |
| 137 | { |
| 138 | IP::Protocol addressType = IP::Protocol::IPv4; |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 139 | createIPObject(addressType, "10.10.10.10", 16); |
| 140 | createIPObject(addressType, "20.20.20.20", 16); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 141 | EXPECT_EQ(true, isIPObjectExist("10.10.10.10")); |
| 142 | EXPECT_EQ(true, isIPObjectExist("20.20.20.20")); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | TEST_F(TestEthernetInterface, DeleteIPAddress) |
| 146 | { |
| 147 | IP::Protocol addressType = IP::Protocol::IPv4; |
William A. Kennington III | e25f8b4 | 2022-10-11 14:43:28 -0700 | [diff] [blame] | 148 | createIPObject(addressType, "10.10.10.10", 16); |
| 149 | createIPObject(addressType, "20.20.20.20", 16); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 150 | deleteIPObject("10.10.10.10"); |
| 151 | EXPECT_EQ(false, isIPObjectExist("10.10.10.10")); |
| 152 | EXPECT_EQ(true, isIPObjectExist("20.20.20.20")); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | TEST_F(TestEthernetInterface, DeleteInvalidIPAddress) |
| 156 | { |
| 157 | EXPECT_EQ(false, deleteIPObject("10.10.10.10")); |
| 158 | } |
| 159 | |
| 160 | TEST_F(TestEthernetInterface, CheckObjectPath) |
| 161 | { |
| 162 | std::string ipaddress = "10.10.10.10"; |
| 163 | uint8_t prefix = 16; |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 164 | IP::AddressOrigin origin = IP::AddressOrigin::Static; |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 165 | |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 166 | auto path = getObjectPath(ipaddress, prefix, origin); |
| 167 | auto pathsv = std::string_view(path); |
| 168 | constexpr auto expectedPrefix = "/xyz/openbmc_test/network/test0/ipv4/"sv; |
| 169 | EXPECT_TRUE(pathsv.starts_with(expectedPrefix)); |
| 170 | pathsv.remove_prefix(expectedPrefix.size()); |
| 171 | uint32_t val; |
| 172 | auto [ptr, res] = std::from_chars(pathsv.begin(), pathsv.end(), val, 16); |
| 173 | EXPECT_EQ(res, std::errc()); |
| 174 | EXPECT_EQ(ptr, pathsv.end()); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 175 | |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 176 | EXPECT_EQ(path, getObjectPath(ipaddress, prefix, origin)); |
Lei YU | 3402757 | 2021-08-11 15:23:52 +0800 | [diff] [blame] | 177 | origin = IP::AddressOrigin::DHCP; |
William A. Kennington III | 991a8e8 | 2022-10-11 15:02:47 -0700 | [diff] [blame] | 178 | EXPECT_NE(path, getObjectPath(ipaddress, prefix, origin)); |
Ratan Gupta | 47722dc | 2017-05-26 18:32:23 +0530 | [diff] [blame] | 179 | } |
| 180 | |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 181 | TEST_F(TestEthernetInterface, addStaticNameServers) |
Ratan Gupta | 09f6157 | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 182 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 183 | ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"}; |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 184 | EXPECT_CALL(manager, reloadConfigs()); |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 185 | interface.staticNameServers(servers); |
Ratan Gupta | 09f6157 | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 186 | fs::path filePath = confDir; |
| 187 | filePath /= "00-bmc-test0.network"; |
| 188 | config::Parser parser(filePath.string()); |
William A. Kennington III | 34bb3e2 | 2022-08-18 15:17:22 -0700 | [diff] [blame] | 189 | EXPECT_EQ(servers, parser.map.getValueStrings("Network", "DNS")); |
Ratan Gupta | 09f6157 | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 190 | } |
| 191 | |
Manojkiran Eda | acd6dd5 | 2019-10-15 15:00:51 +0530 | [diff] [blame] | 192 | TEST_F(TestEthernetInterface, getDynamicNameServers) |
| 193 | { |
| 194 | ServerList servers = {"9.1.1.1", "9.2.2.2", "9.3.3.3"}; |
| 195 | EXPECT_CALL(interface, getNameServerFromResolvd()) |
| 196 | .WillRepeatedly(testing::Return(servers)); |
| 197 | EXPECT_EQ(interface.getNameServerFromResolvd(), servers); |
| 198 | } |
| 199 | |
Asmitha Karunanithi | 003b8b7 | 2022-01-06 04:17:59 -0600 | [diff] [blame] | 200 | TEST_F(TestEthernetInterface, addStaticNTPServers) |
Ratan Gupta | c9645fe | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 201 | { |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 202 | ServerList servers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"}; |
William A. Kennington III | bd649af | 2021-10-08 17:55:13 -0700 | [diff] [blame] | 203 | EXPECT_CALL(manager, reloadConfigs()); |
Asmitha Karunanithi | 003b8b7 | 2022-01-06 04:17:59 -0600 | [diff] [blame] | 204 | interface.staticNTPServers(servers); |
Ratan Gupta | c9645fe | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 205 | fs::path filePath = confDir; |
| 206 | filePath /= "00-bmc-test0.network"; |
| 207 | config::Parser parser(filePath.string()); |
William A. Kennington III | 34bb3e2 | 2022-08-18 15:17:22 -0700 | [diff] [blame] | 208 | EXPECT_EQ(servers, parser.map.getValueStrings("Network", "NTP")); |
Ratan Gupta | c9645fe | 2017-08-23 16:53:52 +0530 | [diff] [blame] | 209 | } |
| 210 | |
Asmitha Karunanithi | 003b8b7 | 2022-01-06 04:17:59 -0600 | [diff] [blame] | 211 | TEST_F(TestEthernetInterface, addNTPServers) |
| 212 | { |
| 213 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 214 | ServerList servers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"}; |
| 215 | EXPECT_THROW(interface.ntpServers(servers), NotAllowed); |
| 216 | } |
| 217 | |
| 218 | TEST_F(TestEthernetInterface, getNTPServers) |
| 219 | { |
| 220 | ServerList servers = {"10.1.1.1", "10.2.2.2", "10.3.3.3"}; |
| 221 | setNtpServers(); |
| 222 | EXPECT_EQ(getNtpServers(), servers); |
| 223 | } |
| 224 | |
Ravi Teja | a5a0944 | 2020-07-17 00:57:33 -0500 | [diff] [blame] | 225 | TEST_F(TestEthernetInterface, addGateway) |
| 226 | { |
| 227 | std::string gateway = "10.3.3.3"; |
| 228 | interface.defaultGateway(gateway); |
| 229 | EXPECT_EQ(interface.defaultGateway(), gateway); |
Jiaqing Zhao | c2e061f | 2022-04-07 21:55:48 +0800 | [diff] [blame] | 230 | interface.defaultGateway(""); |
| 231 | EXPECT_EQ(interface.defaultGateway(), ""); |
Ravi Teja | a5a0944 | 2020-07-17 00:57:33 -0500 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | TEST_F(TestEthernetInterface, addGateway6) |
| 235 | { |
| 236 | std::string gateway6 = "ffff:ffff:ffff:fe80::1"; |
| 237 | interface.defaultGateway6(gateway6); |
| 238 | EXPECT_EQ(interface.defaultGateway6(), gateway6); |
Jiaqing Zhao | c2e061f | 2022-04-07 21:55:48 +0800 | [diff] [blame] | 239 | interface.defaultGateway6(""); |
| 240 | EXPECT_EQ(interface.defaultGateway6(), ""); |
Ravi Teja | a5a0944 | 2020-07-17 00:57:33 -0500 | [diff] [blame] | 241 | } |
| 242 | |
William A. Kennington III | 8060c0d | 2022-08-18 19:19:34 -0700 | [diff] [blame] | 243 | TEST_F(TestEthernetInterface, DHCPEnabled) |
| 244 | { |
| 245 | EXPECT_CALL(manager, reloadConfigs()).WillRepeatedly(testing::Return()); |
| 246 | |
| 247 | using DHCPConf = EthernetInterfaceIntf::DHCPConf; |
| 248 | auto test = [&](DHCPConf conf, bool dhcp4, bool dhcp6, bool ra) { |
| 249 | EXPECT_EQ(conf, interface.dhcpEnabled()); |
| 250 | EXPECT_EQ(dhcp4, interface.dhcp4()); |
| 251 | EXPECT_EQ(dhcp6, interface.dhcp6()); |
| 252 | EXPECT_EQ(ra, interface.ipv6AcceptRA()); |
| 253 | }; |
| 254 | test(DHCPConf::both, /*dhcp4=*/true, /*dhcp6=*/true, /*ra=*/true); |
| 255 | |
| 256 | auto set_test = [&](DHCPConf conf, bool dhcp4, bool dhcp6, bool ra) { |
| 257 | EXPECT_EQ(conf, interface.dhcpEnabled(conf)); |
| 258 | test(conf, dhcp4, dhcp6, ra); |
| 259 | }; |
| 260 | set_test(DHCPConf::none, /*dhcp4=*/false, /*dhcp6=*/false, /*ra=*/false); |
| 261 | set_test(DHCPConf::v4, /*dhcp4=*/true, /*dhcp6=*/false, /*ra=*/false); |
| 262 | set_test(DHCPConf::v6stateless, /*dhcp4=*/false, /*dhcp6=*/false, |
| 263 | /*ra=*/true); |
| 264 | set_test(DHCPConf::v6, /*dhcp4=*/false, /*dhcp6=*/true, /*ra=*/true); |
| 265 | set_test(DHCPConf::v4v6stateless, /*dhcp4=*/true, /*dhcp6=*/false, |
| 266 | /*ra=*/true); |
| 267 | set_test(DHCPConf::both, /*dhcp4=*/true, /*dhcp6=*/true, /*ra=*/true); |
| 268 | |
| 269 | auto ind_test = [&](DHCPConf conf, bool dhcp4, bool dhcp6, bool ra) { |
| 270 | EXPECT_EQ(dhcp4, interface.dhcp4(dhcp4)); |
| 271 | EXPECT_EQ(dhcp6, interface.dhcp6(dhcp6)); |
| 272 | EXPECT_EQ(ra, interface.ipv6AcceptRA(ra)); |
| 273 | test(conf, dhcp4, dhcp6, ra); |
| 274 | }; |
| 275 | ind_test(DHCPConf::none, /*dhcp4=*/false, /*dhcp6=*/false, /*ra=*/false); |
| 276 | ind_test(DHCPConf::v4, /*dhcp4=*/true, /*dhcp6=*/false, /*ra=*/false); |
| 277 | ind_test(DHCPConf::v6stateless, /*dhcp4=*/false, /*dhcp6=*/false, |
| 278 | /*ra=*/true); |
| 279 | ind_test(DHCPConf::v6, /*dhcp4=*/false, /*dhcp6=*/true, /*ra=*/false); |
| 280 | set_test(DHCPConf::v6, /*dhcp4=*/false, /*dhcp6=*/true, /*ra=*/true); |
| 281 | ind_test(DHCPConf::v4v6stateless, /*dhcp4=*/true, /*dhcp6=*/false, |
| 282 | /*ra=*/true); |
| 283 | ind_test(DHCPConf::both, /*dhcp4=*/true, /*dhcp6=*/true, /*ra=*/false); |
| 284 | set_test(DHCPConf::both, /*dhcp4=*/true, /*dhcp6=*/true, /*ra=*/true); |
| 285 | } |
| 286 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 287 | } // namespace network |
| 288 | } // namespace phosphor |