blob: fe53b539344e40fa4dcd3f0bfa65e1d56e552c1a [file] [log] [blame]
Daniel Park5ff76b72022-09-26 22:58:53 +09001/*
2 * Copyright 2022-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.kubevirtnode.api;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21
22import java.util.Objects;
23
24import static com.google.common.base.Preconditions.checkArgument;
25
26public class DefaultKubernetesExternalLbInterface implements KubernetesExternalLbInterface {
27
28 private static final String NOT_NULL_MSG = "KubernetesExternalLbInterface % cannot be null";
29
30 private String elbBridgeName;
31 private IpAddress elbIp;
32 private IpAddress elbGwIp;
33 private MacAddress elbGwMac;
34
35 public DefaultKubernetesExternalLbInterface(String elbBridgeName, IpAddress elbIp,
36 IpAddress elbGwIp, MacAddress elbGwMac) {
37 this.elbBridgeName = elbBridgeName;
38 this.elbIp = elbIp;
39 this.elbGwIp = elbGwIp;
40 this.elbGwMac = elbGwMac;
41 }
42
43 @Override
44 public String externalLbBridgeName() {
45 return elbBridgeName;
46 }
47
48 @Override
49 public IpAddress externalLbIp() {
50 return elbIp;
51 }
52
53 @Override
54 public IpAddress externalLbGwIp() {
55 return elbGwIp;
56 }
57
58 @Override
59 public MacAddress externalLbGwMac() {
60 return elbGwMac;
61 }
62
63 @Override
64 public boolean equals(Object o) {
65 if (this == o) {
66 return true;
67 }
68 if (o == null || getClass() != o.getClass()) {
69 return false;
70 }
71
72 DefaultKubernetesExternalLbInterface that = (DefaultKubernetesExternalLbInterface) o;
73
74 return Objects.equals(elbBridgeName, that.elbBridgeName) &&
75 Objects.equals(elbIp, that.elbIp) &&
76 Objects.equals(elbGwIp, that.elbGwIp);
77 }
78
79 @Override
80 public String toString() {
81 return MoreObjects.toStringHelper(this)
82 .add("elbBridgeName", elbBridgeName)
83 .add("elbIp", elbIp)
84 .add("elbGwIp", elbGwIp)
85 .add("elbGwMac", elbGwMac)
86 .toString();
87 }
88
89 @Override
90 public int hashCode() {
91 return Objects.hash(elbBridgeName, elbIp, elbGwIp);
92 }
93
94 public static Builder builder() {
95 return new Builder();
96 }
97
98 public static final class Builder implements KubernetesExternalLbInterface.Builder {
99 private String elbBridgeName;
100 private IpAddress elbIp;
101 private IpAddress elbGwIp;
102 private MacAddress elbGwMac;
103
104 private Builder() {
105 }
106
107 @Override
108 public KubernetesExternalLbInterface build() {
109 checkArgument(elbBridgeName != null, NOT_NULL_MSG, "externalLbBridgeName");
110 checkArgument(elbIp != null, NOT_NULL_MSG, "externalLbIp");
111 checkArgument(elbGwIp != null, NOT_NULL_MSG, "externalLbGwIp");
112 checkArgument(elbGwMac != null, NOT_NULL_MSG, "externalLbGwMac");
113
114 return new DefaultKubernetesExternalLbInterface(elbBridgeName, elbIp, elbGwIp, elbGwMac);
115 }
116
117 @Override
118 public Builder externalLbBridgeName(String elbBridgeName) {
119 this.elbBridgeName = elbBridgeName;
120 return this;
121 }
122
123 @Override
124 public Builder externalLbIp(IpAddress elbIp) {
125 this.elbIp = elbIp;
126 return this;
127 }
128
129 @Override
130 public Builder externallbGwIp(IpAddress elbGwIp) {
131 this.elbGwIp = elbGwIp;
132 return this;
133 }
134
135 @Override
136 public Builder externalLbGwMac(MacAddress elbGwMac) {
137 this.elbGwMac = elbGwMac;
138 return this;
139 }
140 }
141}