blob: 5ab72fc9d425d67ccd527479074881cde511386f [file] [log] [blame]
Charles Chanff79dd92018-06-01 16:33:48 -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
19import org.onlab.packet.MacAddress;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.DefaultHost;
22import org.onosproject.net.Host;
23import org.onosproject.net.host.ProbeMode;
24import org.onosproject.net.host.HostProbe;
25
26import java.util.Objects;
27
28import static com.google.common.base.MoreObjects.toStringHelper;
29
30/**
31 * Internal data structure to record the info of a host with location that is under verification.
32 */
33class DefaultHostProbe extends DefaultHost implements HostProbe {
34 private ConnectPoint connectPoint;
35 private int retry;
36 private ProbeMode mode;
37 private MacAddress probeMac;
38
39 /**
40 * Constructs DefaultHostProbe with given retry.
41 *
42 * @param host host to be probed
43 * @param connectPoint location to be verified
44 * @param probeMac source MAC address of the probe
45 * @param mode probe mode
46 * @param retry number of retry
47 */
48 DefaultHostProbe(Host host, ConnectPoint connectPoint, ProbeMode mode, MacAddress probeMac, int retry) {
49 super(host.providerId(), host.id(), host.mac(), host.vlan(), host.locations(), host.ipAddresses(),
50 host.configured());
51
52 this.connectPoint = connectPoint;
53 this.mode = mode;
54 this.probeMac = probeMac;
55 this.retry = retry;
56 }
57
58 @Override
59 public ConnectPoint connectPoint() {
60 return connectPoint;
61 }
62
63 @Override
64 public int retry() {
65 return retry;
66 }
67
68 @Override
69 public void decreaseRetry() {
70 this.retry -= 1;
71 }
72
73 @Override
74 public ProbeMode mode() {
75 return mode;
76 }
77
78 @Override
79 public MacAddress probeMac() {
80 return probeMac;
81 }
82
83 @Override
84 public boolean equals(Object o) {
85 if (this == o) {
86 return true;
87 }
88 if (!(o instanceof DefaultHostProbe)) {
89 return false;
90 }
91 DefaultHostProbe that = (DefaultHostProbe) o;
92 return (super.equals(o) &&
93 Objects.equals(this.connectPoint, that.connectPoint) &&
94 Objects.equals(this.retry, that.retry) &&
95 Objects.equals(this.mode, that.mode)) &&
96 Objects.equals(this.probeMac, that.probeMac);
97 }
98 @Override
99 public int hashCode() {
100 return Objects.hash(super.hashCode(), connectPoint, retry, mode, probeMac);
101 }
102
103 @Override
104 public String toString() {
105 return toStringHelper(getClass())
106 .add("host", super.toString())
107 .add("location", connectPoint)
108 .add("retry", retry)
109 .add("mode", mode)
110 .add("probeMac", probeMac)
111 .toString();
112 }
113}