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); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame^] | 208 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 209 | log.info("Stopped"); |
| 210 | } |
| 211 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 212 | @Modified |
| 213 | public void modified(ComponentContext context) { |
| 214 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 215 | |
| 216 | try { |
| 217 | String s = get(properties, "defaultVlan"); |
| 218 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 219 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 220 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 221 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 222 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 223 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 224 | |
| 225 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 226 | if (p != null) { |
| 227 | enableIgmpOnProvisioning = p; |
| 228 | } |
| 229 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 230 | } catch (Exception e) { |
| 231 | defaultVlan = DEFAULT_VLAN; |
| 232 | } |
| 233 | } |
| 234 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 235 | @Override |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 236 | public void provisionSubscriber(ConnectPoint port, VlanId vlan) { |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 237 | checkNotNull(deviceService.getPort(port.deviceId(), port.port()), |
| 238 | "Invalid connect point"); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 239 | AccessDeviceData olt = oltData.get(port.deviceId()); |
| 240 | |
| 241 | if (olt == null) { |
| 242 | log.warn("No data found for OLT device {}", port.deviceId()); |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 243 | throw new IllegalArgumentException("Missing OLT configuration for device"); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 246 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 247 | processDhcpFilteringObjectives(olt.deviceId(), port.port(), true); |
| 248 | } |
| 249 | |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 250 | provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(), |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 251 | olt.defaultVlan()); |
| 252 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 253 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 254 | processIgmpFilteringObjectives(olt.deviceId(), port.port(), true); |
| 255 | } |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | @Override |
| 259 | public void removeSubscriber(ConnectPoint port) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 260 | AccessDeviceData olt = oltData.get(port.deviceId()); |
| 261 | |
| 262 | if (olt == null) { |
| 263 | log.warn("No data found for OLT device {}", port.deviceId()); |
| 264 | return; |
| 265 | } |
| 266 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 267 | VlanId subscriberVlan = subscribers.remove(port); |
| 268 | |
| 269 | if (subscriberVlan == null) { |
| 270 | log.warn("Unknown subscriber at location {}", port); |
| 271 | return; |
| 272 | } |
| 273 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 274 | if (enableDhcpOnProvisioning) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 275 | processDhcpFilteringObjectives(olt.deviceId(), port.port(), false); |
| 276 | } |
| 277 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 278 | unprovisionSubscriber(olt.deviceId(), olt.uplink(), port.port(), subscriberVlan, |
| 279 | olt.vlan(), olt.defaultVlan()); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 280 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 281 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 282 | processIgmpFilteringObjectives(olt.deviceId(), port.port(), false); |
| 283 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 286 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 287 | @Override |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 288 | public Collection<Map.Entry<ConnectPoint, VlanId>> getSubscribers() { |
| 289 | return subscribers.entrySet(); |
| 290 | } |
| 291 | |
| 292 | @Override |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 293 | public Map<DeviceId, AccessDeviceData> fetchOlts() { |
| 294 | return Maps.newHashMap(oltData); |
| 295 | } |
| 296 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 297 | private void initializeUni(Port port) { |
| 298 | DeviceId deviceId = (DeviceId) port.element().id(); |
| 299 | |
| 300 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, deviceId, port)); |
| 301 | |
| 302 | if (port.isEnabled()) { |
| 303 | processFilteringObjectives(deviceId, port.number(), true); |
| 304 | } |
| 305 | } |
| 306 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 307 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 308 | PortNumber subscriberPort, VlanId subscriberVlan, |
| 309 | VlanId deviceVlan, Optional<VlanId> defaultVlan) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 310 | |
| 311 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 312 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 313 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 314 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
| 315 | subscriberVlan, deviceVlan, |
| 316 | defaultVlan); |
| 317 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
| 318 | subscriberVlan, deviceVlan, |
| 319 | defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 320 | |
| 321 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 322 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 323 | @Override |
| 324 | public void onSuccess(Objective objective) { |
| 325 | upFuture.complete(null); |
| 326 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 327 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 328 | @Override |
| 329 | public void onError(Objective objective, ObjectiveError error) { |
| 330 | upFuture.complete(error); |
| 331 | } |
| 332 | })); |
| 333 | |
| 334 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 335 | @Override |
| 336 | public void onSuccess(Objective objective) { |
| 337 | downFuture.complete(null); |
| 338 | } |
| 339 | |
| 340 | @Override |
| 341 | public void onError(Objective objective, ObjectiveError error) { |
| 342 | downFuture.complete(error); |
| 343 | } |
| 344 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 345 | |
| 346 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 347 | if (upStatus == null && downStatus == null) { |
| 348 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
| 349 | deviceId, |
| 350 | deviceVlan, |
| 351 | subscriberVlan)); |
| 352 | } else if (downStatus != null) { |
| 353 | log.error("Subscriber with vlan {} on device {} " + |
| 354 | "on port {} failed downstream uninstallation: {}", |
| 355 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 356 | } else if (upStatus != null) { |
| 357 | log.error("Subscriber with vlan {} on device {} " + |
| 358 | "on port {} failed upstream uninstallation: {}", |
| 359 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 360 | } |
| 361 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 362 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
| 366 | PortNumber subscriberPort, |
Jonathan Hart | 5299838 | 2015-11-10 16:09:22 -0800 | [diff] [blame] | 367 | VlanId subscriberVlan, VlanId deviceVlan, |
| 368 | Optional<VlanId> defaultVlan) { |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 369 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 370 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 371 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 372 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 373 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
| 374 | subscriberVlan, deviceVlan, |
| 375 | defaultVlan); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 376 | |
| 377 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 378 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
| 379 | subscriberVlan, deviceVlan, |
| 380 | defaultVlan); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 381 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 382 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 383 | subscribers.put(cp, subscriberVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 384 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 385 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 386 | @Override |
| 387 | public void onSuccess(Objective objective) { |
| 388 | upFuture.complete(null); |
| 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public void onError(Objective objective, ObjectiveError error) { |
| 393 | upFuture.complete(error); |
| 394 | } |
| 395 | })); |
| 396 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 397 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 398 | @Override |
| 399 | public void onSuccess(Objective objective) { |
| 400 | downFuture.complete(null); |
| 401 | } |
| 402 | |
| 403 | @Override |
| 404 | public void onError(Objective objective, ObjectiveError error) { |
| 405 | downFuture.complete(error); |
| 406 | } |
| 407 | })); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 408 | |
| 409 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 410 | if (upStatus == null && downStatus == null) { |
| 411 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
| 412 | deviceId, |
| 413 | deviceVlan, |
| 414 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 415 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 416 | } else if (downStatus != null) { |
| 417 | log.error("Subscriber with vlan {} on device {} " + |
| 418 | "on port {} failed downstream installation: {}", |
| 419 | subscriberVlan, deviceId, subscriberPort, downStatus); |
| 420 | } else if (upStatus != null) { |
| 421 | log.error("Subscriber with vlan {} on device {} " + |
| 422 | "on port {} failed upstream installation: {}", |
| 423 | subscriberVlan, deviceId, subscriberPort, upStatus); |
| 424 | } |
| 425 | }, oltInstallers); |
| 426 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 427 | } |
| 428 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 429 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 430 | PortNumber subscriberPort, |
| 431 | VlanId subscriberVlan, |
| 432 | VlanId deviceVlan, |
| 433 | Optional<VlanId> defaultVlan) { |
| 434 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 435 | .matchVlanId(deviceVlan) |
| 436 | .matchInPort(uplinkPort) |
| 437 | .matchInnerVlanId(subscriberVlan) |
| 438 | .build(); |
| 439 | |
| 440 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 441 | .popVlan() |
| 442 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 443 | .setOutput(subscriberPort) |
| 444 | .build(); |
| 445 | |
| 446 | return DefaultForwardingObjective.builder() |
| 447 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 448 | .withPriority(1000) |
| 449 | .makePermanent() |
| 450 | .withSelector(downstream) |
| 451 | .fromApp(appId) |
| 452 | .withTreatment(downstreamTreatment); |
| 453 | } |
| 454 | |
| 455 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 456 | PortNumber subscriberPort, |
| 457 | VlanId subscriberVlan, |
| 458 | VlanId deviceVlan, |
| 459 | Optional<VlanId> defaultVlan) { |
| 460 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 461 | .matchVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
| 462 | .matchInPort(subscriberPort) |
| 463 | .build(); |
| 464 | |
| 465 | |
| 466 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 467 | .pushVlan() |
| 468 | .setVlanId(subscriberVlan) |
| 469 | .pushVlan() |
| 470 | .setVlanId(deviceVlan) |
| 471 | .setOutput(uplinkPort) |
| 472 | .build(); |
| 473 | |
| 474 | return DefaultForwardingObjective.builder() |
| 475 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 476 | .withPriority(1000) |
| 477 | .makePermanent() |
| 478 | .withSelector(upstream) |
| 479 | .fromApp(appId) |
| 480 | .withTreatment(upstreamTreatment); |
| 481 | } |
| 482 | |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 483 | private void processFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 484 | if (!mastershipService.isLocalMaster(devId)) { |
| 485 | return; |
| 486 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 487 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 488 | |
| 489 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 490 | .withKey(Criteria.matchInPort(port)) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 491 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 492 | .withMeta(DefaultTrafficTreatment.builder() |
| 493 | .setOutput(PortNumber.CONTROLLER).build()) |
| 494 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 495 | .withPriority(10000) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 496 | .add(new ObjectiveContext() { |
| 497 | @Override |
| 498 | public void onSuccess(Objective objective) { |
| 499 | log.info("Eapol filter for {} on {} installed.", |
| 500 | devId, port); |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public void onError(Objective objective, ObjectiveError error) { |
| 505 | log.info("Eapol filter for {} on {} failed because {}", |
| 506 | devId, port, error); |
| 507 | } |
| 508 | }); |
| 509 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 510 | flowObjectiveService.filter(devId, eapol); |
alshabib | 000b6fc | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 511 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 514 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 515 | if (!mastershipService.isLocalMaster(devId)) { |
| 516 | return; |
| 517 | } |
| 518 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 519 | |
| 520 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 521 | .withKey(Criteria.matchInPort(port)) |
| 522 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 523 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 524 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(68))) |
| 525 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(67))) |
| 526 | .withMeta(DefaultTrafficTreatment.builder() |
| 527 | .setOutput(PortNumber.CONTROLLER).build()) |
| 528 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 529 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 530 | .add(new ObjectiveContext() { |
| 531 | @Override |
| 532 | public void onSuccess(Objective objective) { |
| 533 | log.info("DHCP filter for {} on {} installed.", |
| 534 | devId, port); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public void onError(Objective objective, ObjectiveError error) { |
| 539 | log.info("DHCP filter for {} on {} failed because {}", |
| 540 | devId, port, error); |
| 541 | } |
| 542 | }); |
| 543 | |
| 544 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 545 | } |
| 546 | |
| 547 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 548 | if (!mastershipService.isLocalMaster(devId)) { |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 553 | |
| 554 | builder = install ? builder.permit() : builder.deny(); |
| 555 | |
| 556 | FilteringObjective igmp = builder |
| 557 | .withKey(Criteria.matchInPort(port)) |
| 558 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 559 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 560 | .withMeta(DefaultTrafficTreatment.builder() |
| 561 | .setOutput(PortNumber.CONTROLLER).build()) |
| 562 | .fromApp(appId) |
| 563 | .withPriority(10000) |
| 564 | .add(new ObjectiveContext() { |
| 565 | @Override |
| 566 | public void onSuccess(Objective objective) { |
| 567 | log.info("Igmp filter for {} on {} installed.", |
| 568 | devId, port); |
| 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public void onError(Objective objective, ObjectiveError error) { |
| 573 | log.info("Igmp filter for {} on {} failed because {}.", |
| 574 | devId, port, error); |
| 575 | } |
| 576 | }); |
| 577 | |
| 578 | flowObjectiveService.filter(devId, igmp); |
| 579 | } |
| 580 | |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 581 | private boolean isUni(Port port) { |
| 582 | return !oltData.get(port.element().id()).uplink().equals(port.number()); |
| 583 | } |
| 584 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 585 | private class InternalDeviceListener implements DeviceListener { |
| 586 | @Override |
| 587 | public void event(DeviceEvent event) { |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 588 | DeviceId devId = event.subject().id(); |
| 589 | if (!oltData.containsKey(devId)) { |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 590 | return; |
| 591 | } |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 592 | if (event.type() != DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 593 | log.debug("Olt got {} event for {}", event.type(), event.subject()); |
| 594 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 595 | switch (event.type()) { |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 596 | //TODO: Port handling and bookkeeping should be improved once |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 597 | // olt firmware handles correct behaviour. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 598 | case PORT_ADDED: |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 599 | if (!oltData.get(devId).uplink().equals(event.port().number())) { |
| 600 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
| 601 | |
| 602 | if (event.port().isEnabled()) { |
| 603 | processFilteringObjectives(devId, event.port().number(), true); |
| 604 | } |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 605 | } |
| 606 | break; |
| 607 | case PORT_REMOVED: |
| 608 | AccessDeviceData olt = oltData.get(devId); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 609 | VlanId vlan = subscribers.get(new ConnectPoint(devId, |
| 610 | event.port().number())); |
dvaddire | c63dc82 | 2017-10-05 22:25:13 +0530 | [diff] [blame] | 611 | if (vlan != null) { |
| 612 | unprovisionSubscriber(devId, olt.uplink(), |
| 613 | event.port().number(), |
| 614 | vlan, olt.vlan(), olt.defaultVlan()); |
| 615 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 616 | if (!oltData.get(devId).uplink().equals(event.port().number())) { |
| 617 | if (event.port().isEnabled()) { |
| 618 | processFilteringObjectives(devId, event.port().number(), false); |
| 619 | } |
| 620 | |
| 621 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 622 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 623 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 624 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 625 | case PORT_UPDATED: |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 626 | if (oltData.get(devId).uplink().equals(event.port().number())) { |
| 627 | break; |
| 628 | } |
| 629 | if (event.port().isEnabled()) { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 630 | processFilteringObjectives(devId, event.port().number(), true); |
Jonathan Hart | 6960f82 | 2018-07-02 15:19:14 -0700 | [diff] [blame] | 631 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 632 | } else { |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 633 | processFilteringObjectives(devId, event.port().number(), false); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 634 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 635 | break; |
| 636 | case DEVICE_ADDED: |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 637 | post(new AccessDeviceEvent( |
| 638 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 639 | null, null)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 640 | |
| 641 | // Send UNI_ADDED events for all existing ports |
| 642 | deviceService.getPorts(devId).stream() |
| 643 | .filter(Olt.this::isUni) |
Jonathan Hart | 98de8a7 | 2018-05-30 17:47:01 -0700 | [diff] [blame] | 644 | .filter(Port::isEnabled) |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 645 | .forEach(p -> post(new AccessDeviceEvent( |
| 646 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 647 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 648 | provisionDefaultFlows(devId); |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 649 | break; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 650 | case DEVICE_REMOVED: |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 651 | deviceService.getPorts(devId).stream() |
| 652 | .filter(Olt.this::isUni) |
| 653 | .forEach(p -> post(new AccessDeviceEvent( |
| 654 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
| 655 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 656 | post(new AccessDeviceEvent( |
| 657 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 658 | null, null)); |
| 659 | break; |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 660 | case DEVICE_AVAILABILITY_CHANGED: |
| 661 | if (deviceService.isAvailable(devId)) { |
| 662 | post(new AccessDeviceEvent( |
| 663 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 664 | null, null)); |
| 665 | } else { |
| 666 | post(new AccessDeviceEvent( |
| 667 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 668 | null, null)); |
| 669 | } |
| 670 | break; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 671 | case DEVICE_UPDATED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 672 | case DEVICE_SUSPENDED: |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 673 | case PORT_STATS_UPDATED: |
| 674 | default: |
| 675 | return; |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 680 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 681 | @Override |
| 682 | public void event(NetworkConfigEvent event) { |
| 683 | switch (event.type()) { |
| 684 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 685 | case CONFIG_ADDED: |
| 686 | case CONFIG_UPDATED: |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 687 | |
| 688 | AccessDeviceConfig config = |
| 689 | networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS); |
| 690 | if (config != null) { |
| 691 | oltData.put(config.getOlt().deviceId(), config.getOlt()); |
| 692 | provisionDefaultFlows((DeviceId) event.subject()); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 693 | } |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 694 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 695 | break; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 696 | case CONFIG_REGISTERED: |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 697 | case CONFIG_UNREGISTERED: |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 698 | break; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 699 | case CONFIG_REMOVED: |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 700 | oltData.remove(event.subject()); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 701 | default: |
| 702 | break; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 705 | |
| 706 | @Override |
| 707 | public boolean isRelevant(NetworkConfigEvent event) { |
| 708 | return event.configClass().equals(CONFIG_CLASS); |
| 709 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 710 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 711 | |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 712 | private void provisionDefaultFlows(DeviceId deviceId) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 713 | if (!mastershipService.isLocalMaster(deviceId)) { |
| 714 | return; |
| 715 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 716 | List<Port> ports = deviceService.getPorts(deviceId); |
| 717 | |
| 718 | ports.stream() |
| 719 | .filter(p -> !oltData.get(p.element().id()).uplink().equals(p.number())) |
| 720 | .filter(p -> p.isEnabled()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 721 | .forEach(p -> processFilteringObjectives((DeviceId) p.element().id(), |
| 722 | p.number(), true)); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 723 | |
| 724 | } |
| 725 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 726 | } |