blob: 3c377ffa0dbf885a0bc0645ad705e4f77edd3215 [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.PortNumber;
19
20import java.util.Objects;
21import java.util.Set;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Represents L2 load balancer information.
27 */
28public class L2Lb {
29 private L2LbId l2LbId;
30 private Set<PortNumber> ports;
31 private L2LbMode mode;
32
33 /**
34 * Constructs a L2 load balancer.
35 *
36 * @param l2LbId L2 load balancer ID
37 * @param ports Set of member ports
38 * @param mode L2 load balancer mode
39 */
40 public L2Lb(L2LbId l2LbId, Set<PortNumber> ports, L2LbMode mode) {
41 this.l2LbId = l2LbId;
42 this.ports = ports;
43 this.mode = mode;
44 }
45
46 /**
47 * Gets L2 load balancer ID.
48 *
49 * @return L2 load balancer ID
50 */
51 public L2LbId l2LbId() {
52 return l2LbId;
53 }
54
55 /**
56 * Gets set of member ports.
57 *
58 * @return Set of member ports
59 */
60 public Set<PortNumber> ports() {
61 return ports;
62 }
63
64 /**
65 * Gets L2 load balancer mode.
66 *
67 * @return L2 load balancer mode.
68 */
69 public L2LbMode mode() {
70 return mode;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(l2LbId, ports, mode);
76 }
77
78 @Override
79 public boolean equals(final Object obj) {
80 if (this == obj) {
81 return true;
82 }
83 if (!(obj instanceof L2Lb)) {
84 return false;
85 }
86 final L2Lb other = (L2Lb) obj;
87
88 return Objects.equals(this.l2LbId, other.l2LbId) &&
89 Objects.equals(this.ports, other.ports) &&
90 this.mode == other.mode;
91 }
92
93 @Override
94 public String toString() {
95 return toStringHelper(getClass())
96 .add("l2LbId", l2LbId)
97 .add("ports", ports)
98 .add("mode", mode)
99 .toString();
100 }
101}