Brian O'Connor | 5dcf578 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | d6a135a | 2017-08-03 22:46:05 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Brian O'Connor | 5dcf578 | 2016-04-09 02:13:23 -0700 | [diff] [blame] | 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 | */ |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 16 | package org.opencord.olt; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 17 | |
| 18 | import org.onlab.packet.VlanId; |
| 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.DeviceId; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 21 | import org.onosproject.net.Port; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 22 | |
| 23 | import java.util.Optional; |
| 24 | |
| 25 | /** |
| 26 | * Describes an access device event. |
| 27 | */ |
| 28 | public class AccessDeviceEvent extends AbstractEvent<AccessDeviceEvent.Type, DeviceId> { |
| 29 | |
| 30 | private final Optional<VlanId> sVlan; |
| 31 | private final Optional<VlanId> cVlan; |
| 32 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 33 | private final Optional<Port> port; |
| 34 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 35 | public enum Type { |
| 36 | /** |
| 37 | * A subscriber was registered and provisioned. |
| 38 | */ |
| 39 | SUBSCRIBER_REGISTERED, |
| 40 | |
| 41 | /** |
| 42 | * A subscriber was unregistered and deprovisioned. |
| 43 | */ |
| 44 | SUBSCRIBER_UNREGISTERED, |
| 45 | |
| 46 | /** |
| 47 | * An access device connected. |
| 48 | */ |
| 49 | DEVICE_CONNECTED, |
| 50 | |
| 51 | /** |
| 52 | * An access device disconnected. |
| 53 | */ |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 54 | DEVICE_DISCONNECTED, |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 55 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 56 | /** |
| 57 | * A new UNI port has been detected. |
| 58 | */ |
| 59 | UNI_ADDED, |
| 60 | |
| 61 | /** |
| 62 | * An existing UNI port was removed. |
| 63 | */ |
| 64 | UNI_REMOVED |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
| 68 | * |
| 69 | * Creates an event of a given type and for the specified device, |
| 70 | * along with the cVlanId and sVlanId. The vlan fields may not be provisioned |
| 71 | * if the event is related to the access device (dis)connection. |
| 72 | * |
| 73 | * @param type the event type |
| 74 | * @param deviceId the device id |
| 75 | * @param sVlanId the service vlan |
| 76 | * @param cVlanId the customer vlan |
| 77 | */ |
| 78 | public AccessDeviceEvent(Type type, DeviceId deviceId, |
| 79 | VlanId sVlanId, |
| 80 | VlanId cVlanId) { |
| 81 | super(type, deviceId); |
| 82 | this.sVlan = Optional.ofNullable(sVlanId); |
| 83 | this.cVlan = Optional.ofNullable(cVlanId); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 84 | this.port = Optional.empty(); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /** |
| 88 | * |
| 89 | * Creates an event of a given type and for the specified device, and timestamp |
| 90 | * along with the cVlanId and sVlanId. The vlan fields may not be provisioned |
| 91 | * if the event is related to the access device (dis)connection. |
| 92 | * |
| 93 | * @param type the event type |
| 94 | * @param deviceId the device id |
| 95 | * @param time a timestamp |
| 96 | * @param sVlanId the service vlan |
| 97 | * @param cVlanId the customer vlan |
| 98 | */ |
| 99 | protected AccessDeviceEvent(Type type, DeviceId deviceId, long time, |
| 100 | VlanId sVlanId, |
| 101 | VlanId cVlanId) { |
| 102 | super(type, deviceId, time); |
| 103 | this.sVlan = Optional.ofNullable(sVlanId); |
| 104 | this.cVlan = Optional.ofNullable(cVlanId); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 105 | this.port = Optional.empty(); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 106 | |
| 107 | } |
| 108 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 109 | public AccessDeviceEvent(Type type, DeviceId deviceId, Port port) { |
| 110 | super(type, deviceId); |
| 111 | this.sVlan = Optional.empty(); |
| 112 | this.cVlan = Optional.empty(); |
| 113 | this.port = Optional.ofNullable(port); |
| 114 | } |
| 115 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 116 | public Optional<VlanId> sVlanId() { |
| 117 | return sVlan; |
| 118 | } |
| 119 | |
| 120 | public Optional<VlanId> cVlanId() { |
| 121 | return cVlan; |
| 122 | } |
| 123 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 124 | public Optional<Port> port() { |
| 125 | return port; |
| 126 | } |
| 127 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 128 | } |