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