Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.k8snetworking.api; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | |
| 22 | /** |
| 23 | * Default implementation of kubernetes IPAM instance. |
| 24 | */ |
| 25 | public final class DefaultK8sIpam implements K8sIpam { |
| 26 | |
Jian Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 27 | private final String ipamId; |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 28 | private final IpAddress ipAddress; |
| 29 | private final String networkId; |
| 30 | |
| 31 | // private constructor not intended for external invocation |
Jian Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 32 | public DefaultK8sIpam(String ipamId, IpAddress ipAddress, String networkId) { |
| 33 | this.ipamId = ipamId; |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 34 | this.ipAddress = ipAddress; |
| 35 | this.networkId = networkId; |
| 36 | } |
| 37 | |
| 38 | @Override |
Jian Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 39 | public String ipamId() { |
| 40 | return ipamId; |
| 41 | } |
| 42 | |
| 43 | @Override |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 44 | 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 Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 62 | return Objects.equal(ipamId, that.ipamId) && |
| 63 | Objects.equal(ipAddress, that.ipAddress) && |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 64 | Objects.equal(networkId, that.networkId); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public int hashCode() { |
Jian Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 69 | return Objects.hashCode(ipamId, ipAddress, networkId); |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return MoreObjects.toStringHelper(this) |
Jian Li | 9b19916 | 2019-02-10 18:00:35 +0900 | [diff] [blame] | 75 | .add("ipamId", ipamId) |
Jian Li | 9ee9c8b | 2019-01-24 11:48:12 +0900 | [diff] [blame] | 76 | .add("ipAddress", ipAddress) |
| 77 | .add("networkId", networkId) |
| 78 | .toString(); |
| 79 | } |
| 80 | } |