blob: 9f7338d2a5e2dce0b0a1d17c541a45f4722a0bd9 [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
samanwita pale7c08de2015-09-24 21:59:49 -070018import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.MacAddress;
23import org.onosproject.net.Host;
24import org.onosproject.net.HostId;
25import org.onosproject.net.HostLocation;
26import org.onosproject.net.host.DefaultHostDescription;
27import org.onosproject.net.host.HostDescription;
28import org.onosproject.net.provider.ProviderId;
samanwita pale7c08de2015-09-24 21:59:49 -070029import org.onosproject.store.service.TestStorageService;
30
31import java.util.HashSet;
32import java.util.Set;
33
Sho SHIMIZU53bcc242016-08-15 11:19:24 -070034import static junit.framework.TestCase.assertTrue;
35import static org.junit.Assert.assertFalse;
36
samanwita pale7c08de2015-09-24 21:59:49 -070037/**
38 * Tests for the ECHostStore.
39 */
Sho SHIMIZU53bcc242016-08-15 11:19:24 -070040public class DistributedHostStoreTest {
samanwita pale7c08de2015-09-24 21:59:49 -070041
alshabib8a4a6002015-11-25 14:31:16 -080042 private DistributedHostStore ecXHostStore;
samanwita pale7c08de2015-09-24 21:59:49 -070043
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() {
alshabib8a4a6002015-11-25 14:31:16 -080053 ecXHostStore = new DistributedHostStore();
samanwita pale7c08de2015-09-24 21:59:49 -070054
55 ecXHostStore.storageService = new TestStorageService();
samanwita pale7c08de2015-09-24 21:59:49 -070056 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 SHIMIZU53bcc242016-08-15 11:19:24 -070085}