blob: dc105076c1cd9b6108511165b42e361f2b92855c [file] [log] [blame]
Charles Chan35a32322017-08-14 11:42:11 -07001/*
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.store.host.impl;
18
Charles Chanba90df12017-11-30 15:37:50 -080019import org.onosproject.net.ConnectPoint;
Charles Chan35a32322017-08-14 11:42:11 -070020import org.onosproject.net.HostId;
Charles Chanba90df12017-11-30 15:37:50 -080021import org.onosproject.net.host.HostLocationProbingService.ProbeMode;
Charles Chan35a32322017-08-14 11:42:11 -070022
23import java.util.Objects;
24
25import 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 */
30class PendingHostLocation {
31 private HostId hostId;
Charles Chanba90df12017-11-30 15:37:50 -080032 private ConnectPoint connectPoint;
Charles Chan35a32322017-08-14 11:42:11 -070033 private boolean expired;
Charles Chanba90df12017-11-30 15:37:50 -080034 private ProbeMode probeMode;
Charles Chan35a32322017-08-14 11:42:11 -070035
36 /**
37 * Constructs PendingHostLocation.
38 *
39 * @param hostId Host ID
Charles Chanba90df12017-11-30 15:37:50 -080040 * @param connectPoint location to be verified
41 * @param probeMode probe mode
Charles Chan35a32322017-08-14 11:42:11 -070042 */
Charles Chanba90df12017-11-30 15:37:50 -080043 PendingHostLocation(HostId hostId, ConnectPoint connectPoint, ProbeMode probeMode) {
Charles Chan35a32322017-08-14 11:42:11 -070044 this.hostId = hostId;
Charles Chanba90df12017-11-30 15:37:50 -080045 this.connectPoint = connectPoint;
Charles Chan35a32322017-08-14 11:42:11 -070046 this.expired = false;
Charles Chanba90df12017-11-30 15:37:50 -080047 this.probeMode = probeMode;
Charles Chan35a32322017-08-14 11:42:11 -070048 }
49
50 /**
51 * Gets HostId of this entry.
52 *
53 * @return host id
54 */
55 HostId hostId() {
56 return hostId;
57 }
58
59 /**
Charles Chanba90df12017-11-30 15:37:50 -080060 * Gets connect point of this entry.
Charles Chan35a32322017-08-14 11:42:11 -070061 *
Charles Chanba90df12017-11-30 15:37:50 -080062 * @return connect point
Charles Chan35a32322017-08-14 11:42:11 -070063 */
Charles Chanba90df12017-11-30 15:37:50 -080064 ConnectPoint connectPoint() {
65 return connectPoint;
Charles Chan35a32322017-08-14 11:42:11 -070066 }
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 Chanba90df12017-11-30 15:37:50 -080086 /**
87 * Gets probe mode of this entry.
88 *
89 * @return probe mode
90 */
91 ProbeMode probeMode() {
92 return probeMode;
93 }
94
Charles Chan35a32322017-08-14 11:42:11 -070095 @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 Chanba90df12017-11-30 15:37:50 -0800105 Objects.equals(this.connectPoint, that.connectPoint) &&
106 Objects.equals(this.expired, that.expired) &&
107 Objects.equals(this.probeMode, that.probeMode));
Charles Chan35a32322017-08-14 11:42:11 -0700108 }
109 @Override
110 public int hashCode() {
Charles Chanba90df12017-11-30 15:37:50 -0800111 return Objects.hash(hostId, connectPoint, expired, probeMode);
Charles Chan35a32322017-08-14 11:42:11 -0700112 }
113
114 @Override
115 public String toString() {
116 return toStringHelper(getClass())
117 .add("hostId", hostId)
Charles Chanba90df12017-11-30 15:37:50 -0800118 .add("location", connectPoint)
Charles Chan35a32322017-08-14 11:42:11 -0700119 .add("expired", expired)
Charles Chanba90df12017-11-30 15:37:50 -0800120 .add("probeMode", probeMode)
Charles Chan35a32322017-08-14 11:42:11 -0700121 .toString();
122 }
123}