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; |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 26 | import java.util.Arrays; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 27 | import java.util.ArrayList; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 28 | import java.util.Collection; |
| 29 | import java.util.Dictionary; |
| 30 | import java.util.List; |
| 31 | import java.util.Map; |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 32 | import java.util.Objects; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 33 | import java.util.Optional; |
| 34 | import java.util.Properties; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 35 | import java.util.Set; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 36 | import java.util.concurrent.CompletableFuture; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 37 | import java.util.concurrent.ConcurrentHashMap; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 38 | import java.util.concurrent.ExecutorService; |
| 39 | import java.util.concurrent.Executors; |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 40 | import java.util.stream.Collectors; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 41 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 42 | import com.google.common.collect.ImmutableSet; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 43 | import org.apache.felix.scr.annotations.Activate; |
| 44 | import org.apache.felix.scr.annotations.Component; |
| 45 | import org.apache.felix.scr.annotations.Deactivate; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 46 | import org.apache.felix.scr.annotations.Modified; |
| 47 | import org.apache.felix.scr.annotations.Property; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 48 | import org.apache.felix.scr.annotations.Reference; |
| 49 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 50 | import org.apache.felix.scr.annotations.Service; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 51 | import org.onlab.packet.EthType; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 52 | import org.onlab.packet.IPv4; |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 53 | import org.onlab.packet.IPv6; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 54 | import org.onlab.packet.TpPort; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 55 | import org.onlab.packet.VlanId; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 56 | import org.onlab.util.Tools; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 57 | import org.onosproject.cfg.ComponentConfigService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 58 | import org.onosproject.core.ApplicationId; |
| 59 | import org.onosproject.core.CoreService; |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 60 | import org.onosproject.event.AbstractListenerManager; |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 61 | import org.onosproject.mastership.MastershipService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 62 | import org.onosproject.net.AnnotationKeys; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 63 | import org.onosproject.net.ConnectPoint; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 64 | import org.onosproject.net.Device; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 65 | import org.onosproject.net.DeviceId; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 66 | import org.onosproject.net.Port; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 67 | import org.onosproject.net.PortNumber; |
| 68 | import org.onosproject.net.device.DeviceEvent; |
| 69 | import org.onosproject.net.device.DeviceListener; |
| 70 | import org.onosproject.net.device.DeviceService; |
| 71 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 72 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 73 | import org.onosproject.net.flow.TrafficSelector; |
| 74 | import org.onosproject.net.flow.TrafficTreatment; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 75 | import org.onosproject.net.flow.criteria.Criteria; |
| 76 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 77 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 78 | import org.onosproject.net.flowobjective.FilteringObjective; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 79 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 80 | import org.onosproject.net.flowobjective.ForwardingObjective; |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 81 | import org.onosproject.net.flowobjective.Objective; |
| 82 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 83 | import org.onosproject.net.flowobjective.ObjectiveError; |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 84 | import org.onosproject.store.serializers.KryoNamespaces; |
| 85 | import org.onosproject.store.service.ConsistentMultimap; |
| 86 | import org.onosproject.store.service.Serializer; |
| 87 | import org.onosproject.store.service.StorageService; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 88 | import org.onosproject.net.meter.Band; |
| 89 | import org.onosproject.net.meter.DefaultBand; |
| 90 | import org.onosproject.net.meter.DefaultMeterRequest; |
| 91 | import org.onosproject.net.meter.Meter; |
| 92 | import org.onosproject.net.meter.MeterContext; |
| 93 | import org.onosproject.net.meter.MeterFailReason; |
| 94 | import org.onosproject.net.meter.MeterKey; |
| 95 | import org.onosproject.net.meter.MeterService; |
| 96 | import org.onosproject.net.meter.MeterListener; |
| 97 | import org.onosproject.net.meter.MeterRequest; |
| 98 | import org.onosproject.net.meter.MeterId; |
| 99 | import org.onosproject.net.meter.MeterEvent; |
alshabib | 36a4d73 | 2016-06-01 16:03:59 -0700 | [diff] [blame] | 100 | import org.opencord.olt.AccessDeviceEvent; |
| 101 | import org.opencord.olt.AccessDeviceListener; |
| 102 | import org.opencord.olt.AccessDeviceService; |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 103 | import org.opencord.olt.AccessSubscriberId; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 104 | import org.opencord.sadis.BandwidthProfileInformation; |
| 105 | import org.opencord.sadis.BaseInformationService; |
| 106 | import org.opencord.sadis.SadisService; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 107 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 108 | import org.osgi.service.component.ComponentContext; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 109 | import org.slf4j.Logger; |
| 110 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 111 | import com.google.common.collect.ImmutableMap; |
| 112 | import com.google.common.collect.Maps; |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 113 | import com.google.common.collect.Sets; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 116 | * Provisions rules on access devices. |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 117 | */ |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 118 | @Service |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 119 | @Component(immediate = true) |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 120 | public class Olt |
| 121 | extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> |
| 122 | implements AccessDeviceService { |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 123 | private static final String APP_NAME = "org.opencord.olt"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 124 | |
| 125 | private static final short DEFAULT_VLAN = 0; |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 126 | private static final short EAPOL_DEFAULT_VLAN = 4091; |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 127 | private static final int DEFAULT_TP_ID = 64; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 128 | private static final String DEFAULT_BP_ID = "Default"; |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 129 | private static final String ADDITIONAL_VLANS = "additional-vlans"; |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 130 | private static final String NO_UPLINK_PORT = "No uplink port found for OLT device {}"; |
| 131 | private static final String INSTALLED = "installed"; |
| 132 | private static final String REMOVED = "removed"; |
| 133 | private static final String INSTALLATION = "installation"; |
| 134 | private static final String REMOVAL = "removal"; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 135 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 136 | private final Logger log = getLogger(getClass()); |
| 137 | |
| 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 139 | protected FlowObjectiveService flowObjectiveService; |
| 140 | |
| 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 142 | protected MastershipService mastershipService; |
| 143 | |
| 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 145 | protected DeviceService deviceService; |
| 146 | |
| 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 148 | protected CoreService coreService; |
| 149 | |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 151 | protected ComponentConfigService componentConfigService; |
| 152 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 154 | protected SadisService sadisService; |
| 155 | |
| 156 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 157 | protected MeterService meterService; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 158 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 160 | protected StorageService storageService; |
| 161 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 162 | @Property(name = "defaultVlan", intValue = DEFAULT_VLAN, |
| 163 | label = "Default VLAN RG<->ONU traffic") |
| 164 | private int defaultVlan = DEFAULT_VLAN; |
| 165 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 166 | @Property(name = "enableDhcpOnProvisioning", boolValue = true, |
| 167 | label = "Create the DHCP Flow rules when a subscriber is provisioned") |
| 168 | protected boolean enableDhcpOnProvisioning = false; |
| 169 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 170 | @Property(name = "enableDhcpV4", boolValue = true, |
| 171 | label = "Enable flows for DHCP v4") |
| 172 | protected boolean enableDhcpV4 = true; |
| 173 | |
| 174 | @Property(name = "enableDhcpV6", boolValue = true, |
| 175 | label = "Enable flows for DHCP v6") |
| 176 | protected boolean enableDhcpV6 = false; |
| 177 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 178 | @Property(name = "enableIgmpOnProvisioning", boolValue = false, |
| 179 | label = "Create IGMP Flow rules when a subscriber is provisioned") |
| 180 | protected boolean enableIgmpOnProvisioning = false; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 181 | |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 182 | @Property(name = "deleteMeters", boolValue = true, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 183 | label = "Deleting Meters based on flow count statistics") |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 184 | protected boolean deleteMeters = true; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 185 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 186 | @Property(name = "defaultTechProfileId", intValue = DEFAULT_TP_ID, |
| 187 | label = "Default technology profile id that is used for authentication trap flows") |
| 188 | protected int defaultTechProfileId = DEFAULT_TP_ID; |
| 189 | |
| 190 | @Property(name = "defaultBpId", value = DEFAULT_BP_ID, |
| 191 | label = "Default bandwidth profile id that is used for authentication trap flows") |
| 192 | protected String defaultBpId = DEFAULT_BP_ID; |
| 193 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 194 | @Property(name = "enableEapol", boolValue = true, |
| 195 | label = "Send EAPOL authentication trap flows before subscriber provisioning") |
| 196 | protected boolean enableEapol = true; |
| 197 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 198 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 199 | private final MeterListener meterListener = new InternalMeterListener(); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 200 | |
| 201 | private ApplicationId appId; |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 202 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
| 203 | private BaseInformationService<BandwidthProfileInformation> bpService; |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 204 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 205 | private Map<String, List<MeterKey>> bpInfoToMeter = new ConcurrentHashMap<>(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 206 | |
| 207 | private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, |
| 208 | groupedThreads("onos/olt-service", |
| 209 | "olt-installer-%d")); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 210 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 211 | private ConsistentMultimap<ConnectPoint, Map.Entry<VlanId, VlanId>> additionalVlans; |
| 212 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 213 | protected ExecutorService eventExecutor; |
| 214 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 215 | private Map<ConnectPoint, SubscriberAndDeviceInformation> programmedSubs; |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 216 | private Set<MeterKey> programmedMeters; |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 217 | |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 218 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 219 | @Activate |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 220 | public void activate(ComponentContext context) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 221 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("onos/olt", "events-%d", log)); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 222 | modified(context); |
Charles Chan | 54f110f | 2017-01-20 11:22:42 -0800 | [diff] [blame] | 223 | appId = coreService.registerApplication(APP_NAME); |
Saurav Das | 62ad75e | 2019-03-05 12:22:22 -0800 | [diff] [blame] | 224 | |
| 225 | // ensure that flow rules are purged from flow-store upon olt-disconnection |
| 226 | // when olt reconnects, the port-numbers may change for the ONUs |
| 227 | // making flows pushed earlier invalid |
| 228 | componentConfigService |
| 229 | .preSetProperty("org.onosproject.net.flow.impl.FlowRuleManager", |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 230 | "purgeOnDisconnection", "true"); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 231 | componentConfigService |
| 232 | .preSetProperty("org.onosproject.net.meter.impl.MeterManager", |
| 233 | "purgeOnDisconnection", "true"); |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 234 | componentConfigService.registerProperties(getClass()); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 235 | programmedSubs = Maps.newConcurrentMap(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 236 | programmedMeters = ConcurrentHashMap.newKeySet(); |
alshabib | c4dfe85 | 2015-06-05 13:35:13 -0700 | [diff] [blame] | 237 | |
alshabib | 8e4fd2f | 2016-01-12 15:55:53 -0800 | [diff] [blame] | 238 | eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); |
| 239 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 240 | subsService = sadisService.getSubscriberInfoService(); |
| 241 | bpService = sadisService.getBandwidthProfileService(); |
| 242 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 243 | // look for all provisioned devices in Sadis and create EAPOL flows for the |
| 244 | // UNI ports |
| 245 | Iterable<Device> devices = deviceService.getDevices(); |
| 246 | for (Device d : devices) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 247 | checkAndCreateDeviceFlows(d); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 248 | } |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 249 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 250 | additionalVlans = storageService.<ConnectPoint, Map.Entry<VlanId, VlanId>>consistentMultimapBuilder() |
| 251 | .withName(ADDITIONAL_VLANS) |
| 252 | .withSerializer(Serializer.using(Arrays.asList(KryoNamespaces.API), |
| 253 | AbstractMap.SimpleEntry.class)) |
| 254 | .build(); |
| 255 | |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 256 | deviceService.addListener(deviceListener); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 257 | meterService.addListener(meterListener); |
alshabib | ba35749 | 2016-01-27 13:49:46 -0800 | [diff] [blame] | 258 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 259 | log.info("Started with Application ID {}", appId.id()); |
| 260 | } |
| 261 | |
| 262 | @Deactivate |
| 263 | public void deactivate() { |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 264 | componentConfigService.unregisterProperties(getClass(), false); |
alshabib | 62e9ce7 | 2016-02-11 17:31:36 -0800 | [diff] [blame] | 265 | deviceService.removeListener(deviceListener); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 266 | meterService.removeListener(meterListener); |
Jonathan Hart | 5f1c814 | 2018-07-24 17:31:59 -0700 | [diff] [blame] | 267 | eventDispatcher.removeSink(AccessDeviceEvent.class); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 268 | log.info("Stopped"); |
| 269 | } |
| 270 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 271 | @Modified |
| 272 | public void modified(ComponentContext context) { |
| 273 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 274 | |
| 275 | try { |
| 276 | String s = get(properties, "defaultVlan"); |
| 277 | defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 278 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 279 | Boolean o = Tools.isPropertyEnabled(properties, "enableDhcpOnProvisioning"); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 280 | if (o != null) { |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 281 | enableDhcpOnProvisioning = o; |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 282 | } |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 283 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 284 | Boolean v4 = Tools.isPropertyEnabled(properties, "enableDhcpV4"); |
| 285 | if (v4 != null) { |
| 286 | enableDhcpV4 = v4; |
| 287 | } |
| 288 | |
| 289 | Boolean v6 = Tools.isPropertyEnabled(properties, "enableDhcpV6"); |
| 290 | if (v6 != null) { |
| 291 | enableDhcpV6 = v6; |
| 292 | } |
| 293 | |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 294 | Boolean p = Tools.isPropertyEnabled(properties, "enableIgmpOnProvisioning"); |
| 295 | if (p != null) { |
| 296 | enableIgmpOnProvisioning = p; |
| 297 | } |
| 298 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 299 | log.info("DHCP Settings [enableDhcpOnProvisioning: {}, enableDhcpV4: {}, enableDhcpV6: {}]", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 300 | enableDhcpOnProvisioning, enableDhcpV4, enableDhcpV6); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 301 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 302 | Boolean d = Tools.isPropertyEnabled(properties, "deleteMeters"); |
| 303 | if (d != null) { |
| 304 | deleteMeters = d; |
| 305 | } |
| 306 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 307 | String tpId = get(properties, "defaultTechProfileId"); |
| 308 | defaultTechProfileId = isNullOrEmpty(s) ? DEFAULT_TP_ID : Integer.parseInt(tpId.trim()); |
| 309 | |
| 310 | String bpId = get(properties, "defaultBpId"); |
| 311 | defaultBpId = bpId; |
| 312 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 313 | Boolean eap = Tools.isPropertyEnabled(properties, "enableEapol"); |
| 314 | if (eap != null) { |
| 315 | enableEapol = eap; |
| 316 | } |
| 317 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 318 | } catch (Exception e) { |
| 319 | defaultVlan = DEFAULT_VLAN; |
| 320 | } |
| 321 | } |
| 322 | |
alshabib | 32232c8 | 2016-02-25 17:57:24 -0500 | [diff] [blame] | 323 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 324 | public boolean provisionSubscriber(ConnectPoint connectPoint) { |
| 325 | |
| 326 | DeviceId deviceId = connectPoint.deviceId(); |
| 327 | PortNumber subscriberPortNo = connectPoint.port(); |
| 328 | |
| 329 | checkNotNull(deviceService.getPort(deviceId, subscriberPortNo), |
Jonathan Hart | 94b9049 | 2018-04-24 14:02:25 -0700 | [diff] [blame] | 330 | "Invalid connect point"); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 331 | // Find the subscriber on this connect point |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 332 | SubscriberAndDeviceInformation sub = getSubscriber(connectPoint); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 333 | if (sub == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 334 | log.warn("No subscriber found for {}", connectPoint); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 335 | return false; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 336 | } |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 337 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 338 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 339 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 340 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 341 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 342 | return false; |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 345 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 346 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 347 | //delete Eapol authentication flow with default bandwidth |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 348 | //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 349 | processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, filterFuture, |
| 350 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 351 | removeMeterIdFromBpMapping(deviceId, defaultBpId); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 352 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 353 | //install subscriber flows |
| 354 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 355 | if (filterStatus == null) { |
| 356 | provisionSubscriberBasedFlows(connectPoint, uplinkPort.number(), Optional.empty(), sub); |
| 357 | } |
| 358 | }); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 359 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 360 | // cache subscriber info |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 361 | programmedSubs.put(connectPoint, sub); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 362 | return true; |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | @Override |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 366 | public boolean removeSubscriber(ConnectPoint connectPoint) { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 367 | // Get the subscriber connected to this port from the local cache |
| 368 | // as if we don't know about the subscriber there's no need to remove it |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 369 | |
| 370 | DeviceId deviceId = connectPoint.deviceId(); |
| 371 | PortNumber subscriberPortNo = connectPoint.port(); |
| 372 | |
| 373 | SubscriberAndDeviceInformation subscriber = programmedSubs.get(connectPoint); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 374 | if (subscriber == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 375 | log.warn("Subscriber on connectionPoint {} was not previously programmed, " + |
| 376 | "no need to remove it", connectPoint); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 377 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 380 | // Get the uplink port |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 381 | Port uplinkPort = getUplinkPort(deviceService.getDevice(deviceId)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 382 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 383 | log.warn(NO_UPLINK_PORT, deviceId); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 384 | return false; |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 387 | //delete dhcp & igmp trap flows |
| 388 | MeterId upstreamMeterId = getMeterIdFromBpMapping(deviceId, subscriber.upstreamBandwidthProfile()); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 389 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 390 | //process dhcp filtering |
| 391 | processDhcpFilteringObjectives(deviceId, subscriberPortNo, |
| 392 | upstreamMeterId, subscriber.technologyProfileId(), false, true); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 393 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 394 | //process igmp filtering |
| 395 | processIgmpFilteringObjectives(deviceId, subscriberPortNo, |
| 396 | upstreamMeterId, subscriber.technologyProfileId(), false); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 397 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 398 | //unprovision vlans |
| 399 | unprovisionVlans(deviceId, uplinkPort.number(), subscriberPortNo, subscriber, Optional.empty()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 400 | |
| 401 | // Remove if there are any flows for the additional Vlans |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 402 | Collection<? extends Map.Entry<VlanId, VlanId>> vlansList = additionalVlans.get(connectPoint).value(); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 403 | |
| 404 | // Remove the flows for the additional vlans for this subscriber |
| 405 | for (Map.Entry<VlanId, VlanId> vlans : vlansList) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 406 | unprovisionTransparentFlows(deviceId, uplinkPort.number(), subscriberPortNo, |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 407 | vlans.getValue(), vlans.getKey()); |
| 408 | |
| 409 | // Remove it from the map also |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 410 | additionalVlans.remove(connectPoint, vlans); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 413 | //re-install eapol |
| 414 | processEapolFilteringObjectives(deviceId, subscriberPortNo, |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 415 | subscriber.upstreamBandwidthProfile(), null, subscriber.cTag(), false); |
| 416 | processEapolFilteringObjectives(deviceId, subscriberPortNo, defaultBpId, |
| 417 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 418 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 419 | programmedSubs.remove(connectPoint); |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 420 | return true; |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 421 | } |
| 422 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 423 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 424 | public boolean provisionSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 425 | |
| 426 | log.info("Provisioning subscriber using subscriberId {}, sTag {}, cTag {}", subscriberId, sTag, cTag); |
| 427 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 428 | // Check if we can find the connect point to which this subscriber is connected |
| 429 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 430 | if (subsPort == null) { |
| 431 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 432 | return false; |
| 433 | } |
| 434 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 435 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 436 | return provisionSubscriber(subsPort); |
| 437 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 438 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 439 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 440 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 441 | return false; |
| 442 | } |
| 443 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 444 | CompletableFuture<ObjectiveError> filterFuture = new CompletableFuture(); |
| 445 | |
| 446 | //delete Eapol authentication flow with default bandwidth |
| 447 | //wait until Eapol rule with defaultBpId is removed to install subscriber-based rules |
| 448 | processEapolFilteringObjectives(subsPort.deviceId(), subsPort.port(), defaultBpId, filterFuture, |
| 449 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), false); |
| 450 | removeMeterIdFromBpMapping(subsPort.deviceId(), defaultBpId); |
| 451 | |
| 452 | //install subscriber flows |
| 453 | filterFuture.thenAcceptAsync(filterStatus -> { |
| 454 | if (filterStatus == null) { |
| 455 | provisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 456 | cTag.get(), sTag.get()); |
| 457 | } |
| 458 | }); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 459 | return true; |
| 460 | } else { |
| 461 | log.warn("Provisioning failed for subscriber: {}", subscriberId); |
| 462 | return false; |
| 463 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 464 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 465 | |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 466 | @Override |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 467 | public boolean removeSubscriber(AccessSubscriberId subscriberId, Optional<VlanId> sTag, Optional<VlanId> cTag) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 468 | // Check if we can find the connect point to which this subscriber is connected |
| 469 | ConnectPoint subsPort = findSubscriberConnectPoint(subscriberId.toString()); |
| 470 | if (subsPort == null) { |
| 471 | log.warn("ConnectPoint for {} not found", subscriberId); |
| 472 | return false; |
| 473 | } |
| 474 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 475 | if (!sTag.isPresent() && !cTag.isPresent()) { |
| 476 | return removeSubscriber(subsPort); |
| 477 | } else if (sTag.isPresent() && cTag.isPresent()) { |
| 478 | // Get the uplink port |
| 479 | Port uplinkPort = getUplinkPort(deviceService.getDevice(subsPort.deviceId())); |
| 480 | if (uplinkPort == null) { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 481 | log.warn(NO_UPLINK_PORT, subsPort.deviceId()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 482 | return false; |
| 483 | } |
| 484 | |
| 485 | unprovisionTransparentFlows(subsPort.deviceId(), uplinkPort.number(), subsPort.port(), |
| 486 | cTag.get(), sTag.get()); |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 487 | |
| 488 | programmedSubs.remove(subsPort); |
| 489 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 490 | return true; |
| 491 | } else { |
| 492 | log.warn("Removing subscriber failed for: {}", subscriberId); |
| 493 | return false; |
| 494 | } |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public Collection<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> getSubscribers() { |
| 499 | ArrayList<Map.Entry<ConnectPoint, Map.Entry<VlanId, VlanId>>> subs = new ArrayList<>(); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 500 | |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 501 | // Get the subscribers for all the devices configured in sadis |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 502 | // If the port is UNI, is enabled and exists in Sadis then copy it |
| 503 | for (Device d : deviceService.getDevices()) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 504 | if (getOltInfo(d) == null) { |
| 505 | continue; // not an olt, or not configured in sadis |
| 506 | } |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 507 | for (Port p : deviceService.getPorts(d.id())) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 508 | if (isUniPort(d, p) && p.isEnabled()) { |
| 509 | ConnectPoint cp = new ConnectPoint(d.id(), p.number()); |
| 510 | |
| 511 | SubscriberAndDeviceInformation sub = getSubscriber(cp); |
| 512 | if (sub != null) { |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 513 | Map.Entry<VlanId, VlanId> vlans = new AbstractMap.SimpleEntry(sub.sTag(), sub.cTag()); |
| 514 | subs.add(new AbstractMap.SimpleEntry(cp, vlans)); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | return subs; |
Jonathan Hart | fd6c1b3 | 2016-03-08 14:09:09 -0800 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 524 | public ImmutableMap<ConnectPoint, SubscriberAndDeviceInformation> getProgSubs() { |
| 525 | return ImmutableMap.copyOf(programmedSubs); |
| 526 | } |
| 527 | |
| 528 | @Override |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 529 | public ImmutableSet<MeterKey> getProgMeters() { |
| 530 | return ImmutableSet.copyOf(programmedMeters); |
| 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public ImmutableMap<String, List<MeterKey>> getBpMeterMappings() { |
| 535 | return ImmutableMap.copyOf(bpInfoToMeter); |
| 536 | } |
| 537 | |
| 538 | @Override |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 539 | public List<DeviceId> fetchOlts() { |
| 540 | // look through all the devices and find the ones that are OLTs as per Sadis |
| 541 | List<DeviceId> olts = new ArrayList<>(); |
| 542 | Iterable<Device> devices = deviceService.getDevices(); |
| 543 | for (Device d : devices) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 544 | if (getOltInfo(d) != null) { |
| 545 | // So this is indeed an OLT device |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 546 | olts.add(d.id()); |
| 547 | } |
| 548 | } |
| 549 | return olts; |
alshabib | e055967 | 2016-02-21 14:49:51 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Amit Ghosh | 3193952 | 2018-08-16 13:28:21 +0100 | [diff] [blame] | 552 | /** |
| 553 | * Finds the connect point to which a subscriber is connected. |
| 554 | * |
| 555 | * @param id The id of the subscriber, this is the same ID as in Sadis |
| 556 | * @return Subscribers ConnectPoint if found else null |
| 557 | */ |
| 558 | private ConnectPoint findSubscriberConnectPoint(String id) { |
| 559 | |
| 560 | Iterable<Device> devices = deviceService.getDevices(); |
| 561 | for (Device d : devices) { |
| 562 | for (Port p : deviceService.getPorts(d.id())) { |
| 563 | log.trace("Comparing {} with {}", p.annotations().value(AnnotationKeys.PORT_NAME), id); |
| 564 | if (p.annotations().value(AnnotationKeys.PORT_NAME).equals(id)) { |
| 565 | log.debug("Found on device {} port {}", d.id(), p.number()); |
| 566 | return new ConnectPoint(d.id(), p.number()); |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | return null; |
| 571 | } |
| 572 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 573 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 574 | if (bandwidthProfile == null) { |
| 575 | return null; |
| 576 | } |
| 577 | return bpService.get(bandwidthProfile); |
| 578 | } |
| 579 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 580 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 581 | * Removes subscriber vlan flows. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 582 | * |
| 583 | * @param deviceId the device identifier |
| 584 | * @param uplink uplink port of the OLT |
| 585 | * @param subscriberPort uni port |
| 586 | * @param subscriber subscriber info that includes s, c tags, tech profile and bandwidth profile references |
| 587 | * @param defaultVlan default vlan of the subscriber |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 588 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 589 | private void unprovisionVlans(DeviceId deviceId, PortNumber uplink, |
| 590 | PortNumber subscriberPort, SubscriberAndDeviceInformation subscriber, |
| 591 | Optional<VlanId> defaultVlan) { |
| 592 | |
| 593 | log.info("Unprovisioning vlans..."); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 594 | |
| 595 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 596 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 597 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 598 | VlanId deviceVlan = subscriber.sTag(); |
| 599 | VlanId subscriberVlan = subscriber.cTag(); |
| 600 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 601 | MeterId upstreamMeterId = getMeterIdFromBpMapping(deviceId, subscriber.upstreamBandwidthProfile()); |
| 602 | MeterId downstreamMeterId = getMeterIdFromBpMapping(deviceId, subscriber.downstreamBandwidthProfile()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 603 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 604 | ForwardingObjective.Builder upFwd = upBuilder(uplink, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 605 | subscriberVlan, deviceVlan, |
| 606 | defaultVlan, upstreamMeterId, subscriber.technologyProfileId()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 607 | ForwardingObjective.Builder downFwd = downBuilder(uplink, subscriberPort, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 608 | subscriberVlan, deviceVlan, |
| 609 | defaultVlan, downstreamMeterId, subscriber.technologyProfileId()); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 610 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 611 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 612 | @Override |
| 613 | public void onSuccess(Objective objective) { |
| 614 | upFuture.complete(null); |
| 615 | } |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 616 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 617 | @Override |
| 618 | public void onError(Objective objective, ObjectiveError error) { |
| 619 | upFuture.complete(error); |
| 620 | } |
| 621 | })); |
| 622 | |
| 623 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 624 | @Override |
| 625 | public void onSuccess(Objective objective) { |
| 626 | downFuture.complete(null); |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public void onError(Objective objective, ObjectiveError error) { |
| 631 | downFuture.complete(error); |
| 632 | } |
| 633 | })); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 634 | |
| 635 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 636 | if (upStatus == null && downStatus == null) { |
| 637 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_UNREGISTERED, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 638 | deviceId, |
| 639 | deviceVlan, |
| 640 | subscriberVlan)); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 641 | } else if (downStatus != null) { |
| 642 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 643 | "on port {} failed downstream uninstallation: {}", |
| 644 | subscriberVlan, deviceId, subscriberPort, downStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 645 | } else if (upStatus != null) { |
| 646 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 647 | "on port {} failed upstream uninstallation: {}", |
| 648 | subscriberVlan, deviceId, subscriberPort, upStatus); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 649 | } |
| 650 | }, oltInstallers); |
alshabib | b7a9e17 | 2016-01-13 11:23:53 -0800 | [diff] [blame] | 651 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 652 | programmedMeters.remove(MeterKey.key(deviceId, upstreamMeterId)); |
| 653 | programmedMeters.remove(MeterKey.key(deviceId, downstreamMeterId)); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 654 | log.debug("programmed Meters size {}", programmedMeters.size()); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 657 | /** |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 658 | * Adds subscriber vlan flows, dhcp, eapol and igmp trap flows for the related uni port. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 659 | * |
| 660 | * @param port the connection point of the subscriber |
| 661 | * @param uplinkPort uplink port of the OLT |
| 662 | * @param defaultVlan default vlan of the subscriber |
| 663 | * @param sub subscriber information that includes s, c tags, tech profile and bandwidth profile references |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 664 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 665 | private void provisionSubscriberBasedFlows(ConnectPoint port, PortNumber uplinkPort, Optional<VlanId> defaultVlan, |
| 666 | SubscriberAndDeviceInformation sub) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 667 | |
| 668 | log.info("Provisioning vlans..."); |
| 669 | |
| 670 | DeviceId deviceId = port.deviceId(); |
| 671 | PortNumber subscriberPort = port.port(); |
| 672 | VlanId deviceVlan = sub.sTag(); |
| 673 | VlanId subscriberVlan = sub.cTag(); |
| 674 | int techProfId = sub.technologyProfileId(); |
| 675 | |
| 676 | BandwidthProfileInformation upstreamBpInfo = getBandwidthProfileInformation(sub.upstreamBandwidthProfile()); |
| 677 | BandwidthProfileInformation downstreamBpInfo = getBandwidthProfileInformation(sub.downstreamBandwidthProfile()); |
| 678 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 679 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 680 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 681 | CompletableFuture<Object> upstreamMeterFuture = new CompletableFuture<>(); |
| 682 | CompletableFuture<Object> downsteamMeterFuture = new CompletableFuture<>(); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 683 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 684 | MeterId upstreamMeterId = createMeter(deviceId, upstreamBpInfo, upstreamMeterFuture); |
| 685 | MeterId downstreamMeterId = createMeter(deviceId, downstreamBpInfo, downsteamMeterFuture); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 686 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 687 | //install upstream flows |
| 688 | upstreamMeterFuture.thenAcceptAsync(result -> { |
| 689 | if (result == null) { |
| 690 | log.info("Upstream Meter {} is sent to the device {}. " + |
| 691 | "Sending subscriber flows.", upstreamMeterId, deviceId); |
| 692 | ForwardingObjective.Builder upFwd = upBuilder(uplinkPort, subscriberPort, |
| 693 | subscriberVlan, deviceVlan, |
| 694 | defaultVlan, upstreamMeterId, techProfId); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 695 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 696 | |
| 697 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 698 | @Override |
| 699 | public void onSuccess(Objective objective) { |
| 700 | upFuture.complete(null); |
| 701 | } |
| 702 | |
| 703 | @Override |
| 704 | public void onError(Objective objective, ObjectiveError error) { |
| 705 | upFuture.complete(error); |
| 706 | } |
| 707 | })); |
| 708 | } else { |
| 709 | log.warn("Meter installation error while sending upstream flows. " + |
| 710 | "Result {} and MeterId {}", result, upstreamMeterId); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 711 | } |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 712 | }); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 713 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 714 | //install downstream flows |
| 715 | downsteamMeterFuture.thenAcceptAsync(result -> { |
| 716 | if (result == null) { |
| 717 | log.info("Downstream Meter {} is sent to the device {}. " + |
| 718 | "Sending subscriber flows.", downstreamMeterId, deviceId); |
| 719 | ForwardingObjective.Builder downFwd = downBuilder(uplinkPort, subscriberPort, |
| 720 | subscriberVlan, deviceVlan, |
| 721 | defaultVlan, downstreamMeterId, techProfId); |
| 722 | |
| 723 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 724 | @Override |
| 725 | public void onSuccess(Objective objective) { |
| 726 | downFuture.complete(null); |
| 727 | } |
| 728 | |
| 729 | @Override |
| 730 | public void onError(Objective objective, ObjectiveError error) { |
| 731 | downFuture.complete(error); |
| 732 | } |
| 733 | })); |
| 734 | } else { |
| 735 | log.warn("Meter installation error while sending downstream flows. " + |
| 736 | "Result {} and MeterId {}", result, downstreamMeterId); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 737 | } |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 738 | }); |
alshabib | bf23a1f | 2016-01-14 17:27:11 -0800 | [diff] [blame] | 739 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 740 | //send eapol & dhcp & igmp flows |
| 741 | //send Subscriber Registered event |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 742 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 743 | if (upStatus == null && downStatus == null) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 744 | |
| 745 | if (upstreamMeterId != null) { |
| 746 | //re-install Eapol authentication flow with the subscribers' upstream bandwidth profile |
| 747 | processEapolFilteringObjectives(deviceId, subscriberPort, sub.upstreamBandwidthProfile(), |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 748 | null, sub.cTag(), true); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 749 | |
| 750 | processDhcpFilteringObjectives(deviceId, subscriberPort, |
| 751 | upstreamMeterId, sub.technologyProfileId(), true, true); |
| 752 | |
| 753 | processIgmpFilteringObjectives(deviceId, subscriberPort, |
| 754 | upstreamMeterId, sub.technologyProfileId(), true); |
| 755 | } |
| 756 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 757 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.SUBSCRIBER_REGISTERED, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 758 | deviceId, |
| 759 | deviceVlan, |
| 760 | subscriberVlan)); |
alshabib | 50d9fc5 | 2016-02-12 15:47:20 -0800 | [diff] [blame] | 761 | |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 762 | } else if (downStatus != null) { |
| 763 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 764 | "on port {} failed downstream installation: {}", |
| 765 | subscriberVlan, deviceId, subscriberPort, downStatus); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 766 | } else if (upStatus != null) { |
| 767 | log.error("Subscriber with vlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 768 | "on port {} failed upstream installation: {}", |
| 769 | subscriberVlan, deviceId, subscriberPort, upStatus); |
alshabib | 3ea8264 | 2016-01-12 18:06:53 -0800 | [diff] [blame] | 770 | } |
| 771 | }, oltInstallers); |
Jonathan Hart | e533a42 | 2015-10-20 17:31:24 -0700 | [diff] [blame] | 772 | } |
| 773 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 774 | private MeterId createMeter(DeviceId deviceId, BandwidthProfileInformation bpInfo, |
| 775 | CompletableFuture<Object> meterFuture) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 776 | if (bpInfo == null) { |
| 777 | log.warn("Bandwidth profile information is not found"); |
| 778 | return null; |
| 779 | } |
| 780 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 781 | MeterId meterId = getMeterIdFromBpMapping(deviceId, bpInfo.id()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 782 | if (meterId != null) { |
| 783 | log.info("Meter is already added. MeterId {}", meterId); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 784 | meterFuture.complete(null); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 785 | return meterId; |
| 786 | } |
| 787 | |
| 788 | List<Band> meterBands = createMeterBands(bpInfo); |
| 789 | |
| 790 | MeterRequest meterRequest = DefaultMeterRequest.builder() |
| 791 | .withBands(meterBands) |
| 792 | .withUnit(Meter.Unit.KB_PER_SEC) |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 793 | .withContext(new MeterContext() { |
| 794 | @Override |
| 795 | public void onSuccess(MeterRequest op) { |
| 796 | log.debug("meter addition completed"); |
| 797 | meterFuture.complete(null); |
| 798 | } |
| 799 | |
| 800 | @Override |
| 801 | public void onError(MeterRequest op, MeterFailReason reason) { |
| 802 | meterFuture.complete(reason); |
| 803 | } |
| 804 | }) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 805 | .forDevice(deviceId) |
| 806 | .fromApp(appId) |
| 807 | .burst() |
| 808 | .add(); |
| 809 | |
| 810 | Meter meter = meterService.submit(meterRequest); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 811 | addMeterIdToBpMapping(deviceId, meter.id(), bpInfo.id()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 812 | log.info("Meter is created. Meter Id {}", meter.id()); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 813 | programmedMeters.add(MeterKey.key(deviceId, meter.id())); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 814 | log.debug("programmed Meters size {}", programmedMeters.size()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 815 | return meter.id(); |
| 816 | } |
| 817 | |
| 818 | private List<Band> createMeterBands(BandwidthProfileInformation bpInfo) { |
| 819 | List<Band> meterBands = new ArrayList<>(); |
| 820 | |
| 821 | meterBands.add(createMeterBand(bpInfo.committedInformationRate(), bpInfo.committedBurstSize())); |
| 822 | meterBands.add(createMeterBand(bpInfo.exceededInformationRate(), bpInfo.exceededBurstSize())); |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 823 | meterBands.add(createMeterBand(bpInfo.assuredInformationRate(), 0L)); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 824 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 825 | return meterBands; |
| 826 | } |
| 827 | |
| 828 | private Band createMeterBand(long rate, Long burst) { |
| 829 | return DefaultBand.builder() |
| 830 | .withRate(rate) //already Kbps |
| 831 | .burstSize(burst) // already Kbits |
| 832 | .ofType(Band.Type.DROP) // no matter |
| 833 | .build(); |
| 834 | } |
| 835 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 836 | private ForwardingObjective.Builder downBuilder(PortNumber uplinkPort, |
| 837 | PortNumber subscriberPort, |
| 838 | VlanId subscriberVlan, |
| 839 | VlanId deviceVlan, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 840 | Optional<VlanId> defaultVlan, |
| 841 | MeterId meterId, |
| 842 | int techProfId) { |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 843 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 844 | .matchVlanId(deviceVlan) |
| 845 | .matchInPort(uplinkPort) |
| 846 | .matchInnerVlanId(subscriberVlan) |
| 847 | .build(); |
| 848 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 849 | TrafficTreatment.Builder downstreamTreatmentBuilder = DefaultTrafficTreatment.builder() |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 850 | .popVlan() |
| 851 | .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan))) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 852 | .setOutput(subscriberPort); |
| 853 | |
| 854 | if (meterId != null) { |
| 855 | downstreamTreatmentBuilder.meter(meterId); |
| 856 | } |
| 857 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 858 | downstreamTreatmentBuilder.writeMetadata(createMetadata(subscriberVlan, techProfId, subscriberPort), 0); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 859 | |
| 860 | return DefaultForwardingObjective.builder() |
| 861 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 862 | .withPriority(1000) |
| 863 | .makePermanent() |
| 864 | .withSelector(downstream) |
| 865 | .fromApp(appId) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 866 | .withTreatment(downstreamTreatmentBuilder.build()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | private ForwardingObjective.Builder upBuilder(PortNumber uplinkPort, |
| 870 | PortNumber subscriberPort, |
| 871 | VlanId subscriberVlan, |
| 872 | VlanId deviceVlan, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 873 | Optional<VlanId> defaultVlan, |
| 874 | MeterId meterId, |
| 875 | int technologyProfileId) { |
| 876 | |
| 877 | |
| 878 | VlanId dVlan = defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan)); |
| 879 | |
| 880 | if (subscriberVlan.toShort() == 4096) { |
| 881 | dVlan = subscriberVlan; |
| 882 | } |
| 883 | |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 884 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 885 | .matchVlanId(dVlan) |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 886 | .matchInPort(subscriberPort) |
| 887 | .build(); |
| 888 | |
| 889 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 890 | TrafficTreatment.Builder upstreamTreatmentBuilder = DefaultTrafficTreatment.builder() |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 891 | .pushVlan() |
| 892 | .setVlanId(subscriberVlan) |
| 893 | .pushVlan() |
| 894 | .setVlanId(deviceVlan) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 895 | .setOutput(uplinkPort); |
| 896 | |
| 897 | if (meterId != null) { |
| 898 | upstreamTreatmentBuilder.meter(meterId); |
| 899 | } |
| 900 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 901 | upstreamTreatmentBuilder.writeMetadata(createMetadata(deviceVlan, technologyProfileId, uplinkPort), 0L); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 902 | |
| 903 | return DefaultForwardingObjective.builder() |
| 904 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 905 | .withPriority(1000) |
| 906 | .makePermanent() |
| 907 | .withSelector(upstream) |
| 908 | .fromApp(appId) |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 909 | .withTreatment(upstreamTreatmentBuilder.build()); |
alshabib | 4ceaed3 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 910 | } |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 911 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 912 | private void provisionTransparentFlows(DeviceId deviceId, PortNumber uplinkPort, |
| 913 | PortNumber subscriberPort, |
| 914 | VlanId innerVlan, |
| 915 | VlanId outerVlan) { |
| 916 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 917 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 918 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 919 | SubscriberAndDeviceInformation subInfo = getSubscriber(cp); |
| 920 | |
| 921 | BandwidthProfileInformation upstreamBpInfo = getBandwidthProfileInformation( |
| 922 | subInfo.upstreamBandwidthProfile()); |
| 923 | BandwidthProfileInformation downstreamBpInfo = getBandwidthProfileInformation( |
| 924 | subInfo.downstreamBandwidthProfile()); |
| 925 | |
| 926 | CompletableFuture<Object> upstreamMeterFuture = new CompletableFuture<>(); |
| 927 | CompletableFuture<Object> downsteamMeterFuture = new CompletableFuture<>(); |
| 928 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 929 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 930 | |
| 931 | MeterId upstreamMeterId = createMeter(deviceId, upstreamBpInfo, upstreamMeterFuture); |
| 932 | MeterId downstreamMeterId = createMeter(deviceId, downstreamBpInfo, downsteamMeterFuture); |
| 933 | |
| 934 | upstreamMeterFuture.thenAcceptAsync(result -> { |
| 935 | if (result == null) { |
| 936 | log.info("Upstream Meter {} is sent to the device {}. " + |
| 937 | "Sending subscriber flows.", upstreamMeterId, deviceId); |
| 938 | |
| 939 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplinkPort, subscriberPort, |
| 940 | innerVlan, outerVlan, upstreamMeterId, subInfo); |
| 941 | |
| 942 | flowObjectiveService.forward(deviceId, upFwd.add(new ObjectiveContext() { |
| 943 | @Override |
| 944 | public void onSuccess(Objective objective) { |
| 945 | upFuture.complete(null); |
| 946 | } |
| 947 | |
| 948 | @Override |
| 949 | public void onError(Objective objective, ObjectiveError error) { |
| 950 | upFuture.complete(error); |
| 951 | } |
| 952 | })); |
| 953 | |
| 954 | } else { |
| 955 | log.warn("Meter installation error while sending upstream flows. " + |
| 956 | "Result {} and MeterId {}", result, upstreamMeterId); |
| 957 | } |
| 958 | }); |
| 959 | |
| 960 | downsteamMeterFuture.thenAcceptAsync(result -> { |
| 961 | if (result == null) { |
| 962 | log.info("Downstream Meter {} is sent to the device {}. " + |
| 963 | "Sending subscriber flows.", downstreamMeterId, deviceId); |
| 964 | |
| 965 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplinkPort, subscriberPort, |
| 966 | innerVlan, outerVlan, downstreamMeterId, subInfo); |
| 967 | |
| 968 | flowObjectiveService.forward(deviceId, downFwd.add(new ObjectiveContext() { |
| 969 | @Override |
| 970 | public void onSuccess(Objective objective) { |
| 971 | downFuture.complete(null); |
| 972 | } |
| 973 | |
| 974 | @Override |
| 975 | public void onError(Objective objective, ObjectiveError error) { |
| 976 | downFuture.complete(error); |
| 977 | } |
| 978 | })); |
| 979 | } else { |
| 980 | log.warn("Meter installation error while sending upstream flows. " + |
| 981 | "Result {} and MeterId {}", result, downstreamMeterId); |
| 982 | } |
| 983 | }); |
| 984 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 985 | additionalVlans.put(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 986 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 987 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 988 | if (downStatus != null) { |
| 989 | log.error("Flow with innervlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 990 | "on port {} failed downstream installation: {}", |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 991 | innerVlan, outerVlan, deviceId, cp, downStatus); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 992 | } else if (upStatus != null) { |
| 993 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 994 | "on port {} failed upstream installation: {}", |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 995 | innerVlan, outerVlan, deviceId, cp, upStatus); |
| 996 | } else { |
| 997 | processEapolFilteringObjectives(deviceId, subscriberPort, subInfo.upstreamBandwidthProfile(), |
| 998 | null, subInfo.cTag(), true); |
| 999 | |
| 1000 | // cache subscriber info |
| 1001 | programmedSubs.put(cp, subInfo); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1002 | } |
| 1003 | }, oltInstallers); |
| 1004 | |
| 1005 | } |
| 1006 | |
| 1007 | private ForwardingObjective.Builder transparentDownBuilder(PortNumber uplinkPort, |
| 1008 | PortNumber subscriberPort, |
| 1009 | VlanId innerVlan, |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1010 | VlanId outerVlan, |
| 1011 | MeterId downstreamMeterId, |
| 1012 | SubscriberAndDeviceInformation subInfo) { |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1013 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 1014 | .matchVlanId(outerVlan) |
| 1015 | .matchInPort(uplinkPort) |
| 1016 | .matchInnerVlanId(innerVlan) |
| 1017 | .build(); |
| 1018 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1019 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1020 | if (downstreamMeterId != null) { |
| 1021 | tBuilder.meter(downstreamMeterId); |
| 1022 | } |
| 1023 | |
| 1024 | TrafficTreatment downstreamTreatment = tBuilder |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1025 | .setOutput(subscriberPort) |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1026 | .writeMetadata(createMetadata(subInfo.cTag(), subInfo.technologyProfileId(), subscriberPort), 0) |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1027 | .build(); |
| 1028 | |
| 1029 | return DefaultForwardingObjective.builder() |
| 1030 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 1031 | .withPriority(1000) |
| 1032 | .makePermanent() |
| 1033 | .withSelector(downstream) |
| 1034 | .fromApp(appId) |
| 1035 | .withTreatment(downstreamTreatment); |
| 1036 | } |
| 1037 | |
| 1038 | private ForwardingObjective.Builder transparentUpBuilder(PortNumber uplinkPort, |
| 1039 | PortNumber subscriberPort, |
| 1040 | VlanId innerVlan, |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1041 | VlanId outerVlan, |
| 1042 | MeterId upstreamMeterId, |
| 1043 | SubscriberAndDeviceInformation subInfo) { |
| 1044 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1045 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
| 1046 | .matchVlanId(outerVlan) |
| 1047 | .matchInPort(subscriberPort) |
| 1048 | .matchInnerVlanId(innerVlan) |
| 1049 | .build(); |
| 1050 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1051 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 1052 | if (upstreamMeterId != null) { |
| 1053 | tBuilder.meter(upstreamMeterId); |
| 1054 | } |
| 1055 | |
| 1056 | TrafficTreatment upstreamTreatment = tBuilder |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1057 | .setOutput(uplinkPort) |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1058 | .writeMetadata(createMetadata(subInfo.sTag(), subInfo.technologyProfileId(), uplinkPort), 0) |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1059 | .build(); |
| 1060 | |
| 1061 | return DefaultForwardingObjective.builder() |
| 1062 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 1063 | .withPriority(1000) |
| 1064 | .makePermanent() |
| 1065 | .withSelector(upstream) |
| 1066 | .fromApp(appId) |
| 1067 | .withTreatment(upstreamTreatment); |
| 1068 | } |
| 1069 | |
| 1070 | private void unprovisionTransparentFlows(DeviceId deviceId, PortNumber uplink, |
| 1071 | PortNumber subscriberPort, VlanId innerVlan, |
| 1072 | VlanId outerVlan) { |
| 1073 | |
| 1074 | ConnectPoint cp = new ConnectPoint(deviceId, subscriberPort); |
| 1075 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1076 | SubscriberAndDeviceInformation subInfo = programmedSubs.get(cp); |
| 1077 | if (subInfo == null) { |
| 1078 | log.warn("Subscriber is not programmed before for the connectPoint {}", cp); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1082 | additionalVlans.remove(cp, new AbstractMap.SimpleEntry(outerVlan, innerVlan)); |
| 1083 | |
| 1084 | CompletableFuture<ObjectiveError> downFuture = new CompletableFuture(); |
| 1085 | CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); |
| 1086 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1087 | MeterId upstreamMeterId = getMeterIdFromBpMapping(deviceId, subInfo.upstreamBandwidthProfile()); |
| 1088 | MeterId downstreamMeterId = getMeterIdFromBpMapping(deviceId, subInfo.downstreamBandwidthProfile()); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1089 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1090 | ForwardingObjective.Builder upFwd = transparentUpBuilder(uplink, subscriberPort, |
| 1091 | innerVlan, outerVlan, upstreamMeterId, subInfo); |
| 1092 | ForwardingObjective.Builder downFwd = transparentDownBuilder(uplink, subscriberPort, |
| 1093 | innerVlan, outerVlan, downstreamMeterId, subInfo); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1094 | |
| 1095 | flowObjectiveService.forward(deviceId, upFwd.remove(new ObjectiveContext() { |
| 1096 | @Override |
| 1097 | public void onSuccess(Objective objective) { |
| 1098 | upFuture.complete(null); |
| 1099 | } |
| 1100 | |
| 1101 | @Override |
| 1102 | public void onError(Objective objective, ObjectiveError error) { |
| 1103 | upFuture.complete(error); |
| 1104 | } |
| 1105 | })); |
| 1106 | |
| 1107 | flowObjectiveService.forward(deviceId, downFwd.remove(new ObjectiveContext() { |
| 1108 | @Override |
| 1109 | public void onSuccess(Objective objective) { |
| 1110 | downFuture.complete(null); |
| 1111 | } |
| 1112 | |
| 1113 | @Override |
| 1114 | public void onError(Objective objective, ObjectiveError error) { |
| 1115 | downFuture.complete(error); |
| 1116 | } |
| 1117 | })); |
| 1118 | |
| 1119 | upFuture.thenAcceptBothAsync(downFuture, (upStatus, downStatus) -> { |
| 1120 | if (downStatus != null) { |
| 1121 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1122 | "on port {} failed downstream uninstallation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1123 | innerVlan, outerVlan, deviceId, subscriberPort, downStatus); |
| 1124 | } else if (upStatus != null) { |
| 1125 | log.error("Flow with innerVlan {} and outerVlan {} on device {} " + |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1126 | "on port {} failed upstream uninstallation: {}", |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1127 | innerVlan, outerVlan, deviceId, subscriberPort, upStatus); |
| 1128 | } |
| 1129 | }, oltInstallers); |
| 1130 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1131 | //re-install eapol |
| 1132 | processEapolFilteringObjectives(deviceId, subscriberPort, |
| 1133 | subInfo.upstreamBandwidthProfile(), null, subInfo.cTag(), false); |
| 1134 | processEapolFilteringObjectives(deviceId, subscriberPort, defaultBpId, |
| 1135 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
| 1136 | |
| 1137 | programmedMeters.remove(MeterKey.key(deviceId, upstreamMeterId)); |
| 1138 | programmedMeters.remove(MeterKey.key(deviceId, downstreamMeterId)); |
Amit Ghosh | e1d3f09 | 2018-10-09 19:44:33 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1141 | private int getDefaultTechProfileId(DeviceId devId, PortNumber portNumber) { |
| 1142 | Port port = deviceService.getPort(devId, portNumber); |
| 1143 | SubscriberAndDeviceInformation info = subsService.get(port.annotations().value(AnnotationKeys.PORT_NAME)); |
| 1144 | if (info != null && info.technologyProfileId() != -1) { |
| 1145 | return info.technologyProfileId(); |
| 1146 | } |
| 1147 | return defaultTechProfileId; |
| 1148 | } |
| 1149 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1150 | /** |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1151 | * Returns the write metadata value including tech profile reference and innerVlan. |
| 1152 | * For param cVlan, null can be sent |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1153 | * |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1154 | * @param cVlan c (customer) tag of one subscriber |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1155 | * @param techProfileId tech profile id of one subscriber |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1156 | * @return the write metadata value including tech profile reference and innerVlan |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1157 | */ |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1158 | private Long createTechProfValueForWm(VlanId cVlan, int techProfileId) { |
| 1159 | if (cVlan == null) { |
| 1160 | return (long) techProfileId << 32; |
| 1161 | } |
| 1162 | return ((long) (cVlan.id()) << 48 | (long) techProfileId << 32); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Trap eapol authentication packets to the controller. |
| 1167 | * |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1168 | * @param devId the device identifier |
| 1169 | * @param portNumber the port for which this trap flow is designated |
| 1170 | * @param bpId bandwidth profile id to add the related meter to the flow |
| 1171 | * @param filterFuture completable future for this filtering objective operation |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1172 | * @param vlanId the default or customer tag for a subscriber |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1173 | * @param install true to install the flow, false to remove the flow |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1174 | */ |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1175 | private void processEapolFilteringObjectives(DeviceId devId, PortNumber portNumber, String bpId, |
| 1176 | CompletableFuture<ObjectiveError> filterFuture, |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1177 | VlanId vlanId, boolean install) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1178 | |
| 1179 | if (!enableEapol) { |
| 1180 | log.debug("Eapol filtering is disabled."); |
| 1181 | if (filterFuture != null) { |
| 1182 | filterFuture.complete(null); |
| 1183 | } |
| 1184 | return; |
| 1185 | } |
| 1186 | |
alshabib | 09753b5 | 2016-03-04 14:55:19 -0800 | [diff] [blame] | 1187 | if (!mastershipService.isLocalMaster(devId)) { |
| 1188 | return; |
| 1189 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1190 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1191 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1192 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1193 | MeterId meterId; |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1194 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1195 | BandwidthProfileInformation bpInfo = getBandwidthProfileInformation(bpId); |
| 1196 | if (bpInfo != null) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1197 | meterId = createMeter(devId, bpInfo, meterFuture); |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1198 | treatmentBuilder.meter(meterId); |
| 1199 | } else { |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1200 | log.warn("Bandwidth profile {} is not found. Authentication flow will not be installed", bpId); |
| 1201 | return; |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1204 | meterFuture.thenAcceptAsync(result -> { |
| 1205 | if (result == null) { |
| 1206 | log.info("Meter {} for the device {} is installed. " + |
| 1207 | "{} EAPOL trap flow", meterId, devId, install ? "Installing " : "Removing "); |
| 1208 | int techProfileId = getDefaultTechProfileId(devId, portNumber); |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1209 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1210 | //Authentication trap flow uses only tech profile id as write metadata value |
| 1211 | FilteringObjective eapol = (install ? builder.permit() : builder.deny()) |
| 1212 | .withKey(Criteria.matchInPort(portNumber)) |
| 1213 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1214 | .addCondition(Criteria.matchVlanId(vlanId)) |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1215 | .withMeta(treatmentBuilder |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1216 | .writeMetadata(createTechProfValueForWm(vlanId, techProfileId), 0) |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1217 | .setOutput(PortNumber.CONTROLLER).build()) |
| 1218 | .fromApp(appId) |
| 1219 | .withPriority(10000) |
| 1220 | .add(new ObjectiveContext() { |
| 1221 | @Override |
| 1222 | public void onSuccess(Objective objective) { |
| 1223 | log.info("Eapol filter for {} on {} {} with meter {}.", |
| 1224 | devId, portNumber, (install) ? INSTALLED : REMOVED, meterId); |
| 1225 | if (filterFuture != null) { |
| 1226 | filterFuture.complete(null); |
| 1227 | } |
| 1228 | } |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 1229 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1230 | @Override |
| 1231 | public void onError(Objective objective, ObjectiveError error) { |
| 1232 | log.info("Eapol filter for {} on {} with meter {} failed {} because {}", |
| 1233 | devId, portNumber, meterId, (install) ? INSTALLATION : REMOVAL, |
| 1234 | error); |
| 1235 | if (filterFuture != null) { |
| 1236 | filterFuture.complete(error); |
| 1237 | } |
| 1238 | } |
| 1239 | }); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 1240 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1241 | flowObjectiveService.filter(devId, eapol); |
| 1242 | } else { |
| 1243 | log.warn("Meter installation error while sending eapol trap flow. " + |
| 1244 | "Result {} and MeterId {}", result, meterId); |
| 1245 | } |
| 1246 | }); |
alshabib | dec2e25 | 2016-01-15 12:20:25 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1249 | /** |
| 1250 | * Installs trap filtering objectives for particular traffic types on an |
| 1251 | * NNI port. |
| 1252 | * |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1253 | * @param devId device ID |
| 1254 | * @param port port number |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1255 | * @param install true to install, false to remove |
| 1256 | */ |
| 1257 | private void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
| 1258 | processLldpFilteringObjective(devId, port, install); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1259 | processDhcpFilteringObjectives(devId, port, null, -1, install, false); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | private void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
| 1263 | if (!mastershipService.isLocalMaster(devId)) { |
| 1264 | return; |
| 1265 | } |
| 1266 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 1267 | |
| 1268 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 1269 | .withKey(Criteria.matchInPort(port)) |
| 1270 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 1271 | .withMeta(DefaultTrafficTreatment.builder() |
| 1272 | .setOutput(PortNumber.CONTROLLER).build()) |
| 1273 | .fromApp(appId) |
| 1274 | .withPriority(10000) |
| 1275 | .add(new ObjectiveContext() { |
| 1276 | @Override |
| 1277 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1278 | log.info("LLDP filter for device {} on port {} {}.", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1279 | devId, port, (install) ? INSTALLED : REMOVED); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | @Override |
| 1283 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1284 | log.info("LLDP filter for device {} on port {} failed {} because {}", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1285 | devId, port, (install) ? INSTALLATION : REMOVAL, |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1286 | error); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1287 | } |
| 1288 | }); |
| 1289 | |
| 1290 | flowObjectiveService.filter(devId, lldp); |
| 1291 | |
| 1292 | } |
| 1293 | |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1294 | /** |
| 1295 | * Trap dhcp packets to the controller. |
| 1296 | * |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1297 | * @param devId the device identifier |
| 1298 | * @param port the port for which this trap flow is designated |
| 1299 | * @param upstreamMeterId the upstream meter id that includes the upstream |
| 1300 | * bandwidth profile values such as PIR,CIR. If no meter id needs to be referenced, |
| 1301 | * null can be sent |
| 1302 | * @param techProfileId the technology profile id that is used to create write |
| 1303 | * metadata instruction value. If no tech profile id needs to be referenced, |
| 1304 | * -1 can be sent |
| 1305 | * @param install true to install the flow, false to remove the flow |
| 1306 | * @param upstream true if trapped packets are flowing upstream towards |
| 1307 | * server, false if packets are flowing downstream towards client |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1308 | */ |
| 1309 | private void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1310 | MeterId upstreamMeterId, |
| 1311 | int techProfileId, |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1312 | boolean install, |
| 1313 | boolean upstream) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1314 | |
| 1315 | if (!enableDhcpOnProvisioning) { |
| 1316 | log.debug("Dhcp provisioning is disabled."); |
| 1317 | return; |
| 1318 | } |
| 1319 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1320 | if (!mastershipService.isLocalMaster(devId)) { |
| 1321 | return; |
| 1322 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1323 | |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1324 | if (enableDhcpV4) { |
| 1325 | int udpSrc = (upstream) ? 68 : 67; |
| 1326 | int udpDst = (upstream) ? 67 : 68; |
| 1327 | |
| 1328 | EthType ethType = EthType.EtherType.IPV4.ethType(); |
| 1329 | byte protocol = IPv4.PROTOCOL_UDP; |
| 1330 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1331 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
| 1332 | upstreamMeterId, techProfileId, protocol, install); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | if (enableDhcpV6) { |
| 1336 | int udpSrc = (upstream) ? 547 : 546; |
| 1337 | int udpDst = (upstream) ? 546 : 547; |
| 1338 | |
| 1339 | EthType ethType = EthType.EtherType.IPV6.ethType(); |
| 1340 | byte protocol = IPv6.PROTOCOL_UDP; |
| 1341 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1342 | this.addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
| 1343 | upstreamMeterId, techProfileId, protocol, install); |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | } |
| 1347 | |
| 1348 | private void addDhcpFilteringObjectives(DeviceId devId, |
| 1349 | PortNumber port, |
| 1350 | int udpSrc, |
| 1351 | int udpDst, |
| 1352 | EthType ethType, |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1353 | MeterId upstreamMeterId, |
| 1354 | int techProfileId, |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1355 | byte protocol, |
| 1356 | boolean install) { |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1357 | |
| 1358 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1359 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1360 | |
| 1361 | if (upstreamMeterId != null) { |
| 1362 | treatmentBuilder.meter(upstreamMeterId); |
| 1363 | } |
| 1364 | |
| 1365 | if (techProfileId != -1) { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1366 | treatmentBuilder.writeMetadata(createTechProfValueForWm(null, techProfileId), 0); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1369 | FilteringObjective dhcpUpstream = (install ? builder.permit() : builder.deny()) |
| 1370 | .withKey(Criteria.matchInPort(port)) |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1371 | .addCondition(Criteria.matchEthType(ethType)) |
| 1372 | .addCondition(Criteria.matchIPProtocol(protocol)) |
Saurav Das | acc5eeb | 2018-10-11 10:58:01 -0700 | [diff] [blame] | 1373 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 1374 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1375 | .withMeta(treatmentBuilder |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1376 | .setOutput(PortNumber.CONTROLLER).build()) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1377 | .fromApp(appId) |
Matt Jeanneret | 3f57926 | 2018-06-14 17:16:23 -0400 | [diff] [blame] | 1378 | .withPriority(10000) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1379 | .add(new ObjectiveContext() { |
| 1380 | @Override |
| 1381 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1382 | log.info("DHCP {} filter for device {} on port {} {}.", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1383 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1384 | devId, port, (install) ? INSTALLED : REMOVED); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | @Override |
| 1388 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 63460d1 | 2018-11-02 16:19:04 -0700 | [diff] [blame] | 1389 | log.info("DHCP {} filter for device {} on port {} failed {} because {}", |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1390 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? "v4" : "v6", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1391 | devId, port, (install) ? INSTALLATION : REMOVAL, |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1392 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1393 | } |
| 1394 | }); |
| 1395 | |
| 1396 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 1397 | } |
| 1398 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1399 | private void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, |
| 1400 | MeterId upstreamMeterId, |
| 1401 | int techProfileId, |
| 1402 | boolean install) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1403 | |
Gamze Abaka | f59c091 | 2019-04-19 08:24:28 +0000 | [diff] [blame^] | 1404 | if (!enableIgmpOnProvisioning) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1405 | log.debug("Igmp provisioning is disabled."); |
| 1406 | return; |
| 1407 | } |
| 1408 | |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1409 | if (!mastershipService.isLocalMaster(devId)) { |
| 1410 | return; |
| 1411 | } |
| 1412 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1413 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1414 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1415 | |
| 1416 | if (upstreamMeterId != null) { |
| 1417 | treatmentBuilder.meter(upstreamMeterId); |
| 1418 | } |
| 1419 | |
| 1420 | if (techProfileId != -1) { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1421 | treatmentBuilder.writeMetadata(createTechProfValueForWm(null, techProfileId), 0); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1422 | } |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1423 | |
| 1424 | builder = install ? builder.permit() : builder.deny(); |
| 1425 | |
| 1426 | FilteringObjective igmp = builder |
| 1427 | .withKey(Criteria.matchInPort(port)) |
| 1428 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 1429 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1430 | .withMeta(treatmentBuilder |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1431 | .setOutput(PortNumber.CONTROLLER).build()) |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1432 | .fromApp(appId) |
| 1433 | .withPriority(10000) |
| 1434 | .add(new ObjectiveContext() { |
| 1435 | @Override |
| 1436 | public void onSuccess(Objective objective) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1437 | log.info("Igmp filter for {} on {} {}.", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1438 | devId, port, (install) ? INSTALLED : REMOVED); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | @Override |
| 1442 | public void onError(Objective objective, ObjectiveError error) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1443 | log.info("Igmp filter for {} on {} failed {} because {}.", |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1444 | devId, port, (install) ? INSTALLATION : REMOVAL, |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1445 | error); |
Amit Ghosh | 95e2f65 | 2017-08-23 12:49:46 +0100 | [diff] [blame] | 1446 | } |
| 1447 | }); |
| 1448 | |
| 1449 | flowObjectiveService.filter(devId, igmp); |
| 1450 | } |
| 1451 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1452 | /** |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1453 | * Creates trap flows for device, including DHCP and LLDP trap on NNI and |
| 1454 | * EAPOL trap on the UNIs, if device is present in Sadis config. |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1455 | * |
| 1456 | * @param dev Device to look for |
| 1457 | */ |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1458 | private void checkAndCreateDeviceFlows(Device dev) { |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1459 | // we create only for the ones we are master of |
| 1460 | if (!mastershipService.isLocalMaster(dev.id())) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1461 | return; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1462 | } |
| 1463 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1464 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1465 | log.debug("checkAndCreateDeviceFlows: deviceInfo {}", deviceInfo); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1466 | |
| 1467 | if (deviceInfo != null) { |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1468 | // 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] | 1469 | for (Port p : deviceService.getPorts(dev.id())) { |
| 1470 | if (isUniPort(dev, p)) { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1471 | processEapolFilteringObjectives(dev.id(), p.number(), defaultBpId, null, |
| 1472 | VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1473 | } else { |
| 1474 | processNniFilteringObjectives(dev.id(), p.number(), true); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1475 | } |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1480 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1481 | /** |
| 1482 | * Get the uplink for of the OLT device. |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1483 | * <p> |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1484 | * This assumes that the OLT has a single uplink port. When more uplink ports need to be supported |
| 1485 | * this logic needs to be changed |
| 1486 | * |
| 1487 | * @param dev Device to look for |
| 1488 | * @return The uplink Port of the OLT |
| 1489 | */ |
| 1490 | private Port getUplinkPort(Device dev) { |
| 1491 | // check if this device is provisioned in Sadis |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1492 | SubscriberAndDeviceInformation deviceInfo = getOltInfo(dev); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1493 | log.debug("getUplinkPort: deviceInfo {}", deviceInfo); |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1494 | if (deviceInfo == null) { |
| 1495 | log.warn("Device {} is not configured in SADIS .. cannot fetch device" |
| 1496 | + " info", dev.id()); |
| 1497 | return null; |
| 1498 | } |
| 1499 | // 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] | 1500 | for (Port p : deviceService.getPorts(dev.id())) { |
Saurav Das | 82b8e6d | 2018-10-04 15:25:12 -0700 | [diff] [blame] | 1501 | if (p.number().toLong() == deviceInfo.uplinkPort()) { |
| 1502 | log.debug("getUplinkPort: Found port {}", p); |
| 1503 | return p; |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1507 | log.debug("getUplinkPort: " + NO_UPLINK_PORT, dev.id()); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1508 | return null; |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Return the subscriber on a port. |
| 1513 | * |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1514 | * @param cp ConnectPoint on which to find the subscriber |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1515 | * @return subscriber if found else null |
| 1516 | */ |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1517 | SubscriberAndDeviceInformation getSubscriber(ConnectPoint cp) { |
| 1518 | Port port = deviceService.getPort(cp); |
| 1519 | checkNotNull(port, "Invalid connect point"); |
| 1520 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1521 | return subsService.get(portName); |
| 1522 | } |
| 1523 | |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1524 | /** |
| 1525 | * Write metadata instruction value (metadata) is 8 bytes. |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1526 | * <p> |
Gamze Abaka | ad32965 | 2018-12-20 10:12:21 +0000 | [diff] [blame] | 1527 | * MS 2 bytes: C Tag |
| 1528 | * Next 2 bytes: Technology Profile Id |
| 1529 | * Next 4 bytes: Port number (uni or nni) |
| 1530 | */ |
| 1531 | |
| 1532 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 1533 | |
| 1534 | if (techProfileId == -1) { |
| 1535 | techProfileId = DEFAULT_TP_ID; |
| 1536 | } |
| 1537 | |
| 1538 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 1539 | } |
| 1540 | |
Amit Ghosh | 1ed9aef | 2018-07-17 17:08:16 +0100 | [diff] [blame] | 1541 | private boolean isUniPort(Device d, Port p) { |
| 1542 | Port ulPort = getUplinkPort(d); |
| 1543 | if (ulPort != null) { |
| 1544 | return (ulPort.number().toLong() != p.number().toLong()); |
| 1545 | } |
| 1546 | return false; |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1549 | private SubscriberAndDeviceInformation getOltInfo(Device dev) { |
| 1550 | String devSerialNo = dev.serialNumber(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1551 | return subsService.get(devSerialNo); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1554 | private MeterId getMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfile) { |
| 1555 | |
| 1556 | if (bpInfoToMeter.get(bandwidthProfile) == null) { |
| 1557 | log.warn("Bandwidth Profile '{}' is not found in bandwidth profile map.", bandwidthProfile); |
| 1558 | return null; |
| 1559 | } |
| 1560 | |
| 1561 | Optional<MeterKey> meterKeyForDevice = bpInfoToMeter.get(bandwidthProfile) |
| 1562 | .stream() |
| 1563 | .filter(meterKey -> meterKey.deviceId().equals(deviceId)) |
| 1564 | .findFirst(); |
| 1565 | return meterKeyForDevice.isPresent() ? meterKeyForDevice.get().meterId() : null; |
| 1566 | } |
| 1567 | |
| 1568 | private void addMeterIdToBpMapping(DeviceId deviceId, MeterId meterId, String bandwidthProfile) { |
| 1569 | |
| 1570 | if (bpInfoToMeter.get(bandwidthProfile) == null) { |
| 1571 | bpInfoToMeter.put(bandwidthProfile, |
| 1572 | new ArrayList<>(Arrays.asList(MeterKey.key(deviceId, meterId)))); |
| 1573 | } else { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1574 | List<MeterKey> meterKeyListForBp = bpInfoToMeter.get(bandwidthProfile); |
| 1575 | meterKeyListForBp.add(MeterKey.key(deviceId, meterId)); |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | private void removeMeterIdFromBpMapping(DeviceId deviceId, String bandwidthProfileId) { |
| 1580 | List<MeterKey> meterKeysForBp = bpInfoToMeter.get(bandwidthProfileId); |
| 1581 | if (meterKeysForBp != null) { |
| 1582 | meterKeysForBp.stream() |
| 1583 | .filter(meterKey -> meterKey.deviceId().equals(deviceId)) |
| 1584 | .findFirst().ifPresent(mk -> { |
| 1585 | meterKeysForBp.remove(mk); |
| 1586 | programmedMeters.remove(mk); |
| 1587 | }); |
| 1588 | } |
| 1589 | } |
| 1590 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1591 | private class InternalDeviceListener implements DeviceListener { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1592 | private Set<DeviceId> programmedDevices = Sets.newConcurrentHashSet(); |
| 1593 | |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1594 | @Override |
| 1595 | public void event(DeviceEvent event) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1596 | eventExecutor.execute(() -> { |
| 1597 | DeviceId devId = event.subject().id(); |
| 1598 | Device dev = event.subject(); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1599 | Port port = event.port(); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1600 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1601 | if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) { |
| 1602 | return; |
| 1603 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1604 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1605 | if (getOltInfo(dev) == null) { |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1606 | // it's possible that we got an event for a previously |
| 1607 | // programmed OLT that is no longer available in SADIS |
| 1608 | // we let such events go through |
| 1609 | if (!programmedDevices.contains(devId)) { |
| 1610 | log.warn("No device info found for {}, this is either " |
| 1611 | + "not an OLT or not known to sadis", dev); |
| 1612 | return; |
| 1613 | } |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1614 | } |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1615 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1616 | log.debug("OLT got {} event for {}", event.type(), event.subject()); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1617 | |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1618 | switch (event.type()) { |
| 1619 | //TODO: Port handling and bookkeeping should be improved once |
| 1620 | // olt firmware handles correct behaviour. |
| 1621 | case PORT_ADDED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1622 | if (isUniPort(dev, port)) { |
| 1623 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Jonathan Hart | 4c53800 | 2018-08-23 10:11:54 -0700 | [diff] [blame] | 1624 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1625 | if (port.isEnabled()) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1626 | processEapolFilteringObjectives(devId, port.number(), defaultBpId, |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1627 | null, VlanId.vlanId(EAPOL_DEFAULT_VLAN), true); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1628 | } |
| 1629 | } else { |
| 1630 | checkAndCreateDeviceFlows(dev); |
| 1631 | } |
| 1632 | break; |
| 1633 | case PORT_REMOVED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1634 | if (isUniPort(dev, port)) { |
Gamze Abaka | 853bf25 | 2019-03-25 10:27:06 +0000 | [diff] [blame] | 1635 | removeSubscriber(new ConnectPoint(devId, port.number())); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1636 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | break; |
| 1640 | case PORT_UPDATED: |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1641 | if (!isUniPort(dev, port)) { |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1642 | break; |
| 1643 | } |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1644 | |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1645 | SubscriberAndDeviceInformation sub = programmedSubs |
| 1646 | .get(new ConnectPoint(devId, port.number())); |
| 1647 | VlanId vlanId = sub == null ? VlanId.vlanId(EAPOL_DEFAULT_VLAN) : sub.cTag(); |
| 1648 | |
| 1649 | String bpId = getCurrentBandwidthProfile(new ConnectPoint(devId, port.number())); |
| 1650 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1651 | if (port.isEnabled()) { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1652 | processEapolFilteringObjectives(devId, port.number(), bpId, |
| 1653 | null, vlanId, true); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1654 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1655 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_ADDED, devId, port)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1656 | } else { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1657 | processEapolFilteringObjectives(devId, port.number(), bpId, |
| 1658 | null, vlanId, false); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1659 | post(new AccessDeviceEvent(AccessDeviceEvent.Type.UNI_REMOVED, devId, port)); |
Jonathan Hart | 1d34c8b | 2018-05-05 15:37:28 -0700 | [diff] [blame] | 1660 | } |
alshabib | bb83aa2 | 2016-02-10 15:08:23 -0800 | [diff] [blame] | 1661 | break; |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1662 | case DEVICE_ADDED: |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1663 | post(new AccessDeviceEvent( |
| 1664 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1665 | null, null)); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1666 | programmedDevices.add(devId); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1667 | // Send UNI_ADDED events for all existing ports |
| 1668 | deviceService.getPorts(devId).stream() |
| 1669 | .filter(p -> isUniPort(dev, p)) |
| 1670 | .filter(Port::isEnabled) |
| 1671 | .forEach(p -> post(new AccessDeviceEvent( |
| 1672 | AccessDeviceEvent.Type.UNI_ADDED, devId, p))); |
| 1673 | |
Jonathan Hart | 403372d | 2018-08-22 11:44:13 -0700 | [diff] [blame] | 1674 | checkAndCreateDeviceFlows(dev); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1675 | break; |
| 1676 | case DEVICE_REMOVED: |
| 1677 | deviceService.getPorts(devId).stream() |
| 1678 | .filter(p -> isUniPort(dev, p)) |
| 1679 | .forEach(p -> post(new AccessDeviceEvent( |
| 1680 | AccessDeviceEvent.Type.UNI_REMOVED, devId, p))); |
Saurav Das | a9d5f44 | 2019-03-06 19:32:48 -0800 | [diff] [blame] | 1681 | programmedDevices.remove(devId); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1682 | removeAllSubscribers(devId); |
alshabib | 7c19001 | 2016-02-09 18:22:33 -0800 | [diff] [blame] | 1683 | post(new AccessDeviceEvent( |
| 1684 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1685 | null, null)); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1686 | break; |
| 1687 | case DEVICE_AVAILABILITY_CHANGED: |
| 1688 | if (deviceService.isAvailable(devId)) { |
| 1689 | post(new AccessDeviceEvent( |
| 1690 | AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, |
| 1691 | null, null)); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1692 | programmedDevices.add(devId); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1693 | checkAndCreateDeviceFlows(dev); |
| 1694 | } else { |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1695 | programmedDevices.remove(devId); |
| 1696 | removeAllSubscribers(devId); |
Matteo Scandolo | 632f0fc | 2018-09-07 12:21:45 -0700 | [diff] [blame] | 1697 | post(new AccessDeviceEvent( |
| 1698 | AccessDeviceEvent.Type.DEVICE_DISCONNECTED, devId, |
| 1699 | null, null)); |
| 1700 | } |
| 1701 | break; |
| 1702 | case DEVICE_UPDATED: |
| 1703 | case DEVICE_SUSPENDED: |
| 1704 | case PORT_STATS_UPDATED: |
| 1705 | default: |
| 1706 | return; |
| 1707 | } |
| 1708 | }); |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1709 | } |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1710 | |
| 1711 | private String getCurrentBandwidthProfile(ConnectPoint connectPoint) { |
| 1712 | SubscriberAndDeviceInformation sub = programmedSubs.get(connectPoint); |
| 1713 | if (sub != null) { |
| 1714 | return sub.upstreamBandwidthProfile(); |
| 1715 | } |
| 1716 | return defaultBpId; |
| 1717 | } |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1718 | |
| 1719 | private void removeAllSubscribers(DeviceId deviceId) { |
| 1720 | List<ConnectPoint> connectPoints = programmedSubs.keySet().stream() |
| 1721 | .filter(ks -> Objects.equals(ks.deviceId(), deviceId)) |
| 1722 | .collect(Collectors.toList()); |
| 1723 | |
| 1724 | connectPoints.forEach(cp -> programmedSubs.remove(cp)); |
| 1725 | } |
alshabib | f0e7e70 | 2015-05-30 18:22:36 -0700 | [diff] [blame] | 1726 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1727 | |
| 1728 | private class InternalMeterListener implements MeterListener { |
| 1729 | |
| 1730 | @Override |
| 1731 | public void event(MeterEvent meterEvent) { |
| 1732 | if (deleteMeters && MeterEvent.Type.METER_REFERENCE_COUNT_ZERO.equals(meterEvent.type())) { |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1733 | log.info("Zero Count Meter Event is received. Meter is {}", meterEvent.subject()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1734 | Meter meter = meterEvent.subject(); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1735 | if (meter != null && appId.equals(meter.appId()) && |
| 1736 | !programmedMeters.contains(MeterKey.key(meter.deviceId(), meter.id()))) { |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1737 | deleteMeter(meter.deviceId(), meter.id()); |
| 1738 | } |
| 1739 | } else if (MeterEvent.Type.METER_REMOVED.equals(meterEvent.type())) { |
Gamze Abaka | 1efc80c | 2019-02-15 12:10:54 +0000 | [diff] [blame] | 1740 | log.info("Meter removed event is received. Meter is {}", meterEvent.subject()); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1741 | removeMeterFromBpMap(meterEvent.subject()); |
| 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | private void deleteMeter(DeviceId deviceId, MeterId meterId) { |
| 1746 | Meter meter = meterService.getMeter(deviceId, meterId); |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1747 | if (meter != null) { |
| 1748 | MeterRequest meterRequest = DefaultMeterRequest.builder() |
| 1749 | .withBands(meter.bands()) |
| 1750 | .withUnit(meter.unit()) |
| 1751 | .forDevice(deviceId) |
| 1752 | .fromApp(appId) |
| 1753 | .burst() |
| 1754 | .remove(); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1755 | |
Gamze Abaka | 838d814 | 2019-02-21 07:06:55 +0000 | [diff] [blame] | 1756 | meterService.withdraw(meterRequest, meterId); |
| 1757 | } |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | private void removeMeterFromBpMap(Meter meter) { |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1761 | bpInfoToMeter.values().forEach(meterKeys -> meterKeys.stream() |
| 1762 | .filter(meterKey -> (meterKey.deviceId().equals(meter.deviceId())) |
| 1763 | && meterKey.meterId().equals(meter.id())).findFirst(). |
| 1764 | ifPresent(mk -> { |
| 1765 | meterKeys.remove(mk); |
Gamze Abaka | da282b4 | 2019-03-11 13:16:48 +0000 | [diff] [blame] | 1766 | programmedMeters.remove(mk); |
Gamze Abaka | 33feef5 | 2019-02-27 08:16:47 +0000 | [diff] [blame] | 1767 | log.info("Deleted from the internal map. MeterKey {}", mk); |
| 1768 | log.info("Programmed meters {}", programmedMeters); |
| 1769 | })); |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | } |