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