alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | d6a135a | 2017-08-03 22:46:05 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -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.impl; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 17 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 18 | import org.apache.felix.scr.annotations.Activate; |
| 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Modified; |
| 22 | import org.apache.felix.scr.annotations.Property; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Service; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 26 | import org.onlab.packet.EthType; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 27 | import org.onlab.packet.IPv4; |
| 28 | import org.onlab.packet.TpPort; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 30 | import org.onlab.util.Tools; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 31 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 34 | import org.onosproject.event.AbstractListenerManager; |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 35 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 36 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 37 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 38 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 39 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 40 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 41 | import org.onosproject.net.PortNumber; |
| 42 | import org.onosproject.net.device.DeviceEvent; |
| 43 | import org.onosproject.net.device.DeviceListener; |
| 44 | import org.onosproject.net.device.DeviceService; |
| 45 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 46 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 47 | import org.onosproject.net.flow.TrafficSelector; |
| 48 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 49 | import org.onosproject.net.flow.criteria.Criteria; |
| 50 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 52 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 53 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 54 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 55 | import org.onosproject.net.flowobjective.Objective; |
| 56 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 57 | import org.onosproject.net.flowobjective.ObjectiveError; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 58 | import org.opencord.olt.AccessDeviceEvent; |
| 59 | import org.opencord.olt.AccessDeviceListener; |
| 60 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 61 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 62 | import org.opencord.sadis.SubscriberAndDeviceInformationService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 63 | import org.osgi.service.component.ComponentContext; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 64 | import org.slf4j.Logger; |
| 65 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 66 | import java.util.AbstractMap; |
| 67 | import java.util.ArrayList; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 68 | import java.util.Collection; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 69 | import java.util.Dictionary; |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 70 | import java.util.List; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 71 | import java.util.Map; |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 72 | import java.util.Optional; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 73 | import java.util.Properties; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 74 | import java.util.concurrent.CompletableFuture; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 75 | import java.util.concurrent.ExecutorService; |
| 76 | import java.util.concurrent.Executors; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 77 | |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 78 | import static com.google.common.base.Preconditions.checkNotNull; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 79 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 80 | import static org.onlab.util.Tools.get; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 81 | import static org.onlab.util.Tools.groupedThreads; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 82 | import static org.slf4j.LoggerFactory.getLogger; |
| 83 | |
| 84 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 85 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 86 | */ |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 87 | @Service |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 88 | @Component(immediate = true) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 89 | public class Olt |
| 90 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 91 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 92 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 93 | |
| 94 | private static final short DEFAULT_VLAN = 0; |
| 95 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 96 | private final Logger log = getLogger(getClass()); |
| 97 | |
| 98 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 99 | protected FlowObjectiveService flowObjectiveService; |
| 100 | |
| 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 102 | protected MastershipService mastershipService; |
| 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 105 | protected DeviceService deviceService; |
| 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 108 | protected CoreService coreService; |
| 109 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 111 | protected ComponentConfigService componentConfigService; |
| 112 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 114 | protected SubscriberAndDeviceInformationService subsService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 115 | |
| 116 | @Property(name = "defaultVlan", intValue = DEFAULT_VLAN, |
| 117 | label = "Default VLAN RG<->ONU traffic") |
| 118 | private int defaultVlan = DEFAULT_VLAN; |
| 119 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 120 | @Property(name = "enableDhcpOnProvisioning", boolValue = true, |
| 121 | label = "Create the DHCP Flow rules when a subscriber is provisioned") |
| 122 | protected boolean enableDhcpOnProvisioning = false; |
| 123 | |
| 124 | @Property(name = "enableIgmpOnProvisioning", boolValue = false, |
| 125 | label = "Create IGMP Flow rules when a subscriber is provisioned") |
| 126 | protected boolean enableIgmpOnProvisioning = false; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 127 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 128 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
| 129 | |
| 130 | private ApplicationId appId; |
| 131 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 132 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 133 | groupedThreads("onos/olt-service", |
| 134 | "olt-installer-%d")); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 135 | |
| 136 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 137 | public void activate(ComponentContext context) { |
| 138 | modified(context); |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 139 | appId = coreService.registerApplication(APP_NAME); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 140 | componentConfigService.registerProperties(getClass()); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 141 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 142 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 143 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 144 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 145 | // UNI ports |
| 146 | Iterable<Device> devices = deviceService.getDevices(); |
| 147 | for (Device d : devices) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 148 | checkAndCreateDeviceFlows(d); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 149 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 150 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 151 | deviceService.addListener(deviceListener); |
| 152 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 153 | log.info("Started with Application ID {}", appId.id()); |
| 154 | } |
| 155 | |
| 156 | @Deactivate |
| 157 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 158 | componentConfigService.unregisterProperties(getClass(), false); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 159 | deviceService.removeListener(deviceListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 160 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 161 | log.info("Stopped"); |
| 162 | } |
| 163 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 164 | @Modified |
| 165 | public void modified(ComponentContext context) { |
| 166 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 167 | |
| 168 | try { |
| 169 | String s = get(properties, "defaultVlan"); |
| 170 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 171 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 172 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 173 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 174 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 175 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 176 | |
| 177 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 178 | if (p != null) { |
| 179 | enableIgmpOnProvisioning = p; |
| 180 | } |
| 181 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 182 | } catch (Exception e) { |
| 183 | defaultVlan = DEFAULT_VLAN; |
| 184 | } |
| 185 | } |
| 186 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 187 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 188 | public void provisionSubscriber(ConnectPoint port) { |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 189 | checkNotNull(deviceService.getPort(port.deviceId(), port.port()), |
| 190 | "Invalid connect point"); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 191 | // Find the subscriber on this connect point |
| 192 | SubscriberAndDeviceInformation sub = getSubscriber(port); |
| 193 | if (sub == null) { |
| 194 | log.warn("No subscriber found for {}", port); |
| 195 | return; |
| 196 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 197 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 198 | // Get the uplink port |
| 199 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 200 | if (uplinkPort == null) { |
| 201 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
| 202 | return; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 205 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 206 | processDhcpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 209 | Optional<VlanId> defaultVlan = Optional.empty(); |
| 210 | provisionVlans(port.deviceId(), uplinkPort.number(), port.port(), sub.cTag(), sub.sTag(), |
| 211 | defaultVlan); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 212 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 213 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 214 | processIgmpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 215 | } |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void removeSubscriber(ConnectPoint port) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 220 | // Get the subscriber connected to this port from Sadis |
| 221 | SubscriberAndDeviceInformation subscriber = getSubscriber(port); |
| 222 | if (subscriber == null) { |
| 223 | log.warn("Subscriber on port {} not found", port); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 224 | return; |
| 225 | } |
| 226 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 227 | // Get the uplink port |
| 228 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 229 | if (uplinkPort == null) { |
| 230 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 231 | return; |
| 232 | } |
| 233 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 234 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 235 | processDhcpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 238 | Optional<VlanId> defaultVlan = Optional.empty(); |
| 239 | unprovisionSubscriber(port.deviceId(), uplinkPort.number(), port.port(), subscriber.cTag(), |
| 240 | subscriber.sTag(), defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 241 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 242 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 243 | processIgmpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 244 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 247 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 248 | @Override |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 249 | public Collection<Map.Entry<ConnectPoint, VlanId>> getSubscribers() { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 250 | ArrayList<Map.Entry<ConnectPoint, VlanId>> subs = new ArrayList<>(); |
| 251 | |
| 252 | // Get the subscribers for all the devices |
| 253 | // If the port is UNI, is enabled and exists in Sadis then copy it |
| 254 | for (Device d : deviceService.getDevices()) { |
| 255 | for (Port p: deviceService.getPorts(d.id())) { |
| 256 | if (isUniPort(d, p) && p.isEnabled()) { |
| 257 | ConnectPoint cp = new ConnectPoint(d.id(), p.number()); |
| 258 | |
| 259 | SubscriberAndDeviceInformation sub = getSubscriber(cp); |
| 260 | if (sub != null) { |
| 261 | subs.add(new AbstractMap.SimpleEntry(cp, sub.cTag())); |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | return subs; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 271 | public List<DeviceId> fetchOlts() { |
| 272 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 273 | List<DeviceId> olts = new ArrayList<>(); |
| 274 | Iterable<Device> devices = deviceService.getDevices(); |
| 275 | for (Device d : devices) { |
| 276 | String devSerialNo = d.serialNumber(); |
| 277 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 278 | |
| 279 | if (deviceInfo != null) { |
| 280 | // So this is indeed a OLT device |
| 281 | olts.add(d.id()); |
| 282 | } |
| 283 | } |
| 284 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 287 | private void initializeUni(Port port) { |
| 288 | DeviceId deviceId = (DeviceId) port.element().id(); |
| 289 | |
| 290 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, deviceId, port)); |
| 291 | |
| 292 | if (port.isEnabled()) { |
| 293 | processFilteringObjectives(deviceId, port.number(), true); |
| 294 | } |
| 295 | } |
| 296 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 297 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 298 | PortNumber subscriberPort, VlanId subscriberVlan, |
| 299 | VlanId deviceVlan, Optional<VlanId> defaultVlan) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 300 | |
| 301 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 302 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 303 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 304 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
| 305 | subscriberVlan, deviceVlan, |
| 306 | defaultVlan); |
| 307 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
| 308 | subscriberVlan, deviceVlan, |
| 309 | defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 310 | |
| 311 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 312 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 313 | @Override |
| 314 | public void onSuccess(Objective objective) { |
| 315 | upFuture.complete(null); |
| 316 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 317 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 318 | @Override |
| 319 | public void onError(Objective objective, ObjectiveError error) { |
| 320 | upFuture.complete(error); |
| 321 | } |
| 322 | })); |
| 323 | |
| 324 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 325 | @Override |
| 326 | public void onSuccess(Objective objective) { |
| 327 | downFuture.complete(null); |
| 328 | } |
| 329 | |
| 330 | @Override |
| 331 | public void onError(Objective objective, ObjectiveError error) { |
| 332 | downFuture.complete(error); |
| 333 | } |
| 334 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 335 | |
| 336 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 337 | if (upStatus == null && downStatus == null) { |
| 338 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
| 339 | deviceId, |
| 340 | deviceVlan, |
| 341 | subscriberVlan)); |
| 342 | } else if (downStatus != null) { |
| 343 | log.error("Subscriber with vlan {} on device {} " + |
| 344 | "on port {} failed downstream uninstallation: {}", |
| 345 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 346 | } else if (upStatus != null) { |
| 347 | log.error("Subscriber with vlan {} on device {} " + |
| 348 | "on port {} failed upstream uninstallation: {}", |
| 349 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 350 | } |
| 351 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 352 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
| 356 | PortNumber subscriberPort, |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 357 | VlanId subscriberVlan, VlanId deviceVlan, |
| 358 | Optional<VlanId> defaultVlan) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 359 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 360 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 361 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 362 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 363 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
| 364 | subscriberVlan, deviceVlan, |
| 365 | defaultVlan); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 366 | |
| 367 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 368 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
| 369 | subscriberVlan, deviceVlan, |
| 370 | defaultVlan); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 371 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 372 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 373 | @Override |
| 374 | public void onSuccess(Objective objective) { |
| 375 | upFuture.complete(null); |
| 376 | } |
| 377 | |
| 378 | @Override |
| 379 | public void onError(Objective objective, ObjectiveError error) { |
| 380 | upFuture.complete(error); |
| 381 | } |
| 382 | })); |
| 383 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 384 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 385 | @Override |
| 386 | public void onSuccess(Objective objective) { |
| 387 | downFuture.complete(null); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void onError(Objective objective, ObjectiveError error) { |
| 392 | downFuture.complete(error); |
| 393 | } |
| 394 | })); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 395 | |
| 396 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 397 | if (upStatus == null && downStatus == null) { |
| 398 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
| 399 | deviceId, |
| 400 | deviceVlan, |
| 401 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 402 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 403 | } else if (downStatus != null) { |
| 404 | log.error("Subscriber with vlan {} on device {} " + |
| 405 | "on port {} failed downstream installation: {}", |
| 406 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 407 | } else if (upStatus != null) { |
| 408 | log.error("Subscriber with vlan {} on device {} " + |
| 409 | "on port {} failed upstream installation: {}", |
| 410 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 411 | } |
| 412 | }, oltInstallers); |
| 413 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 414 | } |
| 415 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 416 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 417 | PortNumber subscriberPort, |
| 418 | VlanId subscriberVlan, |
| 419 | VlanId deviceVlan, |
| 420 | Optional<VlanId> defaultVlan) { |
| 421 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 422 | .matchVlanId(deviceVlan) |
| 423 | .matchInPort(uplinkPort) |
| 424 | .matchInnerVlanId(subscriberVlan) |
| 425 | .build(); |
| 426 | |
| 427 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 428 | .popVlan() |
| 429 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 430 | .setOutput(subscriberPort) |
| 431 | .build(); |
| 432 | |
| 433 | return DefaultForwardingObjective.builder() |
| 434 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 435 | .withPriority(1000) |
| 436 | .makePermanent() |
| 437 | .withSelector(downstream) |
| 438 | .fromApp(appId) |
| 439 | .withTreatment(downstreamTreatment); |
| 440 | } |
| 441 | |
| 442 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 443 | PortNumber subscriberPort, |
| 444 | VlanId subscriberVlan, |
| 445 | VlanId deviceVlan, |
| 446 | Optional<VlanId> defaultVlan) { |
| 447 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 448 | .matchVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 449 | .matchInPort(subscriberPort) |
| 450 | .build(); |
| 451 | |
| 452 | |
| 453 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 454 | .pushVlan() |
| 455 | .setVlanId(subscriberVlan) |
| 456 | .pushVlan() |
| 457 | .setVlanId(deviceVlan) |
| 458 | .setOutput(uplinkPort) |
| 459 | .build(); |
| 460 | |
| 461 | return DefaultForwardingObjective.builder() |
| 462 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 463 | .withPriority(1000) |
| 464 | .makePermanent() |
| 465 | .withSelector(upstream) |
| 466 | .fromApp(appId) |
| 467 | .withTreatment(upstreamTreatment); |
| 468 | } |
| 469 | |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 470 | private void processFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 471 | if (!mastershipService.isLocalMaster(devId)) { |
| 472 | return; |
| 473 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 474 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 475 | |
| 476 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 477 | .withKey(Criteria.matchInPort(port)) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 478 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 479 | .withMeta(DefaultTrafficTreatment.builder() |
| 480 | .setOutput(PortNumber.CONTROLLER).build()) |
| 481 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 482 | .withPriority(10000) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 483 | .add(new ObjectiveContext() { |
| 484 | @Override |
| 485 | public void onSuccess(Objective objective) { |
| 486 | log.info("Eapol filter for {} on {} installed.", |
| 487 | devId, port); |
| 488 | } |
| 489 | |
| 490 | @Override |
| 491 | public void onError(Objective objective, ObjectiveError error) { |
| 492 | log.info("Eapol filter for {} on {} failed because {}", |
| 493 | devId, port, error); |
| 494 | } |
| 495 | }); |
| 496 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 497 | flowObjectiveService.filter(devId, eapol); |
alshabib | 000b6fc | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 498 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 499 | } |
| 500 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 501 | /** |
| 502 | * Installs trap filtering objectives for particular traffic types on an |
| 503 | * NNI port. |
| 504 | * |
| 505 | * @param devId device ID |
| 506 | * @param port port number |
| 507 | * @param install true to install, false to remove |
| 508 | */ |
| 509 | private void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 510 | processLldpFilteringObjective(devId, port, install); |
| 511 | processDhcpFilteringObjectives(devId, port, install); |
| 512 | } |
| 513 | |
| 514 | private void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
| 515 | if (!mastershipService.isLocalMaster(devId)) { |
| 516 | return; |
| 517 | } |
| 518 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 519 | |
| 520 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 521 | .withKey(Criteria.matchInPort(port)) |
| 522 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 523 | .withMeta(DefaultTrafficTreatment.builder() |
| 524 | .setOutput(PortNumber.CONTROLLER).build()) |
| 525 | .fromApp(appId) |
| 526 | .withPriority(10000) |
| 527 | .add(new ObjectiveContext() { |
| 528 | @Override |
| 529 | public void onSuccess(Objective objective) { |
| 530 | log.info("LLDP filter for {} on {} installed.", |
| 531 | devId, port); |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public void onError(Objective objective, ObjectiveError error) { |
| 536 | log.info("LLDP filter for {} on {} failed because {}", |
| 537 | devId, port, error); |
| 538 | } |
| 539 | }); |
| 540 | |
| 541 | flowObjectiveService.filter(devId, lldp); |
| 542 | |
| 543 | } |
| 544 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 545 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 546 | if (!mastershipService.isLocalMaster(devId)) { |
| 547 | return; |
| 548 | } |
| 549 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 550 | |
| 551 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 552 | .withKey(Criteria.matchInPort(port)) |
| 553 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 554 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 555 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(68))) |
| 556 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(67))) |
| 557 | .withMeta(DefaultTrafficTreatment.builder() |
| 558 | .setOutput(PortNumber.CONTROLLER).build()) |
| 559 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 560 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 561 | .add(new ObjectiveContext() { |
| 562 | @Override |
| 563 | public void onSuccess(Objective objective) { |
| 564 | log.info("DHCP filter for {} on {} installed.", |
| 565 | devId, port); |
| 566 | } |
| 567 | |
| 568 | @Override |
| 569 | public void onError(Objective objective, ObjectiveError error) { |
| 570 | log.info("DHCP filter for {} on {} failed because {}", |
| 571 | devId, port, error); |
| 572 | } |
| 573 | }); |
| 574 | |
| 575 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 576 | } |
| 577 | |
| 578 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 579 | if (!mastershipService.isLocalMaster(devId)) { |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 584 | |
| 585 | builder = install ? builder.permit() : builder.deny(); |
| 586 | |
| 587 | FilteringObjective igmp = builder |
| 588 | .withKey(Criteria.matchInPort(port)) |
| 589 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 590 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 591 | .withMeta(DefaultTrafficTreatment.builder() |
| 592 | .setOutput(PortNumber.CONTROLLER).build()) |
| 593 | .fromApp(appId) |
| 594 | .withPriority(10000) |
| 595 | .add(new ObjectiveContext() { |
| 596 | @Override |
| 597 | public void onSuccess(Objective objective) { |
| 598 | log.info("Igmp filter for {} on {} installed.", |
| 599 | devId, port); |
| 600 | } |
| 601 | |
| 602 | @Override |
| 603 | public void onError(Objective objective, ObjectiveError error) { |
| 604 | log.info("Igmp filter for {} on {} failed because {}.", |
| 605 | devId, port, error); |
| 606 | } |
| 607 | }); |
| 608 | |
| 609 | flowObjectiveService.filter(devId, igmp); |
| 610 | } |
| 611 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 612 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 613 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 614 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 615 | * |
| 616 | * @param dev Device to look for |
| 617 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 618 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 619 | // we create only for the ones we are master of |
| 620 | if (!mastershipService.isLocalMaster(dev.id())) { |
| 621 | return; |
| 622 | } |
| 623 | // check if this device is provisioned in Sadis |
| 624 | String devSerialNo = dev.serialNumber(); |
| 625 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 626 | log.debug("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 627 | |
| 628 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 629 | // This is an OLT device as per Sadis, we create flows for UNI and NNI ports |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 630 | for (Port p : deviceService.getPorts(dev.id())) { |
| 631 | if (isUniPort(dev, p)) { |
| 632 | processFilteringObjectives(dev.id(), p.number(), true); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 633 | } else { |
| 634 | processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 640 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 641 | /** |
| 642 | * Get the uplink for of the OLT device. |
| 643 | * |
| 644 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 645 | * this logic needs to be changed |
| 646 | * |
| 647 | * @param dev Device to look for |
| 648 | * @return The uplink Port of the OLT |
| 649 | */ |
| 650 | private Port getUplinkPort(Device dev) { |
| 651 | // check if this device is provisioned in Sadis |
| 652 | String devSerialNo = dev.serialNumber(); |
| 653 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 654 | log.debug("getUplinkPort: deviceInfo {}", deviceInfo); |
| 655 | |
| 656 | if (deviceInfo != null) { |
| 657 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
| 658 | for (Port p: deviceService.getPorts(dev.id())) { |
| 659 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
| 660 | log.debug("getUplinkPort: Found port {}", p); |
| 661 | return p; |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | log.debug("getUplinkPort: No uplink port found for OLT {}", dev); |
| 667 | return null; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Return the subscriber on a port. |
| 672 | * |
| 673 | * @param port On which to find the subscriber |
| 674 | * @return subscriber if found else null |
| 675 | */ |
| 676 | private SubscriberAndDeviceInformation getSubscriber(ConnectPoint port) { |
| 677 | String portName = deviceService.getPort(port).annotations() |
| 678 | .value(AnnotationKeys.PORT_NAME); |
| 679 | |
| 680 | return subsService.get(portName); |
| 681 | } |
| 682 | |
| 683 | private boolean isUniPort(Device d, Port p) { |
| 684 | Port ulPort = getUplinkPort(d); |
| 685 | if (ulPort != null) { |
| 686 | return (ulPort.number().toLong() != p.number().toLong()); |
| 687 | } |
| 688 | return false; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 691 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 692 | String devSerialNo = dev.serialNumber(); |
| 693 | SubscriberAndDeviceInformation deviceInfo = subsService.get(devSerialNo); |
| 694 | return deviceInfo; |
| 695 | } |
| 696 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 697 | private class InternalDeviceListener implements DeviceListener { |
| 698 | @Override |
| 699 | public void event(DeviceEvent event) { |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 700 | DeviceId devId = event.subject().id(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 701 | Device dev = event.subject(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 702 | |
| 703 | |
| 704 | if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 705 | return; |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 706 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 707 | |
| 708 | if (getOltInfo(dev) == null) { |
| 709 | log.debug("No device info found, this is not an OLT"); |
| 710 | return; |
| 711 | } |
| 712 | |
| 713 | log.debug("OLT got {} event for {}", event.type(), event.subject()); |
| 714 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 715 | switch (event.type()) { |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 716 | //TODO: Port handling and bookkeeping should be improved once |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 717 | // olt firmware handles correct behaviour. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 718 | case PORT_ADDED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 719 | if (isUniPort(dev, event.port())) { |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 720 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
| 721 | |
| 722 | if (event.port().isEnabled()) { |
| 723 | processFilteringObjectives(devId, event.port().number(), true); |
| 724 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 725 | } else { |
| 726 | checkAndCreateDeviceFlows(dev); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 727 | } |
| 728 | break; |
| 729 | case PORT_REMOVED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 730 | if (isUniPort(dev, event.port())) { |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 731 | if (event.port().isEnabled()) { |
| 732 | processFilteringObjectives(devId, event.port().number(), false); |
Nicolas Palpacuer | 33397af | 2018-08-16 14:32:26 -0400 | [diff] [blame] | 733 | removeSubscriber(new ConnectPoint(devId, event.port().number())); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 737 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 738 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 739 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 740 | case PORT_UPDATED: |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 741 | if (!isUniPort(dev, event.port())) { |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 742 | break; |
| 743 | } |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 744 | |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 745 | if (event.port().isEnabled()) { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 746 | processFilteringObjectives(devId, event.port().number(), true); |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 747 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 748 | } else { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 749 | processFilteringObjectives(devId, event.port().number(), false); |
Matteo Scandolo | 480c3b1 | 2018-08-16 11:40:45 -0700 | [diff] [blame] | 750 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 751 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 752 | break; |
| 753 | case DEVICE_ADDED: |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 754 | post(new AccessDeviceEvent( |
| 755 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 756 | null, null)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 757 | |
| 758 | // Send UNI_ADDED events for all existing ports |
| 759 | deviceService.getPorts(devId).stream() |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 760 | .filter(p -> isUniPort(dev, p)) |
Jonathan Hart | 98de8a7 | 2018-05-30 17:47:01 -0700 | [diff] [blame] | 761 | .filter(Port::isEnabled) |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 762 | .forEach(p -> post(new AccessDeviceEvent( |
| 763 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 764 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 765 | checkAndCreateDeviceFlows(dev); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 766 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 767 | case DEVICE_REMOVED: |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 768 | deviceService.getPorts(devId).stream() |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 769 | .filter(p -> isUniPort(dev, p)) |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 770 | .forEach(p -> post(new AccessDeviceEvent( |
| 771 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
| 772 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 773 | post(new AccessDeviceEvent( |
| 774 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 775 | null, null)); |
| 776 | break; |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 777 | case DEVICE_AVAILABILITY_CHANGED: |
| 778 | if (deviceService.isAvailable(devId)) { |
| 779 | post(new AccessDeviceEvent( |
| 780 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 781 | null, null)); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 782 | checkAndCreateDeviceFlows(dev); |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 783 | } else { |
| 784 | post(new AccessDeviceEvent( |
| 785 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 786 | null, null)); |
| 787 | } |
| 788 | break; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 789 | case DEVICE_UPDATED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 790 | case DEVICE_SUSPENDED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 791 | case PORT_STATS_UPDATED: |
| 792 | default: |
| 793 | return; |
| 794 | } |
| 795 | } |
| 796 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 797 | } |