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