samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.host.impl; |
| 17 | |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.MacAddress; |
| 23 | import org.onosproject.net.Host; |
| 24 | import org.onosproject.net.HostId; |
| 25 | import org.onosproject.net.HostLocation; |
| 26 | import org.onosproject.net.host.DefaultHostDescription; |
| 27 | import org.onosproject.net.host.HostDescription; |
| 28 | import org.onosproject.net.provider.ProviderId; |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 29 | import org.onosproject.store.service.TestStorageService; |
| 30 | |
| 31 | import java.util.HashSet; |
| 32 | import java.util.Set; |
| 33 | |
Sho SHIMIZU | 53bcc24 | 2016-08-15 11:19:24 -0700 | [diff] [blame^] | 34 | import static junit.framework.TestCase.assertTrue; |
| 35 | import static org.junit.Assert.assertFalse; |
| 36 | |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Tests for the ECHostStore. |
| 39 | */ |
Sho SHIMIZU | 53bcc24 | 2016-08-15 11:19:24 -0700 | [diff] [blame^] | 40 | public class DistributedHostStoreTest { |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 41 | |
alshabib | 8a4a600 | 2015-11-25 14:31:16 -0800 | [diff] [blame] | 42 | private DistributedHostStore ecXHostStore; |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 43 | |
| 44 | private static final HostId HOSTID = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a")); |
| 45 | |
| 46 | private static final IpAddress IP1 = IpAddress.valueOf("10.2.0.2"); |
| 47 | private static final IpAddress IP2 = IpAddress.valueOf("10.2.0.3"); |
| 48 | |
| 49 | private static final ProviderId PID = new ProviderId("of", "foo"); |
| 50 | |
| 51 | @Before |
| 52 | public void setUp() { |
alshabib | 8a4a600 | 2015-11-25 14:31:16 -0800 | [diff] [blame] | 53 | ecXHostStore = new DistributedHostStore(); |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 54 | |
| 55 | ecXHostStore.storageService = new TestStorageService(); |
samanwita pal | e7c08de | 2015-09-24 21:59:49 -0700 | [diff] [blame] | 56 | ecXHostStore.activate(); |
| 57 | } |
| 58 | |
| 59 | @After |
| 60 | public void tearDown() { |
| 61 | ecXHostStore.deactivate(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Tests the removeIp method call. |
| 66 | */ |
| 67 | @Test |
| 68 | public void testRemoveIp() { |
| 69 | Set<IpAddress> ips = new HashSet<>(); |
| 70 | ips.add(IP1); |
| 71 | ips.add(IP2); |
| 72 | |
| 73 | HostDescription description = new DefaultHostDescription(HOSTID.mac(), |
| 74 | HOSTID.vlanId(), |
| 75 | HostLocation.NONE, |
| 76 | ips); |
| 77 | ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false); |
| 78 | ecXHostStore.removeIp(HOSTID, IP1); |
| 79 | Host host = ecXHostStore.getHost(HOSTID); |
| 80 | |
| 81 | assertFalse(host.ipAddresses().contains(IP1)); |
| 82 | assertTrue(host.ipAddresses().contains(IP2)); |
| 83 | } |
| 84 | |
Sho SHIMIZU | 53bcc24 | 2016-08-15 11:19:24 -0700 | [diff] [blame^] | 85 | } |