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