blob: 3290b1df0fb04dca112795532fb197d89d5b2eb5 [file] [log] [blame]
Jian Li0b93b002018-07-31 13:41:08 +09001/*
2 * Copyright 2018-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 */
16package org.onosproject.openstacktroubleshoot.impl;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onosproject.openstacktroubleshoot.api.Reachability;
21
22import java.util.Objects;
23
24/**
25 * Implementation of reachability.
26 */
27public final class DefaultReachability implements Reachability {
28
29 private final IpAddress srcIp;
30 private final IpAddress dstIp;
31 private final boolean isReachable;
32
33 private DefaultReachability(IpAddress srcIp, IpAddress dstIp, boolean isReachable) {
34 this.srcIp = srcIp;
35 this.dstIp = dstIp;
36 this.isReachable = isReachable;
37 }
38
39 @Override
40 public IpAddress srcIp() {
41 return srcIp;
42 }
43
44 @Override
45 public IpAddress dstIp() {
46 return dstIp;
47 }
48
49 @Override
50 public boolean isReachable() {
51 return isReachable;
52 }
53
54 @Override
55 public boolean equals(Object obj) {
56 if (this == obj) {
57 return true;
58 }
59
60 if (obj instanceof DefaultReachability) {
61 DefaultReachability that = (DefaultReachability) obj;
62 return Objects.equals(srcIp, that.srcIp) &&
63 Objects.equals(dstIp, that.dstIp) &&
64 Objects.equals(isReachable, that.isReachable);
65 }
66 return false;
67 }
68
69 @Override
70 public int hashCode() {
71 return Objects.hash(srcIp, dstIp, isReachable);
72 }
73
74 @Override
75 public String toString() {
76 return MoreObjects.toStringHelper(getClass())
77 .add("srcIp", srcIp)
78 .add("dstIp", dstIp)
79 .add("isReachable", isReachable)
80 .toString();
81 }
82
83 /**
84 * Obtains a reachability builder.
85 *
86 * @return reachability builder
87 */
88 public static Builder builder() {
89 return new DefaultBuilder();
90 }
91
92 /**
93 * A builder class for reachability.
94 */
95 public static final class DefaultBuilder implements Builder {
96
97 private IpAddress srcIp;
98 private IpAddress dstIp;
99 private boolean isReachable;
100
101 @Override
102 public Builder srcIp(IpAddress srcIp) {
103 this.srcIp = srcIp;
104 return this;
105 }
106
107 @Override
108 public Builder dstIp(IpAddress dstIp) {
109 this.dstIp = dstIp;
110 return this;
111 }
112
113 @Override
114 public Builder isReachable(boolean isReachable) {
115 this.isReachable = isReachable;
116 return this;
117 }
118
119 @Override
120 public Reachability build() {
121 return new DefaultReachability(srcIp, dstIp, isReachable);
122 }
123 }
124}