blob: 605cdea5e1cee100b26a33c1bea316026ebc90b1 [file] [log] [blame]
Jian Li9ee9c8b2019-01-24 11:48:12 +09001/*
2 * Copyright 2019-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.k8snetworking.api;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.base.Objects;
20import org.onlab.packet.IpAddress;
21
22/**
23 * Default implementation of kubernetes IPAM instance.
24 */
25public final class DefaultK8sIpam implements K8sIpam {
26
Jian Li9b199162019-02-10 18:00:35 +090027 private final String ipamId;
Jian Li9ee9c8b2019-01-24 11:48:12 +090028 private final IpAddress ipAddress;
29 private final String networkId;
30
31 // private constructor not intended for external invocation
Jian Li9b199162019-02-10 18:00:35 +090032 public DefaultK8sIpam(String ipamId, IpAddress ipAddress, String networkId) {
33 this.ipamId = ipamId;
Jian Li9ee9c8b2019-01-24 11:48:12 +090034 this.ipAddress = ipAddress;
35 this.networkId = networkId;
36 }
37
38 @Override
Jian Li9b199162019-02-10 18:00:35 +090039 public String ipamId() {
40 return ipamId;
41 }
42
43 @Override
Jian Li9ee9c8b2019-01-24 11:48:12 +090044 public IpAddress ipAddress() {
45 return ipAddress;
46 }
47
48 @Override
49 public String networkId() {
50 return networkId;
51 }
52
53 @Override
54 public boolean equals(Object o) {
55 if (this == o) {
56 return true;
57 }
58 if (o == null || getClass() != o.getClass()) {
59 return false;
60 }
61 DefaultK8sIpam that = (DefaultK8sIpam) o;
Jian Li9b199162019-02-10 18:00:35 +090062 return Objects.equal(ipamId, that.ipamId) &&
63 Objects.equal(ipAddress, that.ipAddress) &&
Jian Li9ee9c8b2019-01-24 11:48:12 +090064 Objects.equal(networkId, that.networkId);
65 }
66
67 @Override
68 public int hashCode() {
Jian Li9b199162019-02-10 18:00:35 +090069 return Objects.hashCode(ipamId, ipAddress, networkId);
Jian Li9ee9c8b2019-01-24 11:48:12 +090070 }
71
72 @Override
73 public String toString() {
74 return MoreObjects.toStringHelper(this)
Jian Li9b199162019-02-10 18:00:35 +090075 .add("ipamId", ipamId)
Jian Li9ee9c8b2019-01-24 11:48:12 +090076 .add("ipAddress", ipAddress)
77 .add("networkId", networkId)
78 .toString();
79 }
80}