Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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. |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 4 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 5 | #include "shill/device_info.h" |
| 6 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 7 | #include <glib.h> |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 8 | #include <sys/socket.h> |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 9 | #include <linux/if.h> |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 10 | #include <linux/netlink.h> // Needs typedefs from sys/socket.h. |
| 11 | #include <linux/rtnetlink.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 12 | |
| 13 | #include <base/callback_old.h> |
| 14 | #include <base/logging.h> |
| 15 | #include <base/memory/ref_counted.h> |
| 16 | #include <base/message_loop.h> |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 17 | #include <base/stl_util-inl.h> |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
| 19 | #include <gmock/gmock.h> |
| 20 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 21 | #include "shill/ip_address.h" |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 22 | #include "shill/manager.h" |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 23 | #include "shill/mock_control.h" |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 24 | #include "shill/mock_glib.h" |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 25 | #include "shill/mock_manager.h" |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 26 | #include "shill/mock_rtnl_handler.h" |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 27 | #include "shill/mock_sockets.h" |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 28 | #include "shill/rtnl_message.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 29 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 30 | using std::map; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 31 | using std::string; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 32 | using std::vector; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 33 | using testing::_; |
| 34 | using testing::Return; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 35 | using testing::StrictMock; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 36 | using testing::Test; |
| 37 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 38 | namespace shill { |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 39 | |
| 40 | class TestEventDispatcher : public EventDispatcher { |
| 41 | public: |
| 42 | virtual IOInputHandler *CreateInputHandler( |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 43 | int /*fd*/, |
| 44 | Callback1<InputData*>::Type */*callback*/) { |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 45 | return NULL; |
| 46 | } |
| 47 | }; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 48 | |
| 49 | class DeviceInfoTest : public Test { |
| 50 | public: |
| 51 | DeviceInfoTest() |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 52 | : manager_(&control_interface_, &dispatcher_, &glib_), |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 53 | device_info_(&control_interface_, &dispatcher_, &manager_) { |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 54 | } |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 55 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 56 | virtual void SetUp() { |
| 57 | device_info_.rtnl_handler_ = &rtnl_handler_; |
| 58 | EXPECT_CALL(rtnl_handler_, RequestDump(RTNLHandler::kRequestLink | |
| 59 | RTNLHandler::kRequestAddr)); |
| 60 | } |
| 61 | |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 62 | protected: |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 63 | static const int kTestDeviceIndex; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 64 | static const char kTestDeviceName[]; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 65 | static const char kTestMACAddress[]; |
| 66 | static const char kTestIPAddress0[]; |
| 67 | static const int kTestIPAddressPrefix0; |
| 68 | static const char kTestIPAddress1[]; |
| 69 | static const int kTestIPAddressPrefix1; |
| 70 | static const char kTestIPAddress2[]; |
| 71 | static const char kTestIPAddress3[]; |
| 72 | static const char kTestIPAddress4[]; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 73 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 74 | RTNLMessage *BuildLinkMessage(RTNLMessage::Mode mode); |
| 75 | RTNLMessage *BuildAddressMessage(RTNLMessage::Mode mode, |
| 76 | const IPAddress &address, |
| 77 | unsigned char flags, |
| 78 | unsigned char scope); |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 79 | void SendMessageToDeviceInfo(const RTNLMessage &message); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 80 | |
Darin Petkov | afa6fc4 | 2011-06-21 16:21:08 -0700 | [diff] [blame] | 81 | MockGLib glib_; |
Chris Masone | 46eaaf5 | 2011-05-24 13:08:30 -0700 | [diff] [blame] | 82 | MockControl control_interface_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 83 | StrictMock<MockManager> manager_; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 84 | DeviceInfo device_info_; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 85 | TestEventDispatcher dispatcher_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 86 | StrictMock<MockRTNLHandler> rtnl_handler_; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 89 | const int DeviceInfoTest::kTestDeviceIndex = 123456; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 90 | const char DeviceInfoTest::kTestDeviceName[] = "test-device"; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 91 | const char DeviceInfoTest::kTestMACAddress[] = { |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 92 | 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 93 | const char DeviceInfoTest::kTestIPAddress0[] = "192.168.1.1"; |
| 94 | const int DeviceInfoTest::kTestIPAddressPrefix0 = 24; |
| 95 | const char DeviceInfoTest::kTestIPAddress1[] = "fe80::1aa9:5ff:abcd:1234"; |
| 96 | const int DeviceInfoTest::kTestIPAddressPrefix1 = 64; |
| 97 | const char DeviceInfoTest::kTestIPAddress2[] = "fe80::1aa9:5ff:abcd:1235"; |
| 98 | const char DeviceInfoTest::kTestIPAddress3[] = "fe80::1aa9:5ff:abcd:1236"; |
| 99 | const char DeviceInfoTest::kTestIPAddress4[] = "fe80::1aa9:5ff:abcd:1237"; |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 100 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 101 | RTNLMessage *DeviceInfoTest::BuildLinkMessage(RTNLMessage::Mode mode) { |
| 102 | RTNLMessage *message = new RTNLMessage( |
| 103 | RTNLMessage::kTypeLink, |
| 104 | mode, |
| 105 | 0, |
| 106 | 0, |
| 107 | 0, |
| 108 | kTestDeviceIndex, |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 109 | IPAddress::kFamilyIPv4); |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 110 | message->SetAttribute(static_cast<uint16>(IFLA_IFNAME), |
| 111 | ByteString(kTestDeviceName, true)); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 112 | ByteString test_address(kTestMACAddress, sizeof(kTestMACAddress)); |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 113 | message->SetAttribute(IFLA_ADDRESS, test_address); |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 114 | return message; |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 117 | RTNLMessage *DeviceInfoTest::BuildAddressMessage(RTNLMessage::Mode mode, |
| 118 | const IPAddress &address, |
| 119 | unsigned char flags, |
| 120 | unsigned char scope) { |
| 121 | RTNLMessage *message = new RTNLMessage( |
| 122 | RTNLMessage::kTypeAddress, |
| 123 | mode, |
| 124 | 0, |
| 125 | 0, |
| 126 | 0, |
| 127 | kTestDeviceIndex, |
| 128 | address.family()); |
| 129 | message->SetAttribute(IFA_ADDRESS, address.address()); |
| 130 | message->set_address_status( |
| 131 | RTNLMessage::AddressStatus(address.prefix(), flags, scope)); |
| 132 | return message; |
| 133 | } |
| 134 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 135 | void DeviceInfoTest::SendMessageToDeviceInfo(const RTNLMessage &message) { |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 136 | if (message.type() == RTNLMessage::kTypeLink) { |
| 137 | device_info_.LinkMsgHandler(message); |
| 138 | } else if (message.type() == RTNLMessage::kTypeAddress) { |
| 139 | device_info_.AddressMsgHandler(message); |
| 140 | } else { |
| 141 | NOTREACHED(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | MATCHER_P(IsIPAddress, address, "") { |
| 146 | // NB: IPAddress objects don't support the "==" operator as per style, so |
| 147 | // we need a custom matcher. |
| 148 | return address.Equals(arg); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | TEST_F(DeviceInfoTest, DeviceEnumeration) { |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 152 | // Start our own private device_info |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 153 | device_info_.Start(); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 154 | scoped_ptr<RTNLMessage> message(BuildLinkMessage(RTNLMessage::kModeAdd)); |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 155 | message->set_link_status(RTNLMessage::LinkStatus(0, IFF_LOWER_UP, 0)); |
| 156 | EXPECT_FALSE(device_info_.GetDevice(kTestDeviceIndex).get()); |
| 157 | SendMessageToDeviceInfo(*message); |
| 158 | EXPECT_TRUE(device_info_.GetDevice(kTestDeviceIndex).get()); |
| 159 | unsigned int flags = 0; |
| 160 | EXPECT_TRUE(device_info_.GetFlags(kTestDeviceIndex, &flags)); |
| 161 | EXPECT_EQ(IFF_LOWER_UP, flags); |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 162 | ByteString address; |
Paul Stewart | 3285296 | 2011-08-30 14:06:53 -0700 | [diff] [blame] | 163 | EXPECT_TRUE(device_info_.GetMACAddress(kTestDeviceIndex, &address)); |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 164 | EXPECT_FALSE(address.IsEmpty()); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 165 | EXPECT_TRUE(address.Equals(ByteString(kTestMACAddress, |
| 166 | sizeof(kTestMACAddress)))); |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 167 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 168 | message.reset(BuildLinkMessage(RTNLMessage::kModeAdd)); |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 169 | message->set_link_status(RTNLMessage::LinkStatus(0, IFF_UP | IFF_RUNNING, 0)); |
| 170 | SendMessageToDeviceInfo(*message); |
| 171 | EXPECT_TRUE(device_info_.GetFlags(kTestDeviceIndex, &flags)); |
| 172 | EXPECT_EQ(IFF_UP | IFF_RUNNING, flags); |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 173 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 174 | message.reset(BuildLinkMessage(RTNLMessage::kModeDelete)); |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 175 | SendMessageToDeviceInfo(*message); |
| 176 | EXPECT_FALSE(device_info_.GetDevice(kTestDeviceIndex).get()); |
| 177 | EXPECT_FALSE(device_info_.GetFlags(kTestDeviceIndex, NULL)); |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 178 | |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 179 | device_info_.Stop(); |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 180 | } |
| 181 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 182 | TEST_F(DeviceInfoTest, DeviceBlackList) { |
| 183 | device_info_.AddDeviceToBlackList(kTestDeviceName); |
| 184 | device_info_.Start(); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 185 | scoped_ptr<RTNLMessage> message(BuildLinkMessage(RTNLMessage::kModeAdd)); |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 186 | SendMessageToDeviceInfo(*message); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 187 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 188 | DeviceRefPtr device = device_info_.GetDevice(kTestDeviceIndex); |
| 189 | ASSERT_TRUE(device.get()); |
Paul Stewart | fdd1607 | 2011-09-16 12:41:35 -0700 | [diff] [blame] | 190 | EXPECT_TRUE(device->TechnologyIs(Technology::kBlacklisted)); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 191 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 192 | device_info_.Stop(); |
| 193 | } |
| 194 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 195 | TEST_F(DeviceInfoTest, DeviceAddressList) { |
| 196 | device_info_.Start(); |
| 197 | scoped_ptr<RTNLMessage> message(BuildLinkMessage(RTNLMessage::kModeAdd)); |
| 198 | SendMessageToDeviceInfo(*message); |
| 199 | |
| 200 | vector<DeviceInfo::AddressData> addresses; |
| 201 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 202 | EXPECT_TRUE(addresses.empty()); |
| 203 | |
| 204 | // Add an address to the device address list |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 205 | IPAddress ip_address0(IPAddress::kFamilyIPv4); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 206 | EXPECT_TRUE(ip_address0.SetAddressFromString(kTestIPAddress0)); |
| 207 | ip_address0.set_prefix(kTestIPAddressPrefix0); |
| 208 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, ip_address0, 0, 0)); |
| 209 | SendMessageToDeviceInfo(*message); |
| 210 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 211 | EXPECT_EQ(1, addresses.size()); |
| 212 | EXPECT_TRUE(ip_address0.Equals(addresses[0].address)); |
| 213 | |
| 214 | // Re-adding the same address shouldn't cause the address list to change |
| 215 | SendMessageToDeviceInfo(*message); |
| 216 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 217 | EXPECT_EQ(1, addresses.size()); |
| 218 | EXPECT_TRUE(ip_address0.Equals(addresses[0].address)); |
| 219 | |
| 220 | // Adding a new address should expand the list |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 221 | IPAddress ip_address1(IPAddress::kFamilyIPv6); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 222 | EXPECT_TRUE(ip_address1.SetAddressFromString(kTestIPAddress1)); |
| 223 | ip_address1.set_prefix(kTestIPAddressPrefix1); |
| 224 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, ip_address1, 0, 0)); |
| 225 | SendMessageToDeviceInfo(*message); |
| 226 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 227 | EXPECT_EQ(2, addresses.size()); |
| 228 | EXPECT_TRUE(ip_address0.Equals(addresses[0].address)); |
| 229 | EXPECT_TRUE(ip_address1.Equals(addresses[1].address)); |
| 230 | |
| 231 | // Deleting an address should reduce the list |
| 232 | message.reset(BuildAddressMessage(RTNLMessage::kModeDelete, |
| 233 | ip_address0, |
| 234 | 0, |
| 235 | 0)); |
| 236 | SendMessageToDeviceInfo(*message); |
| 237 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 238 | EXPECT_EQ(1, addresses.size()); |
| 239 | EXPECT_TRUE(ip_address1.Equals(addresses[0].address)); |
| 240 | |
| 241 | // Delete last item |
| 242 | message.reset(BuildAddressMessage(RTNLMessage::kModeDelete, |
| 243 | ip_address1, |
| 244 | 0, |
| 245 | 0)); |
| 246 | SendMessageToDeviceInfo(*message); |
| 247 | EXPECT_TRUE(device_info_.GetAddresses(kTestDeviceIndex, &addresses)); |
| 248 | EXPECT_TRUE(addresses.empty()); |
| 249 | |
| 250 | // Delete device |
| 251 | message.reset(BuildLinkMessage(RTNLMessage::kModeDelete)); |
| 252 | SendMessageToDeviceInfo(*message); |
| 253 | |
| 254 | // Should be able to handle message for interface that doesn't exist |
| 255 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, ip_address0, 0, 0)); |
| 256 | SendMessageToDeviceInfo(*message); |
| 257 | EXPECT_FALSE(device_info_.GetDevice(kTestDeviceIndex).get()); |
| 258 | |
| 259 | device_info_.Stop(); |
| 260 | } |
| 261 | |
| 262 | TEST_F(DeviceInfoTest, FlushAddressList) { |
| 263 | device_info_.Start(); |
| 264 | scoped_ptr<RTNLMessage> message(BuildLinkMessage(RTNLMessage::kModeAdd)); |
| 265 | SendMessageToDeviceInfo(*message); |
| 266 | |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 267 | IPAddress address1(IPAddress::kFamilyIPv6); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 268 | EXPECT_TRUE(address1.SetAddressFromString(kTestIPAddress1)); |
| 269 | address1.set_prefix(kTestIPAddressPrefix1); |
| 270 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, |
| 271 | address1, |
| 272 | 0, |
| 273 | RT_SCOPE_UNIVERSE)); |
| 274 | SendMessageToDeviceInfo(*message); |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 275 | IPAddress address2(IPAddress::kFamilyIPv6); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 276 | EXPECT_TRUE(address2.SetAddressFromString(kTestIPAddress2)); |
| 277 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, |
| 278 | address2, |
| 279 | IFA_F_TEMPORARY, |
| 280 | RT_SCOPE_UNIVERSE)); |
| 281 | SendMessageToDeviceInfo(*message); |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 282 | IPAddress address3(IPAddress::kFamilyIPv6); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 283 | EXPECT_TRUE(address3.SetAddressFromString(kTestIPAddress3)); |
| 284 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, |
| 285 | address3, |
| 286 | 0, |
| 287 | RT_SCOPE_LINK)); |
| 288 | SendMessageToDeviceInfo(*message); |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 289 | IPAddress address4(IPAddress::kFamilyIPv6); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 290 | EXPECT_TRUE(address4.SetAddressFromString(kTestIPAddress4)); |
| 291 | message.reset(BuildAddressMessage(RTNLMessage::kModeAdd, |
| 292 | address4, |
| 293 | IFA_F_PERMANENT, |
| 294 | RT_SCOPE_UNIVERSE)); |
| 295 | SendMessageToDeviceInfo(*message); |
| 296 | |
| 297 | // DeviceInfo now has 4 addresses associated with it, but only two of |
| 298 | // them are valid for flush. |
| 299 | EXPECT_CALL(rtnl_handler_, RemoveInterfaceAddress(kTestDeviceIndex, |
| 300 | IsIPAddress(address1))); |
| 301 | EXPECT_CALL(rtnl_handler_, RemoveInterfaceAddress(kTestDeviceIndex, |
| 302 | IsIPAddress(address2))); |
| 303 | device_info_.FlushAddresses(kTestDeviceIndex); |
| 304 | device_info_.Stop(); |
| 305 | } |
| 306 | |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 307 | } // namespace shill |