blob: 3f9348863f84a63eb94a6eb6a414e18643550abd [file] [log] [blame]
samanwita pale7c08de2015-09-24 21:59:49 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
samanwita pale7c08de2015-09-24 21:59:49 -07003 *
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 */
16package org.onosproject.store.host.impl;
17
18import junit.framework.TestCase;
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.IpAddress;
23import org.onlab.packet.MacAddress;
24import org.onosproject.net.Host;
25import org.onosproject.net.HostId;
26import org.onosproject.net.HostLocation;
27import org.onosproject.net.host.DefaultHostDescription;
28import org.onosproject.net.host.HostDescription;
29import org.onosproject.net.provider.ProviderId;
samanwita pale7c08de2015-09-24 21:59:49 -070030import org.onosproject.store.service.TestStorageService;
31
32import java.util.HashSet;
33import java.util.Set;
34
35/**
36 * Tests for the ECHostStore.
37 */
alshabib8a4a6002015-11-25 14:31:16 -080038public class DistributedHostStoreTest extends TestCase {
samanwita pale7c08de2015-09-24 21:59:49 -070039
alshabib8a4a6002015-11-25 14:31:16 -080040 private DistributedHostStore ecXHostStore;
samanwita pale7c08de2015-09-24 21:59:49 -070041
42 private static final HostId HOSTID = HostId.hostId(MacAddress.valueOf("1a:1a:1a:1a:1a:1a"));
43
44 private static final IpAddress IP1 = IpAddress.valueOf("10.2.0.2");
45 private static final IpAddress IP2 = IpAddress.valueOf("10.2.0.3");
46
47 private static final ProviderId PID = new ProviderId("of", "foo");
48
49 @Before
50 public void setUp() {
alshabib8a4a6002015-11-25 14:31:16 -080051 ecXHostStore = new DistributedHostStore();
samanwita pale7c08de2015-09-24 21:59:49 -070052
53 ecXHostStore.storageService = new TestStorageService();
samanwita pale7c08de2015-09-24 21:59:49 -070054 ecXHostStore.activate();
55 }
56
57 @After
58 public void tearDown() {
59 ecXHostStore.deactivate();
60 }
61
62 /**
63 * Tests the removeIp method call.
64 */
65 @Test
66 public void testRemoveIp() {
67 Set<IpAddress> ips = new HashSet<>();
68 ips.add(IP1);
69 ips.add(IP2);
70
71 HostDescription description = new DefaultHostDescription(HOSTID.mac(),
72 HOSTID.vlanId(),
73 HostLocation.NONE,
74 ips);
75 ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
76 ecXHostStore.removeIp(HOSTID, IP1);
77 Host host = ecXHostStore.getHost(HOSTID);
78
79 assertFalse(host.ipAddresses().contains(IP1));
80 assertTrue(host.ipAddresses().contains(IP2));
81 }
82
samanwita pale7c08de2015-09-24 21:59:49 -070083}