blob: 8d837f4eb58384c89b84940d574df4c7420e84c3 [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
Gustavo Silva29fb20e2022-05-26 09:59:54 -030017package org.opencord.olt;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070018
Gustavo Silva29fb20e2022-05-26 09:59:54 -030019import org.onosproject.net.AnnotationKeys;
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070020import org.onosproject.net.Device;
21import org.onosproject.net.Port;
22import org.opencord.sadis.SubscriberAndDeviceInformation;
23
24import java.util.Objects;
25
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070026/**
27 * Contains a subscriber's information and status for a specific device and port.
28 */
29public 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 Campanella34ce61a2022-04-28 18:55:46 +020037 // Used for the remove subscriber calls from REST/CLI
38 ADMIN_REMOVED,
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070039 }
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 Silva29fb20e2022-05-26 09:59:54 -030071 return getPortName(port);
Matteo Scandoloaa2adde2021-09-13 12:45:32 -070072 }
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 Silva29fb20e2022-05-26 09:59:54 -0300102
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 Scandoloaa2adde2021-09-13 12:45:32 -0700112}