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