blob: cc19ff778dd1555d28f92ab59852ad173de64e05 [file] [log] [blame]
Jian Lie2a04ce2020-07-01 19:07:02 +09001/*
2 * Copyright 2020-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.k8snode.api;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21
22import java.util.Objects;
23
24/**
25 * Representation of a external network.
26 */
27public class DefaultK8sExternalNetwork implements K8sExternalNetwork {
28
29 private final IpAddress extBridgeIp;
30 private final IpAddress extGatewayIp;
31 private final MacAddress extGatewayMac;
32
33 protected DefaultK8sExternalNetwork(IpAddress extBridgeIp, IpAddress extGatewayIp,
34 MacAddress extGatewayMac) {
35 this.extBridgeIp = extBridgeIp;
36 this.extGatewayIp = extGatewayIp;
37 this.extGatewayMac = extGatewayMac;
38 }
39
40 @Override
41 public IpAddress extBridgeIp() {
42 return extBridgeIp;
43 }
44
45 @Override
46 public IpAddress extGatewayIp() {
47 return extGatewayIp;
48 }
49
50 @Override
51 public MacAddress extGatewayMac() {
52 return extGatewayMac;
53 }
54
55 /**
56 * Returns new builder instance.
57 *
58 * @return kubernetes node builder
59 */
60 public static Builder builder() {
61 return new Builder();
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) {
67 return true;
68 }
69 if (o == null || getClass() != o.getClass()) {
70 return false;
71 }
72 DefaultK8sExternalNetwork that = (DefaultK8sExternalNetwork) o;
73 return extBridgeIp.equals(that.extBridgeIp) &&
74 extGatewayIp.equals(that.extGatewayIp);
75 }
76
77 @Override
78 public int hashCode() {
79 return Objects.hash(extBridgeIp, extGatewayIp, extGatewayMac);
80 }
81
82 @Override
83 public String toString() {
84 return MoreObjects.toStringHelper(this)
85 .add("extBridgeIp", extBridgeIp)
86 .add("extGatewayIp", extGatewayIp)
87 .add("extGatewayMac", extGatewayMac)
88 .toString();
89 }
90
91 public static final class Builder implements K8sExternalNetwork.Builder {
92
93 private IpAddress extBridgeIp;
94 private IpAddress extGatewayIp;
95 private MacAddress extGatewayMac;
96
97 // private constructor not intended to use from external
98 private Builder() {
99 }
100
101 @Override
102 public K8sExternalNetwork build() {
103 return new DefaultK8sExternalNetwork(extBridgeIp, extGatewayIp, extGatewayMac);
104 }
105
106 @Override
107 public Builder extBridgeIp(IpAddress extBridgeIp) {
108 this.extBridgeIp = extBridgeIp;
109 return this;
110 }
111
112 @Override
113 public Builder extGatewayIp(IpAddress extGatewayIp) {
114 this.extGatewayIp = extGatewayIp;
115 return this;
116 }
117
118 @Override
119 public Builder extGatewayMac(MacAddress extGatewayMac) {
120 this.extGatewayMac = extGatewayMac;
121 return this;
122 }
123 }
124}