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 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 20 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 21 | import static org.onlab.util.Tools.get; |
| 22 | import static org.onlab.util.Tools.groupedThreads; |
| 23 | import static org.slf4j.LoggerFactory.getLogger; |
| 24 | |
| 25 | import java.util.AbstractMap; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 26 | import java.util.Arrays; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | import java.util.Collection; |
| 29 | import java.util.Dictionary; |
| 30 | import java.util.List; |
| 31 | import java.util.Map; |
| 32 | import java.util.Optional; |
| 33 | import java.util.Properties; |
| 34 | import java.util.concurrent.CompletableFuture; |
| 35 | import java.util.concurrent.ExecutorService; |
| 36 | import java.util.concurrent.Executors; |
| 37 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 38 | import org.apache.felix.scr.annotations.Activate; |
| 39 | import org.apache.felix.scr.annotations.Component; |
| 40 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 41 | import org.apache.felix.scr.annotations.Modified; |
| 42 | import org.apache.felix.scr.annotations.Property; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 43 | import org.apache.felix.scr.annotations.Reference; |
| 44 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 45 | import org.apache.felix.scr.annotations.Service; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 46 | import org.onlab.packet.EthType; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 47 | import org.onlab.packet.IPv4; |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 48 | import org.onlab.packet.IPv6; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 49 | import org.onlab.packet.TpPort; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 50 | import org.onlab.packet.VlanId; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 51 | import org.onlab.util.Tools; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 52 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 53 | import org.onosproject.core.ApplicationId; |
| 54 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 55 | import org.onosproject.event.AbstractListenerManager; |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 56 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 57 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 58 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 59 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 60 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 61 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 62 | import org.onosproject.net.PortNumber; |
| 63 | import org.onosproject.net.device.DeviceEvent; |
| 64 | import org.onosproject.net.device.DeviceListener; |
| 65 | import org.onosproject.net.device.DeviceService; |
| 66 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 67 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 68 | import org.onosproject.net.flow.TrafficSelector; |
| 69 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 70 | import org.onosproject.net.flow.criteria.Criteria; |
| 71 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 72 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 73 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 74 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 75 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 76 | import org.onosproject.net.flowobjective.Objective; |
| 77 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 78 | import org.onosproject.net.flowobjective.ObjectiveError; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 79 | import org.onosproject.store.serializers.KryoNamespaces; |
| 80 | import org.onosproject.store.service.ConsistentMultimap; |
| 81 | import org.onosproject.store.service.Serializer; |
| 82 | import org.onosproject.store.service.StorageService; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 83 | import org.onosproject.net.meter.Band; |
| 84 | import org.onosproject.net.meter.DefaultBand; |
| 85 | import org.onosproject.net.meter.DefaultMeterRequest; |
| 86 | import org.onosproject.net.meter.Meter; |
| 87 | import org.onosproject.net.meter.MeterService; |
| 88 | import org.onosproject.net.meter.MeterListener; |
| 89 | import org.onosproject.net.meter.MeterRequest; |
| 90 | import org.onosproject.net.meter.MeterId; |
| 91 | import org.onosproject.net.meter.MeterEvent; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 92 | import org.opencord.olt.AccessDeviceEvent; |
| 93 | import org.opencord.olt.AccessDeviceListener; |
| 94 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 95 | import org.opencord.olt.AccessSubscriberId; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 96 | import org.opencord.sadis.BandwidthProfileInformation; |
| 97 | import org.opencord.sadis.BaseInformationService; |
| 98 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 99 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 100 | import org.osgi.service.component.ComponentContext; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 101 | import org.slf4j.Logger; |
| 102 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 103 | import java.util.HashMap; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 104 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 105 | import com.google.common.collect.ImmutableMap; |
| 106 | import com.google.common.collect.Maps; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 109 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 110 | */ |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 111 | @Service |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 112 | @Component(immediate = true) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 113 | public class Olt |
| 114 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 115 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 116 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 117 | |
| 118 | private static final short DEFAULT_VLAN = 0; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 119 | private static final int DEFAULT_TP_ID = 10; |
| 120 | private static final String DEFAULT_BP_ID = "Default"; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 121 | private static final String ADDITIONAL_VLANS = "additional-vlans"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 122 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 123 | private final Logger log = getLogger(getClass()); |
| 124 | |
| 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 126 | protected FlowObjectiveService flowObjectiveService; |
| 127 | |
| 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 129 | protected MastershipService mastershipService; |
| 130 | |
| 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 132 | protected DeviceService deviceService; |
| 133 | |
| 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 135 | protected CoreService coreService; |
| 136 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 137 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 138 | protected ComponentConfigService componentConfigService; |
| 139 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 140 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 141 | protected SadisService sadisService; |
| 142 | |
| 143 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 144 | protected MeterService meterService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 145 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 146 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 147 | protected StorageService storageService; |
| 148 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 149 | @Property(name = "defaultVlan", intValue = DEFAULT_VLAN, |
| 150 | label = "Default VLAN RG<->ONU traffic") |
| 151 | private int defaultVlan = DEFAULT_VLAN; |
| 152 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 153 | @Property(name = "enableDhcpOnProvisioning", boolValue = true, |
| 154 | label = "Create the DHCP Flow rules when a subscriber is provisioned") |
| 155 | protected boolean enableDhcpOnProvisioning = false; |
| 156 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 157 | @Property(name = "enableDhcpV4", boolValue = true, |
| 158 | label = "Enable flows for DHCP v4") |
| 159 | protected boolean enableDhcpV4 = true; |
| 160 | |
| 161 | @Property(name = "enableDhcpV6", boolValue = true, |
| 162 | label = "Enable flows for DHCP v6") |
| 163 | protected boolean enableDhcpV6 = false; |
| 164 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 165 | @Property(name = "enableIgmpOnProvisioning", boolValue = false, |
| 166 | label = "Create IGMP Flow rules when a subscriber is provisioned") |
| 167 | protected boolean enableIgmpOnProvisioning = false; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 168 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 169 | // needed because no implementation for meter statistics in Voltha yet |
| 170 | @Property(name = "deleteMeters", boolValue = false, |
| 171 | label = "Deleting Meters based on flow count statistics") |
| 172 | protected boolean deleteMeters = false; |
| 173 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 174 | @Property(name = "defaultTechProfileId", intValue = DEFAULT_TP_ID, |
| 175 | label = "Default technology profile id that is used for authentication trap flows") |
| 176 | protected int defaultTechProfileId = DEFAULT_TP_ID; |
| 177 | |
| 178 | @Property(name = "defaultBpId", value = DEFAULT_BP_ID, |
| 179 | label = "Default bandwidth profile id that is used for authentication trap flows") |
| 180 | protected String defaultBpId = DEFAULT_BP_ID; |
| 181 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 182 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 183 | private final MeterListener meterListener = new InternalMeterListener(); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 184 | |
| 185 | private ApplicationId appId; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 186 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
| 187 | private BaseInformationService<BandwidthProfileInformation> bpService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 188 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 189 | private Map<String, MeterId> bpInfoToMeter = new HashMap<>(); |
| 190 | |
| 191 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
| 192 | groupedThreads("onos/olt-service", |
| 193 | "olt-installer-%d")); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 194 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 195 | private ConsistentMultimap<ConnectPoint, Map.Entry<VlanId, VlanId>> additionalVlans; |
| 196 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 197 | protected ExecutorService eventExecutor; |
| 198 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 199 | private Map<ConnectPoint, SubscriberAndDeviceInformation> programmedSubs; |
| 200 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 201 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 202 | public void activate(ComponentContext context) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 203 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt", "events-%d", log)); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 204 | modified(context); |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 205 | appId = coreService.registerApplication(APP_NAME); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 206 | componentConfigService.registerProperties(getClass()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 207 | programmedSubs = Maps.newConcurrentMap(); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 208 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 209 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 210 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 211 | subsService = sadisService.getSubscriberInfoService(); |
| 212 | bpService = sadisService.getBandwidthProfileService(); |
| 213 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 214 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 215 | // UNI ports |
| 216 | Iterable<Device> devices = deviceService.getDevices(); |
| 217 | for (Device d : devices) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 218 | checkAndCreateDeviceFlows(d); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 219 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 220 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 221 | additionalVlans = storageService.<ConnectPoint, Map.Entry<VlanId, VlanId>>consistentMultimapBuilder() |
| 222 | .withName(ADDITIONAL_VLANS) |
| 223 | .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), |
| 224 | AbstractMap.SimpleEntry.class)) |
| 225 | .build(); |
| 226 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 227 | deviceService.addListener(deviceListener); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 228 | meterService.addListener(meterListener); |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 229 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 230 | log.info("Started with Application ID {}", appId.id()); |
| 231 | } |
| 232 | |
| 233 | @Deactivate |
| 234 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 235 | componentConfigService.unregisterProperties(getClass(), false); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 236 | deviceService.removeListener(deviceListener); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 237 | meterService.removeListener(meterListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 238 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 239 | log.info("Stopped"); |
| 240 | } |
| 241 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 242 | @Modified |
| 243 | public void modified(ComponentContext context) { |
| 244 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 245 | |
| 246 | try { |
| 247 | String s = get(properties, "defaultVlan"); |
| 248 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 249 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 250 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 251 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 252 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 253 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 254 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 255 | Boolean v4 = Tools.isPropertyEnabled(properties, "enableDhcpV4"); |
| 256 | if (v4 != null) { |
| 257 | enableDhcpV4 = v4; |
| 258 | } |
| 259 | |
| 260 | Boolean v6 = Tools.isPropertyEnabled(properties, "enableDhcpV6"); |
| 261 | if (v6 != null) { |
| 262 | enableDhcpV6 = v6; |
| 263 | } |
| 264 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 265 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 266 | if (p != null) { |
| 267 | enableIgmpOnProvisioning = p; |
| 268 | } |
| 269 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 270 | log.info("DHCP Settings [enableDhcpOnProvisioning: {}, enableDhcpV4: {}, enableDhcpV6: {}]", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 271 | enableDhcpOnProvisioning, enableDhcpV4, enableDhcpV6); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 272 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 273 | Boolean d = Tools.isPropertyEnabled(properties, "deleteMeters"); |
| 274 | if (d != null) { |
| 275 | deleteMeters = d; |
| 276 | } |
| 277 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 278 | String tpId = get(properties, "defaultTechProfileId"); |
| 279 | defaultTechProfileId = isNullOrEmpty(s) ? DEFAULT_TP_ID : Integer.parseInt(tpId.trim()); |
| 280 | |
| 281 | String bpId = get(properties, "defaultBpId"); |
| 282 | defaultBpId = bpId; |
| 283 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 284 | } catch (Exception e) { |
| 285 | defaultVlan = DEFAULT_VLAN; |
| 286 | } |
| 287 | } |
| 288 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 289 | @Override |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 290 | public boolean provisionSubscriber(ConnectPoint port) { |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 291 | checkNotNull(deviceService.getPort(port.deviceId(), port.port()), |
| 292 | "Invalid connect point"); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 293 | // Find the subscriber on this connect point |
| 294 | SubscriberAndDeviceInformation sub = getSubscriber(port); |
| 295 | if (sub == null) { |
| 296 | log.warn("No subscriber found for {}", port); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 297 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 298 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 299 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 300 | // Get the uplink port |
| 301 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 302 | if (uplinkPort == null) { |
| 303 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 304 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 307 | if (enableDhcpOnProvisioning) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 308 | processDhcpFilteringObjectives(port.deviceId(), port.port(), true, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 309 | true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 310 | } |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 311 | log.info("Programming vlans for subscriber: {}", sub); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 312 | Optional<VlanId> defaultVlan = Optional.empty(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 313 | provisionVlans(port, uplinkPort.number(), defaultVlan, sub); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 314 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 315 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 316 | processIgmpFilteringObjectives(port.deviceId(), port.port(), true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 317 | } |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 318 | // cache subscriber info |
| 319 | programmedSubs.put(port, sub); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 320 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @Override |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 324 | public boolean removeSubscriber(ConnectPoint port) { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 325 | // Get the subscriber connected to this port from the local cache |
| 326 | // as if we don't know about the subscriber there's no need to remove it |
| 327 | SubscriberAndDeviceInformation subscriber = programmedSubs.get(port); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 328 | if (subscriber == null) { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 329 | log.warn("Subscriber on port {} was not previously programmed, no need to remove it", port); |
| 330 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 333 | // Get the uplink port |
| 334 | Port uplinkPort = getUplinkPort(deviceService.getDevice(port.deviceId())); |
| 335 | if (uplinkPort == null) { |
| 336 | log.warn("No uplink port found for OLT device {}", port.deviceId()); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 337 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 340 | if (enableDhcpOnProvisioning) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 341 | processDhcpFilteringObjectives(port.deviceId(), port.port(), false, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 342 | true); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 345 | log.info("Removing programmed vlans for subscriber: {}", subscriber); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 346 | Optional<VlanId> defaultVlan = Optional.empty(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 347 | unprovisionSubscriber(port.deviceId(), uplinkPort.number(), port.port(), subscriber, defaultVlan); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 348 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 349 | if (enableIgmpOnProvisioning) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 350 | processIgmpFilteringObjectives(port.deviceId(), port.port(), false); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 351 | } |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 352 | |
| 353 | // Remove if there are any flows for the additional Vlans |
| 354 | Collection<? extends Map.Entry<VlanId, VlanId>> vlansList = additionalVlans.get(port).value(); |
| 355 | |
| 356 | // Remove the flows for the additional vlans for this subscriber |
| 357 | for (Map.Entry<VlanId, VlanId> vlans : vlansList) { |
| 358 | unprovisionTransparentFlows(port.deviceId(), uplinkPort.number(), port.port(), |
| 359 | vlans.getValue(), vlans.getKey()); |
| 360 | |
| 361 | // Remove it from the map also |
| 362 | additionalVlans.remove(port, vlans); |
| 363 | } |
| 364 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 365 | programmedSubs.remove(port); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 366 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 369 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 370 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 371 | // Check if we can find the connect point to which this subscriber is connected |
| 372 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 373 | if (subsPort == null) { |
| 374 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 375 | return false; |
| 376 | } |
| 377 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 378 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 379 | return provisionSubscriber(subsPort); |
| 380 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 381 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 382 | if (uplinkPort == null) { |
| 383 | log.warn("No uplink port found for OLT device {}", subsPort.deviceId()); |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | provisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 388 | cTag.get(), sTag.get()); |
| 389 | return true; |
| 390 | } else { |
| 391 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 392 | return false; |
| 393 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 394 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 395 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 396 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 397 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 398 | // Check if we can find the connect point to which this subscriber is connected |
| 399 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 400 | if (subsPort == null) { |
| 401 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 402 | return false; |
| 403 | } |
| 404 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 405 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 406 | return removeSubscriber(subsPort); |
| 407 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 408 | // Get the uplink port |
| 409 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 410 | if (uplinkPort == null) { |
| 411 | log.warn("No uplink port found for OLT device {}", subsPort.deviceId()); |
| 412 | return false; |
| 413 | } |
| 414 | |
| 415 | unprovisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 416 | cTag.get(), sTag.get()); |
| 417 | return true; |
| 418 | } else { |
| 419 | log.warn("Removing subscriber failed for: {}", subscriberId); |
| 420 | return false; |
| 421 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public Collection<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> getSubscribers() { |
| 426 | ArrayList<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> subs = new ArrayList<>(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 427 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 428 | // Get the subscribers for all the devices configured in sadis |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 429 | // If the port is UNI, is enabled and exists in Sadis then copy it |
| 430 | for (Device d : deviceService.getDevices()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 431 | if (getOltInfo(d) == null) { |
| 432 | continue; // not an olt, or not configured in sadis |
| 433 | } |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 434 | for (Port p : deviceService.getPorts(d.id())) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 435 | if (isUniPort(d, p) && p.isEnabled()) { |
| 436 | ConnectPoint cp = new ConnectPoint(d.id(), p.number()); |
| 437 | |
| 438 | SubscriberAndDeviceInformation sub = getSubscriber(cp); |
| 439 | if (sub != null) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 440 | Map.Entry<VlanId, VlanId> vlans = new AbstractMap.SimpleEntry(sub.sTag(), sub.cTag()); |
| 441 | subs.add(new AbstractMap.SimpleEntry(cp, vlans)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return subs; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | @Override |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 451 | public ImmutableMap<ConnectPoint, SubscriberAndDeviceInformation> getProgSubs() { |
| 452 | return ImmutableMap.copyOf(programmedSubs); |
| 453 | } |
| 454 | |
| 455 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 456 | public List<DeviceId> fetchOlts() { |
| 457 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 458 | List<DeviceId> olts = new ArrayList<>(); |
| 459 | Iterable<Device> devices = deviceService.getDevices(); |
| 460 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 461 | if (getOltInfo(d) != null) { |
| 462 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 463 | olts.add(d.id()); |
| 464 | } |
| 465 | } |
| 466 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 469 | /** |
| 470 | * Finds the connect point to which a subscriber is connected. |
| 471 | * |
| 472 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 473 | * @return Subscribers ConnectPoint if found else null |
| 474 | */ |
| 475 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 476 | |
| 477 | Iterable<Device> devices = deviceService.getDevices(); |
| 478 | for (Device d : devices) { |
| 479 | for (Port p : deviceService.getPorts(d.id())) { |
| 480 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 481 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 482 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 483 | return new ConnectPoint(d.id(), p.number()); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | return null; |
| 488 | } |
| 489 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 490 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 491 | if (bandwidthProfile == null) { |
| 492 | return null; |
| 493 | } |
| 494 | return bpService.get(bandwidthProfile); |
| 495 | } |
| 496 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 497 | private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 498 | PortNumber subscriberPort, SubscriberAndDeviceInformation subscriber, |
| 499 | Optional<VlanId> defaultVlan) { |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 500 | |
| 501 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 502 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 503 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 504 | VlanId deviceVlan = subscriber.sTag(); |
| 505 | VlanId subscriberVlan = subscriber.cTag(); |
| 506 | |
| 507 | MeterId upstreamMeterId = bpInfoToMeter.get(subscriber.upstreamBandwidthProfile()); |
| 508 | MeterId downstreamMeterId = bpInfoToMeter.get(subscriber.downstreamBandwidthProfile()); |
| 509 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 510 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 511 | subscriberVlan, deviceVlan, |
| 512 | defaultVlan, upstreamMeterId, subscriber.technologyProfileId()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 513 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 514 | subscriberVlan, deviceVlan, |
| 515 | defaultVlan, downstreamMeterId, subscriber.technologyProfileId()); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 516 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 517 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 518 | @Override |
| 519 | public void onSuccess(Objective objective) { |
| 520 | upFuture.complete(null); |
| 521 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 522 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 523 | @Override |
| 524 | public void onError(Objective objective, ObjectiveError error) { |
| 525 | upFuture.complete(error); |
| 526 | } |
| 527 | })); |
| 528 | |
| 529 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 530 | @Override |
| 531 | public void onSuccess(Objective objective) { |
| 532 | downFuture.complete(null); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public void onError(Objective objective, ObjectiveError error) { |
| 537 | downFuture.complete(error); |
| 538 | } |
| 539 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 540 | |
| 541 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 542 | if (upStatus == null && downStatus == null) { |
| 543 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 544 | deviceId, |
| 545 | deviceVlan, |
| 546 | subscriberVlan)); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 547 | } else if (downStatus != null) { |
| 548 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 549 | "on port {} failed downstream uninstallation: {}", |
| 550 | subscriberVlan, deviceId, subscriberPort, downStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 551 | } else if (upStatus != null) { |
| 552 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 553 | "on port {} failed upstream uninstallation: {}", |
| 554 | subscriberVlan, deviceId, subscriberPort, upStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 555 | } |
| 556 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 557 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 560 | private void provisionVlans(ConnectPoint port, PortNumber uplinkPort, Optional<VlanId> defaultVlan, |
| 561 | SubscriberAndDeviceInformation sub) { |
| 562 | |
| 563 | log.info("Provisioning vlans..."); |
| 564 | |
| 565 | DeviceId deviceId = port.deviceId(); |
| 566 | PortNumber subscriberPort = port.port(); |
| 567 | VlanId deviceVlan = sub.sTag(); |
| 568 | VlanId subscriberVlan = sub.cTag(); |
| 569 | int techProfId = sub.technologyProfileId(); |
| 570 | |
| 571 | BandwidthProfileInformation upstreamBpInfo = getBandwidthProfileInformation(sub.upstreamBandwidthProfile()); |
| 572 | BandwidthProfileInformation downstreamBpInfo = getBandwidthProfileInformation(sub.downstreamBandwidthProfile()); |
| 573 | |
| 574 | MeterId usptreamMeterId = createMeter(deviceId, upstreamBpInfo); |
| 575 | MeterId downstreamMeterId = createMeter(deviceId, downstreamBpInfo); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 576 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 577 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 578 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 579 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 580 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 581 | subscriberVlan, deviceVlan, |
| 582 | defaultVlan, usptreamMeterId, techProfId); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 583 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 584 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 585 | subscriberVlan, deviceVlan, |
| 586 | defaultVlan, downstreamMeterId, techProfId); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 587 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 588 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 589 | @Override |
| 590 | public void onSuccess(Objective objective) { |
| 591 | upFuture.complete(null); |
| 592 | } |
| 593 | |
| 594 | @Override |
| 595 | public void onError(Objective objective, ObjectiveError error) { |
| 596 | upFuture.complete(error); |
| 597 | } |
| 598 | })); |
| 599 | |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 600 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 601 | @Override |
| 602 | public void onSuccess(Objective objective) { |
| 603 | downFuture.complete(null); |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void onError(Objective objective, ObjectiveError error) { |
| 608 | downFuture.complete(error); |
| 609 | } |
| 610 | })); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 611 | |
| 612 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 613 | if (upStatus == null && downStatus == null) { |
| 614 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 615 | deviceId, |
| 616 | deviceVlan, |
| 617 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 618 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 619 | } else if (downStatus != null) { |
| 620 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 621 | "on port {} failed downstream installation: {}", |
| 622 | subscriberVlan, deviceId, subscriberPort, downStatus); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 623 | } else if (upStatus != null) { |
| 624 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 625 | "on port {} failed upstream installation: {}", |
| 626 | subscriberVlan, deviceId, subscriberPort, upStatus); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 627 | } |
| 628 | }, oltInstallers); |
| 629 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 630 | } |
| 631 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 632 | private MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo) { |
| 633 | |
| 634 | if (bpInfo == null) { |
| 635 | log.warn("Bandwidth profile information is not found"); |
| 636 | return null; |
| 637 | } |
| 638 | |
| 639 | MeterId meterId = bpInfoToMeter.get(bpInfo.id()); |
| 640 | if (meterId != null) { |
| 641 | log.info("Meter is already added. MeterId {}", meterId); |
| 642 | return meterId; |
| 643 | } |
| 644 | |
| 645 | List<Band> meterBands = createMeterBands(bpInfo); |
| 646 | |
| 647 | MeterRequest meterRequest = DefaultMeterRequest.builder() |
| 648 | .withBands(meterBands) |
| 649 | .withUnit(Meter.Unit.KB_PER_SEC) |
| 650 | .forDevice(deviceId) |
| 651 | .fromApp(appId) |
| 652 | .burst() |
| 653 | .add(); |
| 654 | |
| 655 | Meter meter = meterService.submit(meterRequest); |
| 656 | bpInfoToMeter.put(bpInfo.id(), meter.id()); |
| 657 | log.info("Meter is created. Meter Id {}", meter.id()); |
| 658 | return meter.id(); |
| 659 | } |
| 660 | |
| 661 | private List<Band> createMeterBands(BandwidthProfileInformation bpInfo) { |
| 662 | List<Band> meterBands = new ArrayList<>(); |
| 663 | |
| 664 | meterBands.add(createMeterBand(bpInfo.committedInformationRate(), bpInfo.committedBurstSize())); |
| 665 | meterBands.add(createMeterBand(bpInfo.exceededInformationRate(), bpInfo.exceededBurstSize())); |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 666 | meterBands.add(createMeterBand(bpInfo.assuredInformationRate(), 0L)); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 667 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 668 | return meterBands; |
| 669 | } |
| 670 | |
| 671 | private Band createMeterBand(long rate, Long burst) { |
| 672 | return DefaultBand.builder() |
| 673 | .withRate(rate) //already Kbps |
| 674 | .burstSize(burst) // already Kbits |
| 675 | .ofType(Band.Type.DROP) // no matter |
| 676 | .build(); |
| 677 | } |
| 678 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 679 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 680 | PortNumber subscriberPort, |
| 681 | VlanId subscriberVlan, |
| 682 | VlanId deviceVlan, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 683 | Optional<VlanId> defaultVlan, |
| 684 | MeterId meterId, |
| 685 | int techProfId) { |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 686 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 687 | .matchVlanId(deviceVlan) |
| 688 | .matchInPort(uplinkPort) |
| 689 | .matchInnerVlanId(subscriberVlan) |
| 690 | .build(); |
| 691 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 692 | TrafficTreatment.Builder downstreamTreatmentBuilder = DefaultTrafficTreatment.builder() |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 693 | .popVlan() |
| 694 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 695 | .setOutput(subscriberPort); |
| 696 | |
| 697 | if (meterId != null) { |
| 698 | downstreamTreatmentBuilder.meter(meterId); |
| 699 | } |
| 700 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 701 | downstreamTreatmentBuilder.writeMetadata(createMetadata(subscriberVlan, techProfId, subscriberPort), 0); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 702 | |
| 703 | return DefaultForwardingObjective.builder() |
| 704 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 705 | .withPriority(1000) |
| 706 | .makePermanent() |
| 707 | .withSelector(downstream) |
| 708 | .fromApp(appId) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 709 | .withTreatment(downstreamTreatmentBuilder.build()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 713 | PortNumber subscriberPort, |
| 714 | VlanId subscriberVlan, |
| 715 | VlanId deviceVlan, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 716 | Optional<VlanId> defaultVlan, |
| 717 | MeterId meterId, |
| 718 | int technologyProfileId) { |
| 719 | |
| 720 | |
| 721 | VlanId dVlan = defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan)); |
| 722 | |
| 723 | if (subscriberVlan.toShort() == 4096) { |
| 724 | dVlan = subscriberVlan; |
| 725 | } |
| 726 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 727 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 728 | .matchVlanId(dVlan) |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 729 | .matchInPort(subscriberPort) |
| 730 | .build(); |
| 731 | |
| 732 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 733 | TrafficTreatment.Builder upstreamTreatmentBuilder = DefaultTrafficTreatment.builder() |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 734 | .pushVlan() |
| 735 | .setVlanId(subscriberVlan) |
| 736 | .pushVlan() |
| 737 | .setVlanId(deviceVlan) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 738 | .setOutput(uplinkPort); |
| 739 | |
| 740 | if (meterId != null) { |
| 741 | upstreamTreatmentBuilder.meter(meterId); |
| 742 | } |
| 743 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 744 | upstreamTreatmentBuilder.writeMetadata(createMetadata(deviceVlan, technologyProfileId, uplinkPort), 0L); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 745 | |
| 746 | return DefaultForwardingObjective.builder() |
| 747 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 748 | .withPriority(1000) |
| 749 | .makePermanent() |
| 750 | .withSelector(upstream) |
| 751 | .fromApp(appId) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 752 | .withTreatment(upstreamTreatmentBuilder.build()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 753 | } |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 754 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 755 | private void provisionTransparentFlows(DeviceId deviceId, PortNumber uplinkPort, |
| 756 | PortNumber subscriberPort, |
| 757 | VlanId innerVlan, |
| 758 | VlanId outerVlan) { |
| 759 | |
| 760 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 761 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 762 | |
| 763 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplinkPort, subscriberPort, |
| 764 | innerVlan, outerVlan); |
| 765 | |
| 766 | |
| 767 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplinkPort, subscriberPort, |
| 768 | innerVlan, outerVlan); |
| 769 | |
| 770 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 771 | |
| 772 | additionalVlans.put(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 773 | |
| 774 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 775 | @Override |
| 776 | public void onSuccess(Objective objective) { |
| 777 | upFuture.complete(null); |
| 778 | } |
| 779 | |
| 780 | @Override |
| 781 | public void onError(Objective objective, ObjectiveError error) { |
| 782 | upFuture.complete(error); |
| 783 | } |
| 784 | })); |
| 785 | |
| 786 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 787 | @Override |
| 788 | public void onSuccess(Objective objective) { |
| 789 | downFuture.complete(null); |
| 790 | } |
| 791 | |
| 792 | @Override |
| 793 | public void onError(Objective objective, ObjectiveError error) { |
| 794 | downFuture.complete(error); |
| 795 | } |
| 796 | })); |
| 797 | |
| 798 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 799 | if (downStatus != null) { |
| 800 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 801 | "on port {} failed downstream installation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 802 | innerVlan, outerVlan, deviceId, subscriberPort, downStatus); |
| 803 | } else if (upStatus != null) { |
| 804 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 805 | "on port {} failed upstream installation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 806 | innerVlan, outerVlan, deviceId, subscriberPort, upStatus); |
| 807 | } |
| 808 | }, oltInstallers); |
| 809 | |
| 810 | } |
| 811 | |
| 812 | private ForwardingObjective.Builder transparentDownBuilder(PortNumber uplinkPort, |
| 813 | PortNumber subscriberPort, |
| 814 | VlanId innerVlan, |
| 815 | VlanId outerVlan) { |
| 816 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 817 | .matchVlanId(outerVlan) |
| 818 | .matchInPort(uplinkPort) |
| 819 | .matchInnerVlanId(innerVlan) |
| 820 | .build(); |
| 821 | |
| 822 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 823 | .setOutput(subscriberPort) |
| 824 | .build(); |
| 825 | |
| 826 | return DefaultForwardingObjective.builder() |
| 827 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 828 | .withPriority(1000) |
| 829 | .makePermanent() |
| 830 | .withSelector(downstream) |
| 831 | .fromApp(appId) |
| 832 | .withTreatment(downstreamTreatment); |
| 833 | } |
| 834 | |
| 835 | private ForwardingObjective.Builder transparentUpBuilder(PortNumber uplinkPort, |
| 836 | PortNumber subscriberPort, |
| 837 | VlanId innerVlan, |
| 838 | VlanId outerVlan) { |
| 839 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 840 | .matchVlanId(outerVlan) |
| 841 | .matchInPort(subscriberPort) |
| 842 | .matchInnerVlanId(innerVlan) |
| 843 | .build(); |
| 844 | |
| 845 | TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() |
| 846 | .setOutput(uplinkPort) |
| 847 | .build(); |
| 848 | |
| 849 | return DefaultForwardingObjective.builder() |
| 850 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 851 | .withPriority(1000) |
| 852 | .makePermanent() |
| 853 | .withSelector(upstream) |
| 854 | .fromApp(appId) |
| 855 | .withTreatment(upstreamTreatment); |
| 856 | } |
| 857 | |
| 858 | private void unprovisionTransparentFlows(DeviceId deviceId, PortNumber uplink, |
| 859 | PortNumber subscriberPort, VlanId innerVlan, |
| 860 | VlanId outerVlan) { |
| 861 | |
| 862 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 863 | |
| 864 | additionalVlans.remove(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 865 | |
| 866 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 867 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 868 | |
| 869 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplink, subscriberPort, |
| 870 | innerVlan, outerVlan); |
| 871 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplink, subscriberPort, |
| 872 | innerVlan, outerVlan); |
| 873 | |
| 874 | |
| 875 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 876 | @Override |
| 877 | public void onSuccess(Objective objective) { |
| 878 | upFuture.complete(null); |
| 879 | } |
| 880 | |
| 881 | @Override |
| 882 | public void onError(Objective objective, ObjectiveError error) { |
| 883 | upFuture.complete(error); |
| 884 | } |
| 885 | })); |
| 886 | |
| 887 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 888 | @Override |
| 889 | public void onSuccess(Objective objective) { |
| 890 | downFuture.complete(null); |
| 891 | } |
| 892 | |
| 893 | @Override |
| 894 | public void onError(Objective objective, ObjectiveError error) { |
| 895 | downFuture.complete(error); |
| 896 | } |
| 897 | })); |
| 898 | |
| 899 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 900 | if (downStatus != null) { |
| 901 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 902 | "on port {} failed downstream uninstallation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 903 | innerVlan, outerVlan, deviceId, subscriberPort, downStatus); |
| 904 | } else if (upStatus != null) { |
| 905 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 906 | "on port {} failed upstream uninstallation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 907 | innerVlan, outerVlan, deviceId, subscriberPort, upStatus); |
| 908 | } |
| 909 | }, oltInstallers); |
| 910 | |
| 911 | } |
| 912 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 913 | private void processEapolFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 914 | if (!mastershipService.isLocalMaster(devId)) { |
| 915 | return; |
| 916 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 917 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 918 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 919 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 920 | BandwidthProfileInformation defaultBpInfo = getBandwidthProfileInformation(defaultBpId); |
| 921 | if (defaultBpInfo != null) { |
| 922 | MeterId meterId = createMeter(devId, defaultBpInfo); |
| 923 | treatmentBuilder.meter(meterId); |
| 924 | } else { |
| 925 | log.warn("Default bandwidth profile is not found. Authentication flow will be installed without meter"); |
| 926 | } |
| 927 | |
| 928 | //Authentication trap flow uses only tech profile id as metadata |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 929 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 930 | .withKey(Criteria.matchInPort(port)) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 931 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 932 | .withMeta(treatmentBuilder |
| 933 | .writeMetadata((long) defaultTechProfileId << 32, 0) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 934 | .setOutput(PortNumber.CONTROLLER).build()) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 935 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 936 | .withPriority(10000) |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 937 | .add(new ObjectiveContext() { |
| 938 | @Override |
| 939 | public void onSuccess(Objective objective) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 940 | log.info("Eapol filter for {} on {} {}.", |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 941 | devId, port, (install) ? "installed" : "removed"); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public void onError(Objective objective, ObjectiveError error) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 946 | log.info("Eapol filter for {} on {} failed {} because {}", |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 947 | devId, port, (install) ? "installation" : "removal", |
| 948 | error); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 949 | } |
| 950 | }); |
| 951 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 952 | flowObjectiveService.filter(devId, eapol); |
alshabib | 000b6fc | 2016-02-01 17:25:00 -0800 | [diff] [blame] | 953 | |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 956 | /** |
| 957 | * Installs trap filtering objectives for particular traffic types on an |
| 958 | * NNI port. |
| 959 | * |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 960 | * @param devId device ID |
| 961 | * @param port port number |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 962 | * @param install true to install, false to remove |
| 963 | */ |
| 964 | private void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 965 | processLldpFilteringObjective(devId, port, install); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 966 | if (enableDhcpOnProvisioning) { |
| 967 | processDhcpFilteringObjectives(devId, port, install, false); |
| 968 | } |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | private void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
| 972 | if (!mastershipService.isLocalMaster(devId)) { |
| 973 | return; |
| 974 | } |
| 975 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 976 | |
| 977 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 978 | .withKey(Criteria.matchInPort(port)) |
| 979 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 980 | .withMeta(DefaultTrafficTreatment.builder() |
| 981 | .setOutput(PortNumber.CONTROLLER).build()) |
| 982 | .fromApp(appId) |
| 983 | .withPriority(10000) |
| 984 | .add(new ObjectiveContext() { |
| 985 | @Override |
| 986 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 987 | log.info("LLDP filter for device {} on port {} {}.", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 988 | devId, port, (install) ? "installed" : "removed"); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | @Override |
| 992 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 993 | log.info("LLDP filter for device {} on port {} failed {} because {}", |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 994 | devId, port, (install) ? "installation" : "removal", |
| 995 | error); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 996 | } |
| 997 | }); |
| 998 | |
| 999 | flowObjectiveService.filter(devId, lldp); |
| 1000 | |
| 1001 | } |
| 1002 | |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1003 | /** |
| 1004 | * Trap dhcp packets to the controller. |
| 1005 | * |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1006 | * @param devId the device identifier |
| 1007 | * @param port the port for which this trap flow is designated |
| 1008 | * @param install true to install the flow, false to remove the flow |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1009 | * @param upstream true if trapped packets are flowing upstream towards |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1010 | * server, false if packets are flowing dowstream towards client |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1011 | */ |
| 1012 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, |
| 1013 | boolean install, |
| 1014 | boolean upstream) { |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1015 | if (!mastershipService.isLocalMaster(devId)) { |
| 1016 | return; |
| 1017 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1018 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1019 | if (enableDhcpV4) { |
| 1020 | int udpSrc = (upstream) ? 68 : 67; |
| 1021 | int udpDst = (upstream) ? 67 : 68; |
| 1022 | |
| 1023 | EthType ethType = EthType.EtherType.IPV4.ethType(); |
| 1024 | byte protocol = IPv4.PROTOCOL_UDP; |
| 1025 | |
| 1026 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, protocol, install); |
| 1027 | } |
| 1028 | |
| 1029 | if (enableDhcpV6) { |
| 1030 | int udpSrc = (upstream) ? 547 : 546; |
| 1031 | int udpDst = (upstream) ? 546 : 547; |
| 1032 | |
| 1033 | EthType ethType = EthType.EtherType.IPV6.ethType(); |
| 1034 | byte protocol = IPv6.PROTOCOL_UDP; |
| 1035 | |
| 1036 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, protocol, install); |
| 1037 | } |
| 1038 | |
| 1039 | } |
| 1040 | |
| 1041 | private void addDhcpFilteringObjectives(DeviceId devId, |
| 1042 | PortNumber port, |
| 1043 | int udpSrc, |
| 1044 | int udpDst, |
| 1045 | EthType ethType, |
| 1046 | byte protocol, |
| 1047 | boolean install) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1048 | |
| 1049 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1050 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 1051 | .withKey(Criteria.matchInPort(port)) |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1052 | .addCondition(Criteria.matchEthType(ethType)) |
| 1053 | .addCondition(Criteria.matchIPProtocol(protocol)) |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1054 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 1055 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1056 | .withMeta(DefaultTrafficTreatment.builder() |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1057 | .setOutput(PortNumber.CONTROLLER).build()) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1058 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 1059 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1060 | .add(new ObjectiveContext() { |
| 1061 | @Override |
| 1062 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1063 | log.info("DHCP {} filter for device {} on port {} {}.", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1064 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
| 1065 | devId, port, (install) ? "installed" : "removed"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | @Override |
| 1069 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1070 | log.info("DHCP {} filter for device {} on port {} failed {} because {}", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1071 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
| 1072 | devId, port, (install) ? "installation" : "removal", |
| 1073 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1074 | } |
| 1075 | }); |
| 1076 | |
| 1077 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 1078 | } |
| 1079 | |
| 1080 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 1081 | if (!mastershipService.isLocalMaster(devId)) { |
| 1082 | return; |
| 1083 | } |
| 1084 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1085 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1086 | |
| 1087 | builder = install ? builder.permit() : builder.deny(); |
| 1088 | |
| 1089 | FilteringObjective igmp = builder |
| 1090 | .withKey(Criteria.matchInPort(port)) |
| 1091 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 1092 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 1093 | .withMeta(DefaultTrafficTreatment.builder() |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1094 | .setOutput(PortNumber.CONTROLLER).build()) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1095 | .fromApp(appId) |
| 1096 | .withPriority(10000) |
| 1097 | .add(new ObjectiveContext() { |
| 1098 | @Override |
| 1099 | public void onSuccess(Objective objective) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1100 | log.info("Igmp filter for {} on {} {}.", |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1101 | devId, port, (install) ? "installed" : "removed"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | @Override |
| 1105 | public void onError(Objective objective, ObjectiveError error) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1106 | log.info("Igmp filter for {} on {} failed {} because {}.", |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1107 | devId, port, (install) ? "installation" : "removal", |
| 1108 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1109 | } |
| 1110 | }); |
| 1111 | |
| 1112 | flowObjectiveService.filter(devId, igmp); |
| 1113 | } |
| 1114 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1115 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1116 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 1117 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1118 | * |
| 1119 | * @param dev Device to look for |
| 1120 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1121 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1122 | // we create only for the ones we are master of |
| 1123 | if (!mastershipService.isLocalMaster(dev.id())) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1124 | return; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1125 | } |
| 1126 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1127 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1128 | log.debug("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1129 | |
| 1130 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1131 | // This is an OLT device as per Sadis, we create flows for UNI and NNI ports |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1132 | for (Port p : deviceService.getPorts(dev.id())) { |
| 1133 | if (isUniPort(dev, p)) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1134 | processEapolFilteringObjectives(dev.id(), p.number(), true); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1135 | } else { |
| 1136 | processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1142 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1143 | /** |
| 1144 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1145 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1146 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 1147 | * this logic needs to be changed |
| 1148 | * |
| 1149 | * @param dev Device to look for |
| 1150 | * @return The uplink Port of the OLT |
| 1151 | */ |
| 1152 | private Port getUplinkPort(Device dev) { |
| 1153 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1154 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1155 | log.debug("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1156 | if (deviceInfo == null) { |
| 1157 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
| 1158 | + " info", dev.id()); |
| 1159 | return null; |
| 1160 | } |
| 1161 | // Return the port that has been configured as the uplink port of this OLT in Sadis |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1162 | for (Port p : deviceService.getPorts(dev.id())) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1163 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
| 1164 | log.debug("getUplinkPort: Found port {}", p); |
| 1165 | return p; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1169 | log.debug("getUplinkPort: No uplink port found for OLT {}", dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1170 | return null; |
| 1171 | } |
| 1172 | |
| 1173 | /** |
| 1174 | * Return the subscriber on a port. |
| 1175 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1176 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1177 | * @return subscriber if found else null |
| 1178 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1179 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1180 | Port port = deviceService.getPort(cp); |
| 1181 | checkNotNull(port, "Invalid connect point"); |
| 1182 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1183 | return subsService.get(portName); |
| 1184 | } |
| 1185 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame^] | 1186 | /** |
| 1187 | * Write metadata instruction value (metadata) is 8 bytes. |
| 1188 | * |
| 1189 | * MS 2 bytes: C Tag |
| 1190 | * Next 2 bytes: Technology Profile Id |
| 1191 | * Next 4 bytes: Port number (uni or nni) |
| 1192 | */ |
| 1193 | |
| 1194 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 1195 | |
| 1196 | if (techProfileId == -1) { |
| 1197 | techProfileId = DEFAULT_TP_ID; |
| 1198 | } |
| 1199 | |
| 1200 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 1201 | } |
| 1202 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1203 | private boolean isUniPort(Device d, Port p) { |
| 1204 | Port ulPort = getUplinkPort(d); |
| 1205 | if (ulPort != null) { |
| 1206 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1207 | } |
| 1208 | return false; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1211 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 1212 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1213 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1216 | private class InternalDeviceListener implements DeviceListener { |
| 1217 | @Override |
| 1218 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1219 | eventExecutor.execute(() -> { |
| 1220 | DeviceId devId = event.subject().id(); |
| 1221 | Device dev = event.subject(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1222 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1223 | if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 1224 | return; |
| 1225 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1226 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1227 | if (getOltInfo(dev) == null) { |
| 1228 | log.debug("No device info found, this is not an OLT"); |
| 1229 | return; |
| 1230 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1231 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1232 | log.debug("OLT got {} event for {}", event.type(), event.subject()); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1233 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1234 | switch (event.type()) { |
| 1235 | //TODO: Port handling and bookkeeping should be improved once |
| 1236 | // olt firmware handles correct behaviour. |
| 1237 | case PORT_ADDED: |
| 1238 | if (isUniPort(dev, event.port())) { |
| 1239 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1240 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1241 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1242 | processEapolFilteringObjectives(devId, event.port().number(), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1243 | } |
| 1244 | } else { |
| 1245 | checkAndCreateDeviceFlows(dev); |
| 1246 | } |
| 1247 | break; |
| 1248 | case PORT_REMOVED: |
| 1249 | if (isUniPort(dev, event.port())) { |
| 1250 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1251 | processEapolFilteringObjectives(devId, event.port().number(), false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1252 | removeSubscriber(new ConnectPoint(devId, event.port().number())); |
| 1253 | } |
| 1254 | |
| 1255 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
| 1256 | } |
| 1257 | |
| 1258 | break; |
| 1259 | case PORT_UPDATED: |
| 1260 | if (!isUniPort(dev, event.port())) { |
| 1261 | break; |
| 1262 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1263 | |
| 1264 | if (event.port().isEnabled()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1265 | processEapolFilteringObjectives(devId, event.port().number(), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1266 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, event.port())); |
| 1267 | } else { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1268 | processEapolFilteringObjectives(devId, event.port().number(), false); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1269 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, event.port())); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1270 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1271 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1272 | case DEVICE_ADDED: |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1273 | post(new AccessDeviceEvent( |
| 1274 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1275 | null, null)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1276 | |
| 1277 | // Send UNI_ADDED events for all existing ports |
| 1278 | deviceService.getPorts(devId).stream() |
| 1279 | .filter(p -> isUniPort(dev, p)) |
| 1280 | .filter(Port::isEnabled) |
| 1281 | .forEach(p -> post(new AccessDeviceEvent( |
| 1282 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 1283 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1284 | checkAndCreateDeviceFlows(dev); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1285 | break; |
| 1286 | case DEVICE_REMOVED: |
| 1287 | deviceService.getPorts(devId).stream() |
| 1288 | .filter(p -> isUniPort(dev, p)) |
| 1289 | .forEach(p -> post(new AccessDeviceEvent( |
| 1290 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
| 1291 | |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1292 | post(new AccessDeviceEvent( |
| 1293 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1294 | null, null)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1295 | break; |
| 1296 | case DEVICE_AVAILABILITY_CHANGED: |
| 1297 | if (deviceService.isAvailable(devId)) { |
| 1298 | post(new AccessDeviceEvent( |
| 1299 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1300 | null, null)); |
| 1301 | checkAndCreateDeviceFlows(dev); |
| 1302 | } else { |
| 1303 | post(new AccessDeviceEvent( |
| 1304 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1305 | null, null)); |
| 1306 | } |
| 1307 | break; |
| 1308 | case DEVICE_UPDATED: |
| 1309 | case DEVICE_SUSPENDED: |
| 1310 | case PORT_STATS_UPDATED: |
| 1311 | default: |
| 1312 | return; |
| 1313 | } |
| 1314 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1315 | } |
| 1316 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1317 | |
| 1318 | private class InternalMeterListener implements MeterListener { |
| 1319 | |
| 1320 | @Override |
| 1321 | public void event(MeterEvent meterEvent) { |
| 1322 | if (deleteMeters && MeterEvent.Type.METER_REFERENCE_COUNT_ZERO.equals(meterEvent.type())) { |
| 1323 | log.debug("Zero Count Meter Event is received. Meter is {}", meterEvent.subject()); |
| 1324 | Meter meter = meterEvent.subject(); |
| 1325 | if (meter != null && appId.equals(meter.appId())) { |
| 1326 | deleteMeter(meter.deviceId(), meter.id()); |
| 1327 | } |
| 1328 | } else if (MeterEvent.Type.METER_REMOVED.equals(meterEvent.type())) { |
| 1329 | log.debug("Meter removed event is received. Meter is {}", meterEvent.subject()); |
| 1330 | removeMeterFromBpMap(meterEvent.subject()); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | private void deleteMeter(DeviceId deviceId, MeterId meterId) { |
| 1335 | Meter meter = meterService.getMeter(deviceId, meterId); |
| 1336 | MeterRequest meterRequest = DefaultMeterRequest.builder() |
| 1337 | .withBands(meter.bands()) |
| 1338 | .withUnit(meter.unit()) |
| 1339 | .forDevice(deviceId) |
| 1340 | .fromApp(appId) |
| 1341 | .burst() |
| 1342 | .remove(); |
| 1343 | |
| 1344 | meterService.withdraw(meterRequest, meterId); |
| 1345 | |
| 1346 | } |
| 1347 | |
| 1348 | private void removeMeterFromBpMap(Meter meter) { |
| 1349 | for (Map.Entry<String, MeterId> entry : bpInfoToMeter.entrySet()) { |
| 1350 | if (entry.getValue().equals(meter.id())) { |
| 1351 | bpInfoToMeter.remove(entry.getKey()); |
| 1352 | log.info("Deleted from the internal map. Profile {} and Meter {}", entry.getKey(), meter.id()); |
| 1353 | break; |
| 1354 | } |
| 1355 | } |
| 1356 | } |
| 1357 | } |
| 1358 | } |