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