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