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; |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 255 | Byte vlanPcp = tagInformation != null ? (byte) tagInformation.getUsPonCTagPriority() : null; |
| 256 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 257 | |
| 258 | if (enableDhcpV4) { |
| 259 | int udpSrc = (upstream) ? 68 : 67; |
| 260 | int udpDst = (upstream) ? 67 : 68; |
| 261 | |
| 262 | EthType ethType = EthType.EtherType.IPV4.ethType(); |
| 263 | byte protocol = IPv4.PROTOCOL_UDP; |
| 264 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 265 | addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 266 | upstreamMeterId, techProfileId, protocol, cTag, unitagMatch, |
| 267 | vlanPcp, upstream, install); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if (enableDhcpV6) { |
| 271 | int udpSrc = (upstream) ? 547 : 546; |
| 272 | int udpDst = (upstream) ? 546 : 547; |
| 273 | |
| 274 | EthType ethType = EthType.EtherType.IPV6.ethType(); |
| 275 | byte protocol = IPv6.PROTOCOL_UDP; |
| 276 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 277 | addDhcpFilteringObjectives(devId, port, udpSrc, udpDst, ethType, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 278 | upstreamMeterId, techProfileId, protocol, cTag, unitagMatch, |
| 279 | vlanPcp, upstream, install); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
| 283 | private void addDhcpFilteringObjectives(DeviceId devId, PortNumber port, int udpSrc, int udpDst, |
| 284 | EthType ethType, MeterId upstreamMeterId, int techProfileId, byte protocol, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 285 | VlanId cTag, VlanId unitagMatch, |
| 286 | Byte vlanPcp, boolean upstream, |
| 287 | boolean install) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 288 | |
| 289 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 290 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 291 | |
| 292 | if (upstreamMeterId != null) { |
| 293 | treatmentBuilder.meter(upstreamMeterId); |
| 294 | } |
| 295 | |
| 296 | if (techProfileId != NONE_TP_ID) { |
| 297 | treatmentBuilder.writeMetadata(createTechProfValueForWm(unitagMatch, techProfileId), 0); |
| 298 | } |
| 299 | |
| 300 | FilteringObjective.Builder dhcpUpstreamBuilder = (install ? builder.permit() : builder.deny()) |
| 301 | .withKey(Criteria.matchInPort(port)) |
| 302 | .addCondition(Criteria.matchEthType(ethType)) |
| 303 | .addCondition(Criteria.matchIPProtocol(protocol)) |
| 304 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 305 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 306 | .fromApp(appId) |
| 307 | .withPriority(MAX_PRIORITY); |
| 308 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 309 | //VLAN changes and PCP matching need to happen only in the upstream directions |
| 310 | if (upstream) { |
| 311 | treatmentBuilder.setVlanId(cTag); |
| 312 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 313 | dhcpUpstreamBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 314 | } |
| 315 | if (vlanPcp != null) { |
| 316 | treatmentBuilder.setVlanPcp(vlanPcp); |
| 317 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 320 | dhcpUpstreamBuilder.withMeta(treatmentBuilder |
| 321 | .setOutput(PortNumber.CONTROLLER).build()); |
| 322 | |
| 323 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 324 | FilteringObjective dhcpUpstream = dhcpUpstreamBuilder.add(new ObjectiveContext() { |
| 325 | @Override |
| 326 | public void onSuccess(Objective objective) { |
| 327 | log.info("DHCP {} filter for device {} on port {} {}.", |
| 328 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 329 | devId, port, (install) ? INSTALLED : REMOVED); |
| 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public void onError(Objective objective, ObjectiveError error) { |
| 334 | log.info("DHCP {} filter for device {} on port {} failed {} because {}", |
| 335 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 336 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 337 | error); |
| 338 | } |
| 339 | }); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 340 | flowObjectiveService.filter(devId, dhcpUpstream); |
| 341 | |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public void processIgmpFilteringObjectives(DeviceId devId, PortNumber port, |
| 346 | MeterId upstreamMeterId, |
| 347 | UniTagInformation tagInformation, |
| 348 | boolean install, |
| 349 | boolean upstream) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 350 | if (upstream) { |
| 351 | // for UNI ports |
| 352 | if (tagInformation != null && !tagInformation.getIsIgmpRequired()) { |
| 353 | log.debug("Igmp provisioning is disabled for UNI port {} on " |
| 354 | + "device {} for service {}", port, devId, |
| 355 | tagInformation.getServiceName()); |
| 356 | return; |
| 357 | } |
| 358 | } else { |
| 359 | // for NNI ports |
| 360 | if (!enableIgmpOnNni) { |
| 361 | log.debug("Igmp provisioning is disabled for NNI port {} on device {}", |
| 362 | port, devId); |
| 363 | return; |
| 364 | } |
Matteo Scandolo | 34556e5 | 2020-05-08 12:34:13 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 367 | log.debug("{} IGMP flows on {}:{}", (install) ? |
| 368 | "Installing" : "Removing", devId, port); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 369 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 370 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 371 | if (upstream) { |
| 372 | |
| 373 | if (tagInformation.getTechnologyProfileId() != NONE_TP_ID) { |
| 374 | treatmentBuilder.writeMetadata(createTechProfValueForWm(null, |
| 375 | tagInformation.getTechnologyProfileId()), 0); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | if (upstreamMeterId != null) { |
| 380 | treatmentBuilder.meter(upstreamMeterId); |
| 381 | } |
| 382 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 383 | if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getUniTagMatch())) { |
| 384 | filterBuilder.addCondition(Criteria.matchVlanId(tagInformation.getUniTagMatch())); |
| 385 | } |
| 386 | |
| 387 | if (!VlanId.vlanId(VlanId.NO_VID).equals(tagInformation.getPonCTag())) { |
| 388 | treatmentBuilder.setVlanId(tagInformation.getPonCTag()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | if (tagInformation.getUsPonCTagPriority() != NO_PCP) { |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 392 | treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 396 | filterBuilder = install ? filterBuilder.permit() : filterBuilder.deny(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 397 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 398 | FilteringObjective igmp = filterBuilder |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 399 | .withKey(Criteria.matchInPort(port)) |
| 400 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 401 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 402 | .withMeta(treatmentBuilder |
| 403 | .setOutput(PortNumber.CONTROLLER).build()) |
| 404 | .fromApp(appId) |
| 405 | .withPriority(MAX_PRIORITY) |
| 406 | .add(new ObjectiveContext() { |
| 407 | @Override |
| 408 | public void onSuccess(Objective objective) { |
| 409 | log.info("Igmp filter for {} on {} {}.", |
| 410 | devId, port, (install) ? INSTALLED : REMOVED); |
| 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void onError(Objective objective, ObjectiveError error) { |
| 415 | log.info("Igmp filter for {} on {} failed {} because {}.", |
| 416 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 417 | error); |
| 418 | } |
| 419 | }); |
| 420 | |
| 421 | flowObjectiveService.filter(devId, igmp); |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public void processEapolFilteringObjectives(DeviceId devId, PortNumber portNumber, String bpId, |
| 426 | CompletableFuture<ObjectiveError> filterFuture, |
| 427 | VlanId vlanId, boolean install) { |
| 428 | |
| 429 | if (!enableEapol) { |
| 430 | log.debug("Eapol filtering is disabled. Completing filteringFuture immediately for the device {}", devId); |
| 431 | if (filterFuture != null) { |
| 432 | filterFuture.complete(null); |
| 433 | } |
| 434 | return; |
| 435 | } |
| 436 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 437 | BandwidthProfileInformation bpInfo = getBandwidthProfileInformation(bpId); |
| 438 | if (bpInfo == null) { |
| 439 | log.warn("Bandwidth profile {} is not found. Authentication flow" |
| 440 | + " will not be installed", bpId); |
| 441 | if (filterFuture != null) { |
| 442 | filterFuture.complete(ObjectiveError.BADPARAMS); |
| 443 | } |
| 444 | return; |
| 445 | } |
| 446 | |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 447 | ConnectPoint cp = new ConnectPoint(devId, portNumber); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 448 | if (install) { |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 449 | boolean added = pendingAddEapol.add(cp); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 450 | if (!added) { |
| 451 | if (filterFuture != null) { |
| 452 | log.warn("The eapol flow is processing for the port {}. Ignoring this request", portNumber); |
| 453 | filterFuture.complete(null); |
| 454 | } |
| 455 | return; |
| 456 | } |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 457 | log.info("connectPoint added to pendingAddEapol map {}", cp.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 460 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 461 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 462 | CompletableFuture<Object> meterFuture = new CompletableFuture<>(); |
| 463 | |
| 464 | // check if meter exists and create it only for an install |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 465 | final MeterId meterId = oltMeterService.getMeterIdFromBpMapping(devId, bpInfo.id()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 466 | if (meterId == null) { |
| 467 | if (install) { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 468 | log.debug("Need to install meter for EAPOL with bwp {}", bpInfo.id()); |
| 469 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 470 | new UniTagInformation.Builder() |
| 471 | .setPonCTag(vlanId).build(), |
| 472 | null, null, |
| 473 | null, bpInfo.id()); |
| 474 | pendingEapolForMeters.add(fi); |
| 475 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 476 | if (oltMeterService.isMeterPending(devId, bpInfo)) { |
| 477 | log.debug("Meter is already pending for EAPOL on {} with bp {}", |
| 478 | devId, bpInfo); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 479 | return; |
| 480 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 481 | oltMeterService.addToPendingMeters(devId, bpInfo); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 482 | MeterId innerMeterId = oltMeterService.createMeter(devId, bpInfo, |
| 483 | meterFuture); |
| 484 | fi.setUpMeterId(innerMeterId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 485 | } else { |
| 486 | // this case should not happen as the request to remove an eapol |
| 487 | // flow should mean that the flow points to a meter that exists. |
| 488 | // Nevertheless we can still delete the flow as we only need the |
| 489 | // correct 'match' to do so. |
| 490 | log.warn("Unknown meter id for bp {}, still proceeding with " |
| 491 | + "delete of eapol flow for {}/{}", bpInfo.id(), devId, portNumber); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 492 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 493 | new UniTagInformation.Builder() |
| 494 | .setPonCTag(vlanId).build(), |
| 495 | null, meterId, |
| 496 | null, bpInfo.id()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 497 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 498 | } |
| 499 | } else { |
| 500 | log.debug("Meter {} was previously created for bp {}", meterId, bpInfo.id()); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 501 | SubscriberFlowInfo fi = new SubscriberFlowInfo(devId, null, cp.port(), |
| 502 | new UniTagInformation.Builder() |
| 503 | .setPonCTag(vlanId).build(), |
| 504 | null, meterId, |
| 505 | null, bpInfo.id()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 506 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, meterId); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 507 | //No need for the future, meter is present. |
| 508 | return; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 509 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 510 | meterFuture.thenAcceptAsync(result -> { |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 511 | //for each pending eapol flow we check if the meter is there. |
| 512 | Iterator<SubscriberFlowInfo> eapIterator = pendingEapolForMeters.iterator(); |
| 513 | while (eapIterator.hasNext()) { |
| 514 | SubscriberFlowInfo fi = eapIterator.next(); |
| 515 | if (result == null) { |
| 516 | MeterId mId = oltMeterService |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 517 | .getMeterIdFromBpMapping(devId, fi.getUpBpInfo()); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 518 | if (mId != null) { |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 519 | handleEapol(filterFuture, install, cp, filterBuilder, treatmentBuilder, fi, mId); |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 520 | eapIterator.remove(); |
| 521 | } |
| 522 | } else { |
| 523 | log.warn("Meter installation error while sending eapol trap flow. " + |
| 524 | "Result {} and MeterId {}", result, meterId); |
| 525 | eapIterator.remove(); |
| 526 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 527 | oltMeterService.removeFromPendingMeters(devId, bpInfo); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 528 | } |
| 529 | }); |
| 530 | } |
| 531 | |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 532 | private void handleEapol(CompletableFuture<ObjectiveError> filterFuture, |
| 533 | boolean install, ConnectPoint cp, |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 534 | DefaultFilteringObjective.Builder filterBuilder, |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 535 | TrafficTreatment.Builder treatmentBuilder, |
| 536 | SubscriberFlowInfo fi, MeterId mId) { |
| 537 | log.info("Meter {} for {} on {}/{} exists. {} EAPOL trap flow", |
| 538 | mId, fi.getUpBpInfo(), fi.getDevId(), fi.getUniPort(), |
| 539 | (install) ? "Installing" : "Removing"); |
| 540 | int techProfileId = getDefaultTechProfileId(fi.getDevId(), fi.getUniPort()); |
| 541 | // can happen in case of removal |
| 542 | if (mId != null) { |
| 543 | treatmentBuilder.meter(mId); |
| 544 | } |
| 545 | //Authentication trap flow uses only tech profile id as write metadata value |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 546 | FilteringObjective eapol = (install ? filterBuilder.permit() : filterBuilder.deny()) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 547 | .withKey(Criteria.matchInPort(fi.getUniPort())) |
| 548 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 549 | .withMeta(treatmentBuilder |
| 550 | .writeMetadata(createTechProfValueForWm( |
| 551 | fi.getTagInfo().getPonCTag(), |
| 552 | techProfileId), 0) |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame^] | 553 | .setOutput(PortNumber.CONTROLLER) |
| 554 | .pushVlan() |
| 555 | .setVlanId(fi.getTagInfo().getPonCTag()) |
| 556 | .build()) |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 557 | .fromApp(appId) |
| 558 | .withPriority(MAX_PRIORITY) |
| 559 | .add(new ObjectiveContext() { |
| 560 | @Override |
| 561 | public void onSuccess(Objective objective) { |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 562 | log.info("Eapol filter {} for {} on {} {} with meter {}.", |
| 563 | objective.id(), fi.getDevId(), fi.getUniPort(), |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 564 | (install) ? INSTALLED : REMOVED, mId); |
| 565 | if (filterFuture != null) { |
| 566 | filterFuture.complete(null); |
| 567 | } |
| 568 | pendingAddEapol.remove(cp); |
| 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public void onError(Objective objective, ObjectiveError error) { |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 573 | log.error("Eapol filter {} for {} on {} with meter {} " + |
| 574 | "failed {} because {}", objective.id(), |
Andrea Campanella | 3ce4d28 | 2020-06-09 13:46:58 +0200 | [diff] [blame] | 575 | fi.getDevId(), fi.getUniPort(), mId, |
| 576 | (install) ? INSTALLATION : REMOVAL, |
| 577 | error); |
| 578 | if (filterFuture != null) { |
| 579 | filterFuture.complete(error); |
| 580 | } |
| 581 | pendingAddEapol.remove(cp); |
| 582 | } |
| 583 | }); |
| 584 | flowObjectiveService.filter(fi.getDevId(), eapol); |
| 585 | } |
| 586 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 587 | /** |
| 588 | * Installs trap filtering objectives for particular traffic types on an |
| 589 | * NNI port. |
| 590 | * |
| 591 | * @param devId device ID |
| 592 | * @param port port number |
| 593 | * @param install true to install, false to remove |
| 594 | */ |
| 595 | @Override |
| 596 | public void processNniFilteringObjectives(DeviceId devId, PortNumber port, boolean install) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 597 | log.info("{} flows for NNI port {} on device {}", |
| 598 | install ? "Adding" : "Removing", port, devId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 599 | processLldpFilteringObjective(devId, port, install); |
| 600 | processDhcpFilteringObjectives(devId, port, null, null, install, false); |
| 601 | processIgmpFilteringObjectives(devId, port, null, null, install, false); |
| 602 | } |
| 603 | |
| 604 | |
| 605 | @Override |
| 606 | public void processLldpFilteringObjective(DeviceId devId, PortNumber port, boolean install) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 607 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 608 | |
| 609 | FilteringObjective lldp = (install ? builder.permit() : builder.deny()) |
| 610 | .withKey(Criteria.matchInPort(port)) |
| 611 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 612 | .withMeta(DefaultTrafficTreatment.builder() |
| 613 | .setOutput(PortNumber.CONTROLLER).build()) |
| 614 | .fromApp(appId) |
| 615 | .withPriority(MAX_PRIORITY) |
| 616 | .add(new ObjectiveContext() { |
| 617 | @Override |
| 618 | public void onSuccess(Objective objective) { |
| 619 | log.info("LLDP filter for device {} on port {} {}.", |
| 620 | devId, port, (install) ? INSTALLED : REMOVED); |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public void onError(Objective objective, ObjectiveError error) { |
| 625 | log.info("LLDP filter for device {} on port {} failed {} because {}", |
| 626 | devId, port, (install) ? INSTALLATION : REMOVAL, |
| 627 | error); |
| 628 | } |
| 629 | }); |
| 630 | |
| 631 | flowObjectiveService.filter(devId, lldp); |
| 632 | } |
| 633 | |
| 634 | @Override |
| 635 | public ForwardingObjective.Builder createTransparentBuilder(PortNumber uplinkPort, |
| 636 | PortNumber subscriberPort, |
| 637 | MeterId meterId, |
| 638 | UniTagInformation tagInfo, |
| 639 | boolean upstream) { |
| 640 | |
| 641 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 642 | .matchVlanId(tagInfo.getPonSTag()) |
| 643 | .matchInPort(upstream ? subscriberPort : uplinkPort) |
| 644 | .matchInnerVlanId(tagInfo.getPonCTag()) |
| 645 | .build(); |
| 646 | |
| 647 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 648 | if (meterId != null) { |
| 649 | tBuilder.meter(meterId); |
| 650 | } |
| 651 | |
| 652 | TrafficTreatment treatment = tBuilder |
| 653 | .setOutput(upstream ? uplinkPort : subscriberPort) |
| 654 | .writeMetadata(createMetadata(upstream ? tagInfo.getPonSTag() : tagInfo.getPonCTag(), |
| 655 | tagInfo.getTechnologyProfileId(), upstream ? uplinkPort : subscriberPort), 0) |
| 656 | .build(); |
| 657 | |
| 658 | return createForwardingObjectiveBuilder(selector, treatment, MIN_PRIORITY); |
| 659 | } |
| 660 | |
| 661 | @Override |
| 662 | public ForwardingObjective.Builder createUpBuilder(PortNumber uplinkPort, |
| 663 | PortNumber subscriberPort, |
| 664 | MeterId upstreamMeterId, |
| 665 | UniTagInformation uniTagInformation) { |
| 666 | |
| 667 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 668 | .matchInPort(subscriberPort) |
| 669 | .matchVlanId(uniTagInformation.getUniTagMatch()) |
| 670 | .build(); |
| 671 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 672 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 673 | //if the subscriberVlan (cTag) is different than ANY it needs to set. |
| 674 | if (uniTagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 675 | treatmentBuilder.pushVlan() |
| 676 | .setVlanId(uniTagInformation.getPonCTag()); |
| 677 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 678 | |
| 679 | if (uniTagInformation.getUsPonCTagPriority() != NO_PCP) { |
| 680 | treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonCTagPriority()); |
| 681 | } |
| 682 | |
| 683 | treatmentBuilder.pushVlan() |
| 684 | .setVlanId(uniTagInformation.getPonSTag()); |
| 685 | |
| 686 | if (uniTagInformation.getUsPonSTagPriority() != NO_PCP) { |
| 687 | treatmentBuilder.setVlanPcp((byte) uniTagInformation.getUsPonSTagPriority()); |
| 688 | } |
| 689 | |
| 690 | treatmentBuilder.setOutput(uplinkPort) |
| 691 | .writeMetadata(createMetadata(uniTagInformation.getPonCTag(), |
| 692 | uniTagInformation.getTechnologyProfileId(), uplinkPort), 0L); |
| 693 | |
| 694 | if (upstreamMeterId != null) { |
| 695 | treatmentBuilder.meter(upstreamMeterId); |
| 696 | } |
| 697 | |
| 698 | return createForwardingObjectiveBuilder(selector, treatmentBuilder.build(), MIN_PRIORITY); |
| 699 | } |
| 700 | |
| 701 | @Override |
| 702 | public ForwardingObjective.Builder createDownBuilder(PortNumber uplinkPort, |
| 703 | PortNumber subscriberPort, |
| 704 | MeterId downstreamMeterId, |
| 705 | UniTagInformation tagInformation) { |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 706 | |
| 707 | //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] | 708 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder() |
| 709 | .matchVlanId(tagInformation.getPonSTag()) |
| 710 | .matchInPort(uplinkPort) |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 711 | .matchInnerVlanId(tagInformation.getPonCTag()); |
| 712 | |
| 713 | |
| 714 | if (tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 715 | selectorBuilder.matchMetadata(tagInformation.getPonCTag().toShort()); |
| 716 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 717 | |
| 718 | if (tagInformation.getDsPonSTagPriority() != NO_PCP) { |
| 719 | selectorBuilder.matchVlanPcp((byte) tagInformation.getDsPonSTagPriority()); |
| 720 | } |
| 721 | |
| 722 | if (tagInformation.getConfiguredMacAddress() != null && |
Daniele Moro | 7cbf431 | 2020-03-06 17:24:12 -0800 | [diff] [blame] | 723 | !tagInformation.getConfiguredMacAddress().equals("") && |
| 724 | !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress()))) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 725 | selectorBuilder.matchEthDst(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 726 | } |
| 727 | |
| 728 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder() |
| 729 | .popVlan() |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 730 | .setOutput(subscriberPort); |
| 731 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 732 | treatmentBuilder.writeMetadata(createMetadata(tagInformation.getPonCTag(), |
| 733 | tagInformation.getTechnologyProfileId(), |
| 734 | subscriberPort), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 735 | |
| 736 | // to remark inner vlan header |
| 737 | if (tagInformation.getUsPonCTagPriority() != NO_PCP) { |
| 738 | treatmentBuilder.setVlanPcp((byte) tagInformation.getUsPonCTagPriority()); |
| 739 | } |
| 740 | |
Andrea Campanella | 9a77929 | 2020-02-03 19:19:09 +0100 | [diff] [blame] | 741 | if (!VlanId.NONE.equals(tagInformation.getUniTagMatch()) && |
| 742 | tagInformation.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 743 | treatmentBuilder.setVlanId(tagInformation.getUniTagMatch()); |
| 744 | } |
| 745 | |
| 746 | if (downstreamMeterId != null) { |
| 747 | treatmentBuilder.meter(downstreamMeterId); |
| 748 | } |
| 749 | |
| 750 | return createForwardingObjectiveBuilder(selectorBuilder.build(), treatmentBuilder.build(), MIN_PRIORITY); |
| 751 | } |
| 752 | |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 753 | @Override |
| 754 | public void clearDeviceState(DeviceId deviceId) { |
| 755 | pendingEapolForMeters.removeIf(fi -> fi.getDevId().equals(deviceId)); |
| 756 | pendingAddEapol.removeIf(connectPoint -> connectPoint.deviceId().equals(deviceId)); |
| 757 | |
| 758 | } |
| 759 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 760 | private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector, |
| 761 | TrafficTreatment treatment, |
| 762 | Integer priority) { |
| 763 | return DefaultForwardingObjective.builder() |
| 764 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 765 | .withPriority(priority) |
| 766 | .makePermanent() |
| 767 | .withSelector(selector) |
| 768 | .fromApp(appId) |
| 769 | .withTreatment(treatment); |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Returns the write metadata value including tech profile reference and innerVlan. |
| 774 | * For param cVlan, null can be sent |
| 775 | * |
| 776 | * @param cVlan c (customer) tag of one subscriber |
| 777 | * @param techProfileId tech profile id of one subscriber |
| 778 | * @return the write metadata value including tech profile reference and innerVlan |
| 779 | */ |
| 780 | private Long createTechProfValueForWm(VlanId cVlan, int techProfileId) { |
| 781 | if (cVlan == null || VlanId.NONE.equals(cVlan)) { |
| 782 | return (long) techProfileId << 32; |
| 783 | } |
| 784 | return ((long) (cVlan.id()) << 48 | (long) techProfileId << 32); |
| 785 | } |
| 786 | |
| 787 | private BandwidthProfileInformation getBandwidthProfileInformation(String bandwidthProfile) { |
| 788 | if (bandwidthProfile == null) { |
| 789 | return null; |
| 790 | } |
| 791 | return bpService.get(bandwidthProfile); |
| 792 | } |
| 793 | |
| 794 | /** |
| 795 | * It will be used to support AT&T use case (for EAPOL flows). |
| 796 | * If multiple services are found in uniServiceList, returns default tech profile id |
| 797 | * If one service is found, returns the found one |
| 798 | * |
| 799 | * @param devId |
| 800 | * @param portNumber |
| 801 | * @return the default technology profile id |
| 802 | */ |
| 803 | private int getDefaultTechProfileId(DeviceId devId, PortNumber portNumber) { |
| 804 | Port port = deviceService.getPort(devId, portNumber); |
| 805 | if (port != null) { |
| 806 | SubscriberAndDeviceInformation info = subsService.get(port.annotations().value(AnnotationKeys.PORT_NAME)); |
| 807 | if (info != null && info.uniTagList().size() == 1) { |
| 808 | return info.uniTagList().get(0).getTechnologyProfileId(); |
| 809 | } |
| 810 | } |
| 811 | return defaultTechProfileId; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Write metadata instruction value (metadata) is 8 bytes. |
| 816 | * <p> |
| 817 | * MS 2 bytes: C Tag |
| 818 | * Next 2 bytes: Technology Profile Id |
| 819 | * Next 4 bytes: Port number (uni or nni) |
| 820 | */ |
| 821 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 822 | if (techProfileId == NONE_TP_ID) { |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 823 | techProfileId = DEFAULT_TP_ID_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | } |