blob: 226f1b55dd382529aafb8dc7dbb584a4e645f383 [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,
Andrea Campanella34ce61a2022-04-28 18:55:46 +020038 // Used for the remove subscriber calls from REST/CLI
39 ADMIN_REMOVED,
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070040 }
41
42 public Port port;
43 public Device device;
44 public Enum<Status> status;
45 public boolean hasSubscriber;
46 public SubscriberAndDeviceInformation subscriberAndDeviceInformation;
47
48 /**
49 * Creates the class with the proper information.
50 *
51 * @param device the device of the subscriber
52 * @param port the port
53 * @param status the status for this specific subscriber
54 * @param hasSubscriber is the subscriber present
55 * @param si the information about the tags/dhcp and other info.
56 */
57 public DiscoveredSubscriber(Device device, Port port, Status status, boolean hasSubscriber,
58 SubscriberAndDeviceInformation si) {
59 this.device = device;
60 this.port = port;
61 this.status = status;
62 this.hasSubscriber = hasSubscriber;
63 subscriberAndDeviceInformation = si;
64 }
65
66 /**
67 * Returns the port name for the subscriber.
68 *
69 * @return the port name.
70 */
71 public String portName() {
72 return OltUtils.getPortName(port);
73 }
74
75 @Override
76 public String toString() {
77
78 return String.format("%s (status: %s, provisionSubscriber: %s)",
79 portWithName(this.port),
80 this.status, this.hasSubscriber
81 );
82 }
83
84 @Override
85 public boolean equals(Object o) {
86 if (this == o) {
87 return true;
88 }
89 if (o == null || getClass() != o.getClass()) {
90 return false;
91 }
92 DiscoveredSubscriber that = (DiscoveredSubscriber) o;
93 return hasSubscriber == that.hasSubscriber &&
94 port.equals(that.port) &&
95 device.equals(that.device) &&
96 status.equals(that.status);
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(port, device, status, hasSubscriber, subscriberAndDeviceInformation);
102 }
103}