Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 16 | package org.onosproject.portloadbalancer.api; |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.net.DeviceId; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
Charles Chan | 7e6d517 | 2019-01-01 19:36:05 -0800 | [diff] [blame] | 22 | /** |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 23 | * Port load balancer identifier. |
Charles Chan | 7e6d517 | 2019-01-01 19:36:05 -0800 | [diff] [blame] | 24 | * It is used to identify a load balancer across the entire system and therefore has to be unique system-wide. |
| 25 | */ |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 26 | public class PortLoadBalancerId { |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 27 | private final DeviceId deviceId; |
Charles Chan | 7e6d517 | 2019-01-01 19:36:05 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 30 | * Port load balancer key. |
Charles Chan | 7e6d517 | 2019-01-01 19:36:05 -0800 | [diff] [blame] | 31 | * It is used to identify a load balancer on a specific device and therefore has to be unique device-wide. |
| 32 | */ |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 33 | private final int key; |
| 34 | |
| 35 | /** |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 36 | * Constructs port load balancer ID. |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 37 | * |
| 38 | * @param deviceId device ID |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 39 | * @param key port load balancer key |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 40 | */ |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 41 | public PortLoadBalancerId(DeviceId deviceId, int key) { |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 42 | this.deviceId = deviceId; |
| 43 | this.key = key; |
| 44 | } |
| 45 | |
| 46 | /** |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 47 | * Returns port load balancer device ID. |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 48 | * |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 49 | * @return port load balancer device ID |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 50 | */ |
| 51 | public DeviceId deviceId() { |
| 52 | return deviceId; |
| 53 | } |
| 54 | |
| 55 | /** |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 56 | * Returns port load balancer key. |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 57 | * |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 58 | * @return port load balancer key |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 59 | */ |
| 60 | public int key() { |
| 61 | return key; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public int hashCode() { |
| 66 | return Objects.hash(deviceId, key); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(final Object obj) { |
| 71 | if (this == obj) { |
| 72 | return true; |
| 73 | } |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 74 | if (!(obj instanceof PortLoadBalancerId)) { |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 75 | return false; |
| 76 | } |
Charles Chan | f7b1b4b | 2019-01-16 15:30:39 -0800 | [diff] [blame] | 77 | final PortLoadBalancerId other = (PortLoadBalancerId) obj; |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 78 | |
| 79 | return Objects.equals(this.deviceId, other.deviceId) && |
| 80 | Objects.equals(this.key, other.key); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public String toString() { |
Charles Chan | 7e6d517 | 2019-01-01 19:36:05 -0800 | [diff] [blame] | 85 | return deviceId.toString() + ":" + key; |
Charles Chan | 7f987c5 | 2018-07-31 18:22:46 -0700 | [diff] [blame] | 86 | } |
| 87 | } |