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