blob: a102dd5023851cb01ac472177ead54a08aeff25a [file] [log] [blame]
Charles Chan7f987c52018-07-31 18:22:46 -07001/*
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 Chanf7b1b4b2019-01-16 15:30:39 -080016package org.onosproject.portloadbalancer.api;
Charles Chan7f987c52018-07-31 18:22:46 -070017
18import org.onosproject.net.DeviceId;
19
20import java.util.Objects;
21
Charles Chan7e6d5172019-01-01 19:36:05 -080022/**
Charles Chanf7b1b4b2019-01-16 15:30:39 -080023 * Port load balancer identifier.
Charles Chan7e6d5172019-01-01 19:36:05 -080024 * It is used to identify a load balancer across the entire system and therefore has to be unique system-wide.
25 */
Charles Chanf7b1b4b2019-01-16 15:30:39 -080026public class PortLoadBalancerId {
Charles Chan7f987c52018-07-31 18:22:46 -070027 private final DeviceId deviceId;
Charles Chan7e6d5172019-01-01 19:36:05 -080028
29 /**
Charles Chanf7b1b4b2019-01-16 15:30:39 -080030 * Port load balancer key.
Charles Chan7e6d5172019-01-01 19:36:05 -080031 * It is used to identify a load balancer on a specific device and therefore has to be unique device-wide.
32 */
Charles Chan7f987c52018-07-31 18:22:46 -070033 private final int key;
34
35 /**
Charles Chanf7b1b4b2019-01-16 15:30:39 -080036 * Constructs port load balancer ID.
Charles Chan7f987c52018-07-31 18:22:46 -070037 *
38 * @param deviceId device ID
Charles Chanf7b1b4b2019-01-16 15:30:39 -080039 * @param key port load balancer key
Charles Chan7f987c52018-07-31 18:22:46 -070040 */
Charles Chanf7b1b4b2019-01-16 15:30:39 -080041 public PortLoadBalancerId(DeviceId deviceId, int key) {
Charles Chan7f987c52018-07-31 18:22:46 -070042 this.deviceId = deviceId;
43 this.key = key;
44 }
45
46 /**
Charles Chanf7b1b4b2019-01-16 15:30:39 -080047 * Returns port load balancer device ID.
Charles Chan7f987c52018-07-31 18:22:46 -070048 *
Charles Chanf7b1b4b2019-01-16 15:30:39 -080049 * @return port load balancer device ID
Charles Chan7f987c52018-07-31 18:22:46 -070050 */
51 public DeviceId deviceId() {
52 return deviceId;
53 }
54
55 /**
Charles Chanf7b1b4b2019-01-16 15:30:39 -080056 * Returns port load balancer key.
Charles Chan7f987c52018-07-31 18:22:46 -070057 *
Charles Chanf7b1b4b2019-01-16 15:30:39 -080058 * @return port load balancer key
Charles Chan7f987c52018-07-31 18:22:46 -070059 */
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 Chanf7b1b4b2019-01-16 15:30:39 -080074 if (!(obj instanceof PortLoadBalancerId)) {
Charles Chan7f987c52018-07-31 18:22:46 -070075 return false;
76 }
Charles Chanf7b1b4b2019-01-16 15:30:39 -080077 final PortLoadBalancerId other = (PortLoadBalancerId) obj;
Charles Chan7f987c52018-07-31 18:22:46 -070078
79 return Objects.equals(this.deviceId, other.deviceId) &&
80 Objects.equals(this.key, other.key);
81 }
82
83 @Override
84 public String toString() {
Charles Chan7e6d5172019-01-01 19:36:05 -080085 return deviceId.toString() + ":" + key;
Charles Chan7f987c52018-07-31 18:22:46 -070086 }
87}