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