blob: 4280eafd9e79cd3365acfac2dceb4304db55d7d2 [file] [log] [blame]
Matteo Scandoloaa2adde2021-09-13 12:45:32 -07001/*
2 * Copyright 2021-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 */
16
17package org.opencord.olt.impl;
18
19import org.onosproject.net.Device;
20import org.onosproject.net.Port;
21import org.opencord.sadis.SubscriberAndDeviceInformation;
22
23import java.util.Objects;
24
25import static org.opencord.olt.impl.OltUtils.portWithName;
26
27/**
28 * Contains a subscriber's information and status for a specific device and port.
29 */
30public class DiscoveredSubscriber {
31
32 /**
33 * Describe whether the subscriber needs to be added or removed.
34 */
35 public enum Status {
36 ADDED,
37 REMOVED,
38 }
39
40 public Port port;
41 public Device device;
42 public Enum<Status> status;
43 public boolean hasSubscriber;
44 public SubscriberAndDeviceInformation subscriberAndDeviceInformation;
45
46 /**
47 * Creates the class with the proper information.
48 *
49 * @param device the device of the subscriber
50 * @param port the port
51 * @param status the status for this specific subscriber
52 * @param hasSubscriber is the subscriber present
53 * @param si the information about the tags/dhcp and other info.
54 */
55 public DiscoveredSubscriber(Device device, Port port, Status status, boolean hasSubscriber,
56 SubscriberAndDeviceInformation si) {
57 this.device = device;
58 this.port = port;
59 this.status = status;
60 this.hasSubscriber = hasSubscriber;
61 subscriberAndDeviceInformation = si;
62 }
63
64 /**
65 * Returns the port name for the subscriber.
66 *
67 * @return the port name.
68 */
69 public String portName() {
70 return OltUtils.getPortName(port);
71 }
72
73 @Override
74 public String toString() {
75
76 return String.format("%s (status: %s, provisionSubscriber: %s)",
77 portWithName(this.port),
78 this.status, this.hasSubscriber
79 );
80 }
81
82 @Override
83 public boolean equals(Object o) {
84 if (this == o) {
85 return true;
86 }
87 if (o == null || getClass() != o.getClass()) {
88 return false;
89 }
90 DiscoveredSubscriber that = (DiscoveredSubscriber) o;
91 return hasSubscriber == that.hasSubscriber &&
92 port.equals(that.port) &&
93 device.equals(that.device) &&
94 status.equals(that.status);
95 }
96
97 @Override
98 public int hashCode() {
99 return Objects.hash(port, device, status, hasSubscriber, subscriberAndDeviceInformation);
100 }
101}