blob: b0cdf43911590143aeac92ededccaab05b97871d [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;
22import org.onosproject.net.host.HostLocationProbingService;
23
24import java.util.List;
25import java.util.Objects;
26
27public class MockLocationProbingService implements HostLocationProbingService {
28 List<Probe> probes;
29
30 private class Probe {
31 private Host host;
32 private ConnectPoint connectPoint;
33 private ProbeMode probeMode;
34
35 Probe(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
36 this.host = host;
37 this.connectPoint = connectPoint;
38 this.probeMode = probeMode;
39 }
40
41 @Override
42 public boolean equals(Object o) {
43 if (this == o) {
44 return true;
45 }
46 if (!(o instanceof Probe)) {
47 return false;
48 }
49 Probe that = (Probe) o;
50 return (Objects.equals(this.host, that.host) &&
51 Objects.equals(this.connectPoint, that.connectPoint) &&
52 Objects.equals(this.probeMode, that.probeMode));
53 }
54
55 @Override
56 public int hashCode() {
57 return Objects.hash(host, connectPoint, probeMode);
58 }
59 }
60
61 MockLocationProbingService() {
62 probes = Lists.newArrayList();
63 }
64
65 boolean verifyProbe(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
66 Probe probe = new Probe(host, connectPoint, probeMode);
67 return probes.contains(probe);
68 }
69
70 @Override
71 public void probeHostLocation(Host host, ConnectPoint connectPoint, ProbeMode probeMode) {
72 probes.add(new Probe(host, connectPoint, probeMode));
73 }
74}