blob: 6cd8df172ffc58138e0b0ddf54442acccac13af6 [file] [log] [blame]
Charles Chanf7b1b4b2019-01-16 15:30:39 -08001/*
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.portloadbalancer.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 port load balancer information.
27 */
28public class PortLoadBalancer {
29 private PortLoadBalancerId portLoadBalancerId;
30 private Set<PortNumber> ports;
31 private PortLoadBalancerMode mode;
32
33 /**
34 * Constructs a port load balancer.
35 *
36 * @param portLoadBalancerId port load balancer ID
37 * @param ports Set of member ports
38 * @param mode port load balancer mode
39 */
40 public PortLoadBalancer(PortLoadBalancerId portLoadBalancerId, Set<PortNumber> ports, PortLoadBalancerMode mode) {
41 this.portLoadBalancerId = portLoadBalancerId;
42 this.ports = ports;
43 this.mode = mode;
44 }
45
46 /**
47 * Gets port load balancer ID.
48 *
49 * @return port load balancer ID
50 */
51 public PortLoadBalancerId portLoadBalancerId() {
52 return portLoadBalancerId;
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 port load balancer mode.
66 *
67 * @return port load balancer mode.
68 */
69 public PortLoadBalancerMode mode() {
70 return mode;
71 }
72
73 /**
74 * Gets port load balancer data.
75 *
76 * @return port load balancer data
77 */
78 public PortLoadBalancerData data() {
79 return new PortLoadBalancerData(portLoadBalancerId);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(portLoadBalancerId, ports, mode);
85 }
86
87 @Override
88 public boolean equals(final Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (!(obj instanceof PortLoadBalancer)) {
93 return false;
94 }
95 final PortLoadBalancer other = (PortLoadBalancer) obj;
96
97 return Objects.equals(this.portLoadBalancerId, other.portLoadBalancerId) &&
98 Objects.equals(this.ports, other.ports) &&
99 this.mode == other.mode;
100 }
101
102 @Override
103 public String toString() {
104 return toStringHelper(getClass())
105 .add("id", portLoadBalancerId)
106 .add("ports", ports)
107 .add("mode", mode)
108 .toString();
109 }
110}