blob: 68bcc478e8e5d39fac25c366d86670adae3c97ac [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 */
16package org.onosproject.l2lb.api;
17
18import org.onosproject.net.DeviceId;
19
20import java.util.Objects;
21
Charles Chan7e6d5172019-01-01 19:36:05 -080022/**
23 * L2 load balancer identifier.
24 * It is used to identify a load balancer across the entire system and therefore has to be unique system-wide.
25 */
Charles Chan7f987c52018-07-31 18:22:46 -070026public class L2LbId {
27 private final DeviceId deviceId;
Charles Chan7e6d5172019-01-01 19:36:05 -080028
29 /**
30 * L2 load balancer key.
31 * 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 /**
36 * Constructs L2 load balancer ID.
37 *
38 * @param deviceId device ID
39 * @param key L2 load balancer key
40 */
41 public L2LbId(DeviceId deviceId, int key) {
42 this.deviceId = deviceId;
43 this.key = key;
44 }
45
46 /**
47 * Returns L2 load balancer device ID.
48 *
49 * @return L2 load balancer device ID
50 */
51 public DeviceId deviceId() {
52 return deviceId;
53 }
54
55 /**
56 * Returns L2 load balancer key.
57 *
58 * @return L2 load balancer key
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 }
74 if (!(obj instanceof L2LbId)) {
75 return false;
76 }
77 final L2LbId other = (L2LbId) obj;
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 Chan7e6d5172019-01-01 19:36:05 -080085 return deviceId.toString() + ":" + key;
Charles Chan7f987c52018-07-31 18:22:46 -070086 }
87}