Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.store.host.impl; |
| 18 | |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 19 | import org.onosproject.net.ConnectPoint; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 20 | import org.onosproject.net.HostId; |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 21 | import org.onosproject.net.host.HostLocationProbingService.ProbeMode; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 26 | |
| 27 | /** |
| 28 | * Internal data structure to record the info of a host with location that is under verification. |
| 29 | */ |
| 30 | class PendingHostLocation { |
| 31 | private HostId hostId; |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 32 | private ConnectPoint connectPoint; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 33 | private boolean expired; |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 34 | private ProbeMode probeMode; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Constructs PendingHostLocation. |
| 38 | * |
| 39 | * @param hostId Host ID |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 40 | * @param connectPoint location to be verified |
| 41 | * @param probeMode probe mode |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 42 | */ |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 43 | PendingHostLocation(HostId hostId, ConnectPoint connectPoint, ProbeMode probeMode) { |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 44 | this.hostId = hostId; |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 45 | this.connectPoint = connectPoint; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 46 | this.expired = false; |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 47 | this.probeMode = probeMode; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Gets HostId of this entry. |
| 52 | * |
| 53 | * @return host id |
| 54 | */ |
| 55 | HostId hostId() { |
| 56 | return hostId; |
| 57 | } |
| 58 | |
| 59 | /** |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 60 | * Gets connect point of this entry. |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 61 | * |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 62 | * @return connect point |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 63 | */ |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 64 | ConnectPoint connectPoint() { |
| 65 | return connectPoint; |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Determine whether this probe is expired or not. |
| 70 | * |
| 71 | * @return true if this entry is expired and waiting to be removed from the cache |
| 72 | */ |
| 73 | boolean expired() { |
| 74 | return expired; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Sets whether this probe is expired or not. |
| 79 | * |
| 80 | * @param expired true if this entry is expired and waiting to be removed from the cache |
| 81 | */ |
| 82 | void setExpired(boolean expired) { |
| 83 | this.expired = expired; |
| 84 | } |
| 85 | |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 86 | /** |
| 87 | * Gets probe mode of this entry. |
| 88 | * |
| 89 | * @return probe mode |
| 90 | */ |
| 91 | ProbeMode probeMode() { |
| 92 | return probeMode; |
| 93 | } |
| 94 | |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 95 | @Override |
| 96 | public boolean equals(Object o) { |
| 97 | if (this == o) { |
| 98 | return true; |
| 99 | } |
| 100 | if (!(o instanceof PendingHostLocation)) { |
| 101 | return false; |
| 102 | } |
| 103 | PendingHostLocation that = (PendingHostLocation) o; |
| 104 | return (Objects.equals(this.hostId, that.hostId) && |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 105 | Objects.equals(this.connectPoint, that.connectPoint) && |
| 106 | Objects.equals(this.expired, that.expired) && |
| 107 | Objects.equals(this.probeMode, that.probeMode)); |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 108 | } |
| 109 | @Override |
| 110 | public int hashCode() { |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 111 | return Objects.hash(hostId, connectPoint, expired, probeMode); |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String toString() { |
| 116 | return toStringHelper(getClass()) |
| 117 | .add("hostId", hostId) |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 118 | .add("location", connectPoint) |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 119 | .add("expired", expired) |
Charles Chan | ba90df1 | 2017-11-30 15:37:50 -0800 | [diff] [blame] | 120 | .add("probeMode", probeMode) |
Charles Chan | 35a3232 | 2017-08-14 11:42:11 -0700 | [diff] [blame] | 121 | .toString(); |
| 122 | } |
| 123 | } |