Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1 | /* |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 2 | * Copyright 2021-present Open Networking Foundation |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 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 | */ |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 16 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 17 | package org.opencord.olt.impl; |
| 18 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 20 | import org.onlab.packet.EthType; |
| 21 | import org.onlab.packet.IPv4; |
| 22 | import org.onlab.packet.IPv6; |
| 23 | import org.onlab.packet.MacAddress; |
| 24 | import org.onlab.packet.TpPort; |
| 25 | import org.onlab.packet.VlanId; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 26 | import org.onlab.util.KryoNamespace; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 27 | import org.onlab.util.Tools; |
| 28 | import org.onosproject.cfg.ComponentConfigService; |
| 29 | import org.onosproject.core.ApplicationId; |
| 30 | import org.onosproject.core.CoreService; |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 31 | import org.onosproject.net.AnnotationKeys; |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 32 | import org.onosproject.net.Annotations; |
Matteo Scandolo | 3a037a3 | 2020-04-01 12:17:50 -0700 | [diff] [blame] | 33 | import org.onosproject.net.ConnectPoint; |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 34 | import org.onosproject.net.DefaultAnnotations; |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 35 | import org.onosproject.net.DefaultPort; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 36 | import org.onosproject.net.Device; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 37 | import org.onosproject.net.DeviceId; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 38 | import org.onosproject.net.Host; |
| 39 | import org.onosproject.net.Port; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 40 | import org.onosproject.net.PortNumber; |
| 41 | import org.onosproject.net.device.DeviceService; |
| 42 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 44 | import org.onosproject.net.flow.FlowRule; |
| 45 | import org.onosproject.net.flow.FlowRuleEvent; |
| 46 | import org.onosproject.net.flow.FlowRuleListener; |
| 47 | import org.onosproject.net.flow.FlowRuleService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 48 | import org.onosproject.net.flow.TrafficSelector; |
| 49 | import org.onosproject.net.flow.TrafficTreatment; |
| 50 | import org.onosproject.net.flow.criteria.Criteria; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 51 | import org.onosproject.net.flow.criteria.Criterion; |
| 52 | import org.onosproject.net.flow.criteria.EthTypeCriterion; |
| 53 | import org.onosproject.net.flow.criteria.IPProtocolCriterion; |
| 54 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 55 | import org.onosproject.net.flow.criteria.UdpPortCriterion; |
| 56 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
| 57 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 58 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 59 | import org.onosproject.net.flowobjective.DefaultForwardingObjective; |
| 60 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 61 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 62 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 63 | import org.onosproject.net.flowobjective.Objective; |
| 64 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 65 | import org.onosproject.net.flowobjective.ObjectiveError; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 66 | import org.onosproject.net.host.HostService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 67 | import org.onosproject.net.meter.MeterId; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 68 | import org.onosproject.store.serializers.KryoNamespaces; |
| 69 | import org.onosproject.store.service.Serializer; |
| 70 | import org.onosproject.store.service.StorageService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 71 | import org.opencord.sadis.BandwidthProfileInformation; |
| 72 | import org.opencord.sadis.BaseInformationService; |
| 73 | import org.opencord.sadis.SadisService; |
| 74 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 75 | import org.opencord.sadis.UniTagInformation; |
| 76 | import org.osgi.service.component.ComponentContext; |
| 77 | import org.osgi.service.component.annotations.Activate; |
| 78 | import org.osgi.service.component.annotations.Component; |
| 79 | import org.osgi.service.component.annotations.Deactivate; |
| 80 | import org.osgi.service.component.annotations.Modified; |
| 81 | import org.osgi.service.component.annotations.Reference; |
| 82 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 83 | import org.osgi.service.component.annotations.ReferencePolicy; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 84 | import org.slf4j.Logger; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 85 | import org.slf4j.LoggerFactory; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 86 | |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 87 | import java.util.ArrayList; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 88 | import java.util.Dictionary; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 89 | import java.util.HashMap; |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 90 | import java.util.HashSet; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 91 | import java.util.Iterator; |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 92 | import java.util.List; |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 93 | import java.util.Map; |
Andrea Campanella | bfb47af | 2021-06-03 11:09:45 +0200 | [diff] [blame] | 94 | import java.util.Optional; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 95 | import java.util.Properties; |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 96 | import java.util.Set; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 97 | import java.util.concurrent.atomic.AtomicBoolean; |
| 98 | import java.util.concurrent.locks.Lock; |
| 99 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
Andrea Campanella | 7a1d7e7 | 2020-11-05 10:40:10 +0100 | [diff] [blame] | 100 | |
| 101 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 102 | import static org.onlab.util.Tools.get; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 103 | import static org.onosproject.net.flow.instructions.Instruction.Type.L2MODIFICATION; |
| 104 | import static org.opencord.olt.impl.OltUtils.completeFlowOpToString; |
| 105 | import static org.opencord.olt.impl.OltUtils.flowOpToString; |
| 106 | import static org.opencord.olt.impl.OltUtils.getPortName; |
| 107 | import static org.opencord.olt.impl.OltUtils.portWithName; |
| 108 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_TP_ID; |
| 109 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_TP_ID_DEFAULT; |
| 110 | import static org.opencord.olt.impl.OsgiPropertyConstants.DOWNSTREAM_OLT; |
| 111 | import static org.opencord.olt.impl.OsgiPropertyConstants.DOWNSTREAM_ONU; |
| 112 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_ON_NNI; |
| 113 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_ON_NNI_DEFAULT; |
| 114 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_V4; |
| 115 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_V4_DEFAULT; |
| 116 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_V6; |
| 117 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_DHCP_V6_DEFAULT; |
| 118 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_EAPOL; |
| 119 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_EAPOL_DEFAULT; |
| 120 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_IGMP_ON_NNI; |
| 121 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_IGMP_ON_NNI_DEFAULT; |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 122 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_PPPOE_ON_NNI; |
| 123 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_PPPOE_ON_NNI_DEFAULT; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 124 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_PPPOE; |
| 125 | import static org.opencord.olt.impl.OsgiPropertyConstants.ENABLE_PPPOE_DEFAULT; |
| 126 | import static org.opencord.olt.impl.OsgiPropertyConstants.UPSTREAM_OLT; |
| 127 | import static org.opencord.olt.impl.OsgiPropertyConstants.UPSTREAM_ONU; |
| 128 | import static org.opencord.olt.impl.OsgiPropertyConstants.WAIT_FOR_REMOVAL; |
| 129 | import static org.opencord.olt.impl.OsgiPropertyConstants.WAIT_FOR_REMOVAL_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 130 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 131 | @Component(immediate = true, property = { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 132 | ENABLE_DHCP_ON_NNI + ":Boolean=" + ENABLE_DHCP_ON_NNI_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 133 | ENABLE_DHCP_V4 + ":Boolean=" + ENABLE_DHCP_V4_DEFAULT, |
| 134 | ENABLE_DHCP_V6 + ":Boolean=" + ENABLE_DHCP_V6_DEFAULT, |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 135 | ENABLE_IGMP_ON_NNI + ":Boolean=" + ENABLE_IGMP_ON_NNI_DEFAULT, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 136 | ENABLE_EAPOL + ":Boolean=" + ENABLE_EAPOL_DEFAULT, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 137 | ENABLE_PPPOE_ON_NNI + ":Boolean=" + ENABLE_PPPOE_ON_NNI_DEFAULT, |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 138 | ENABLE_PPPOE + ":Boolean=" + ENABLE_PPPOE_DEFAULT, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 139 | DEFAULT_TP_ID + ":Integer=" + DEFAULT_TP_ID_DEFAULT, |
| 140 | // FIXME remove this option as potentially dangerous in production |
| 141 | WAIT_FOR_REMOVAL + ":Boolean=" + WAIT_FOR_REMOVAL_DEFAULT |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 142 | }) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 143 | public class OltFlowService implements OltFlowServiceInterface { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 144 | |
| 145 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 146 | protected CoreService coreService; |
| 147 | |
| 148 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 149 | protected ComponentConfigService cfgService; |
| 150 | |
| 151 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 152 | protected FlowObjectiveService flowObjectiveService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 153 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 154 | @Reference(cardinality = ReferenceCardinality.OPTIONAL, |
| 155 | bind = "bindSadisService", |
| 156 | unbind = "unbindSadisService", |
| 157 | policy = ReferencePolicy.DYNAMIC) |
| 158 | protected volatile SadisService sadisService; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 159 | |
| 160 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 161 | protected OltMeterServiceInterface oltMeterService; |
| 162 | |
| 163 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 164 | protected OltDeviceServiceInterface oltDeviceService; |
| 165 | |
| 166 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 167 | protected FlowRuleService flowRuleService; |
| 168 | |
| 169 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 170 | protected HostService hostService; |
| 171 | |
| 172 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 173 | protected DeviceService deviceService; |
| 174 | |
| 175 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 176 | protected StorageService storageService; |
| 177 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 178 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
| 179 | protected BaseInformationService<BandwidthProfileInformation> bpService; |
| 180 | |
| 181 | private static final String APP_NAME = "org.opencord.olt"; |
| 182 | protected ApplicationId appId; |
| 183 | private static final Integer MAX_PRIORITY = 10000; |
| 184 | private static final Integer MIN_PRIORITY = 1000; |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 185 | protected static final short EAPOL_DEFAULT_VLAN = 4091; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 186 | private static final int NONE_TP_ID = -1; |
| 187 | private static final String V4 = "V4"; |
| 188 | private static final String V6 = "V6"; |
| 189 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 190 | |
| 191 | protected UniTagInformation defaultEapolUniTag = new UniTagInformation.Builder() |
| 192 | .setServiceName("defaultEapol").build(); |
| 193 | protected UniTagInformation nniUniTag = new UniTagInformation.Builder() |
| 194 | .setServiceName("nni") |
| 195 | .setTechnologyProfileId(NONE_TP_ID) |
| 196 | .setPonCTag(VlanId.NONE) |
| 197 | .setUniTagMatch(VlanId.ANY) |
| 198 | .setUsPonCTagPriority(-1) |
| 199 | .build(); |
| 200 | |
| 201 | /** |
| 202 | * Connect Point status map. |
| 203 | * Used to keep track of which cp has flows that needs to be removed when the status changes. |
| 204 | */ |
| 205 | protected Map<ServiceKey, OltPortStatus> cpStatus; |
| 206 | private final ReentrantReadWriteLock cpStatusLock = new ReentrantReadWriteLock(); |
| 207 | private final Lock cpStatusWriteLock = cpStatusLock.writeLock(); |
| 208 | private final Lock cpStatusReadLock = cpStatusLock.readLock(); |
| 209 | |
| 210 | /** |
| 211 | * This map contains the subscriber that have been provisioned by the operator. |
| 212 | * They may or may not have flows, depending on the port status. |
| 213 | * The map is used to define whether flows need to be provisioned when a port comes up. |
| 214 | */ |
| 215 | protected Map<ServiceKey, Boolean> provisionedSubscribers; |
| 216 | private final ReentrantReadWriteLock provisionedSubscribersLock = new ReentrantReadWriteLock(); |
| 217 | private final Lock provisionedSubscribersWriteLock = provisionedSubscribersLock.writeLock(); |
| 218 | private final Lock provisionedSubscribersReadLock = provisionedSubscribersLock.readLock(); |
| 219 | |
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 | * Create DHCP trap flow on NNI port(s). |
| 222 | */ |
| 223 | protected boolean enableDhcpOnNni = ENABLE_DHCP_ON_NNI_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 224 | |
| 225 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 226 | * Enable flows for DHCP v4 if dhcp is required in sadis config. |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 227 | **/ |
| 228 | protected boolean enableDhcpV4 = ENABLE_DHCP_V4_DEFAULT; |
| 229 | |
| 230 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 231 | * Enable flows for DHCP v6 if dhcp is required in sadis config. |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 232 | **/ |
| 233 | protected boolean enableDhcpV6 = ENABLE_DHCP_V6_DEFAULT; |
| 234 | |
| 235 | /** |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 236 | * Create IGMP trap flow on NNI port(s). |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 237 | **/ |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 238 | protected boolean enableIgmpOnNni = ENABLE_IGMP_ON_NNI_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * Send EAPOL authentication trap flows before subscriber provisioning. |
| 242 | **/ |
| 243 | protected boolean enableEapol = ENABLE_EAPOL_DEFAULT; |
| 244 | |
| 245 | /** |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 246 | * Send PPPoED authentication trap flows before subscriber provisioning. |
| 247 | **/ |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 248 | protected boolean enablePppoeOnNni = ENABLE_PPPOE_ON_NNI_DEFAULT; |
| 249 | |
| 250 | /** |
| 251 | * Enable flows for PPPoE if it is required in sadis config. |
| 252 | **/ |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 253 | protected boolean enablePppoe = ENABLE_PPPOE_DEFAULT; |
| 254 | |
| 255 | /** |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 256 | * Default technology profile id that is used for authentication trap flows. |
| 257 | **/ |
| 258 | protected int defaultTechProfileId = DEFAULT_TP_ID_DEFAULT; |
| 259 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 260 | protected boolean waitForRemoval = WAIT_FOR_REMOVAL_DEFAULT; |
| 261 | |
| 262 | public enum FlowOperation { |
| 263 | ADD, |
| 264 | REMOVE; |
| 265 | |
| 266 | |
| 267 | @Override |
| 268 | public String toString() { |
| 269 | return super.toString().toLowerCase(); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | public enum FlowDirection { |
| 274 | UPSTREAM, |
| 275 | DOWNSTREAM, |
| 276 | } |
| 277 | |
| 278 | public enum OltFlowsStatus { |
| 279 | NONE, |
| 280 | PENDING_ADD, |
| 281 | ADDED, |
| 282 | PENDING_REMOVE, |
| 283 | REMOVED, |
| 284 | ERROR |
| 285 | } |
| 286 | |
| 287 | protected InternalFlowListener internalFlowListener; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 288 | |
| 289 | @Activate |
| 290 | public void activate(ComponentContext context) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 291 | cfgService.registerProperties(getClass()); |
| 292 | appId = coreService.registerApplication(APP_NAME); |
| 293 | internalFlowListener = new InternalFlowListener(); |
| 294 | |
| 295 | modified(context); |
| 296 | |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 297 | KryoNamespace serializer = KryoNamespace.newBuilder() |
| 298 | .register(KryoNamespaces.API) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 299 | .register(OltFlowsStatus.class) |
| 300 | .register(FlowDirection.class) |
| 301 | .register(OltPortStatus.class) |
| 302 | .register(OltFlowsStatus.class) |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 303 | .register(AccessDevicePort.class) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 304 | .register(new ServiceKeySerializer(), ServiceKey.class) |
| 305 | .register(UniTagInformation.class) |
Ilayda Ozdemir | 90a9362 | 2021-02-25 09:40:58 +0000 | [diff] [blame] | 306 | .build(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 307 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 308 | cpStatus = storageService.<ServiceKey, OltPortStatus>consistentMapBuilder() |
| 309 | .withName("volt-cp-status") |
| 310 | .withApplicationId(appId) |
| 311 | .withSerializer(Serializer.using(serializer)) |
| 312 | .build().asJavaMap(); |
| 313 | |
| 314 | provisionedSubscribers = storageService.<ServiceKey, Boolean>consistentMapBuilder() |
| 315 | .withName("volt-provisioned-subscriber") |
| 316 | .withApplicationId(appId) |
| 317 | .withSerializer(Serializer.using(serializer)) |
| 318 | .build().asJavaMap(); |
| 319 | |
| 320 | flowRuleService.addListener(internalFlowListener); |
| 321 | |
| 322 | log.info("Started"); |
| 323 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 324 | |
| 325 | @Deactivate |
| 326 | public void deactivate(ComponentContext context) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 327 | cfgService.unregisterProperties(getClass(), false); |
| 328 | flowRuleService.removeListener(internalFlowListener); |
| 329 | log.info("Stopped"); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Modified |
| 333 | public void modified(ComponentContext context) { |
| 334 | |
| 335 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 336 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 337 | Boolean o = Tools.isPropertyEnabled(properties, ENABLE_DHCP_ON_NNI); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 338 | if (o != null) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 339 | enableDhcpOnNni = o; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 342 | Boolean v4 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V4); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 343 | if (v4 != null) { |
| 344 | enableDhcpV4 = v4; |
| 345 | } |
| 346 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 347 | Boolean v6 = Tools.isPropertyEnabled(properties, ENABLE_DHCP_V6); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 348 | if (v6 != null) { |
| 349 | enableDhcpV6 = v6; |
| 350 | } |
| 351 | |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 352 | Boolean p = Tools.isPropertyEnabled(properties, ENABLE_IGMP_ON_NNI); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 353 | if (p != null) { |
Saurav Das | f62cea8 | 2020-08-26 17:43:04 -0700 | [diff] [blame] | 354 | enableIgmpOnNni = p; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 357 | Boolean eap = Tools.isPropertyEnabled(properties, ENABLE_EAPOL); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 358 | if (eap != null) { |
| 359 | enableEapol = eap; |
| 360 | } |
| 361 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 362 | Boolean pppoeInNni = Tools.isPropertyEnabled(properties, ENABLE_PPPOE_ON_NNI); |
| 363 | if (pppoeInNni != null) { |
| 364 | enablePppoeOnNni = pppoeInNni; |
| 365 | } |
| 366 | |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 367 | Boolean pppoe = Tools.isPropertyEnabled(properties, ENABLE_PPPOE); |
| 368 | if (pppoe != null) { |
| 369 | enablePppoe = pppoe; |
| 370 | } |
| 371 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 372 | Boolean wait = Tools.isPropertyEnabled(properties, WAIT_FOR_REMOVAL); |
| 373 | if (wait != null) { |
| 374 | waitForRemoval = wait; |
| 375 | } |
| 376 | |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 377 | String tpId = get(properties, DEFAULT_TP_ID); |
| 378 | defaultTechProfileId = isNullOrEmpty(tpId) ? DEFAULT_TP_ID_DEFAULT : Integer.parseInt(tpId.trim()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 379 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 380 | log.info("Modified. Values = enableDhcpOnNni: {}, enableDhcpV4: {}, " + "enableDhcpV6:{}, " + |
| 381 | "enableIgmpOnNni:{}, " + "enableEapol:{}, enablePppoeOnNni: {}, enablePppoe:{}, " + |
| 382 | "defaultTechProfileId:{}," + "waitForRemoval:{}", |
| 383 | enableDhcpOnNni, enableDhcpV4, enableDhcpV6, enableIgmpOnNni, enableEapol, |
| 384 | enablePppoeOnNni, enablePppoe, defaultTechProfileId, waitForRemoval); |
Andrea Campanella | fee8642 | 2020-06-04 16:01:27 +0200 | [diff] [blame] | 385 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 389 | public ImmutableMap<ServiceKey, OltPortStatus> getConnectPointStatus() { |
| 390 | try { |
| 391 | cpStatusReadLock.lock(); |
| 392 | return ImmutableMap.copyOf(cpStatus); |
| 393 | } finally { |
| 394 | cpStatusReadLock.unlock(); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 398 | @Override |
| 399 | public ImmutableMap<ServiceKey, UniTagInformation> getProgrammedSubscribers() { |
| 400 | // NOTE we might want to remove this conversion and directly use cpStatus as it contains |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 401 | // all the required information about subscribers |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 402 | Map<ServiceKey, UniTagInformation> subscribers = |
| 403 | new HashMap<>(); |
| 404 | try { |
| 405 | cpStatusReadLock.lock(); |
| 406 | |
| 407 | cpStatus.forEach((sk, status) -> { |
| 408 | if ( |
| 409 | // not NNI Port |
| 410 | !oltDeviceService.isNniPort(deviceService.getDevice(sk.getPort().connectPoint().deviceId()), |
| 411 | sk.getPort().connectPoint().port()) && |
| 412 | // not EAPOL flow |
Andrea Campanella | 982fd33 | 2022-01-19 09:14:12 +0100 | [diff] [blame] | 413 | !sk.getService().equals(defaultEapolUniTag) && |
| 414 | !status.subscriberFlowsStatus.equals(OltFlowsStatus.PENDING_REMOVE) |
| 415 | && !status.subscriberFlowsStatus.equals(OltFlowsStatus.REMOVED) |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 416 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 417 | ) { |
| 418 | subscribers.put(sk, sk.getService()); |
| 419 | } |
| 420 | }); |
| 421 | |
| 422 | return ImmutableMap.copyOf(subscribers); |
| 423 | } finally { |
| 424 | cpStatusReadLock.unlock(); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public Map<ServiceKey, Boolean> getRequestedSubscribers() { |
| 430 | try { |
| 431 | provisionedSubscribersReadLock.lock(); |
| 432 | return ImmutableMap.copyOf(provisionedSubscribers); |
| 433 | } finally { |
| 434 | provisionedSubscribersReadLock.unlock(); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public void handleNniFlows(Device device, Port port, FlowOperation action) { |
| 440 | |
| 441 | // always handle the LLDP flow |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 442 | log.debug("{} LLDP trap flow on NNI {} for device {}", flowOpToString(action), portWithName(port), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 443 | processLldpFilteringObjective(device.id(), port, action); |
| 444 | |
| 445 | if (enableDhcpOnNni) { |
| 446 | if (enableDhcpV4) { |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 447 | log.debug("{} DHCPv4 trap flow on NNI {} for device {}", flowOpToString(action), |
| 448 | portWithName(port), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 449 | processDhcpFilteringObjectives(device.id(), port, action, FlowDirection.DOWNSTREAM, |
| 450 | 67, 68, EthType.EtherType.IPV4.ethType(), IPv4.PROTOCOL_UDP, |
| 451 | null, null, nniUniTag); |
| 452 | } |
| 453 | if (enableDhcpV6) { |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 454 | log.debug("{} DHCPv6 trap flow on NNI {} for device {}", flowOpToString(action), |
| 455 | portWithName(port), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 456 | processDhcpFilteringObjectives(device.id(), port, action, FlowDirection.DOWNSTREAM, |
| 457 | 546, 547, EthType.EtherType.IPV6.ethType(), IPv6.PROTOCOL_UDP, |
| 458 | null, null, nniUniTag); |
| 459 | } |
| 460 | } else { |
Matteo Scandolo | 1f8de33 | 2021-12-06 12:18:24 -0800 | [diff] [blame] | 461 | log.debug("DHCP is not required on NNI {} for device {}", portWithName(port), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | if (enableIgmpOnNni) { |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 465 | log.debug("{} IGMP flow on NNI {} for device {}", flowOpToString(action), portWithName(port), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 466 | processIgmpFilteringObjectives(device.id(), port, action, FlowDirection.DOWNSTREAM, |
| 467 | null, null, NONE_TP_ID, VlanId.NONE, VlanId.ANY, -1); |
| 468 | } |
| 469 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 470 | if (enablePppoeOnNni) { |
Matteo Scandolo | d7aa89c | 2021-12-07 10:21:34 -0800 | [diff] [blame] | 471 | log.debug("{} PPPoE flow on NNI {} for device {}", flowOpToString(action), port.number(), device.id()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 472 | processPPPoEDFilteringObjectives(device.id(), port, action, FlowDirection.DOWNSTREAM, |
| 473 | null, null, NONE_TP_ID, VlanId.NONE, VlanId.ANY, null); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public boolean handleBasicPortFlows(DiscoveredSubscriber sub, String bandwidthProfileId, |
| 479 | String oltBandwidthProfileId) { |
| 480 | |
| 481 | // we only need to something if EAPOL is enabled |
| 482 | if (!enableEapol) { |
| 483 | return true; |
| 484 | } |
| 485 | |
| 486 | if (sub.status == DiscoveredSubscriber.Status.ADDED) { |
| 487 | return addDefaultFlows(sub, bandwidthProfileId, oltBandwidthProfileId); |
| 488 | } else if (sub.status == DiscoveredSubscriber.Status.REMOVED) { |
| 489 | return removeDefaultFlows(sub, bandwidthProfileId, oltBandwidthProfileId); |
| 490 | } else { |
| 491 | log.error("Unknown Status {} on DiscoveredSubscriber {}", sub.status, sub); |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | } |
| 496 | |
| 497 | private boolean addDefaultFlows(DiscoveredSubscriber sub, String bandwidthProfileId, String oltBandwidthProfileId) { |
| 498 | |
| 499 | if (!oltMeterService.createMeter(sub.device.id(), bandwidthProfileId)) { |
| 500 | if (log.isTraceEnabled()) { |
| 501 | log.trace("waiting on meter for bp {} and sub {}", bandwidthProfileId, sub); |
| 502 | } |
| 503 | return false; |
| 504 | } |
| 505 | if (hasDefaultEapol(sub.port)) { |
| 506 | return true; |
| 507 | } |
| 508 | return handleEapolFlow(sub, bandwidthProfileId, |
| 509 | oltBandwidthProfileId, FlowOperation.ADD, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 510 | |
| 511 | } |
| 512 | |
| 513 | private boolean removeDefaultFlows(DiscoveredSubscriber sub, String bandwidthProfile, String oltBandwidthProfile) { |
| 514 | // NOTE that we are not checking for meters as they must have been created to install the flow in first place |
| 515 | return handleEapolFlow(sub, bandwidthProfile, oltBandwidthProfile, |
| 516 | FlowOperation.REMOVE, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 517 | } |
| 518 | |
| 519 | @Override |
| 520 | public boolean handleSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwidthProfile, |
| 521 | String multicastServiceName) { |
| 522 | // NOTE that we are taking defaultBandwithProfile as a parameter as that can be configured in the Olt component |
| 523 | if (sub.status == DiscoveredSubscriber.Status.ADDED) { |
| 524 | return addSubscriberFlows(sub, defaultBandwidthProfile, multicastServiceName); |
| 525 | } else if (sub.status == DiscoveredSubscriber.Status.REMOVED) { |
| 526 | return removeSubscriberFlows(sub, defaultBandwidthProfile, multicastServiceName); |
| 527 | } else { |
| 528 | log.error("don't know how to handle {}", sub); |
| 529 | return false; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | private boolean addSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwithProfile, |
| 534 | String multicastServiceName) { |
| 535 | if (log.isTraceEnabled()) { |
| 536 | log.trace("Provisioning of subscriber on {} started", portWithName(sub.port)); |
| 537 | } |
| 538 | if (enableEapol) { |
| 539 | if (hasDefaultEapol(sub.port)) { |
| 540 | // remove EAPOL flow and throw exception so that we'll retry later |
| 541 | if (!isDefaultEapolPendingRemoval(sub.port)) { |
| 542 | removeDefaultFlows(sub, defaultBandwithProfile, defaultBandwithProfile); |
| 543 | } |
| 544 | |
| 545 | if (waitForRemoval) { |
| 546 | // NOTE wait for removal is a flag only needed to make sure VOLTHA |
| 547 | // does not explode with the flows remove/add in the same batch |
| 548 | log.debug("Awaiting for default flows removal for {}", portWithName(sub.port)); |
| 549 | return false; |
| 550 | } else { |
| 551 | log.warn("continuing provisioning on {}", portWithName(sub.port)); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | } |
| 556 | |
| 557 | // NOTE createMeters will return if the meters are not installed |
| 558 | if (!oltMeterService.createMeters(sub.device.id(), |
Matteo Scandolo | 88df8ae | 2021-11-23 13:12:29 -0800 | [diff] [blame] | 559 | sub.subscriberAndDeviceInformation, multicastServiceName)) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 560 | return false; |
| 561 | } |
| 562 | |
| 563 | // NOTE we need to add the DHCP flow regardless so that the host can be discovered and the MacAddress added |
| 564 | handleSubscriberDhcpFlows(sub.device.id(), sub.port, FlowOperation.ADD, |
| 565 | sub.subscriberAndDeviceInformation); |
| 566 | |
| 567 | if (isMacLearningEnabled(sub.subscriberAndDeviceInformation) |
| 568 | && !isMacAddressAvailable(sub.device.id(), sub.port, |
| 569 | sub.subscriberAndDeviceInformation)) { |
| 570 | log.debug("Awaiting for macAddress on {}", portWithName(sub.port)); |
| 571 | return false; |
| 572 | } |
| 573 | |
Matteo Scandolo | 8a91c0f | 2021-12-03 10:58:14 -0800 | [diff] [blame] | 574 | // NOTE that the EAPOL flows handling is based on the data-plane flows status |
| 575 | // always process them before |
| 576 | handleSubscriberEapolFlows(sub, FlowOperation.ADD, sub.subscriberAndDeviceInformation); |
| 577 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 578 | handleSubscriberPppoeFlows(sub.device.id(), sub.port, FlowOperation.ADD, sub.subscriberAndDeviceInformation); |
| 579 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 580 | handleSubscriberDataFlows(sub.device, sub.port, FlowOperation.ADD, |
| 581 | sub.subscriberAndDeviceInformation, multicastServiceName); |
| 582 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 583 | handleSubscriberIgmpFlows(sub, FlowOperation.ADD); |
| 584 | |
| 585 | log.info("Provisioning of subscriber on {} completed", portWithName(sub.port)); |
| 586 | return true; |
| 587 | } |
| 588 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 589 | protected boolean removeSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwithProfile, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 590 | String multicastServiceName) { |
| 591 | |
| 592 | if (log.isTraceEnabled()) { |
| 593 | log.trace("Removal of subscriber on {} started", |
| 594 | portWithName(sub.port)); |
| 595 | } |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 596 | SubscriberAndDeviceInformation si = sub.subscriberAndDeviceInformation; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 597 | |
| 598 | handleSubscriberDhcpFlows(sub.device.id(), sub.port, FlowOperation.REMOVE, si); |
| 599 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 600 | handleSubscriberPppoeFlows(sub.device.id(), sub.port, FlowOperation.REMOVE, sub.subscriberAndDeviceInformation); |
| 601 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 602 | if (enableEapol) { |
| 603 | // remove the tagged eapol |
| 604 | handleSubscriberEapolFlows(sub, FlowOperation.REMOVE, si); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 605 | } |
| 606 | handleSubscriberDataFlows(sub.device, sub.port, FlowOperation.REMOVE, si, multicastServiceName); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 607 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 608 | handleSubscriberIgmpFlows(sub, FlowOperation.REMOVE); |
| 609 | |
| 610 | if (enableEapol) { |
| 611 | |
| 612 | // if any of the services still has flows, return false |
| 613 | Iterator<UniTagInformation> iter = sub.subscriberAndDeviceInformation.uniTagList().iterator(); |
| 614 | while (iter.hasNext()) { |
| 615 | UniTagInformation entry = iter.next(); |
| 616 | if (areSubscriberFlowsPendingRemoval(sub.port, entry)) { |
| 617 | log.info("Subscriber {} still have flows on service {}, postpone default EAPOL installation.", |
| 618 | portWithName(sub.port), entry.getServiceName()); |
| 619 | return false; |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | // once the flows are removed add the default one back |
| 624 | // (only if the port is ENABLED and still present on the device) |
Matteo Scandolo | 49c4205 | 2021-11-23 13:12:29 -0800 | [diff] [blame] | 625 | if (sub.port.isEnabled() && deviceService.getPort(sub.device.id(), sub.port.number()) != null) { |
| 626 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 627 | // NOTE we remove the subscriber when the port goes down |
| 628 | // but in that case we don't need to add default eapol |
| 629 | handleEapolFlow(sub, defaultBandwithProfile, defaultBandwithProfile, |
| 630 | FlowOperation.ADD, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 631 | } |
| 632 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 633 | // FIXME check the return status of the flow and return accordingly |
| 634 | log.info("Removal of subscriber on {} completed", portWithName(sub.port)); |
| 635 | return true; |
| 636 | } |
| 637 | |
| 638 | @Override |
| 639 | public boolean hasDefaultEapol(Port port) { |
| 640 | OltPortStatus status = getOltPortStatus(port, defaultEapolUniTag); |
| 641 | // NOTE we consider ERROR as a present EAPOL flow as ONOS |
| 642 | // will keep trying to add it |
| 643 | return status != null && (status.defaultEapolStatus == OltFlowsStatus.ADDED || |
| 644 | status.defaultEapolStatus == OltFlowsStatus.PENDING_ADD || |
| 645 | status.defaultEapolStatus == OltFlowsStatus.ERROR); |
| 646 | } |
| 647 | |
| 648 | private OltPortStatus getOltPortStatus(Port port, UniTagInformation uniTagInformation) { |
| 649 | try { |
| 650 | cpStatusReadLock.lock(); |
| 651 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uniTagInformation); |
| 652 | OltPortStatus status = cpStatus.get(sk); |
| 653 | return status; |
| 654 | } finally { |
| 655 | cpStatusReadLock.unlock(); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | public boolean isDefaultEapolPendingRemoval(Port port) { |
| 660 | OltPortStatus status = getOltPortStatus(port, defaultEapolUniTag); |
| 661 | if (log.isTraceEnabled()) { |
| 662 | log.trace("Status during EAPOL flow check {} for port {} and UniTagInformation {}", |
| 663 | status, portWithName(port), defaultEapolUniTag); |
| 664 | } |
| 665 | return status != null && status.defaultEapolStatus == OltFlowsStatus.PENDING_REMOVE; |
| 666 | } |
| 667 | |
| 668 | @Override |
| 669 | public boolean hasDhcpFlows(Port port, UniTagInformation uti) { |
| 670 | OltPortStatus status = getOltPortStatus(port, uti); |
| 671 | if (log.isTraceEnabled()) { |
| 672 | log.trace("Status during DHCP flow check {} for port {} and service {}", |
| 673 | status, portWithName(port), uti.getServiceName()); |
| 674 | } |
| 675 | return status != null && |
| 676 | (status.dhcpStatus == OltFlowsStatus.ADDED || |
| 677 | status.dhcpStatus == OltFlowsStatus.PENDING_ADD); |
| 678 | } |
| 679 | |
| 680 | @Override |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 681 | public boolean hasPppoeFlows(Port port, UniTagInformation uti) { |
| 682 | OltPortStatus status = getOltPortStatus(port, uti); |
| 683 | if (log.isTraceEnabled()) { |
| 684 | log.trace("Status during PPPoE flow check {} for port {} and service {}", |
| 685 | status, portWithName(port), uti.getServiceName()); |
| 686 | } |
| 687 | return status != null && |
| 688 | (status.pppoeStatus == OltFlowsStatus.ADDED || |
| 689 | status.pppoeStatus == OltFlowsStatus.PENDING_ADD); |
| 690 | } |
| 691 | |
| 692 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 693 | public boolean hasSubscriberFlows(Port port, UniTagInformation uti) { |
| 694 | |
| 695 | OltPortStatus status = getOltPortStatus(port, uti); |
| 696 | if (log.isTraceEnabled()) { |
| 697 | log.trace("Status during subscriber flow check {} for port {} and service {}", |
| 698 | status, portWithName(port), uti.getServiceName()); |
| 699 | } |
| 700 | return status != null && (status.subscriberFlowsStatus == OltFlowsStatus.ADDED || |
| 701 | status.subscriberFlowsStatus == OltFlowsStatus.PENDING_ADD); |
| 702 | } |
| 703 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 704 | public boolean areSubscriberFlowsPendingRemoval(Port port, UniTagInformation uti) { |
| 705 | OltPortStatus status = getOltPortStatus(port, uti); |
| 706 | if (log.isTraceEnabled()) { |
| 707 | log.trace("Status during pending_remove flow check {} for port {} and UniTagInformation {}", |
| 708 | status, portWithName(port), uti); |
| 709 | } |
| 710 | return status != null && status.subscriberFlowsStatus == OltFlowsStatus.PENDING_REMOVE; |
| 711 | } |
| 712 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 713 | @Override |
| 714 | public void purgeDeviceFlows(DeviceId deviceId) { |
| 715 | log.debug("Purging flows on device {}", deviceId); |
Matteo Scandolo | b6981dc | 2021-12-02 16:31:44 -0800 | [diff] [blame] | 716 | flowRuleService.purgeFlowRules(deviceId); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 717 | |
| 718 | // removing the status from the cpStatus map |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 719 | if (log.isTraceEnabled()) { |
| 720 | log.trace("Clearing cp status from device {}", deviceId); |
| 721 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 722 | try { |
| 723 | cpStatusWriteLock.lock(); |
| 724 | Iterator<Map.Entry<ServiceKey, OltPortStatus>> iter = cpStatus.entrySet().iterator(); |
| 725 | while (iter.hasNext()) { |
| 726 | Map.Entry<ServiceKey, OltPortStatus> entry = iter.next(); |
| 727 | if (entry.getKey().getPort().connectPoint().deviceId().equals(deviceId)) { |
| 728 | cpStatus.remove(entry.getKey()); |
| 729 | } |
| 730 | } |
| 731 | } finally { |
| 732 | cpStatusWriteLock.unlock(); |
| 733 | } |
| 734 | |
| 735 | // removing subscribers from the provisioned map |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 736 | if (log.isTraceEnabled()) { |
| 737 | log.trace("Clearing provisioned subscribers from device {}", deviceId); |
| 738 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 739 | try { |
| 740 | provisionedSubscribersWriteLock.lock(); |
| 741 | Iterator<Map.Entry<ServiceKey, Boolean>> iter = provisionedSubscribers.entrySet().iterator(); |
| 742 | while (iter.hasNext()) { |
| 743 | Map.Entry<ServiceKey, Boolean> entry = iter.next(); |
| 744 | if (entry.getKey().getPort().connectPoint().deviceId().equals(deviceId)) { |
| 745 | provisionedSubscribers.remove(entry.getKey()); |
| 746 | } |
| 747 | } |
| 748 | } finally { |
| 749 | provisionedSubscribersWriteLock.unlock(); |
| 750 | } |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 751 | log.debug("Done clearing up device flows and subscribers"); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | @Override |
| 755 | public boolean isSubscriberServiceProvisioned(AccessDevicePort cp) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 756 | Set<Map.Entry<ServiceKey, Boolean>> subs; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 757 | try { |
| 758 | provisionedSubscribersReadLock.lock(); |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 759 | subs = new HashSet<>(provisionedSubscribers.entrySet()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 760 | } finally { |
| 761 | provisionedSubscribersReadLock.unlock(); |
| 762 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 763 | |
| 764 | for (Map.Entry<ServiceKey, Boolean> entry : subs) { |
| 765 | if (entry.getKey().getPort().equals(cp) && entry.getValue()) { |
| 766 | return true; |
| 767 | } |
| 768 | } |
| 769 | return false; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | @Override |
| 773 | public boolean isSubscriberServiceProvisioned(ServiceKey sk) { |
| 774 | try { |
| 775 | provisionedSubscribersReadLock.lock(); |
| 776 | Boolean provisioned = provisionedSubscribers.get(sk); |
| 777 | if (provisioned == null || !provisioned) { |
| 778 | return false; |
| 779 | } |
| 780 | } finally { |
| 781 | provisionedSubscribersReadLock.unlock(); |
| 782 | } |
| 783 | return true; |
| 784 | } |
| 785 | |
| 786 | @Override |
| 787 | public void updateProvisionedSubscriberStatus(ServiceKey sk, Boolean status) { |
| 788 | try { |
| 789 | provisionedSubscribersWriteLock.lock(); |
| 790 | provisionedSubscribers.put(sk, status); |
| 791 | } finally { |
| 792 | provisionedSubscribersWriteLock.unlock(); |
| 793 | } |
| 794 | } |
| 795 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 796 | protected boolean handleEapolFlow(DiscoveredSubscriber sub, String bandwidthProfile, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 797 | String oltBandwidthProfile, FlowOperation action, VlanId vlanId) { |
| 798 | |
| 799 | // create a subscriberKey for the EAPOL flow |
| 800 | ServiceKey sk = new ServiceKey(new AccessDevicePort(sub.port), defaultEapolUniTag); |
| 801 | |
| 802 | // NOTE we only need to keep track of the default EAPOL flow in the |
| 803 | // connectpoint status map |
| 804 | if (vlanId.id().equals(EAPOL_DEFAULT_VLAN)) { |
| 805 | OltFlowsStatus status = action == FlowOperation.ADD ? |
| 806 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 807 | updateConnectPointStatus(sk, status, OltFlowsStatus.NONE, OltFlowsStatus.NONE, OltFlowsStatus.NONE); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 808 | |
| 809 | } |
| 810 | |
| 811 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
| 812 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 813 | |
| 814 | int techProfileId = getDefaultTechProfileId(sub.port); |
| 815 | MeterId meterId = oltMeterService.getMeterIdForBandwidthProfile(sub.device.id(), bandwidthProfile); |
| 816 | |
| 817 | // in the delete case the meter should still be there as we remove |
| 818 | // the meters only if no flows are pointing to them |
| 819 | if (meterId == null) { |
| 820 | log.debug("MeterId is null for BandwidthProfile {} on device {}", |
| 821 | bandwidthProfile, sub.device.id()); |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | MeterId oltMeterId = oltMeterService.getMeterIdForBandwidthProfile(sub.device.id(), oltBandwidthProfile); |
| 826 | if (oltMeterId == null) { |
| 827 | log.debug("MeterId is null for OltBandwidthProfile {} on device {}", |
| 828 | oltBandwidthProfile, sub.device.id()); |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | log.info("{} EAPOL flow for {} with vlanId {} and BandwidthProfile {} (meterId {})", |
| 833 | flowOpToString(action), portWithName(sub.port), vlanId, bandwidthProfile, meterId); |
| 834 | |
| 835 | FilteringObjective.Builder eapolAction; |
| 836 | |
| 837 | if (action == FlowOperation.ADD) { |
| 838 | eapolAction = filterBuilder.permit(); |
| 839 | } else if (action == FlowOperation.REMOVE) { |
| 840 | eapolAction = filterBuilder.deny(); |
| 841 | } else { |
| 842 | log.error("Operation {} not supported", action); |
| 843 | return false; |
| 844 | } |
| 845 | |
| 846 | FilteringObjective.Builder baseEapol = eapolAction |
| 847 | .withKey(Criteria.matchInPort(sub.port.number())) |
| 848 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())); |
| 849 | |
| 850 | // NOTE we only need to add the treatment to install the flow, |
| 851 | // we can remove it based in the match |
| 852 | FilteringObjective.Builder eapol; |
| 853 | |
| 854 | TrafficTreatment treatment = treatmentBuilder |
| 855 | .meter(meterId) |
| 856 | .writeMetadata(createTechProfValueForWriteMetadata( |
| 857 | vlanId, |
| 858 | techProfileId, oltMeterId), 0) |
| 859 | .setOutput(PortNumber.CONTROLLER) |
| 860 | .pushVlan() |
| 861 | .setVlanId(vlanId) |
| 862 | .build(); |
| 863 | eapol = baseEapol |
| 864 | .withMeta(treatment); |
| 865 | |
| 866 | FilteringObjective eapolObjective = eapol |
| 867 | .fromApp(appId) |
| 868 | .withPriority(MAX_PRIORITY) |
| 869 | .add(new ObjectiveContext() { |
| 870 | @Override |
| 871 | public void onSuccess(Objective objective) { |
| 872 | log.info("EAPOL flow objective {} for {}", |
| 873 | completeFlowOpToString(action), portWithName(sub.port)); |
| 874 | if (log.isTraceEnabled()) { |
| 875 | log.trace("EAPOL flow details for port {}: {}", portWithName(sub.port), objective); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | @Override |
| 880 | public void onError(Objective objective, ObjectiveError error) { |
| 881 | log.error("Cannot {} eapol flow for {} : {}", action, |
| 882 | portWithName(sub.port), error); |
| 883 | |
| 884 | if (vlanId.id().equals(EAPOL_DEFAULT_VLAN)) { |
| 885 | updateConnectPointStatus(sk, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 886 | OltFlowsStatus.ERROR, null, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 887 | } |
| 888 | } |
| 889 | }); |
| 890 | |
| 891 | flowObjectiveService.filter(sub.device.id(), eapolObjective); |
| 892 | |
| 893 | log.info("{} EAPOL filter for {}", completeFlowOpToString(action), portWithName(sub.port)); |
| 894 | return true; |
| 895 | } |
| 896 | |
| 897 | // FIXME it's confusing that si is not necessarily inside the DiscoveredSubscriber |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 898 | protected boolean handleSubscriberEapolFlows(DiscoveredSubscriber sub, FlowOperation action, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 899 | SubscriberAndDeviceInformation si) { |
| 900 | if (!enableEapol) { |
| 901 | return true; |
| 902 | } |
| 903 | // TODO verify we need an EAPOL flow for EACH service |
| 904 | AtomicBoolean success = new AtomicBoolean(true); |
| 905 | si.uniTagList().forEach(u -> { |
| 906 | // we assume that if subscriber flows are installed, tagged EAPOL is installed as well |
| 907 | boolean hasFlows = hasSubscriberFlows(sub.port, u); |
| 908 | |
| 909 | // if the subscriber flows are present the EAPOL flow is present thus we don't need to install it, |
| 910 | // if the subscriber does not have flows the EAPOL flow is not present thus we don't need to remove it |
| 911 | if (action == FlowOperation.ADD && hasFlows || |
| 912 | action == FlowOperation.REMOVE && !hasFlows) { |
| 913 | log.debug("Not {} EAPOL on {}({}) as subscriber flow status is {}", flowOpToString(action), |
| 914 | portWithName(sub.port), u.getServiceName(), hasFlows); |
| 915 | return; |
| 916 | } |
| 917 | log.info("{} EAPOL flows for subscriber {} on {} and service {}", |
| 918 | flowOpToString(action), si.id(), portWithName(sub.port), u.getServiceName()); |
| 919 | if (!handleEapolFlow(sub, u.getUpstreamBandwidthProfile(), |
| 920 | u.getUpstreamOltBandwidthProfile(), |
| 921 | action, u.getPonCTag())) { |
| 922 | // |
| 923 | log.error("Failed to {} EAPOL with suscriber tags", action); |
| 924 | //TODO this sets it for all services, maybe some services succeeded. |
| 925 | success.set(false); |
| 926 | } |
| 927 | }); |
| 928 | return success.get(); |
| 929 | } |
| 930 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 931 | protected void handleSubscriberIgmpFlows(DiscoveredSubscriber sub, FlowOperation action) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 932 | sub.subscriberAndDeviceInformation.uniTagList().forEach(uti -> { |
| 933 | if (uti.getIsIgmpRequired()) { |
| 934 | DeviceId deviceId = sub.device.id(); |
| 935 | // if we reached here a meter already exists |
| 936 | MeterId meterId = oltMeterService |
| 937 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 938 | MeterId oltMeterId = oltMeterService |
| 939 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 940 | |
| 941 | processIgmpFilteringObjectives(deviceId, sub.port, |
| 942 | action, FlowDirection.UPSTREAM, meterId, oltMeterId, uti.getTechnologyProfileId(), |
| 943 | uti.getPonCTag(), uti.getUniTagMatch(), uti.getUsPonCTagPriority()); |
| 944 | } |
| 945 | }); |
| 946 | } |
| 947 | |
| 948 | private boolean checkSadisRunning() { |
| 949 | if (bpService == null) { |
| 950 | log.warn("Sadis is not running"); |
| 951 | return false; |
| 952 | } |
| 953 | return true; |
| 954 | } |
| 955 | |
| 956 | private int getDefaultTechProfileId(Port port) { |
| 957 | if (!checkSadisRunning()) { |
| 958 | return defaultTechProfileId; |
| 959 | } |
| 960 | if (port != null) { |
| 961 | SubscriberAndDeviceInformation info = subsService.get(getPortName(port)); |
| 962 | if (info != null && info.uniTagList().size() == 1) { |
| 963 | return info.uniTagList().get(0).getTechnologyProfileId(); |
| 964 | } |
| 965 | } |
| 966 | return defaultTechProfileId; |
| 967 | } |
| 968 | |
| 969 | protected Long createTechProfValueForWriteMetadata(VlanId cVlan, int techProfileId, MeterId upstreamOltMeterId) { |
| 970 | Long writeMetadata; |
| 971 | |
| 972 | if (cVlan == null || VlanId.NONE.equals(cVlan)) { |
| 973 | writeMetadata = (long) techProfileId << 32; |
| 974 | } else { |
| 975 | writeMetadata = ((long) (cVlan.id()) << 48 | (long) techProfileId << 32); |
| 976 | } |
| 977 | if (upstreamOltMeterId == null) { |
| 978 | return writeMetadata; |
| 979 | } else { |
| 980 | return writeMetadata | upstreamOltMeterId.id(); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | private void processLldpFilteringObjective(DeviceId deviceId, Port port, FlowOperation action) { |
| 985 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 986 | |
| 987 | FilteringObjective lldp = (action == FlowOperation.ADD ? builder.permit() : builder.deny()) |
| 988 | .withKey(Criteria.matchInPort(port.number())) |
| 989 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 990 | .withMeta(DefaultTrafficTreatment.builder() |
| 991 | .setOutput(PortNumber.CONTROLLER).build()) |
| 992 | .fromApp(appId) |
| 993 | .withPriority(MAX_PRIORITY) |
| 994 | .add(new ObjectiveContext() { |
| 995 | @Override |
| 996 | public void onSuccess(Objective objective) { |
| 997 | log.info("{} LLDP filter for {}.", completeFlowOpToString(action), portWithName(port)); |
| 998 | } |
| 999 | |
| 1000 | @Override |
| 1001 | public void onError(Objective objective, ObjectiveError error) { |
| 1002 | log.error("Falied to {} LLDP filter on {} because {}", action, portWithName(port), |
| 1003 | error); |
| 1004 | } |
| 1005 | }); |
| 1006 | |
| 1007 | flowObjectiveService.filter(deviceId, lldp); |
| 1008 | } |
| 1009 | |
| 1010 | protected void handleSubscriberDhcpFlows(DeviceId deviceId, Port port, |
| 1011 | FlowOperation action, |
| 1012 | SubscriberAndDeviceInformation si) { |
| 1013 | si.uniTagList().forEach(uti -> { |
| 1014 | |
| 1015 | if (!uti.getIsDhcpRequired()) { |
| 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | // if it's an ADD skip if flows are there, |
| 1020 | // if it's a DELETE skip if flows are not there |
| 1021 | boolean hasFlows = hasDhcpFlows(port, uti); |
| 1022 | if (action == FlowOperation.ADD && hasFlows || |
| 1023 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1024 | log.debug("Not dealing with DHCP {} on {} as DHCP flow status is {}", action, |
| 1025 | uti.getServiceName(), hasFlows); |
| 1026 | return; |
| 1027 | } |
| 1028 | |
| 1029 | log.info("{} DHCP flows for subscriber on {} and service {}", |
| 1030 | flowOpToString(action), portWithName(port), uti.getServiceName()); |
| 1031 | |
| 1032 | // if we reached here a meter already exists |
| 1033 | MeterId meterId = oltMeterService |
| 1034 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 1035 | MeterId oltMeterId = oltMeterService |
| 1036 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 1037 | |
| 1038 | if (enableDhcpV4) { |
| 1039 | processDhcpFilteringObjectives(deviceId, port, action, FlowDirection.UPSTREAM, 68, 67, |
| 1040 | EthType.EtherType.IPV4.ethType(), IPv4.PROTOCOL_UDP, meterId, oltMeterId, |
| 1041 | uti); |
| 1042 | } |
| 1043 | if (enableDhcpV6) { |
| 1044 | log.error("DHCP V6 not supported for subscribers"); |
| 1045 | } |
| 1046 | }); |
| 1047 | } |
| 1048 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1049 | protected void handleSubscriberPppoeFlows(DeviceId deviceId, Port port, |
| 1050 | FlowOperation action, |
| 1051 | SubscriberAndDeviceInformation si) { |
| 1052 | si.uniTagList().forEach(uti -> { |
| 1053 | |
| 1054 | if (!uti.getIsPppoeRequired()) { |
| 1055 | return; |
| 1056 | } |
| 1057 | |
| 1058 | // if it's an ADD skip if flows are there, |
| 1059 | // if it's a DELETE skip if flows are not there |
| 1060 | boolean hasFlows = hasPppoeFlows(port, uti); |
| 1061 | if (action == FlowOperation.ADD && hasFlows || |
| 1062 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1063 | log.debug("Not dealing with PPPoE {} on {} as PPPoE flow status is {}", action, |
| 1064 | uti.getServiceName(), hasFlows); |
| 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | log.info("{} PPPoE flows for subscriber on {} and service {}", |
| 1069 | flowOpToString(action), portWithName(port), uti.getServiceName()); |
| 1070 | |
| 1071 | // if we reached here a meter already exists |
| 1072 | MeterId meterId = oltMeterService |
| 1073 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 1074 | MeterId oltMeterId = oltMeterService |
| 1075 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 1076 | |
| 1077 | if (enablePppoe) { |
| 1078 | processPPPoEDFilteringObjectives(deviceId, port, action, FlowDirection.UPSTREAM, meterId, oltMeterId, |
| 1079 | uti.getTechnologyProfileId(), uti.getPonCTag(), uti.getUniTagMatch(), |
| 1080 | (byte) uti.getUsPonCTagPriority()); |
| 1081 | } |
| 1082 | }); |
| 1083 | } |
| 1084 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1085 | // FIXME return boolean, if this fails we need to retry |
| 1086 | protected void handleSubscriberDataFlows(Device device, Port port, |
| 1087 | FlowOperation action, |
| 1088 | SubscriberAndDeviceInformation si, String multicastServiceName) { |
| 1089 | |
| 1090 | Optional<Port> nniPort = oltDeviceService.getNniPort(device); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 1091 | if (nniPort == null || nniPort.isEmpty()) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1092 | log.error("Cannot configure DP flows as upstream port is not configured for subscriber {} on {}", |
| 1093 | si.id(), portWithName(port)); |
| 1094 | return; |
| 1095 | } |
| 1096 | si.uniTagList().forEach(uti -> { |
| 1097 | |
| 1098 | boolean hasFlows = hasSubscriberFlows(port, uti); |
| 1099 | if (action == FlowOperation.ADD && hasFlows || |
| 1100 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1101 | log.debug("Not dealing with DP flows {} on {} as subscriber flow status is {}", action, |
| 1102 | uti.getServiceName(), hasFlows); |
| 1103 | return; |
| 1104 | } |
| 1105 | |
| 1106 | if (multicastServiceName.equals(uti.getServiceName())) { |
| 1107 | log.debug("This is the multicast service ({}) for subscriber {} on {}, " + |
| 1108 | "dataplane flows are not needed", |
| 1109 | uti.getServiceName(), si.id(), portWithName(port)); |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | log.info("{} Data plane flows for subscriber {} on {} and service {}", |
| 1114 | flowOpToString(action), si.id(), portWithName(port), uti.getServiceName()); |
Matteo Scandolo | 80f5e97 | 2021-12-02 14:59:15 -0800 | [diff] [blame] | 1115 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
| 1116 | OltFlowsStatus status = action.equals(FlowOperation.ADD) ? |
| 1117 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1118 | updateConnectPointStatus(sk, null, status, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1119 | |
| 1120 | // upstream flows |
| 1121 | MeterId usMeterId = oltMeterService |
| 1122 | .getMeterIdForBandwidthProfile(device.id(), uti.getUpstreamBandwidthProfile()); |
| 1123 | MeterId oltUsMeterId = oltMeterService |
| 1124 | .getMeterIdForBandwidthProfile(device.id(), uti.getUpstreamOltBandwidthProfile()); |
| 1125 | processUpstreamDataFilteringObjects(device.id(), port, nniPort.get(), action, usMeterId, |
| 1126 | oltUsMeterId, uti); |
| 1127 | |
| 1128 | // downstream flows |
| 1129 | MeterId dsMeterId = oltMeterService |
| 1130 | .getMeterIdForBandwidthProfile(device.id(), uti.getDownstreamBandwidthProfile()); |
| 1131 | MeterId oltDsMeterId = oltMeterService |
| 1132 | .getMeterIdForBandwidthProfile(device.id(), uti.getDownstreamOltBandwidthProfile()); |
| 1133 | processDownstreamDataFilteringObjects(device.id(), port, nniPort.get(), action, dsMeterId, |
| 1134 | oltDsMeterId, uti, getMacAddress(device.id(), port, uti)); |
| 1135 | }); |
| 1136 | } |
| 1137 | |
| 1138 | private void processDhcpFilteringObjectives(DeviceId deviceId, Port port, |
| 1139 | FlowOperation action, FlowDirection direction, |
| 1140 | int udpSrc, int udpDst, EthType ethType, byte protocol, |
| 1141 | MeterId meterId, MeterId oltMeterId, UniTagInformation uti) { |
| 1142 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
| 1143 | log.debug("{} DHCP filtering objectives on {}", flowOpToString(action), sk); |
| 1144 | |
| 1145 | |
| 1146 | OltFlowsStatus status = action.equals(FlowOperation.ADD) ? |
| 1147 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1148 | updateConnectPointStatus(sk, null, null, status, null); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1149 | |
| 1150 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 1151 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1152 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1153 | if (meterId != null) { |
| 1154 | treatmentBuilder.meter(meterId); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1157 | if (uti.getTechnologyProfileId() != NONE_TP_ID) { |
| 1158 | treatmentBuilder.writeMetadata( |
| 1159 | createTechProfValueForWriteMetadata(uti.getUniTagMatch(), |
| 1160 | uti.getTechnologyProfileId(), oltMeterId), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1161 | } |
| 1162 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1163 | FilteringObjective.Builder dhcpBuilder = (action == FlowOperation.ADD ? builder.permit() : builder.deny()) |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1164 | .withKey(Criteria.matchInPort(port.number())) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1165 | .addCondition(Criteria.matchEthType(ethType)) |
| 1166 | .addCondition(Criteria.matchIPProtocol(protocol)) |
| 1167 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 1168 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1169 | .fromApp(appId) |
| 1170 | .withPriority(MAX_PRIORITY); |
| 1171 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1172 | //VLAN changes and PCP matching need to happen only in the upstream directions |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1173 | if (direction == FlowDirection.UPSTREAM) { |
| 1174 | treatmentBuilder.setVlanId(uti.getPonCTag()); |
| 1175 | if (!VlanId.vlanId(VlanId.NO_VID).equals(uti.getUniTagMatch())) { |
| 1176 | dhcpBuilder.addCondition(Criteria.matchVlanId(uti.getUniTagMatch())); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1177 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1178 | if (uti.getUsPonCTagPriority() != -1) { |
| 1179 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1180 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1183 | dhcpBuilder.withMeta(treatmentBuilder |
| 1184 | .setOutput(PortNumber.CONTROLLER).build()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1185 | |
| 1186 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1187 | FilteringObjective dhcpUpstream = dhcpBuilder.add(new ObjectiveContext() { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1188 | @Override |
| 1189 | public void onSuccess(Objective objective) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1190 | log.info("{} DHCP {} filter for {}.", |
| 1191 | completeFlowOpToString(action), (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 1192 | portWithName(port)); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | @Override |
| 1196 | public void onError(Objective objective, ObjectiveError error) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1197 | log.error("DHCP {} filter for {} failed {} because {}", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1198 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 1199 | portWithName(port), |
| 1200 | action, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1201 | error); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1202 | updateConnectPointStatus(sk, null, null, OltFlowsStatus.ERROR, null); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1203 | } |
| 1204 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1205 | flowObjectiveService.filter(deviceId, dhcpUpstream); |
| 1206 | } |
| 1207 | |
| 1208 | private void processIgmpFilteringObjectives(DeviceId deviceId, Port port, |
| 1209 | FlowOperation action, FlowDirection direction, |
| 1210 | MeterId meterId, MeterId oltMeterId, int techProfileId, |
| 1211 | VlanId cTag, VlanId unitagMatch, int vlanPcp) { |
| 1212 | |
| 1213 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
| 1214 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1215 | if (direction == FlowDirection.UPSTREAM) { |
| 1216 | |
| 1217 | if (techProfileId != NONE_TP_ID) { |
| 1218 | treatmentBuilder.writeMetadata(createTechProfValueForWriteMetadata(null, |
| 1219 | techProfileId, oltMeterId), 0); |
| 1220 | } |
| 1221 | |
| 1222 | |
| 1223 | if (meterId != null) { |
| 1224 | treatmentBuilder.meter(meterId); |
| 1225 | } |
| 1226 | |
| 1227 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 1228 | filterBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 1229 | } |
| 1230 | |
| 1231 | if (!VlanId.vlanId(VlanId.NO_VID).equals(cTag)) { |
| 1232 | treatmentBuilder.setVlanId(cTag); |
| 1233 | } |
| 1234 | |
| 1235 | if (vlanPcp != -1) { |
| 1236 | treatmentBuilder.setVlanPcp((byte) vlanPcp); |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | filterBuilder = (action == FlowOperation.ADD) ? filterBuilder.permit() : filterBuilder.deny(); |
| 1241 | |
| 1242 | FilteringObjective igmp = filterBuilder |
| 1243 | .withKey(Criteria.matchInPort(port.number())) |
| 1244 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 1245 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 1246 | .withMeta(treatmentBuilder |
| 1247 | .setOutput(PortNumber.CONTROLLER).build()) |
| 1248 | .fromApp(appId) |
| 1249 | .withPriority(MAX_PRIORITY) |
| 1250 | .add(new ObjectiveContext() { |
| 1251 | @Override |
| 1252 | public void onSuccess(Objective objective) { |
| 1253 | log.info("Igmp filter for {} {}.", portWithName(port), action); |
| 1254 | } |
| 1255 | |
| 1256 | @Override |
| 1257 | public void onError(Objective objective, ObjectiveError error) { |
| 1258 | log.error("Igmp filter for {} failed {} because {}.", portWithName(port), action, |
| 1259 | error); |
| 1260 | } |
| 1261 | }); |
| 1262 | |
| 1263 | flowObjectiveService.filter(deviceId, igmp); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1264 | |
| 1265 | } |
| 1266 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1267 | private void processPPPoEDFilteringObjectives(DeviceId deviceId, Port port, |
| 1268 | FlowOperation action, FlowDirection direction, |
| 1269 | MeterId meterId, MeterId oltMeterId, int techProfileId, |
| 1270 | VlanId cTag, VlanId unitagMatch, Byte vlanPcp) { |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1271 | |
| 1272 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 1273 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1274 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1275 | if (meterId != null) { |
| 1276 | treatmentBuilder.meter(meterId); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | if (techProfileId != NONE_TP_ID) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1280 | treatmentBuilder.writeMetadata(createTechProfValueForWriteMetadata(cTag, techProfileId, oltMeterId), 0); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1281 | } |
| 1282 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1283 | DefaultFilteringObjective.Builder pppoedBuilder = ((action == FlowOperation.ADD) |
| 1284 | ? builder.permit() : builder.deny()) |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1285 | .withKey(Criteria.matchInPort(port.number())) |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1286 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 1287 | .fromApp(appId) |
| 1288 | .withPriority(10000); |
| 1289 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1290 | if (direction == FlowDirection.UPSTREAM) { |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1291 | treatmentBuilder.setVlanId(cTag); |
| 1292 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 1293 | pppoedBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 1294 | } |
| 1295 | if (vlanPcp != null) { |
| 1296 | treatmentBuilder.setVlanPcp(vlanPcp); |
| 1297 | } |
| 1298 | } |
| 1299 | pppoedBuilder = pppoedBuilder.withMeta(treatmentBuilder.setOutput(PortNumber.CONTROLLER).build()); |
| 1300 | |
| 1301 | FilteringObjective pppoed = pppoedBuilder |
| 1302 | .add(new ObjectiveContext() { |
| 1303 | @Override |
| 1304 | public void onSuccess(Objective objective) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1305 | log.info("PPPoED filter for {} {}.", portWithName(port), action); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | @Override |
| 1309 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1310 | log.info("PPPoED filter for {} failed {} because {}", portWithName(port), |
| 1311 | action, error); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1312 | } |
| 1313 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1314 | flowObjectiveService.filter(deviceId, pppoed); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1315 | } |
| 1316 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1317 | private void processUpstreamDataFilteringObjects(DeviceId deviceId, Port port, Port nniPort, |
| 1318 | FlowOperation action, |
| 1319 | MeterId upstreamMeterId, |
| 1320 | MeterId upstreamOltMeterId, |
| 1321 | UniTagInformation uti) { |
| 1322 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1323 | TrafficSelector selector = DefaultTrafficSelector.builder() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1324 | .matchInPort(port.number()) |
| 1325 | .matchVlanId(uti.getUniTagMatch()) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1326 | .build(); |
| 1327 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1328 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1329 | //if the subscriberVlan (cTag) is different than ANY it needs to set. |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1330 | if (uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1331 | treatmentBuilder.pushVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1332 | .setVlanId(uti.getPonCTag()); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1333 | } |
Maria Carmela Cascino | 067ee4d | 2021-11-02 13:14:43 +0100 | [diff] [blame] | 1334 | if (uti.getPonSTag().toShort() == VlanId.ANY_VALUE) { |
| 1335 | treatmentBuilder.popVlan(); |
| 1336 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1337 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1338 | if (uti.getUsPonCTagPriority() != -1) { |
| 1339 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Maria Carmela Cascino | 067ee4d | 2021-11-02 13:14:43 +0100 | [diff] [blame] | 1340 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | treatmentBuilder.pushVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1344 | .setVlanId(uti.getPonSTag()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1345 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1346 | if (uti.getUsPonSTagPriority() != -1) { |
| 1347 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonSTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1350 | treatmentBuilder.setOutput(nniPort.number()) |
| 1351 | .writeMetadata(createMetadata(uti.getPonCTag(), |
| 1352 | uti.getTechnologyProfileId(), nniPort.number()), 0L); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1353 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1354 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
| 1355 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1356 | if (upstreamMeterId != null) { |
| 1357 | treatmentBuilder.meter(upstreamMeterId); |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1358 | annotationBuilder.set(UPSTREAM_ONU, upstreamMeterId.toString()); |
| 1359 | } |
| 1360 | if (upstreamOltMeterId != null) { |
| 1361 | treatmentBuilder.meter(upstreamOltMeterId); |
| 1362 | annotationBuilder.set(UPSTREAM_OLT, upstreamOltMeterId.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1365 | DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selector, |
| 1366 | treatmentBuilder.build(), MIN_PRIORITY, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1367 | annotationBuilder.build()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1368 | |
| 1369 | ObjectiveContext context = new ObjectiveContext() { |
| 1370 | @Override |
| 1371 | public void onSuccess(Objective objective) { |
| 1372 | log.info("{} Upstream Data plane filter for {}.", |
| 1373 | completeFlowOpToString(action), sk); |
| 1374 | } |
| 1375 | |
| 1376 | @Override |
| 1377 | public void onError(Objective objective, ObjectiveError error) { |
| 1378 | log.error("Upstream Data plane filter for {} failed {} because {}.", |
| 1379 | sk, action, error); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1380 | updateConnectPointStatus(sk, null, OltFlowsStatus.ERROR, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1381 | } |
| 1382 | }; |
| 1383 | |
| 1384 | ForwardingObjective flow = null; |
| 1385 | if (action == FlowOperation.ADD) { |
| 1386 | flow = flowBuilder.add(context); |
| 1387 | } else if (action == FlowOperation.REMOVE) { |
| 1388 | flow = flowBuilder.remove(context); |
| 1389 | } else { |
| 1390 | log.error("Flow action not supported: {}", action); |
| 1391 | } |
| 1392 | |
| 1393 | if (flow != null) { |
| 1394 | flowObjectiveService.forward(deviceId, flow); |
| 1395 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1396 | } |
| 1397 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1398 | private void processDownstreamDataFilteringObjects(DeviceId deviceId, Port port, Port nniPort, |
| 1399 | FlowOperation action, |
| 1400 | MeterId downstreamMeterId, |
| 1401 | MeterId downstreamOltMeterId, |
| 1402 | UniTagInformation uti, |
| 1403 | MacAddress macAddress) { |
| 1404 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1405 | //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] | 1406 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1407 | .matchVlanId(uti.getPonSTag()) |
| 1408 | .matchInPort(nniPort.number()) |
| 1409 | .matchInnerVlanId(uti.getPonCTag()); |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 1410 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1411 | if (uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 1412 | selectorBuilder.matchMetadata(uti.getPonCTag().toShort()); |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 1413 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1414 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1415 | if (uti.getDsPonCTagPriority() != -1) { |
| 1416 | selectorBuilder.matchVlanPcp((byte) uti.getDsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1419 | if (macAddress != null) { |
| 1420 | selectorBuilder.matchEthDst(macAddress); |
| 1421 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1422 | |
| 1423 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder() |
| 1424 | .popVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1425 | .setOutput(port.number()); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1426 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1427 | treatmentBuilder.writeMetadata(createMetadata(uti.getPonCTag(), |
| 1428 | uti.getTechnologyProfileId(), |
| 1429 | port.number()), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1430 | |
Andrea Campanella | 981e86c | 2021-03-12 11:35:33 +0100 | [diff] [blame] | 1431 | // Upstream pbit is used to remark inner vlan pbit. |
| 1432 | // Upstream is used to avoid trusting the BNG to send the packet with correct pbit. |
| 1433 | // this is done because ds mode 0 is used because ds mode 3 or 6 that allow for |
| 1434 | // all pbit acceptance are not widely supported by vendors even though present in |
| 1435 | // the OMCI spec. |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1436 | if (uti.getUsPonCTagPriority() != -1) { |
| 1437 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1440 | if (!VlanId.NONE.equals(uti.getUniTagMatch()) && |
| 1441 | uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 1442 | treatmentBuilder.setVlanId(uti.getUniTagMatch()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1445 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
| 1446 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1447 | if (downstreamMeterId != null) { |
| 1448 | treatmentBuilder.meter(downstreamMeterId); |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1449 | annotationBuilder.set(DOWNSTREAM_ONU, downstreamMeterId.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1452 | if (downstreamOltMeterId != null) { |
| 1453 | treatmentBuilder.meter(downstreamOltMeterId); |
| 1454 | annotationBuilder.set(DOWNSTREAM_OLT, downstreamOltMeterId.toString()); |
| 1455 | } |
| 1456 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1457 | DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selectorBuilder.build(), |
| 1458 | treatmentBuilder.build(), MIN_PRIORITY, annotationBuilder.build()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1459 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1460 | ObjectiveContext context = new ObjectiveContext() { |
| 1461 | @Override |
| 1462 | public void onSuccess(Objective objective) { |
| 1463 | log.info("{} Downstream Data plane filter for {}.", |
| 1464 | completeFlowOpToString(action), sk); |
| 1465 | } |
| 1466 | |
| 1467 | @Override |
| 1468 | public void onError(Objective objective, ObjectiveError error) { |
| 1469 | log.info("Downstream Data plane filter for {} failed {} because {}.", |
| 1470 | sk, action, error); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1471 | updateConnectPointStatus(sk, null, OltFlowsStatus.ERROR, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1472 | } |
| 1473 | }; |
| 1474 | |
| 1475 | ForwardingObjective flow = null; |
| 1476 | if (action == FlowOperation.ADD) { |
| 1477 | flow = flowBuilder.add(context); |
| 1478 | } else if (action == FlowOperation.REMOVE) { |
| 1479 | flow = flowBuilder.remove(context); |
| 1480 | } else { |
| 1481 | log.error("Flow action not supported: {}", action); |
| 1482 | } |
| 1483 | |
| 1484 | if (flow != null) { |
| 1485 | if (log.isTraceEnabled()) { |
| 1486 | log.trace("Forwarding rule {}", flow); |
| 1487 | } |
| 1488 | flowObjectiveService.forward(deviceId, flow); |
| 1489 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1492 | private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector, |
| 1493 | TrafficTreatment treatment, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1494 | Integer priority, |
| 1495 | Annotations annotations) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1496 | return DefaultForwardingObjective.builder() |
| 1497 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 1498 | .withPriority(priority) |
| 1499 | .makePermanent() |
| 1500 | .withSelector(selector) |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1501 | .withAnnotations(annotations) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1502 | .fromApp(appId) |
| 1503 | .withTreatment(treatment); |
| 1504 | } |
| 1505 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1506 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 1507 | if (techProfileId == NONE_TP_ID) { |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 1508 | techProfileId = DEFAULT_TP_ID_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 1512 | } |
| 1513 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1514 | private boolean isMacLearningEnabled(SubscriberAndDeviceInformation si) { |
| 1515 | AtomicBoolean requiresMacLearning = new AtomicBoolean(); |
| 1516 | requiresMacLearning.set(false); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1517 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1518 | si.uniTagList().forEach(uniTagInfo -> { |
| 1519 | if (uniTagInfo.getEnableMacLearning()) { |
| 1520 | requiresMacLearning.set(true); |
| 1521 | } |
| 1522 | }); |
| 1523 | |
| 1524 | return requiresMacLearning.get(); |
| 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * Checks whether the subscriber has the MacAddress configured or discovered. |
| 1529 | * |
| 1530 | * @param deviceId DeviceId for this subscriber |
| 1531 | * @param port Port for this subscriber |
| 1532 | * @param si SubscriberAndDeviceInformation |
| 1533 | * @return boolean |
| 1534 | */ |
| 1535 | protected boolean isMacAddressAvailable(DeviceId deviceId, Port port, SubscriberAndDeviceInformation si) { |
| 1536 | AtomicBoolean isConfigured = new AtomicBoolean(); |
| 1537 | isConfigured.set(true); |
| 1538 | |
| 1539 | si.uniTagList().forEach(uniTagInfo -> { |
| 1540 | boolean isMacLearningEnabled = uniTagInfo.getEnableMacLearning(); |
| 1541 | boolean configureMac = isMacAddressValid(uniTagInfo); |
| 1542 | boolean discoveredMac = false; |
| 1543 | Optional<Host> optHost = hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())) |
| 1544 | .stream().filter(host -> host.vlan().equals(uniTagInfo.getPonCTag())).findFirst(); |
| 1545 | if (optHost.isPresent() && optHost.get().mac() != null) { |
| 1546 | discoveredMac = true; |
| 1547 | } |
| 1548 | if (isMacLearningEnabled && !configureMac && !discoveredMac) { |
| 1549 | log.debug("Awaiting for macAddress on {} for service {}", |
| 1550 | portWithName(port), uniTagInfo.getServiceName()); |
| 1551 | isConfigured.set(false); |
| 1552 | } |
| 1553 | }); |
| 1554 | |
| 1555 | return isConfigured.get(); |
| 1556 | } |
| 1557 | |
| 1558 | protected MacAddress getMacAddress(DeviceId deviceId, Port port, UniTagInformation uniTagInfo) { |
| 1559 | boolean configuredMac = isMacAddressValid(uniTagInfo); |
| 1560 | if (configuredMac) { |
| 1561 | return MacAddress.valueOf(uniTagInfo.getConfiguredMacAddress()); |
| 1562 | } else if (uniTagInfo.getEnableMacLearning()) { |
| 1563 | Optional<Host> optHost = hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())) |
| 1564 | .stream().filter(host -> host.vlan().equals(uniTagInfo.getPonCTag())).findFirst(); |
| 1565 | if (optHost.isPresent() && optHost.get().mac() != null) { |
| 1566 | return optHost.get().mac(); |
| 1567 | } |
| 1568 | } |
| 1569 | return null; |
| 1570 | } |
| 1571 | |
| 1572 | private boolean isMacAddressValid(UniTagInformation tagInformation) { |
| 1573 | return tagInformation.getConfiguredMacAddress() != null && |
| 1574 | !tagInformation.getConfiguredMacAddress().trim().equals("") && |
| 1575 | !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 1576 | } |
| 1577 | |
| 1578 | protected void updateConnectPointStatus(ServiceKey key, OltFlowsStatus eapolStatus, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1579 | OltFlowsStatus subscriberFlowsStatus, OltFlowsStatus dhcpStatus, |
| 1580 | OltFlowsStatus pppoeStatus) { |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1581 | if (log.isTraceEnabled()) { |
| 1582 | log.trace("Updating cpStatus {} with values: eapolFlow={}, subscriberFlows={}, dhcpFlow={}", |
| 1583 | key, eapolStatus, subscriberFlowsStatus, dhcpStatus); |
| 1584 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1585 | try { |
| 1586 | cpStatusWriteLock.lock(); |
| 1587 | OltPortStatus status = cpStatus.get(key); |
| 1588 | |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1589 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1590 | if (status == null) { |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1591 | // if we don't have status for the connectPoint |
| 1592 | // and we're only updating status to PENDING_REMOVE or ERROR |
| 1593 | // do not create it. This is because this case will only happen when a device is removed |
| 1594 | // and it's status cleaned |
| 1595 | List<OltFlowsStatus> statusesToIgnore = new ArrayList<>(); |
| 1596 | statusesToIgnore.add(OltFlowsStatus.PENDING_REMOVE); |
| 1597 | statusesToIgnore.add(OltFlowsStatus.ERROR); |
| 1598 | |
| 1599 | if ( |
| 1600 | (statusesToIgnore.contains(subscriberFlowsStatus) && dhcpStatus == null) || |
| 1601 | (subscriberFlowsStatus == null && statusesToIgnore.contains(dhcpStatus)) |
| 1602 | ) { |
| 1603 | if (log.isTraceEnabled()) { |
| 1604 | log.trace("Ignoring cpStatus update as status is meaningless"); |
| 1605 | } |
| 1606 | return; |
| 1607 | } |
| 1608 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1609 | status = new OltPortStatus( |
| 1610 | eapolStatus != null ? eapolStatus : OltFlowsStatus.NONE, |
| 1611 | subscriberFlowsStatus != null ? subscriberFlowsStatus : OltFlowsStatus.NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1612 | dhcpStatus != null ? dhcpStatus : OltFlowsStatus.NONE, |
| 1613 | pppoeStatus != null ? pppoeStatus : OltFlowsStatus.NONE |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1614 | ); |
| 1615 | } else { |
| 1616 | if (eapolStatus != null) { |
| 1617 | status.defaultEapolStatus = eapolStatus; |
| 1618 | } |
| 1619 | if (subscriberFlowsStatus != null) { |
| 1620 | status.subscriberFlowsStatus = subscriberFlowsStatus; |
| 1621 | } |
| 1622 | if (dhcpStatus != null) { |
| 1623 | status.dhcpStatus = dhcpStatus; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | cpStatus.put(key, status); |
| 1628 | } finally { |
| 1629 | cpStatusWriteLock.unlock(); |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | protected class InternalFlowListener implements FlowRuleListener { |
| 1634 | @Override |
| 1635 | public void event(FlowRuleEvent event) { |
| 1636 | if (appId.id() != (event.subject().appId())) { |
| 1637 | return; |
| 1638 | } |
| 1639 | |
| 1640 | if (!oltDeviceService.isLocalLeader(event.subject().deviceId())) { |
| 1641 | if (log.isTraceEnabled()) { |
| 1642 | log.trace("ignoring flow event {} " + |
| 1643 | "as not leader for {}", event, event.subject().deviceId()); |
| 1644 | } |
| 1645 | return; |
| 1646 | } |
| 1647 | |
| 1648 | switch (event.type()) { |
| 1649 | case RULE_ADDED: |
| 1650 | case RULE_REMOVED: |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1651 | DeviceId deviceId = event.subject().deviceId(); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1652 | Port port = getCpFromFlowRule(event.subject()); |
| 1653 | if (port == null) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1654 | log.warn("Port is gone in ONOS, " + |
| 1655 | "manually creating it {}", event.subject()); |
| 1656 | PortNumber inPort = getPortNumberFromFlowRule(event.subject()); |
| 1657 | cpStatusReadLock.lock(); |
| 1658 | Optional<ServiceKey> keyWithPort = cpStatus.keySet() |
| 1659 | .stream().filter(key -> key.getPort().connectPoint() |
| 1660 | .deviceId().equals(deviceId) |
| 1661 | && key.getPort().connectPoint().port() |
| 1662 | .equals(inPort)).findFirst(); |
| 1663 | cpStatusReadLock.unlock(); |
| 1664 | if (keyWithPort.isPresent()) { |
| 1665 | port = new DefaultPort(deviceService.getDevice(deviceId), |
| 1666 | inPort, false, |
| 1667 | DefaultAnnotations.builder() |
| 1668 | .set(AnnotationKeys.PORT_NAME, |
| 1669 | keyWithPort.get().getPort().name()) |
| 1670 | .build()); |
| 1671 | } else { |
| 1672 | log.warn("Can't find corresponding status for {}/{}", deviceId, inPort); |
| 1673 | return; |
| 1674 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1675 | } |
| 1676 | if (log.isTraceEnabled()) { |
| 1677 | log.trace("flow event {} on cp {}: {}", event.type(), |
| 1678 | portWithName(port), event.subject()); |
| 1679 | } |
| 1680 | updateCpStatus(event.type(), port, event.subject()); |
| 1681 | return; |
| 1682 | case RULE_ADD_REQUESTED: |
| 1683 | case RULE_REMOVE_REQUESTED: |
| 1684 | // NOTE that PENDING_ADD/REMOVE is set when we create the flowObjective |
| 1685 | return; |
| 1686 | default: |
| 1687 | return; |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | protected void updateCpStatus(FlowRuleEvent.Type type, Port port, FlowRule flowRule) { |
| 1692 | OltFlowsStatus status = flowRuleStatusToOltFlowStatus(type); |
| 1693 | if (isDefaultEapolFlow(flowRule)) { |
| 1694 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), |
| 1695 | defaultEapolUniTag); |
| 1696 | if (log.isTraceEnabled()) { |
| 1697 | log.trace("update defaultEapolStatus {} on {}", status, sk); |
| 1698 | } |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1699 | updateConnectPointStatus(sk, status, null, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1700 | } else if (isDhcpFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1701 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1702 | if (sk == null) { |
| 1703 | return; |
| 1704 | } |
| 1705 | if (log.isTraceEnabled()) { |
| 1706 | log.trace("update dhcpStatus {} on {}", status, sk); |
| 1707 | } |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1708 | updateConnectPointStatus(sk, null, null, status, null); |
| 1709 | } else if (isPppoeFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1710 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1711 | if (sk == null) { |
| 1712 | return; |
| 1713 | } |
| 1714 | if (log.isTraceEnabled()) { |
| 1715 | log.trace("update pppoeStatus {} on {}", status, sk); |
| 1716 | } |
| 1717 | updateConnectPointStatus(sk, null, null, null, status); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1718 | } else if (isDataFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1719 | PortNumber number = getPortNumberFromFlowRule(flowRule); |
| 1720 | if (number == null) { |
| 1721 | log.error("Can't capture the port number from flow {}", flowRule); |
| 1722 | return; |
| 1723 | } |
| 1724 | if (oltDeviceService.isNniPort(deviceService.getDevice(flowRule.deviceId()), number)) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1725 | // the NNI has data-plane for every subscriber, doesn't make sense to track them |
| 1726 | return; |
| 1727 | } |
| 1728 | |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1729 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1730 | if (sk == null) { |
| 1731 | return; |
| 1732 | } |
| 1733 | if (log.isTraceEnabled()) { |
| 1734 | log.trace("update dataplaneStatus {} on {}", status, sk); |
| 1735 | } |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1736 | updateConnectPointStatus(sk, null, status, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | private boolean isDefaultEapolFlow(FlowRule flowRule) { |
| 1741 | EthTypeCriterion c = (EthTypeCriterion) flowRule.selector().getCriterion(Criterion.Type.ETH_TYPE); |
| 1742 | if (c == null) { |
| 1743 | return false; |
| 1744 | } |
| 1745 | if (c.ethType().equals(EthType.EtherType.EAPOL.ethType())) { |
| 1746 | AtomicBoolean isDefault = new AtomicBoolean(false); |
| 1747 | flowRule.treatment().allInstructions().forEach(instruction -> { |
| 1748 | if (instruction.type() == L2MODIFICATION) { |
| 1749 | L2ModificationInstruction modificationInstruction = (L2ModificationInstruction) instruction; |
| 1750 | if (modificationInstruction.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { |
| 1751 | L2ModificationInstruction.ModVlanIdInstruction vlanInstruction = |
| 1752 | (L2ModificationInstruction.ModVlanIdInstruction) modificationInstruction; |
| 1753 | if (vlanInstruction.vlanId().id().equals(EAPOL_DEFAULT_VLAN)) { |
| 1754 | isDefault.set(true); |
| 1755 | return; |
| 1756 | } |
| 1757 | } |
| 1758 | } |
| 1759 | }); |
| 1760 | return isDefault.get(); |
| 1761 | } |
| 1762 | return false; |
| 1763 | } |
| 1764 | |
| 1765 | /** |
| 1766 | * Returns true if the flow is a DHCP flow. |
| 1767 | * Matches both upstream and downstream flows. |
| 1768 | * |
| 1769 | * @param flowRule The FlowRule to evaluate |
| 1770 | * @return boolean |
| 1771 | */ |
| 1772 | private boolean isDhcpFlow(FlowRule flowRule) { |
| 1773 | IPProtocolCriterion ipCriterion = (IPProtocolCriterion) flowRule.selector() |
| 1774 | .getCriterion(Criterion.Type.IP_PROTO); |
| 1775 | if (ipCriterion == null) { |
| 1776 | return false; |
| 1777 | } |
| 1778 | |
| 1779 | UdpPortCriterion src = (UdpPortCriterion) flowRule.selector().getCriterion(Criterion.Type.UDP_SRC); |
| 1780 | |
| 1781 | if (src == null) { |
| 1782 | return false; |
| 1783 | } |
| 1784 | return ipCriterion.protocol() == IPv4.PROTOCOL_UDP && |
| 1785 | (src.udpPort().toInt() == 68 || src.udpPort().toInt() == 67); |
| 1786 | } |
| 1787 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1788 | private boolean isPppoeFlow(FlowRule flowRule) { |
| 1789 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) flowRule.selector() |
| 1790 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 1791 | |
| 1792 | if (ethTypeCriterion == null) { |
| 1793 | return false; |
| 1794 | } |
| 1795 | return EthType.EtherType.PPPoED.ethType().equals(ethTypeCriterion.ethType()); |
| 1796 | } |
| 1797 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1798 | private boolean isDataFlow(FlowRule flowRule) { |
| 1799 | // we consider subscriber flows the one that matches on VLAN_VID |
| 1800 | // method is valid only because it's the last check after EAPOL and DHCP. |
| 1801 | // this matches mcast flows as well, if we want to avoid that we can |
| 1802 | // filter out the elements that have groups in the treatment or |
| 1803 | // mcastIp in the selector |
| 1804 | // IPV4_DST:224.0.0.22/32 |
| 1805 | // treatment=[immediate=[GROUP:0x1]] |
| 1806 | |
| 1807 | return flowRule.selector().getCriterion(Criterion.Type.VLAN_VID) != null; |
| 1808 | } |
| 1809 | |
| 1810 | private Port getCpFromFlowRule(FlowRule flowRule) { |
| 1811 | DeviceId deviceId = flowRule.deviceId(); |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1812 | PortNumber inPort = getPortNumberFromFlowRule(flowRule); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1813 | if (inPort != null) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1814 | return deviceService.getPort(deviceId, inPort); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1815 | } |
| 1816 | return null; |
| 1817 | } |
| 1818 | |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame^] | 1819 | private PortNumber getPortNumberFromFlowRule(FlowRule flowRule) { |
| 1820 | PortCriterion inPort = (PortCriterion) flowRule.selector().getCriterion(Criterion.Type.IN_PORT); |
| 1821 | if (inPort != null) { |
| 1822 | return inPort.port(); |
| 1823 | } |
| 1824 | return null; |
| 1825 | } |
| 1826 | |
| 1827 | private ServiceKey getSubscriberKeyFromFlowRule(FlowRule flowRule, Port flowPort) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1828 | SubscriberAndDeviceInformation si = subsService.get(getPortName(flowPort)); |
| 1829 | |
| 1830 | Boolean isNni = oltDeviceService.isNniPort(deviceService.getDevice(flowRule.deviceId()), flowPort.number()); |
| 1831 | if (si == null && !isNni) { |
| 1832 | log.error("Subscriber information not found in sadis for port {}", portWithName(flowPort)); |
| 1833 | return null; |
| 1834 | } |
| 1835 | |
| 1836 | if (isNni) { |
| 1837 | return new ServiceKey(new AccessDevicePort(flowPort), nniUniTag); |
| 1838 | } |
| 1839 | |
| 1840 | Optional<UniTagInformation> found = Optional.empty(); |
| 1841 | VlanId flowVlan = null; |
| 1842 | if (isDhcpFlow(flowRule)) { |
| 1843 | // we need to make a special case for DHCP as in the ATT workflow DHCP flows don't match on tags |
| 1844 | L2ModificationInstruction.ModVlanIdInstruction instruction = |
| 1845 | (L2ModificationInstruction.ModVlanIdInstruction) flowRule.treatment().immediate().get(1); |
| 1846 | flowVlan = instruction.vlanId(); |
| 1847 | } else { |
| 1848 | // for now we assume that if it's not DHCP it's dataplane (or at least tagged) |
| 1849 | VlanIdCriterion vlanIdCriterion = |
| 1850 | (VlanIdCriterion) flowRule.selector().getCriterion(Criterion.Type.VLAN_VID); |
| 1851 | if (vlanIdCriterion == null) { |
| 1852 | log.warn("cannot match the flow to a subscriber service as it does not carry vlans"); |
| 1853 | return null; |
| 1854 | } |
| 1855 | flowVlan = vlanIdCriterion.vlanId(); |
| 1856 | } |
| 1857 | |
| 1858 | VlanId finalFlowVlan = flowVlan; |
| 1859 | found = si.uniTagList().stream().filter(uti -> |
| 1860 | uti.getPonCTag().equals(finalFlowVlan) || |
| 1861 | uti.getPonSTag().equals(finalFlowVlan) || |
| 1862 | uti.getUniTagMatch().equals(finalFlowVlan) |
| 1863 | ).findFirst(); |
| 1864 | |
| 1865 | |
| 1866 | if (found.isEmpty()) { |
| 1867 | log.warn("Cannot map flow rule {} to Service in {}", flowRule, si); |
| 1868 | } |
| 1869 | |
| 1870 | return found.isPresent() ? new ServiceKey(new AccessDevicePort(flowPort), found.get()) : null; |
| 1871 | |
| 1872 | } |
| 1873 | |
| 1874 | private OltFlowsStatus flowRuleStatusToOltFlowStatus(FlowRuleEvent.Type type) { |
| 1875 | switch (type) { |
| 1876 | case RULE_ADD_REQUESTED: |
| 1877 | return OltFlowsStatus.PENDING_ADD; |
| 1878 | case RULE_ADDED: |
| 1879 | return OltFlowsStatus.ADDED; |
| 1880 | case RULE_REMOVE_REQUESTED: |
| 1881 | return OltFlowsStatus.PENDING_REMOVE; |
| 1882 | case RULE_REMOVED: |
| 1883 | return OltFlowsStatus.REMOVED; |
| 1884 | default: |
| 1885 | return OltFlowsStatus.NONE; |
| 1886 | } |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | protected void bindSadisService(SadisService service) { |
| 1891 | this.subsService = service.getSubscriberInfoService(); |
| 1892 | this.bpService = service.getBandwidthProfileService(); |
| 1893 | log.info("Sadis service is loaded"); |
| 1894 | } |
| 1895 | |
| 1896 | protected void unbindSadisService(SadisService service) { |
| 1897 | this.subsService = null; |
| 1898 | this.bpService = null; |
| 1899 | log.info("Sadis service is unloaded"); |
| 1900 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1901 | } |