Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 17 | package org.opencord.olt; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 18 | |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 19 | import org.onosproject.net.AnnotationKeys; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
| 21 | import org.onosproject.net.Port; |
| 22 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 23 | |
| 24 | import java.util.Objects; |
| 25 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Contains a subscriber's information and status for a specific device and port. |
| 28 | */ |
| 29 | public class DiscoveredSubscriber { |
| 30 | |
| 31 | /** |
| 32 | * Describe whether the subscriber needs to be added or removed. |
| 33 | */ |
| 34 | public enum Status { |
| 35 | ADDED, |
| 36 | REMOVED, |
Andrea Campanella | 34ce61a | 2022-04-28 18:55:46 +0200 | [diff] [blame] | 37 | // Used for the remove subscriber calls from REST/CLI |
| 38 | ADMIN_REMOVED, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | public Port port; |
| 42 | public Device device; |
| 43 | public Enum<Status> status; |
| 44 | public boolean hasSubscriber; |
| 45 | public SubscriberAndDeviceInformation subscriberAndDeviceInformation; |
| 46 | |
| 47 | /** |
| 48 | * Creates the class with the proper information. |
| 49 | * |
| 50 | * @param device the device of the subscriber |
| 51 | * @param port the port |
| 52 | * @param status the status for this specific subscriber |
| 53 | * @param hasSubscriber is the subscriber present |
| 54 | * @param si the information about the tags/dhcp and other info. |
| 55 | */ |
| 56 | public DiscoveredSubscriber(Device device, Port port, Status status, boolean hasSubscriber, |
| 57 | SubscriberAndDeviceInformation si) { |
| 58 | this.device = device; |
| 59 | this.port = port; |
| 60 | this.status = status; |
| 61 | this.hasSubscriber = hasSubscriber; |
| 62 | subscriberAndDeviceInformation = si; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the port name for the subscriber. |
| 67 | * |
| 68 | * @return the port name. |
| 69 | */ |
| 70 | public String portName() { |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 71 | return getPortName(port); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | |
| 77 | return String.format("%s (status: %s, provisionSubscriber: %s)", |
| 78 | portWithName(this.port), |
| 79 | this.status, this.hasSubscriber |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public boolean equals(Object o) { |
| 85 | if (this == o) { |
| 86 | return true; |
| 87 | } |
| 88 | if (o == null || getClass() != o.getClass()) { |
| 89 | return false; |
| 90 | } |
| 91 | DiscoveredSubscriber that = (DiscoveredSubscriber) o; |
| 92 | return hasSubscriber == that.hasSubscriber && |
| 93 | port.equals(that.port) && |
| 94 | device.equals(that.device) && |
| 95 | status.equals(that.status); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hash(port, device, status, hasSubscriber, subscriberAndDeviceInformation); |
| 101 | } |
Gustavo Silva | 29fb20e | 2022-05-26 09:59:54 -0300 | [diff] [blame] | 102 | |
| 103 | private String portWithName(Port port) { |
| 104 | return port.element().id().toString() + '/' + |
| 105 | port.number() + '[' + |
| 106 | getPortName(port) + ']'; |
| 107 | } |
| 108 | private String getPortName(Port port) { |
| 109 | String name = port.annotations().value(AnnotationKeys.PORT_NAME); |
| 110 | return name == null ? "" : name; |
| 111 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 112 | } |