blob: 807db0c48e0da83ba9af548e30e669aa68901422 [file] [log] [blame]
Charles Chan873661e2017-11-30 15:37:50 -08001/*
2 * Copyright 2017-present Open Networking Foundation
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
17package org.onosproject.segmentrouting;
18
19import com.google.common.collect.Lists;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.Host;
Charles Chanc6bcdf92018-06-01 16:33:48 -070022import org.onosproject.net.host.HostProbingService;
23import org.onosproject.net.host.ProbeMode;
Charles Chan873661e2017-11-30 15:37:50 -080024
25import java.util.List;
26import java.util.Objects;
27
Charles Chanc6bcdf92018-06-01 16:33:48 -070028public class MockHostProbingService implements HostProbingService {
Charles Chan873661e2017-11-30 15:37:50 -080029 List<Probe> probes;
30
31 private class Probe {
32 private Host host;
33 private ConnectPoint connectPoint;
34 private ProbeMode probeMode;
35
36 Probe(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
37 this.host = host;
38 this.connectPoint = connectPoint;
39 this.probeMode = probeMode;
40 }
41
42 @Override
43 public boolean equals(Object o) {
44 if (this == o) {
45 return true;
46 }
47 if (!(o instanceof Probe)) {
48 return false;
49 }
50 Probe that = (Probe) o;
51 return (Objects.equals(this.host, that.host) &&
52 Objects.equals(this.connectPoint, that.connectPoint) &&
53 Objects.equals(this.probeMode, that.probeMode));
54 }
55
56 @Override
57 public int hashCode() {
58 return Objects.hash(host, connectPoint, probeMode);
59 }
60 }
61
Charles Chanc6bcdf92018-06-01 16:33:48 -070062 MockHostProbingService() {
Charles Chan873661e2017-11-30 15:37:50 -080063 probes = Lists.newArrayList();
64 }
65
66 boolean verifyProbe(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
67 Probe probe = new Probe(host, connectPoint, probeMode);
68 return probes.contains(probe);
69 }
70
71 @Override
Charles Chanc6bcdf92018-06-01 16:33:48 -070072 public void probeHost(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
Charles Chan873661e2017-11-30 15:37:50 -080073 probes.add(new Probe(host, connectPoint, probeMode));
74 }
75}