Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 5 | #include "patchpanel/arc_service.h" |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 6 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 7 | #include <net/if.h> |
| 8 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 9 | #include <utility> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include <base/bind.h> |
hscham | 4ce3c99 | 2021-02-19 16:37:23 +0900 | [diff] [blame] | 13 | #include <base/callback_helpers.h> |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 14 | #include <dbus/mock_bus.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 15 | #include <gmock/gmock.h> |
| 16 | #include <gtest/gtest.h> |
| 17 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 18 | #include "patchpanel/address_manager.h" |
| 19 | #include "patchpanel/fake_process_runner.h" |
| 20 | #include "patchpanel/fake_shill_client.h" |
| 21 | #include "patchpanel/mock_datapath.h" |
Jason Jeremy Iman | a7273a3 | 2020-08-04 11:25:31 +0900 | [diff] [blame] | 22 | #include "patchpanel/mock_firewall.h" |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 23 | #include "patchpanel/net_util.h" |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 24 | |
| 25 | using testing::_; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 26 | using testing::AnyNumber; |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 27 | using testing::Eq; |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 28 | using testing::Invoke; |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 29 | using testing::Pair; |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 30 | using testing::Pointee; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 31 | using testing::Return; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 32 | using testing::ReturnRef; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 33 | using testing::StrEq; |
Garrick Evans | 02e6e87 | 2020-11-30 11:53:13 +0900 | [diff] [blame] | 34 | using testing::UnorderedElementsAre; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 35 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 36 | namespace patchpanel { |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 37 | namespace { |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 38 | constexpr pid_t kTestPID = -2; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 39 | constexpr uint32_t kTestCID = 2; |
Garrick Evans | 7a1a9ee | 2020-01-28 11:03:57 +0900 | [diff] [blame] | 40 | constexpr uint32_t kArcHostIP = Ipv4Addr(100, 115, 92, 1); |
| 41 | constexpr uint32_t kArcGuestIP = Ipv4Addr(100, 115, 92, 2); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 42 | constexpr uint32_t kFirstEthHostIP = Ipv4Addr(100, 115, 92, 5); |
| 43 | constexpr uint32_t kFirstEthGuestIP = Ipv4Addr(100, 115, 92, 6); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 44 | constexpr uint32_t kSecondEthHostIP = Ipv4Addr(100, 115, 92, 9); |
| 45 | constexpr uint32_t kFirstWifiHostIP = Ipv4Addr(100, 115, 92, 13); |
| 46 | constexpr uint32_t kSecondWifiHostIP = Ipv4Addr(100, 115, 92, 17); |
| 47 | constexpr uint32_t kFirstCellHostIP = Ipv4Addr(100, 115, 92, 21); |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 48 | constexpr MacAddress kArcVmArc0MacAddr = {0x42, 0x37, 0x05, 0x13, 0x17, 0x01}; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 49 | |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 50 | class MockShillClient : public ShillClient { |
| 51 | public: |
| 52 | explicit MockShillClient(scoped_refptr<dbus::MockBus> bus) |
| 53 | : ShillClient(bus) {} |
| 54 | ~MockShillClient() = default; |
| 55 | |
| 56 | MOCK_METHOD2(GetDeviceProperties, |
| 57 | bool(const std::string& ifname, ShillClient::Device* device)); |
| 58 | }; |
| 59 | |
| 60 | void ExpectGetDeviceProperties(MockShillClient& shill_client, |
| 61 | const std::string& iface, |
| 62 | ShillClient::Device::Type type) { |
| 63 | EXPECT_CALL(shill_client, GetDeviceProperties(StrEq(iface), _)) |
| 64 | .WillRepeatedly( |
| 65 | Invoke([type](const std::string& _, ShillClient::Device* device) { |
| 66 | device->type = type; |
| 67 | return true; |
| 68 | })); |
| 69 | } |
| 70 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 71 | } // namespace |
| 72 | |
| 73 | class ArcServiceTest : public testing::Test { |
| 74 | public: |
Garrick Evans | 4ee5ce2 | 2020-03-18 07:05:17 +0900 | [diff] [blame] | 75 | ArcServiceTest() : testing::Test() {} |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 76 | |
| 77 | protected: |
| 78 | void SetUp() override { |
Taoyu Li | 179dcc6 | 2019-10-17 11:21:08 +0900 | [diff] [blame] | 79 | runner_ = std::make_unique<FakeProcessRunner>(); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 80 | runner_->Capture(false); |
Jason Jeremy Iman | a7273a3 | 2020-08-04 11:25:31 +0900 | [diff] [blame] | 81 | datapath_ = std::make_unique<MockDatapath>(runner_.get(), &firewall_); |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 82 | shill_client_ = std::make_unique<MockShillClient>(shill_helper_.mock_bus()); |
Garrick Evans | 4ee5ce2 | 2020-03-18 07:05:17 +0900 | [diff] [blame] | 83 | addr_mgr_ = std::make_unique<AddressManager>(); |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 84 | guest_devices_.clear(); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 85 | } |
| 86 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 87 | std::unique_ptr<ArcService> NewService(GuestMessage::GuestType guest) { |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 88 | return std::make_unique<ArcService>( |
Hugo Benichi | b9d123e | 2021-02-27 23:37:16 +0900 | [diff] [blame] | 89 | shill_client_.get(), datapath_.get(), addr_mgr_.get(), guest, |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 90 | base::BindRepeating(&ArcServiceTest::DeviceHandler, |
| 91 | base::Unretained(this))); |
| 92 | } |
| 93 | |
| 94 | void DeviceHandler(const Device& device, |
| 95 | Device::ChangeEvent event, |
| 96 | GuestMessage::GuestType guest_type) { |
| 97 | guest_devices_[device.host_ifname()] = event; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 98 | } |
| 99 | |
Garrick Evans | 69b8587 | 2020-02-04 11:40:26 +0900 | [diff] [blame] | 100 | FakeShillClientHelper shill_helper_; |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 101 | std::unique_ptr<MockShillClient> shill_client_; |
Garrick Evans | 4ee5ce2 | 2020-03-18 07:05:17 +0900 | [diff] [blame] | 102 | std::unique_ptr<AddressManager> addr_mgr_; |
Taoyu Li | 179dcc6 | 2019-10-17 11:21:08 +0900 | [diff] [blame] | 103 | std::unique_ptr<MockDatapath> datapath_; |
| 104 | std::unique_ptr<FakeProcessRunner> runner_; |
Jason Jeremy Iman | a7273a3 | 2020-08-04 11:25:31 +0900 | [diff] [blame] | 105 | MockFirewall firewall_; |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 106 | std::map<std::string, Device::ChangeEvent> guest_devices_; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 107 | }; |
| 108 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 109 | TEST_F(ArcServiceTest, NotStarted_AddDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 110 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 111 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 112 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), _, _)).Times(0); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 113 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 114 | StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), _, _, false)) |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 115 | .Times(0); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 116 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 117 | auto svc = NewService(GuestMessage::ARC); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 118 | svc->OnDevicesChanged({"eth0"}, {}); |
| 119 | EXPECT_TRUE(svc->devices_.find("eth0") == svc->devices_.end()); |
| 120 | EXPECT_FALSE(svc->shill_devices_.find("eth0") == svc->shill_devices_.end()); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 121 | } |
| 122 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 123 | TEST_F(ArcServiceTest, NotStarted_AddRemoveDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 124 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 125 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 126 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), _, _)).Times(0); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 127 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 128 | StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), _, _, false)) |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 129 | .Times(0); |
| 130 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 131 | StopRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), _, _, false)) |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 132 | .Times(0); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 133 | EXPECT_CALL(*datapath_, RemoveBridge(StrEq("arc_eth0"))).Times(0); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 134 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 135 | auto svc = NewService(GuestMessage::ARC); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 136 | svc->OnDevicesChanged({"eth0"}, {}); |
| 137 | svc->OnDevicesChanged({}, {"eth0"}); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 138 | EXPECT_TRUE(svc->devices_.find("eth0") == svc->devices_.end()); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 139 | EXPECT_TRUE(svc->shill_devices_.find("eth0") == svc->shill_devices_.end()); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 140 | } |
| 141 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 142 | TEST_F(ArcServiceTest, VerifyAddrConfigs) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 143 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 144 | ShillClient::Device::Type::kEthernet); |
| 145 | ExpectGetDeviceProperties(*shill_client_, "eth1", |
| 146 | ShillClient::Device::Type::kEthernet); |
| 147 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 148 | ShillClient::Device::Type::kWifi); |
| 149 | ExpectGetDeviceProperties(*shill_client_, "wlan1", |
| 150 | ShillClient::Device::Type::kWifi); |
| 151 | ExpectGetDeviceProperties(*shill_client_, "wwan0", |
| 152 | ShillClient::Device::Type::kCellular); |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 153 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 154 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 155 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 156 | .WillOnce(Return(true)); |
| 157 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 158 | .WillOnce(Return(true)); |
| 159 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth1"), kSecondEthHostIP, 30)) |
| 160 | .WillOnce(Return(true)); |
| 161 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wlan0"), kFirstWifiHostIP, 30)) |
| 162 | .WillOnce(Return(true)); |
| 163 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wlan1"), kSecondWifiHostIP, 30)) |
| 164 | .WillOnce(Return(true)); |
| 165 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wwan0"), kFirstCellHostIP, 30)) |
| 166 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 167 | EXPECT_CALL(*datapath_, |
| 168 | ConnectVethPair(kTestPID, StrEq("arc_netns"), _, _, _, _, _, _)) |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 169 | .WillRepeatedly(Return(true)); |
| 170 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 171 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 172 | auto svc = NewService(GuestMessage::ARC); |
| 173 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 174 | svc->OnDevicesChanged({"eth0", "eth1", "wlan0", "wlan1", "wwan0"}, {}); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | TEST_F(ArcServiceTest, VerifyAddrOrder) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 178 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 179 | ShillClient::Device::Type::kWifi); |
| 180 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 181 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 182 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 183 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 184 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 185 | .WillOnce(Return(true)); |
| 186 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 187 | .Times(2) |
| 188 | .WillRepeatedly(Return(true)); |
| 189 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wlan0"), kFirstWifiHostIP, 30)) |
| 190 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 191 | EXPECT_CALL(*datapath_, |
| 192 | ConnectVethPair(kTestPID, StrEq("arc_netns"), _, _, _, _, _, _)) |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 193 | .WillRepeatedly(Return(true)); |
| 194 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 195 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 196 | auto svc = NewService(GuestMessage::ARC); |
| 197 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 198 | svc->OnDevicesChanged({"wlan0"}, {}); |
| 199 | svc->OnDevicesChanged({"eth0"}, {}); |
| 200 | svc->OnDevicesChanged({}, {"eth0"}); |
| 201 | svc->OnDevicesChanged({"eth0"}, {}); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 202 | } |
| 203 | |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 204 | TEST_F(ArcServiceTest, StableArcVmMacAddrs) { |
| 205 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
| 206 | .WillRepeatedly(Return("vmtap")); |
| 207 | EXPECT_CALL(*datapath_, AddBridge(_, _, 30)).WillRepeatedly(Return(true)); |
| 208 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
| 209 | |
| 210 | auto svc = NewService(GuestMessage::ARC_VM); |
| 211 | svc->Start(kTestCID); |
| 212 | auto configs = svc->GetDeviceConfigs(); |
| 213 | EXPECT_EQ(configs.size(), 6); |
| 214 | auto mac_addr = kArcVmArc0MacAddr; |
| 215 | for (const auto* config : configs) { |
| 216 | EXPECT_EQ(config->mac_addr(), mac_addr); |
| 217 | mac_addr[5]++; |
| 218 | } |
| 219 | } |
| 220 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 221 | // ContainerImpl |
| 222 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 223 | TEST_F(ArcServiceTest, ContainerImpl_Start) { |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 224 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 225 | .WillOnce(Return(true)); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 226 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 227 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 228 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 229 | .WillOnce(Return(true)); |
Garrick Evans | 2f581a0 | 2020-05-11 10:43:35 +0900 | [diff] [blame] | 230 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 231 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 232 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 233 | .WillOnce(Return(true)); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 234 | EXPECT_CALL(*datapath_, SetConntrackHelpers(true)).WillOnce(Return(true)); |
| 235 | // Needed because the service will be stopped in dtor. |
| 236 | EXPECT_CALL(*datapath_, SetConntrackHelpers(false)).WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 237 | |
| 238 | auto svc = NewService(GuestMessage::ARC); |
| 239 | svc->Start(kTestPID); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 240 | } |
| 241 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 242 | TEST_F(ArcServiceTest, ContainerImpl_FailsToCreateInterface) { |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 243 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 244 | .WillOnce(Return(true)); |
Garrick Evans | 63378b3 | 2020-01-14 10:36:16 +0900 | [diff] [blame] | 245 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 246 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 247 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 248 | .WillOnce(Return(false)); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 249 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)).Times(0); |
Garrick Evans | 63378b3 | 2020-01-14 10:36:16 +0900 | [diff] [blame] | 250 | EXPECT_CALL(*datapath_, RemoveBridge(_)).Times(0); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 251 | |
| 252 | auto svc = NewService(GuestMessage::ARC); |
| 253 | svc->Start(kTestPID); |
Garrick Evans | 63378b3 | 2020-01-14 10:36:16 +0900 | [diff] [blame] | 254 | } |
| 255 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 256 | TEST_F(ArcServiceTest, ContainerImpl_FailsToAddInterfaceToBridge) { |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 257 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 258 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 259 | EXPECT_CALL(*datapath_, |
| 260 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 261 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
| 262 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 263 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 264 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 265 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
| 266 | .WillOnce(Return(false)); |
| 267 | |
| 268 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vetharc0"))); |
| 269 | EXPECT_CALL(*datapath_, RemoveBridge(_)).Times(0); |
| 270 | |
| 271 | auto svc = NewService(GuestMessage::ARC); |
| 272 | svc->Start(kTestPID); |
| 273 | } |
| 274 | |
| 275 | TEST_F(ArcServiceTest, ContainerImpl_OnStartDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 276 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 277 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 278 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 279 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 280 | // Expectations for arc0 setup. |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 281 | EXPECT_CALL(*datapath_, |
| 282 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 283 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
| 284 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 285 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 286 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 287 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
| 288 | .WillOnce(Return(true)); |
| 289 | // Expectations for eth0 setup. |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 290 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 291 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"), |
| 292 | StrEq("eth0"), _, kFirstEthGuestIP, 30, false)) |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 293 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 294 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 295 | .WillOnce(Return(true)); |
Garrick Evans | 2f581a0 | 2020-05-11 10:43:35 +0900 | [diff] [blame] | 296 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0"))) |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 297 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 298 | EXPECT_CALL(*datapath_, |
| 299 | StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 300 | kFirstEthGuestIP, TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 301 | |
| 302 | auto svc = NewService(GuestMessage::ARC); |
| 303 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 304 | svc->OnDevicesChanged({"eth0"}, {}); |
| 305 | } |
| 306 | |
Garrick Evans | 02e6e87 | 2020-11-30 11:53:13 +0900 | [diff] [blame] | 307 | TEST_F(ArcServiceTest, ContainerImpl_ScanDevices) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 308 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 309 | ShillClient::Device::Type::kEthernet); |
| 310 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 311 | ShillClient::Device::Type::kWifi); |
Garrick Evans | 02e6e87 | 2020-11-30 11:53:13 +0900 | [diff] [blame] | 312 | EXPECT_CALL(*datapath_, NetnsAttachName(_, _)).WillRepeatedly(Return(true)); |
| 313 | EXPECT_CALL(*datapath_, ConnectVethPair(_, _, _, _, _, _, _, _)) |
| 314 | .WillRepeatedly(Return(true)); |
| 315 | EXPECT_CALL(*datapath_, AddBridge(_, _, _)).WillRepeatedly(Return(true)); |
| 316 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
| 317 | |
| 318 | auto svc = NewService(GuestMessage::ARC); |
| 319 | svc->Start(kTestPID); |
| 320 | svc->OnDevicesChanged({"eth0", "wlan0"}, {}); |
| 321 | |
| 322 | std::vector<std::string> devs; |
| 323 | svc->ScanDevices(base::BindRepeating( |
| 324 | [](std::vector<std::string>* list, const Device& device) { |
| 325 | list->push_back(device.host_ifname()); |
| 326 | }, |
| 327 | &devs)); |
| 328 | |
| 329 | EXPECT_EQ(devs.size(), 2); |
| 330 | EXPECT_THAT(devs, |
| 331 | UnorderedElementsAre(StrEq("arc_eth0"), StrEq("arc_wlan0"))); |
| 332 | } |
| 333 | |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 334 | TEST_F(ArcServiceTest, ContainerImpl_DeviceHandler) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 335 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 336 | ShillClient::Device::Type::kEthernet); |
| 337 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 338 | ShillClient::Device::Type::kWifi); |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 339 | EXPECT_CALL(*datapath_, NetnsAttachName(_, _)).WillRepeatedly(Return(true)); |
| 340 | EXPECT_CALL(*datapath_, ConnectVethPair(_, _, _, _, _, _, _, _)) |
| 341 | .WillRepeatedly(Return(true)); |
| 342 | EXPECT_CALL(*datapath_, AddBridge(_, _, _)).WillRepeatedly(Return(true)); |
| 343 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
| 344 | |
| 345 | auto svc = NewService(GuestMessage::ARC); |
| 346 | svc->Start(kTestPID); |
| 347 | |
| 348 | svc->OnDevicesChanged({"eth0", "wlan0"}, {}); |
| 349 | EXPECT_EQ(guest_devices_.size(), 2); |
| 350 | EXPECT_THAT(guest_devices_, |
| 351 | UnorderedElementsAre( |
| 352 | Pair(StrEq("arc_eth0"), Device::ChangeEvent::ADDED), |
| 353 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::ADDED))); |
| 354 | |
| 355 | svc->OnDevicesChanged({}, {"wlan0"}); |
| 356 | EXPECT_THAT(guest_devices_, |
| 357 | UnorderedElementsAre( |
| 358 | Pair(StrEq("arc_eth0"), Device::ChangeEvent::ADDED), |
| 359 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::REMOVED))); |
| 360 | |
| 361 | guest_devices_.clear(); |
| 362 | svc->OnDevicesChanged({"wlan0"}, {}); |
| 363 | EXPECT_THAT(guest_devices_, |
| 364 | UnorderedElementsAre( |
| 365 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::ADDED))); |
| 366 | } |
| 367 | |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 368 | TEST_F(ArcServiceTest, ContainerImpl_StartAfterDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 369 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 370 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 371 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 372 | .WillOnce(Return(true)); |
| 373 | // Expectations for arc0 setup. |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 374 | EXPECT_CALL(*datapath_, |
| 375 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 376 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
| 377 | .WillOnce(Return(true)); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 378 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 379 | .WillOnce(Return(true)); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 380 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
| 381 | .WillOnce(Return(true)); |
| 382 | // Expectations for eth0 setup. |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 383 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 384 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"), |
| 385 | StrEq("eth0"), _, kFirstEthGuestIP, 30, false)) |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 386 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 387 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 388 | .WillOnce(Return(true)); |
| 389 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0"))) |
| 390 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 391 | EXPECT_CALL(*datapath_, |
| 392 | StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 393 | kFirstEthGuestIP, TrafficSource::ARC, false)); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 394 | |
| 395 | auto svc = NewService(GuestMessage::ARC); |
| 396 | svc->OnDevicesChanged({"eth0"}, {}); |
| 397 | svc->Start(kTestPID); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 398 | } |
| 399 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 400 | TEST_F(ArcServiceTest, ContainerImpl_Stop) { |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 401 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 402 | .WillOnce(Return(true)); |
| 403 | EXPECT_CALL(*datapath_, NetnsDeleteName(StrEq("arc_netns"))) |
| 404 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 405 | // Expectations for arc0 setup. |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 406 | EXPECT_CALL(*datapath_, |
| 407 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 408 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
| 409 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 410 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 411 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 412 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
| 413 | .WillOnce(Return(true)); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 414 | EXPECT_CALL(*datapath_, SetConntrackHelpers(true)).WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 415 | // Expectations for arc0 teardown. |
| 416 | EXPECT_CALL(*datapath_, |
| 417 | MaskInterfaceFlags(StrEq("arcbr0"), IFF_DEBUG, IFF_UP)) |
| 418 | .WillOnce(Return(true)); |
Garrick Evans | 2f581a0 | 2020-05-11 10:43:35 +0900 | [diff] [blame] | 419 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vetharc0"))); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 420 | EXPECT_CALL(*datapath_, SetConntrackHelpers(false)).WillOnce(Return(true)); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 421 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 422 | auto svc = NewService(GuestMessage::ARC); |
| 423 | svc->Start(kTestPID); |
| 424 | svc->Stop(kTestPID); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 425 | } |
| 426 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 427 | TEST_F(ArcServiceTest, ContainerImpl_OnStopDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 428 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 429 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | 33860d7 | 2020-07-09 16:34:01 +0900 | [diff] [blame] | 430 | EXPECT_CALL(*datapath_, NetnsAttachName(StrEq("arc_netns"), kTestPID)) |
| 431 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 432 | // Expectations for arc0 setup. |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 433 | EXPECT_CALL(*datapath_, |
| 434 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetharc0"), |
| 435 | StrEq("arc0"), _, kArcGuestIP, 30, false)) |
| 436 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 437 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 438 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 439 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vetharc0"))) |
| 440 | .WillOnce(Return(true)); |
| 441 | // Expectations for eth0 setup. |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 442 | EXPECT_CALL(*datapath_, |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 443 | ConnectVethPair(kTestPID, StrEq("arc_netns"), StrEq("vetheth0"), |
| 444 | StrEq("eth0"), _, kFirstEthGuestIP, 30, false)) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 445 | .WillOnce(Return(true)); |
Hugo Benichi | 82ed5cf | 2020-09-08 21:30:22 +0900 | [diff] [blame] | 446 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 447 | .WillOnce(Return(true)); |
| 448 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vetheth0"))) |
| 449 | .WillOnce(Return(true)); |
| 450 | // Expectations for eth0 teardown. |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 451 | EXPECT_CALL(*datapath_, StopRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
| 452 | Ipv4Addr(100, 115, 92, 6), |
| 453 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 454 | EXPECT_CALL(*datapath_, RemoveBridge(StrEq("arc_eth0"))); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 455 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 456 | auto svc = NewService(GuestMessage::ARC); |
| 457 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 458 | svc->OnDevicesChanged({"eth0"}, {}); |
| 459 | svc->OnDevicesChanged({}, {"eth0"}); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 460 | } |
| 461 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 462 | // VM Impl |
| 463 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 464 | TEST_F(ArcServiceTest, VmImpl_Start) { |
| 465 | // Expectations for tap devices pre-creation. |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 466 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 467 | .WillOnce(Return("vmtap0")) |
| 468 | .WillOnce(Return("vmtap1")) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 469 | .WillOnce(Return("vmtap2")) |
| 470 | .WillOnce(Return("vmtap3")) |
| 471 | .WillOnce(Return("vmtap4")) |
| 472 | .WillOnce(Return("vmtap5")); |
| 473 | // Expectations for "arc0" setup. |
| 474 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 475 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 476 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vmtap0"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 477 | .WillOnce(Return(true)); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 478 | EXPECT_CALL(*datapath_, SetConntrackHelpers(true)).WillOnce(Return(true)); |
| 479 | // Required because the service will be stopped in dtor. |
| 480 | EXPECT_CALL(*datapath_, SetConntrackHelpers(false)).WillOnce(Return(true)); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 481 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 482 | auto svc = NewService(GuestMessage::ARC_VM); |
| 483 | svc->Start(kTestPID); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 484 | } |
| 485 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 486 | TEST_F(ArcServiceTest, VmImpl_StartDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 487 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 488 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 489 | // Expectations for tap devices pre-creation. |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 490 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 491 | .WillOnce(Return("vmtap0")) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 492 | .WillOnce(Return("vmtap1")) |
| 493 | .WillOnce(Return("vmtap2")) |
| 494 | .WillOnce(Return("vmtap3")) |
| 495 | .WillOnce(Return("vmtap4")) |
| 496 | .WillOnce(Return("vmtap5")); |
| 497 | // Expectations for "arc0" setup. |
| 498 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 499 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 500 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vmtap0"))) |
| 501 | .WillOnce(Return(true)); |
| 502 | // Expectations for eth0 setup. |
| 503 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 504 | .WillOnce(Return(true)); |
| 505 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vmtap1"))) |
| 506 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 507 | EXPECT_CALL(*datapath_, StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
| 508 | Ipv4Addr(100, 115, 92, 6), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 509 | TrafficSource::ARC, false)); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 510 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 511 | auto svc = NewService(GuestMessage::ARC_VM); |
| 512 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 513 | svc->OnDevicesChanged({"eth0"}, {}); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 514 | } |
| 515 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 516 | TEST_F(ArcServiceTest, VmImpl_StartMultipleDevices) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 517 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 518 | ShillClient::Device::Type::kEthernet); |
| 519 | ExpectGetDeviceProperties(*shill_client_, "eth1", |
| 520 | ShillClient::Device::Type::kEthernet); |
| 521 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 522 | ShillClient::Device::Type::kWifi); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 523 | // Expectations for tap devices pre-creation. |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 524 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 525 | .WillOnce(Return("vmtap0")) |
| 526 | .WillOnce(Return("vmtap1")) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 527 | .WillOnce(Return("vmtap2")) |
| 528 | .WillOnce(Return("vmtap3")) |
| 529 | .WillOnce(Return("vmtap4")) |
| 530 | .WillOnce(Return("vmtap5")); |
| 531 | // Expectations for "arc0" setup. |
| 532 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 533 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 534 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vmtap0"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 535 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 536 | // Expectations for eth0 setup. |
| 537 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
| 538 | .WillOnce(Return(true)); |
| 539 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vmtap1"))) |
| 540 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 541 | EXPECT_CALL(*datapath_, StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
| 542 | Ipv4Addr(100, 115, 92, 6), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 543 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 544 | // Expectations for wlan0 setup. |
| 545 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_wlan0"), kFirstWifiHostIP, 30)) |
| 546 | .WillOnce(Return(true)); |
| 547 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_wlan0"), StrEq("vmtap3"))) |
| 548 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 549 | EXPECT_CALL(*datapath_, StartRoutingDevice(StrEq("wlan0"), StrEq("arc_wlan0"), |
| 550 | Ipv4Addr(100, 115, 92, 14), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 551 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 552 | // Expectations for eth1 setup. |
| 553 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth1"), kSecondEthHostIP, 30)) |
| 554 | .WillOnce(Return(true)); |
| 555 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth1"), StrEq("vmtap2"))) |
| 556 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 557 | EXPECT_CALL(*datapath_, StartRoutingDevice(StrEq("eth1"), StrEq("arc_eth1"), |
| 558 | Ipv4Addr(100, 115, 92, 10), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 559 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 560 | |
| 561 | auto svc = NewService(GuestMessage::ARC_VM); |
| 562 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 563 | svc->OnDevicesChanged({"eth0"}, {}); |
| 564 | svc->OnDevicesChanged({"wlan0"}, {}); |
| 565 | svc->OnDevicesChanged({"eth1"}, {}); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | TEST_F(ArcServiceTest, VmImpl_Stop) { |
| 569 | // Expectations for tap devices pre-creation. |
| 570 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
| 571 | .WillOnce(Return("vmtap0")) |
| 572 | .WillOnce(Return("vmtap1")) |
| 573 | .WillOnce(Return("vmtap2")) |
| 574 | .WillOnce(Return("vmtap3")) |
| 575 | .WillOnce(Return("vmtap4")) |
| 576 | .WillOnce(Return("vmtap5")); |
| 577 | // Expectations for "arc0" setup. |
| 578 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
| 579 | .WillOnce(Return(true)); |
| 580 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vmtap0"))) |
| 581 | .WillOnce(Return(true)); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 582 | EXPECT_CALL(*datapath_, SetConntrackHelpers(true)).WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 583 | // Expectations for "arc0" teardown. |
| 584 | EXPECT_CALL(*datapath_, |
| 585 | MaskInterfaceFlags(StrEq("arcbr0"), IFF_DEBUG, IFF_UP)) |
| 586 | .WillOnce(Return(true)); |
| 587 | // Expectations for tap devices teardown |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 588 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap0"))); |
| 589 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap1"))); |
| 590 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap2"))); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 591 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap3"))); |
| 592 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap4"))); |
| 593 | EXPECT_CALL(*datapath_, RemoveInterface(StrEq("vmtap5"))); |
Damien Dejean | 61eccae | 2021-05-21 07:11:53 +0000 | [diff] [blame] | 594 | EXPECT_CALL(*datapath_, SetConntrackHelpers(false)).WillOnce(Return(true)); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 595 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 596 | auto svc = NewService(GuestMessage::ARC_VM); |
| 597 | svc->Start(kTestPID); |
| 598 | svc->Stop(kTestPID); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 599 | } |
| 600 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 601 | TEST_F(ArcServiceTest, VmImpl_StopDevice) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 602 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 603 | ShillClient::Device::Type::kEthernet); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 604 | // Expectations for tap devices pre-creation. |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 605 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 606 | .WillOnce(Return("vmtap0")) |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 607 | .WillOnce(Return("vmtap1")) |
| 608 | .WillOnce(Return("vmtap2")) |
| 609 | .WillOnce(Return("vmtap3")) |
| 610 | .WillOnce(Return("vmtap4")) |
| 611 | .WillOnce(Return("vmtap5")); |
| 612 | // Expectations for "arc0" setup. |
| 613 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arcbr0"), kArcHostIP, 30)) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 614 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 615 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arcbr0"), StrEq("vmtap0"))) |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 616 | .WillOnce(Return(true)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 617 | // Expectations for eth0 setup. |
| 618 | EXPECT_CALL(*datapath_, AddBridge(StrEq("arc_eth0"), kFirstEthHostIP, 30)) |
| 619 | .WillOnce(Return(true)); |
| 620 | EXPECT_CALL(*datapath_, AddToBridge(StrEq("arc_eth0"), StrEq("vmtap1"))) |
| 621 | .WillOnce(Return(true)); |
Hugo Benichi | 8d622b5 | 2020-08-13 15:24:12 +0900 | [diff] [blame] | 622 | EXPECT_CALL(*datapath_, StartRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
| 623 | Ipv4Addr(100, 115, 92, 6), |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 624 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 625 | // Expectations for eth0 teardown. |
Hugo Benichi | 93306e5 | 2020-12-04 16:08:00 +0900 | [diff] [blame] | 626 | EXPECT_CALL(*datapath_, StopRoutingDevice(StrEq("eth0"), StrEq("arc_eth0"), |
| 627 | Ipv4Addr(100, 115, 92, 6), |
| 628 | TrafficSource::ARC, false)); |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 629 | EXPECT_CALL(*datapath_, RemoveBridge(StrEq("arc_eth0"))); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 630 | |
Hugo Benichi | ad1bdd9 | 2020-06-12 13:48:37 +0900 | [diff] [blame] | 631 | auto svc = NewService(GuestMessage::ARC_VM); |
| 632 | svc->Start(kTestPID); |
Hugo Benichi | f0f10c7 | 2020-07-09 10:42:45 +0900 | [diff] [blame] | 633 | svc->OnDevicesChanged({"eth0"}, {}); |
| 634 | svc->OnDevicesChanged({}, {"eth0"}); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 635 | } |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 636 | |
Garrick Evans | 02e6e87 | 2020-11-30 11:53:13 +0900 | [diff] [blame] | 637 | TEST_F(ArcServiceTest, VmImpl_ScanDevices) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 638 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 639 | ShillClient::Device::Type::kEthernet); |
| 640 | ExpectGetDeviceProperties(*shill_client_, "eth1", |
| 641 | ShillClient::Device::Type::kEthernet); |
| 642 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 643 | ShillClient::Device::Type::kWifi); |
Garrick Evans | 02e6e87 | 2020-11-30 11:53:13 +0900 | [diff] [blame] | 644 | // Expectations for tap devices pre-creation. |
| 645 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
| 646 | .WillOnce(Return("vmtap0")) |
| 647 | .WillOnce(Return("vmtap1")) |
| 648 | .WillOnce(Return("vmtap2")) |
| 649 | .WillOnce(Return("vmtap3")) |
| 650 | .WillOnce(Return("vmtap4")) |
| 651 | .WillOnce(Return("vmtap5")); |
| 652 | EXPECT_CALL(*datapath_, AddBridge(_, _, _)).WillRepeatedly(Return(true)); |
| 653 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
| 654 | |
| 655 | auto svc = NewService(GuestMessage::ARC_VM); |
| 656 | svc->Start(kTestPID); |
| 657 | svc->OnDevicesChanged({"eth0", "wlan0", "eth1"}, {}); |
| 658 | |
| 659 | std::vector<std::string> devs; |
| 660 | svc->ScanDevices(base::BindRepeating( |
| 661 | [](std::vector<std::string>* list, const Device& device) { |
| 662 | list->push_back(device.host_ifname()); |
| 663 | }, |
| 664 | &devs)); |
| 665 | |
| 666 | EXPECT_EQ(devs.size(), 3); |
| 667 | EXPECT_THAT(devs, UnorderedElementsAre(StrEq("arc_eth0"), StrEq("arc_wlan0"), |
| 668 | StrEq("arc_eth1"))); |
| 669 | } |
| 670 | |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 671 | TEST_F(ArcServiceTest, VmImpl_DeviceHandler) { |
Hugo Benichi | 84d96c4 | 2021-02-26 14:20:13 +0900 | [diff] [blame] | 672 | ExpectGetDeviceProperties(*shill_client_, "eth0", |
| 673 | ShillClient::Device::Type::kEthernet); |
| 674 | ExpectGetDeviceProperties(*shill_client_, "wlan0", |
| 675 | ShillClient::Device::Type::kWifi); |
Garrick Evans | 209a80a | 2020-11-30 14:42:40 +0900 | [diff] [blame] | 676 | // Expectations for tap devices pre-creation. |
| 677 | EXPECT_CALL(*datapath_, AddTAP(StrEq(""), _, nullptr, StrEq("crosvm"))) |
| 678 | .WillOnce(Return("vmtap0")) |
| 679 | .WillOnce(Return("vmtap1")) |
| 680 | .WillOnce(Return("vmtap2")) |
| 681 | .WillOnce(Return("vmtap3")) |
| 682 | .WillOnce(Return("vmtap4")) |
| 683 | .WillOnce(Return("vmtap5")); |
| 684 | EXPECT_CALL(*datapath_, AddBridge(_, _, _)).WillRepeatedly(Return(true)); |
| 685 | EXPECT_CALL(*datapath_, AddToBridge(_, _)).WillRepeatedly(Return(true)); |
| 686 | |
| 687 | auto svc = NewService(GuestMessage::ARC_VM); |
| 688 | svc->Start(kTestPID); |
| 689 | |
| 690 | svc->OnDevicesChanged({"eth0", "wlan0"}, {}); |
| 691 | EXPECT_EQ(guest_devices_.size(), 2); |
| 692 | EXPECT_THAT(guest_devices_, |
| 693 | UnorderedElementsAre( |
| 694 | Pair(StrEq("arc_eth0"), Device::ChangeEvent::ADDED), |
| 695 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::ADDED))); |
| 696 | |
| 697 | svc->OnDevicesChanged({}, {"wlan0"}); |
| 698 | EXPECT_THAT(guest_devices_, |
| 699 | UnorderedElementsAre( |
| 700 | Pair(StrEq("arc_eth0"), Device::ChangeEvent::ADDED), |
| 701 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::REMOVED))); |
| 702 | |
| 703 | guest_devices_.clear(); |
| 704 | svc->OnDevicesChanged({"wlan0"}, {}); |
| 705 | EXPECT_THAT(guest_devices_, |
| 706 | UnorderedElementsAre( |
| 707 | Pair(StrEq("arc_wlan0"), Device::ChangeEvent::ADDED))); |
| 708 | } |
| 709 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 710 | } // namespace patchpanel |