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