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