Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Foundation |
| 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 | */ |
| 16 | package org.opencord.olt.impl; |
| 17 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 18 | import org.onlab.packet.EthType; |
| 19 | import org.onlab.packet.IPv4; |
| 20 | import org.onlab.packet.IPv6; |
| 21 | import org.onlab.packet.MacAddress; |
| 22 | import org.onlab.packet.TpPort; |
| 23 | import org.onlab.packet.VlanId; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 24 | import org.onlab.util.KryoNamespace; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 25 | import org.onlab.util.Tools; |
| 26 | import org.onosproject.cfg.ComponentConfigService; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
| 29 | import org.onosproject.mastership.MastershipService; |
| 30 | import org.onosproject.net.AnnotationKeys; |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 31 | import org.onosproject.net.ConnectPoint; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 32 | import org.onosproject.net.DeviceId; |
| 33 | import org.onosproject.net.Port; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.device.DeviceService; |
| 36 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 37 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 38 | import org.onosproject.net.flow.TrafficSelector; |
| 39 | import org.onosproject.net.flow.TrafficTreatment; |
| 40 | import org.onosproject.net.flow.criteria.Criteria; |
| 41 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 42 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 43 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 44 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 45 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 46 | import org.onosproject.net.flowobjective.Objective; |
| 47 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 48 | import org.onosproject.net.flowobjective.ObjectiveError; |
| 49 | import org.onosproject.net.meter.MeterId; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 50 | import org.onosproject.store.serializers.KryoNamespaces; |
| 51 | import org.onosproject.store.service.Serializer; |
| 52 | import org.onosproject.store.service.StorageService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 53 | import org.opencord.olt.internalapi.AccessDeviceFlowService; |
| 54 | import org.opencord.olt.internalapi.AccessDeviceMeterService; |
| 55 | import org.opencord.sadis.BandwidthProfileInformation; |
| 56 | import org.opencord.sadis.BaseInformationService; |
| 57 | import org.opencord.sadis.SadisService; |
| 58 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 59 | import org.opencord.sadis.UniTagInformation; |
| 60 | import org.osgi.service.component.ComponentContext; |
| 61 | import org.osgi.service.component.annotations.Activate; |
| 62 | import org.osgi.service.component.annotations.Component; |
| 63 | import org.osgi.service.component.annotations.Deactivate; |
| 64 | import org.osgi.service.component.annotations.Modified; |
| 65 | import org.osgi.service.component.annotations.Reference; |
| 66 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 67 | import org.osgi.service.component.annotations.ReferencePolicy; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 68 | import org.slf4j.Logger; |
| 69 | |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 70 | import java.util.Dictionary; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 71 | import java.util.Map; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 72 | import java.util.Properties; |
| 73 | import java.util.concurrent.BlockingQueue; |
| 74 | import java.util.concurrent.CompletableFuture; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 75 | import java.util.concurrent.LinkedBlockingQueue; |
| 76 | |
| 77 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 78 | import static org.onlab.util.Tools.get; |
| 79 | import static org.opencord.olt.impl.OsgiPropertyConstants.*; |
| 80 | import static org.slf4j.LoggerFactory.getLogger; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Provisions flow rules on access devices. |
| 84 | */ |
| 85 | @Component(immediate = true, property = { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 86 | ENABLE_DHCP_ON_NNI + ":Boolean=" + ENABLE_DHCP_ON_NNI_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 87 | ENABLE_DHCP_V4 + ":Boolean=" + ENABLE_DHCP_V4_DEFAULT, |
| 88 | ENABLE_DHCP_V6 + ":Boolean=" + ENABLE_DHCP_V6_DEFAULT, |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 89 | ENABLE_IGMP_ON_NNI + ":Boolean=" + ENABLE_IGMP_ON_NNI_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 90 | ENABLE_EAPOL + ":Boolean=" + ENABLE_EAPOL_DEFAULT, |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 91 | ENABLE_PPPOE + ":Boolean=" + ENABLE_PPPOE_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 92 | DEFAULT_TP_ID + ":Integer=" + DEFAULT_TP_ID_DEFAULT |
| 93 | }) |
| 94 | public class OltFlowService implements AccessDeviceFlowService { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 95 | private static final String SADIS_NOT_RUNNING = "Sadis is not running."; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 96 | private static final String APP_NAME = "org.opencord.olt"; |
| 97 | private static final int NONE_TP_ID = -1; |
| 98 | private static final int NO_PCP = -1; |
| 99 | private static final Integer MAX_PRIORITY = 10000; |
| 100 | private static final Integer MIN_PRIORITY = 1000; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 101 | private static final String INSTALLED = "installed"; |
| 102 | private static final String REMOVED = "removed"; |
| 103 | private static final String INSTALLATION = "installation"; |
| 104 | private static final String REMOVAL = "removal"; |
| 105 | private static final String V4 = "V4"; |
| 106 | private static final String V6 = "V6"; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 107 | |
| 108 | private final Logger log = getLogger(getClass()); |
| 109 | |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 111 | protected FlowObjectiveService flowObjectiveService; |
| 112 | |
| 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 114 | protected CoreService coreService; |
| 115 | |
| 116 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 117 | protected MastershipService mastershipService; |
| 118 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 119 | @Reference(cardinality = ReferenceCardinality.OPTIONAL, |
| 120 | bind = "bindSadisService", |
| 121 | unbind = "unbindSadisService", |
| 122 | policy = ReferencePolicy.DYNAMIC) |
| 123 | protected volatile SadisService sadisService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 124 | |
| 125 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 126 | protected DeviceService deviceService; |
| 127 | |
| 128 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 129 | protected AccessDeviceMeterService oltMeterService; |
| 130 | |
| 131 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 132 | protected ComponentConfigService componentConfigService; |
| 133 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 134 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 135 | protected StorageService storageService; |
| 136 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 137 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 138 | * Create DHCP trap flow on NNI port(s). |
| 139 | */ |
| 140 | protected boolean enableDhcpOnNni = ENABLE_DHCP_ON_NNI_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 141 | |
| 142 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 143 | * Enable flows for DHCP v4 if dhcp is required in sadis config. |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 144 | **/ |
| 145 | protected boolean enableDhcpV4 = ENABLE_DHCP_V4_DEFAULT; |
| 146 | |
| 147 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 148 | * Enable flows for DHCP v6 if dhcp is required in sadis config. |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 149 | **/ |
| 150 | protected boolean enableDhcpV6 = ENABLE_DHCP_V6_DEFAULT; |
| 151 | |
| 152 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 153 | * Create IGMP trap flow on NNI port(s). |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 154 | **/ |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 155 | protected boolean enableIgmpOnNni = ENABLE_IGMP_ON_NNI_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Send EAPOL authentication trap flows before subscriber provisioning. |
| 159 | **/ |
| 160 | protected boolean enableEapol = ENABLE_EAPOL_DEFAULT; |
| 161 | |
| 162 | /** |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 163 | * Send PPPoED authentication trap flows before subscriber provisioning. |
| 164 | **/ |
| 165 | protected boolean enablePppoe = ENABLE_PPPOE_DEFAULT; |
| 166 | |
| 167 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 168 | * Default technology profile id that is used for authentication trap flows. |
| 169 | **/ |
| 170 | protected int defaultTechProfileId = DEFAULT_TP_ID_DEFAULT; |
| 171 | |
| 172 | protected ApplicationId appId; |
| 173 | protected BaseInformationService<BandwidthProfileInformation> bpService; |
| 174 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 175 | protected Map<DeviceId, BlockingQueue<SubscriberFlowInfo>> pendingEapolForDevice; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 176 | |
| 177 | @Activate |
| 178 | public void activate(ComponentContext context) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 179 | if (sadisService != null) { |
| 180 | bpService = sadisService.getBandwidthProfileService(); |
| 181 | subsService = sadisService.getSubscriberInfoService(); |
| 182 | } else { |
| 183 | log.warn(SADIS_NOT_RUNNING); |
| 184 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 185 | componentConfigService.registerProperties(getClass()); |
| 186 | appId = coreService.getAppId(APP_NAME); |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 187 | KryoNamespace serializer = KryoNamespace.newBuilder() |
| 188 | .register(KryoNamespaces.API) |
| 189 | .register(UniTagInformation.class) |
| 190 | .register(SubscriberFlowInfo.class) |
| 191 | .register(LinkedBlockingQueue.class) |
| 192 | .build(); |
| 193 | pendingEapolForDevice = storageService.<DeviceId, BlockingQueue<SubscriberFlowInfo>>consistentMapBuilder() |
| 194 | .withName("volt-pending-eapol") |
| 195 | .withSerializer(Serializer.using(serializer)) |
| 196 | .withApplicationId(appId) |
| 197 | .build().asJavaMap(); |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 198 | log.info("started"); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
| 202 | @Deactivate |
| 203 | public void deactivate(ComponentContext context) { |
| 204 | componentConfigService.unregisterProperties(getClass(), false); |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 205 | log.info("stopped"); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | @Modified |
| 209 | public void modified(ComponentContext context) { |
| 210 | |
| 211 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 212 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 213 | Boolean o = Tools.isPropertyEnabled(properties, ENABLE_DHCP_ON_NNI); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 214 | if (o != null) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 215 | enableDhcpOnNni = o; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 218 | Boolean v4 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V4); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 219 | if (v4 != null) { |
| 220 | enableDhcpV4 = v4; |
| 221 | } |
| 222 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 223 | Boolean v6 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V6); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 224 | if (v6 != null) { |
| 225 | enableDhcpV6 = v6; |
| 226 | } |
| 227 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 228 | Boolean p = Tools.isPropertyEnabled(properties, ENABLE_IGMP_ON_NNI); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 229 | if (p != null) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 230 | enableIgmpOnNni = p; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 233 | Boolean eap = Tools.isPropertyEnabled(properties, ENABLE_EAPOL); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 234 | if (eap != null) { |
| 235 | enableEapol = eap; |
| 236 | } |
| 237 | |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 238 | Boolean pppoe = Tools.isPropertyEnabled(properties, ENABLE_PPPOE); |
| 239 | if (pppoe != null) { |
| 240 | enablePppoe = pppoe; |
| 241 | } |
| 242 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 243 | String tpId = get(properties, DEFAULT_TP_ID); |
| 244 | defaultTechProfileId = isNullOrEmpty(tpId) ? DEFAULT_TP_ID_DEFAULT : Integer.parseInt(tpId.trim()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 245 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 246 | log.info("modified. Values = enableDhcpOnNni: {}, enableDhcpV4: {}, " + |
| 247 | "enableDhcpV6:{}, enableIgmpOnNni:{}, " + |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 248 | "enableEapol{}, enablePppoe{}, defaultTechProfileId: {}", |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 249 | enableDhcpOnNni, enableDhcpV4, enableDhcpV6, |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 250 | enableIgmpOnNni, enableEapol, enablePppoe, |
| 251 | defaultTechProfileId); |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 252 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 255 | protected void bindSadisService(SadisService service) { |
| 256 | sadisService = service; |
| 257 | bpService = sadisService.getBandwidthProfileService(); |
| 258 | subsService = sadisService.getSubscriberInfoService(); |
| 259 | log.info("Sadis-service binds to onos."); |
| 260 | } |
| 261 | |
| 262 | protected void unbindSadisService(SadisService service) { |
| 263 | sadisService = null; |
| 264 | bpService = null; |
| 265 | subsService = null; |
| 266 | log.info("Sadis-service unbinds from onos."); |
| 267 | } |
| 268 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 269 | @Override |
| 270 | public void processDhcpFilteringObjectives(DeviceId devId, PortNumber port, |
| 271 | MeterId upstreamMeterId, |
| 272 | UniTagInformation tagInformation, |
| 273 | boolean install, |
| 274 | boolean upstream) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 275 | if (upstream) { |
| 276 | // for UNI ports |
| 277 | if (tagInformation != null && !tagInformation.getIsDhcpRequired()) { |
| 278 | log.debug("Dhcp provisioning is disabled for UNI port {} on " |
| 279 | + "device {} for service {}", port, devId, |
| 280 | tagInformation.getServiceName()); |
| 281 | return; |
| 282 | } |
| 283 | } else { |
| 284 | // for NNI ports |
| 285 | if (!enableDhcpOnNni) { |
| 286 | log.debug("Dhcp provisioning is disabled for NNI port {} on " |
| 287 | + "device {}", port, devId); |
| 288 | return; |
| 289 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 290 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 291 | int techProfileId = tagInformation != null ? tagInformation.getTechnologyProfileId() : NONE_TP_ID; |
| 292 | VlanId cTag = tagInformation != null ? tagInformation.getPonCTag() : VlanId.NONE; |
| 293 | VlanId unitagMatch = tagInformation != null ? tagInformation.getUniTagMatch() : VlanId.ANY; |
Andrea Campanella | 3a96ce8 | 2021-02-09 12:32:42 +0100 | [diff] [blame] | 294 | Byte vlanPcp = tagInformation != null && tagInformation.getUsPonCTagPriority() != NO_PCP |
| 295 | ? (byte) tagInformation.getUsPonCTagPriority() : null; |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 296 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 297 | |
| 298 | if (enableDhcpV4) { |
| 299 | int udpSrc = (upstream) ? 68 : 67; |
| 300 | int udpDst = (upstream) ? 67 : 68; |
| 301 | |
| 302 | EthType ethType = EthType.EtherType.IPV4.ethType(); |
| 303 | byte protocol = IPv4.PROTOCOL_UDP; |
| 304 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 305 | addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 306 | upstreamMeterId, techProfileId, protocol, cTag, unitagMatch, |
| 307 | vlanPcp, upstream, install); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | if (enableDhcpV6) { |
| 311 | int udpSrc = (upstream) ? 547 : 546; |
| 312 | int udpDst = (upstream) ? 546 : 547; |
| 313 | |
| 314 | EthType ethType = EthType.EtherType.IPV6.ethType(); |
| 315 | byte protocol = IPv6.PROTOCOL_UDP; |
| 316 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 317 | addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 318 | upstreamMeterId, techProfileId, protocol, cTag, unitagMatch, |
| 319 | vlanPcp, upstream, install); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | private void addDhcpFilteringObjectives(DeviceId devId, PortNumber port, int udpSrc, int udpDst, |
| 324 | EthType ethType, MeterId upstreamMeterId, int techProfileId, byte protocol, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 325 | VlanId cTag, VlanId unitagMatch, |
| 326 | Byte vlanPcp, boolean upstream, |
| 327 | boolean install) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 328 | |
| 329 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 330 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 331 | |
| 332 | if (upstreamMeterId != null) { |
| 333 | treatmentBuilder.meter(upstreamMeterId); |
| 334 | } |
| 335 | |
| 336 | if (techProfileId != NONE_TP_ID) { |
| 337 | treatmentBuilder.writeMetadata(createTechProfValueForWm(unitagMatch, techProfileId), 0); |
| 338 | } |
| 339 | |
| 340 | FilteringObjective.Builder dhcpUpstreamBuilder = (install ? builder.permit() : builder.deny()) |
| 341 | .withKey(Criteria.matchInPort(port)) |
| 342 | .addCondition(Criteria.matchEthType(ethType)) |
| 343 | .addCondition(Criteria.matchIPProtocol(protocol)) |
| 344 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 345 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 346 | .fromApp(appId) |
| 347 | .withPriority(MAX_PRIORITY); |
| 348 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 349 | //VLAN changes and PCP matching need to happen only in the upstream directions |
| 350 | if (upstream) { |
| 351 | treatmentBuilder.setVlanId(cTag); |
| 352 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 353 | dhcpUpstreamBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 354 | } |
| 355 | if (vlanPcp != null) { |
| 356 | treatmentBuilder.setVlanPcp(vlanPcp); |
| 357 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 360 | dhcpUpstreamBuilder.withMeta(treatmentBuilder |
| 361 | .setOutput(PortNumber.CONTROLLER).build()); |
| 362 | |
| 363 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 364 | FilteringObjective dhcpUpstream = dhcpUpstreamBuilder.add(new ObjectiveContext() { |
| 365 | @Override |
| 366 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 367 | log.info("DHCP {} filter for dev/port {}/{} {}.", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 368 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 369 | devId, port, (install) ? INSTALLED : REMOVED); |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 374 | log.error("DHCP {} filter for dev/port {}/{} failed {} because {}", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 375 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 376 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 377 | error); |
| 378 | } |
| 379 | }); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 380 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 381 | |
| 382 | } |
| 383 | |
| 384 | @Override |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 385 | public void processPPPoEDFilteringObjectives(DeviceId devId, PortNumber portNumber, |
| 386 | MeterId upstreamMeterId, |
| 387 | UniTagInformation tagInformation, |
| 388 | boolean install, |
| 389 | boolean upstream) { |
| 390 | if (!enablePppoe) { |
| 391 | log.debug("PPPoED filtering is disabled. Ignoring request."); |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | int techProfileId = NONE_TP_ID; |
| 396 | VlanId cTag = VlanId.NONE; |
| 397 | VlanId unitagMatch = VlanId.ANY; |
| 398 | Byte vlanPcp = null; |
| 399 | |
| 400 | if (tagInformation != null) { |
| 401 | techProfileId = tagInformation.getTechnologyProfileId(); |
| 402 | cTag = tagInformation.getPonCTag(); |
| 403 | unitagMatch = tagInformation.getUniTagMatch(); |
| 404 | if (tagInformation.getUsPonCTagPriority() != NO_PCP) { |
| 405 | vlanPcp = (byte) tagInformation.getUsPonCTagPriority(); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 410 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 411 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
| 412 | |
| 413 | if (upstreamMeterId != null) { |
| 414 | treatmentBuilder.meter(upstreamMeterId); |
| 415 | } |
| 416 | |
| 417 | if (techProfileId != NONE_TP_ID) { |
| 418 | treatmentBuilder.writeMetadata(createTechProfValueForWm(cTag, techProfileId), 0); |
| 419 | } |
| 420 | |
| 421 | DefaultFilteringObjective.Builder pppoedBuilder = (install ? builder.permit() : builder.deny()) |
| 422 | .withKey(Criteria.matchInPort(portNumber)) |
| 423 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 424 | .fromApp(appId) |
| 425 | .withPriority(10000); |
| 426 | |
| 427 | if (upstream) { |
| 428 | treatmentBuilder.setVlanId(cTag); |
| 429 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 430 | pppoedBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 431 | } |
| 432 | if (vlanPcp != null) { |
| 433 | treatmentBuilder.setVlanPcp(vlanPcp); |
| 434 | } |
| 435 | } |
| 436 | pppoedBuilder = pppoedBuilder.withMeta(treatmentBuilder.setOutput(PortNumber.CONTROLLER).build()); |
| 437 | |
| 438 | FilteringObjective pppoed = pppoedBuilder |
| 439 | .add(new ObjectiveContext() { |
| 440 | @Override |
| 441 | public void onSuccess(Objective objective) { |
| 442 | log.info("PPPoED filter for {} on {} {}.", |
| 443 | devId, portNumber, (install) ? INSTALLED : REMOVED); |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void onError(Objective objective, ObjectiveError error) { |
| 448 | log.info("PPPoED filter for {} on {} failed {} because {}", |
| 449 | devId, portNumber, (install) ? INSTALLATION : REMOVAL, error); |
| 450 | } |
| 451 | }); |
| 452 | flowObjectiveService.filter(devId, pppoed); |
| 453 | } |
| 454 | |
| 455 | @Override |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 456 | public void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, |
| 457 | MeterId upstreamMeterId, |
| 458 | UniTagInformation tagInformation, |
| 459 | boolean install, |
| 460 | boolean upstream) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 461 | if (upstream) { |
| 462 | // for UNI ports |
| 463 | if (tagInformation != null && !tagInformation.getIsIgmpRequired()) { |
| 464 | log.debug("Igmp provisioning is disabled for UNI port {} on " |
| 465 | + "device {} for service {}", port, devId, |
| 466 | tagInformation.getServiceName()); |
| 467 | return; |
| 468 | } |
| 469 | } else { |
| 470 | // for NNI ports |
| 471 | if (!enableIgmpOnNni) { |
| 472 | log.debug("Igmp provisioning is disabled for NNI port {} on device {}", |
| 473 | port, devId); |
| 474 | return; |
| 475 | } |
Matteo Scandolo | 34556e5 | 2020-05-08 12:34:13 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 478 | log.debug("{} IGMP flows on {}:{}", (install) ? |
| 479 | "Installing" : "Removing", devId, port); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 480 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 481 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 482 | if (upstream) { |
| 483 | |
| 484 | if (tagInformation.getTechnologyProfileId() != NONE_TP_ID) { |
| 485 | treatmentBuilder.writeMetadata(createTechProfValueForWm(null, |
| 486 | tagInformation.getTechnologyProfileId()), 0); |
| 487 | } |
| 488 | |
| 489 | |
| 490 | if (upstreamMeterId != null) { |
| 491 | treatmentBuilder.meter(upstreamMeterId); |
| 492 | } |
| 493 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 494 | if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getUniTagMatch())) { |
| 495 | filterBuilder.addCondition(Criteria.matchVlanId(tagInformation.getUniTagMatch())); |
| 496 | } |
| 497 | |
| 498 | if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getPonCTag())) { |
| 499 | treatmentBuilder.setVlanId(tagInformation.getPonCTag()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | if (tagInformation.getUsPonCTagPriority() != NO_PCP) { |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 503 | treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 507 | filterBuilder = install ? filterBuilder.permit() : filterBuilder.deny(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 508 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 509 | FilteringObjective igmp = filterBuilder |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 510 | .withKey(Criteria.matchInPort(port)) |
| 511 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 512 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 513 | .withMeta(treatmentBuilder |
| 514 | .setOutput(PortNumber.CONTROLLER).build()) |
| 515 | .fromApp(appId) |
| 516 | .withPriority(MAX_PRIORITY) |
| 517 | .add(new ObjectiveContext() { |
| 518 | @Override |
| 519 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 520 | log.info("Igmp filter for dev/port {}/{} {}.", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 521 | devId, port, (install) ? INSTALLED : REMOVED); |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 526 | log.error("Igmp filter for dev/port {}/{} failed {} because {}.", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 527 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 528 | error); |
| 529 | } |
| 530 | }); |
| 531 | |
| 532 | flowObjectiveService.filter(devId, igmp); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public void processEapolFilteringObjectives(DeviceId devId, PortNumber portNumber, String bpId, |
| 537 | CompletableFuture<ObjectiveError> filterFuture, |
| 538 | VlanId vlanId, boolean install) { |
| 539 | |
| 540 | if (!enableEapol) { |
| 541 | log.debug("Eapol filtering is disabled. Completing filteringFuture immediately for the device {}", devId); |
| 542 | if (filterFuture != null) { |
| 543 | filterFuture.complete(null); |
| 544 | } |
| 545 | return; |
| 546 | } |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 547 | log.info("Processing EAPOL with Bandwidth profile {} on {}/{}", bpId, |
| 548 | devId, portNumber); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 549 | BandwidthProfileInformation bpInfo = getBandwidthProfileInformation(bpId); |
| 550 | if (bpInfo == null) { |
| 551 | log.warn("Bandwidth profile {} is not found. Authentication flow" |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 552 | + " will not be installed on {}/{}", bpId, devId, portNumber); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 553 | if (filterFuture != null) { |
| 554 | filterFuture.complete(ObjectiveError.BADPARAMS); |
| 555 | } |
| 556 | return; |
| 557 | } |
| 558 | |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 559 | ConnectPoint cp = new ConnectPoint(devId, portNumber); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 560 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 561 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 562 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 563 | // check if meter exists and create it only for an install |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 564 | final MeterId meterId = oltMeterService.getMeterIdFromBpMapping(devId, bpInfo.id()); |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 565 | log.info("Meter id {} for Bandwidth profile {} associated to EAPOL on {}", meterId, bpInfo.id(), devId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 566 | if (meterId == null) { |
| 567 | if (install) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 568 | log.debug("Need to install meter for EAPOL with bwp {} on dev/port {}", bpInfo.id(), cp.toString()); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 569 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 570 | new UniTagInformation.Builder() |
| 571 | .setPonCTag(vlanId).build(), |
| 572 | null, null, |
| 573 | null, bpInfo.id()); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 574 | pendingEapolForDevice.compute(devId, (id, queue) -> { |
| 575 | if (queue == null) { |
| 576 | queue = new LinkedBlockingQueue<>(); |
| 577 | } |
| 578 | queue.add(fi); |
| 579 | return queue; |
| 580 | }); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 581 | |
Andrea Campanella | d1e2664 | 2020-10-23 12:08:32 +0200 | [diff] [blame] | 582 | //If false the meter is already being installed, skipping installation |
| 583 | if (!oltMeterService.checkAndAddPendingMeter(devId, bpInfo)) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 584 | return; |
| 585 | } |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 586 | MeterId innerMeterId = oltMeterService.createMeter(devId, bpInfo, |
| 587 | meterFuture); |
| 588 | fi.setUpMeterId(innerMeterId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 589 | } else { |
| 590 | // this case should not happen as the request to remove an eapol |
| 591 | // flow should mean that the flow points to a meter that exists. |
| 592 | // Nevertheless we can still delete the flow as we only need the |
| 593 | // correct 'match' to do so. |
| 594 | log.warn("Unknown meter id for bp {}, still proceeding with " |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 595 | + "delete of eapol flow for {}", bpInfo.id(), cp.toString()); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 596 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 597 | new UniTagInformation.Builder() |
| 598 | .setPonCTag(vlanId).build(), |
| 599 | null, meterId, |
| 600 | null, bpInfo.id()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 601 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 602 | } |
| 603 | } else { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 604 | log.debug("Meter {} was previously created for bp {} on {}", meterId, bpInfo.id(), cp.toString()); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 605 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 606 | new UniTagInformation.Builder() |
| 607 | .setPonCTag(vlanId).build(), |
| 608 | null, meterId, |
| 609 | null, bpInfo.id()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 610 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 611 | //No need for the future, meter is present. |
| 612 | return; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 613 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 614 | meterFuture.thenAcceptAsync(result -> { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 615 | //for each pending eapol flow we check if the meter is there. |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 616 | BlockingQueue<SubscriberFlowInfo> queue = pendingEapolForDevice.get(devId); |
| 617 | if (queue != null) { |
| 618 | while (true) { |
| 619 | SubscriberFlowInfo fi = queue.remove(); |
| 620 | if (fi == null) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 621 | pendingEapolForDevice.replace(devId, queue); |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 622 | break; |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 623 | } |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 624 | //TODO this might return the reference and not the actual object |
| 625 | // so it can be actually swapped underneath us. |
| 626 | log.debug("handing pending eapol on {}/{} for {}", fi.getDevId(), fi.getUniPort(), fi); |
| 627 | if (result == null) { |
| 628 | MeterId mId = oltMeterService |
| 629 | .getMeterIdFromBpMapping(devId, fi.getUpBpInfo()); |
| 630 | if (mId != null) { |
| 631 | log.debug("Meter installation completed for subscriber on {}, handling EAPOL trap flow", |
| 632 | cp.toString()); |
| 633 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, mId); |
| 634 | } |
| 635 | } else { |
| 636 | log.warn("Meter installation error while sending EAPOL trap flow to {}. " + |
| 637 | "Result {} and MeterId {}", cp.toString(), result, meterId); |
| 638 | } |
| 639 | oltMeterService.removeFromPendingMeters(devId, bpInfo); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 640 | } |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 641 | } else { |
| 642 | log.info("No pending EAPOLs on {}", devId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 643 | } |
| 644 | }); |
| 645 | } |
| 646 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 647 | private void handleEapol(CompletableFuture<ObjectiveError> filterFuture, |
| 648 | boolean install, ConnectPoint cp, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 649 | DefaultFilteringObjective.Builder filterBuilder, |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 650 | TrafficTreatment.Builder treatmentBuilder, |
| 651 | SubscriberFlowInfo fi, MeterId mId) { |
| 652 | log.info("Meter {} for {} on {}/{} exists. {} EAPOL trap flow", |
| 653 | mId, fi.getUpBpInfo(), fi.getDevId(), fi.getUniPort(), |
| 654 | (install) ? "Installing" : "Removing"); |
| 655 | int techProfileId = getDefaultTechProfileId(fi.getDevId(), fi.getUniPort()); |
| 656 | // can happen in case of removal |
| 657 | if (mId != null) { |
| 658 | treatmentBuilder.meter(mId); |
| 659 | } |
| 660 | //Authentication trap flow uses only tech profile id as write metadata value |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 661 | FilteringObjective eapol = (install ? filterBuilder.permit() : filterBuilder.deny()) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 662 | .withKey(Criteria.matchInPort(fi.getUniPort())) |
| 663 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 664 | .withMeta(treatmentBuilder |
| 665 | .writeMetadata(createTechProfValueForWm( |
| 666 | fi.getTagInfo().getPonCTag(), |
| 667 | techProfileId), 0) |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 668 | .setOutput(PortNumber.CONTROLLER) |
| 669 | .pushVlan() |
| 670 | .setVlanId(fi.getTagInfo().getPonCTag()) |
| 671 | .build()) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 672 | .fromApp(appId) |
| 673 | .withPriority(MAX_PRIORITY) |
| 674 | .add(new ObjectiveContext() { |
| 675 | @Override |
| 676 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 677 | log.info("Eapol filter {} for {} on {}/{} with meter {}.", |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 678 | objective.id(), fi.getDevId(), fi.getUniPort(), |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 679 | (install) ? INSTALLED : REMOVED, mId); |
| 680 | if (filterFuture != null) { |
| 681 | filterFuture.complete(null); |
| 682 | } |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | @Override |
| 686 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 687 | log.error("Eapol filter {} for {}/{} with meter {} " + |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 688 | "failed {} because {}", objective.id(), |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 689 | fi.getDevId(), fi.getUniPort(), mId, |
| 690 | (install) ? INSTALLATION : REMOVAL, |
| 691 | error); |
| 692 | if (filterFuture != null) { |
| 693 | filterFuture.complete(error); |
| 694 | } |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 695 | } |
| 696 | }); |
| 697 | flowObjectiveService.filter(fi.getDevId(), eapol); |
| 698 | } |
| 699 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 700 | /** |
| 701 | * Installs trap filtering objectives for particular traffic types on an |
| 702 | * NNI port. |
| 703 | * |
| 704 | * @param devId device ID |
| 705 | * @param port port number |
| 706 | * @param install true to install, false to remove |
| 707 | */ |
| 708 | @Override |
| 709 | public void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 710 | log.info("{} flows for NNI port {} on device {}", |
| 711 | install ? "Adding" : "Removing", port, devId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 712 | processLldpFilteringObjective(devId, port, install); |
| 713 | processDhcpFilteringObjectives(devId, port, null, null, install, false); |
| 714 | processIgmpFilteringObjectives(devId, port, null, null, install, false); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 715 | processPPPoEDFilteringObjectives(devId, port, null, null, install, false); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | |
| 719 | @Override |
| 720 | public void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 721 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 722 | |
| 723 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 724 | .withKey(Criteria.matchInPort(port)) |
| 725 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 726 | .withMeta(DefaultTrafficTreatment.builder() |
| 727 | .setOutput(PortNumber.CONTROLLER).build()) |
| 728 | .fromApp(appId) |
| 729 | .withPriority(MAX_PRIORITY) |
| 730 | .add(new ObjectiveContext() { |
| 731 | @Override |
| 732 | public void onSuccess(Objective objective) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 733 | log.info("LLDP filter for dev/port {}/{} {}.", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 734 | devId, port, (install) ? INSTALLED : REMOVED); |
| 735 | } |
| 736 | |
| 737 | @Override |
| 738 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | 19b56f6 | 2020-10-29 13:29:21 -0700 | [diff] [blame] | 739 | log.error("LLDP filter for dev/port {}/{} failed {} because {}", |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 740 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 741 | error); |
| 742 | } |
| 743 | }); |
| 744 | |
| 745 | flowObjectiveService.filter(devId, lldp); |
| 746 | } |
| 747 | |
| 748 | @Override |
| 749 | public ForwardingObjective.Builder createTransparentBuilder(PortNumber uplinkPort, |
| 750 | PortNumber subscriberPort, |
| 751 | MeterId meterId, |
| 752 | UniTagInformation tagInfo, |
| 753 | boolean upstream) { |
| 754 | |
| 755 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 756 | .matchVlanId(tagInfo.getPonSTag()) |
| 757 | .matchInPort(upstream ? subscriberPort : uplinkPort) |
| 758 | .matchInnerVlanId(tagInfo.getPonCTag()) |
| 759 | .build(); |
| 760 | |
| 761 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 762 | if (meterId != null) { |
| 763 | tBuilder.meter(meterId); |
| 764 | } |
| 765 | |
| 766 | TrafficTreatment treatment = tBuilder |
| 767 | .setOutput(upstream ? uplinkPort : subscriberPort) |
| 768 | .writeMetadata(createMetadata(upstream ? tagInfo.getPonSTag() : tagInfo.getPonCTag(), |
| 769 | tagInfo.getTechnologyProfileId(), upstream ? uplinkPort : subscriberPort), 0) |
| 770 | .build(); |
| 771 | |
| 772 | return createForwardingObjectiveBuilder(selector, treatment, MIN_PRIORITY); |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public ForwardingObjective.Builder createUpBuilder(PortNumber uplinkPort, |
| 777 | PortNumber subscriberPort, |
| 778 | MeterId upstreamMeterId, |
| 779 | UniTagInformation uniTagInformation) { |
| 780 | |
| 781 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 782 | .matchInPort(subscriberPort) |
| 783 | .matchVlanId(uniTagInformation.getUniTagMatch()) |
| 784 | .build(); |
| 785 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 786 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 787 | //if the subscriberVlan (cTag) is different than ANY it needs to set. |
| 788 | if (uniTagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 789 | treatmentBuilder.pushVlan() |
| 790 | .setVlanId(uniTagInformation.getPonCTag()); |
| 791 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 792 | |
| 793 | if (uniTagInformation.getUsPonCTagPriority() != NO_PCP) { |
| 794 | treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonCTagPriority()); |
| 795 | } |
| 796 | |
| 797 | treatmentBuilder.pushVlan() |
| 798 | .setVlanId(uniTagInformation.getPonSTag()); |
| 799 | |
| 800 | if (uniTagInformation.getUsPonSTagPriority() != NO_PCP) { |
| 801 | treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonSTagPriority()); |
| 802 | } |
| 803 | |
| 804 | treatmentBuilder.setOutput(uplinkPort) |
| 805 | .writeMetadata(createMetadata(uniTagInformation.getPonCTag(), |
| 806 | uniTagInformation.getTechnologyProfileId(), uplinkPort), 0L); |
| 807 | |
| 808 | if (upstreamMeterId != null) { |
| 809 | treatmentBuilder.meter(upstreamMeterId); |
| 810 | } |
| 811 | |
| 812 | return createForwardingObjectiveBuilder(selector, treatmentBuilder.build(), MIN_PRIORITY); |
| 813 | } |
| 814 | |
| 815 | @Override |
| 816 | public ForwardingObjective.Builder createDownBuilder(PortNumber uplinkPort, |
| 817 | PortNumber subscriberPort, |
| 818 | MeterId downstreamMeterId, |
| 819 | UniTagInformation tagInformation) { |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 820 | |
| 821 | //subscriberVlan can be any valid Vlan here including ANY to make sure the packet is tagged |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 822 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder() |
| 823 | .matchVlanId(tagInformation.getPonSTag()) |
| 824 | .matchInPort(uplinkPort) |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 825 | .matchInnerVlanId(tagInformation.getPonCTag()); |
| 826 | |
| 827 | |
| 828 | if (tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 829 | selectorBuilder.matchMetadata(tagInformation.getPonCTag().toShort()); |
| 830 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 831 | |
| 832 | if (tagInformation.getDsPonSTagPriority() != NO_PCP) { |
| 833 | selectorBuilder.matchVlanPcp((byte) tagInformation.getDsPonSTagPriority()); |
| 834 | } |
| 835 | |
| 836 | if (tagInformation.getConfiguredMacAddress() != null && |
Daniele Moro | 7cbf431 | 2020-03-06 17:24:12 -0800 | [diff] [blame] | 837 | !tagInformation.getConfiguredMacAddress().equals("") && |
| 838 | !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress()))) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 839 | selectorBuilder.matchEthDst(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 840 | } |
| 841 | |
| 842 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder() |
| 843 | .popVlan() |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 844 | .setOutput(subscriberPort); |
| 845 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 846 | treatmentBuilder.writeMetadata(createMetadata(tagInformation.getPonCTag(), |
| 847 | tagInformation.getTechnologyProfileId(), |
| 848 | subscriberPort), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 849 | |
| 850 | // to remark inner vlan header |
| 851 | if (tagInformation.getUsPonCTagPriority() != NO_PCP) { |
| 852 | treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority()); |
| 853 | } |
| 854 | |
Andrea Campanella | 9a77929 | 2020-02-03 19:19:09 +0100 | [diff] [blame] | 855 | if (!VlanId.NONE.equals(tagInformation.getUniTagMatch()) && |
| 856 | tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 857 | treatmentBuilder.setVlanId(tagInformation.getUniTagMatch()); |
| 858 | } |
| 859 | |
| 860 | if (downstreamMeterId != null) { |
| 861 | treatmentBuilder.meter(downstreamMeterId); |
| 862 | } |
| 863 | |
| 864 | return createForwardingObjectiveBuilder(selectorBuilder.build(), treatmentBuilder.build(), MIN_PRIORITY); |
| 865 | } |
| 866 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 867 | @Override |
| 868 | public void clearDeviceState(DeviceId deviceId) { |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 869 | pendingEapolForDevice.remove(deviceId); |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 870 | } |
| 871 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 872 | private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector, |
| 873 | TrafficTreatment treatment, |
| 874 | Integer priority) { |
| 875 | return DefaultForwardingObjective.builder() |
| 876 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 877 | .withPriority(priority) |
| 878 | .makePermanent() |
| 879 | .withSelector(selector) |
| 880 | .fromApp(appId) |
| 881 | .withTreatment(treatment); |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Returns the write metadata value including tech profile reference and innerVlan. |
| 886 | * For param cVlan, null can be sent |
| 887 | * |
| 888 | * @param cVlan c (customer) tag of one subscriber |
| 889 | * @param techProfileId tech profile id of one subscriber |
| 890 | * @return the write metadata value including tech profile reference and innerVlan |
| 891 | */ |
| 892 | private Long createTechProfValueForWm(VlanId cVlan, int techProfileId) { |
| 893 | if (cVlan == null || VlanId.NONE.equals(cVlan)) { |
| 894 | return (long) techProfileId << 32; |
| 895 | } |
| 896 | return ((long) (cVlan.id()) << 48 | (long) techProfileId << 32); |
| 897 | } |
| 898 | |
| 899 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 900 | if (bpService == null) { |
| 901 | log.warn(SADIS_NOT_RUNNING); |
| 902 | return null; |
| 903 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 904 | if (bandwidthProfile == null) { |
| 905 | return null; |
| 906 | } |
| 907 | return bpService.get(bandwidthProfile); |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * It will be used to support AT&T use case (for EAPOL flows). |
| 912 | * If multiple services are found in uniServiceList, returns default tech profile id |
| 913 | * If one service is found, returns the found one |
| 914 | * |
| 915 | * @param devId |
| 916 | * @param portNumber |
| 917 | * @return the default technology profile id |
| 918 | */ |
| 919 | private int getDefaultTechProfileId(DeviceId devId, PortNumber portNumber) { |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame^] | 920 | if (subsService == null) { |
| 921 | log.warn(SADIS_NOT_RUNNING); |
| 922 | return defaultTechProfileId; |
| 923 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 924 | Port port = deviceService.getPort(devId, portNumber); |
| 925 | if (port != null) { |
| 926 | SubscriberAndDeviceInformation info = subsService.get(port.annotations().value(AnnotationKeys.PORT_NAME)); |
| 927 | if (info != null && info.uniTagList().size() == 1) { |
| 928 | return info.uniTagList().get(0).getTechnologyProfileId(); |
| 929 | } |
| 930 | } |
| 931 | return defaultTechProfileId; |
| 932 | } |
| 933 | |
| 934 | /** |
| 935 | * Write metadata instruction value (metadata) is 8 bytes. |
| 936 | * <p> |
| 937 | * MS 2 bytes: C Tag |
| 938 | * Next 2 bytes: Technology Profile Id |
| 939 | * Next 4 bytes: Port number (uni or nni) |
| 940 | */ |
| 941 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 942 | if (techProfileId == NONE_TP_ID) { |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 943 | techProfileId = DEFAULT_TP_ID_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 947 | } |
| 948 | |
| 949 | |
| 950 | } |