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) { |
Andrea Campanella | ccb3286 | 2022-02-17 16:29:10 +0100 | [diff] [blame] | 483 | log.debug("Eapol is disabled for {}", portWithName(sub.port)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 484 | return true; |
| 485 | } |
| 486 | |
| 487 | if (sub.status == DiscoveredSubscriber.Status.ADDED) { |
| 488 | return addDefaultFlows(sub, bandwidthProfileId, oltBandwidthProfileId); |
| 489 | } else if (sub.status == DiscoveredSubscriber.Status.REMOVED) { |
| 490 | return removeDefaultFlows(sub, bandwidthProfileId, oltBandwidthProfileId); |
| 491 | } else { |
| 492 | log.error("Unknown Status {} on DiscoveredSubscriber {}", sub.status, sub); |
| 493 | return false; |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |
| 498 | private boolean addDefaultFlows(DiscoveredSubscriber sub, String bandwidthProfileId, String oltBandwidthProfileId) { |
Andrea Campanella | ccb3286 | 2022-02-17 16:29:10 +0100 | [diff] [blame] | 499 | log.debug("Adding default flows for {}, status {}", portWithName(sub.port), sub.status); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 500 | if (!oltMeterService.createMeter(sub.device.id(), bandwidthProfileId)) { |
| 501 | if (log.isTraceEnabled()) { |
| 502 | log.trace("waiting on meter for bp {} and sub {}", bandwidthProfileId, sub); |
| 503 | } |
| 504 | return false; |
| 505 | } |
| 506 | if (hasDefaultEapol(sub.port)) { |
Andrea Campanella | ccb3286 | 2022-02-17 16:29:10 +0100 | [diff] [blame] | 507 | OltPortStatus status = getOltPortStatus(sub.port, defaultEapolUniTag); |
| 508 | log.debug("Eapol is already present for {} with status {}", portWithName(sub.port), status); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 509 | return true; |
| 510 | } |
| 511 | return handleEapolFlow(sub, bandwidthProfileId, |
| 512 | oltBandwidthProfileId, FlowOperation.ADD, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 513 | |
| 514 | } |
| 515 | |
| 516 | private boolean removeDefaultFlows(DiscoveredSubscriber sub, String bandwidthProfile, String oltBandwidthProfile) { |
| 517 | // NOTE that we are not checking for meters as they must have been created to install the flow in first place |
| 518 | return handleEapolFlow(sub, bandwidthProfile, oltBandwidthProfile, |
| 519 | FlowOperation.REMOVE, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 520 | } |
| 521 | |
| 522 | @Override |
| 523 | public boolean handleSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwidthProfile, |
| 524 | String multicastServiceName) { |
| 525 | // NOTE that we are taking defaultBandwithProfile as a parameter as that can be configured in the Olt component |
| 526 | if (sub.status == DiscoveredSubscriber.Status.ADDED) { |
| 527 | return addSubscriberFlows(sub, defaultBandwidthProfile, multicastServiceName); |
| 528 | } else if (sub.status == DiscoveredSubscriber.Status.REMOVED) { |
| 529 | return removeSubscriberFlows(sub, defaultBandwidthProfile, multicastServiceName); |
| 530 | } else { |
| 531 | log.error("don't know how to handle {}", sub); |
| 532 | return false; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | private boolean addSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwithProfile, |
| 537 | String multicastServiceName) { |
| 538 | if (log.isTraceEnabled()) { |
| 539 | log.trace("Provisioning of subscriber on {} started", portWithName(sub.port)); |
| 540 | } |
| 541 | if (enableEapol) { |
| 542 | if (hasDefaultEapol(sub.port)) { |
| 543 | // remove EAPOL flow and throw exception so that we'll retry later |
| 544 | if (!isDefaultEapolPendingRemoval(sub.port)) { |
| 545 | removeDefaultFlows(sub, defaultBandwithProfile, defaultBandwithProfile); |
| 546 | } |
| 547 | |
| 548 | if (waitForRemoval) { |
| 549 | // NOTE wait for removal is a flag only needed to make sure VOLTHA |
| 550 | // does not explode with the flows remove/add in the same batch |
| 551 | log.debug("Awaiting for default flows removal for {}", portWithName(sub.port)); |
| 552 | return false; |
| 553 | } else { |
| 554 | log.warn("continuing provisioning on {}", portWithName(sub.port)); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | } |
| 559 | |
| 560 | // NOTE createMeters will return if the meters are not installed |
| 561 | if (!oltMeterService.createMeters(sub.device.id(), |
Matteo Scandolo | 88df8ae | 2021-11-23 13:12:29 -0800 | [diff] [blame] | 562 | sub.subscriberAndDeviceInformation, multicastServiceName)) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 563 | return false; |
| 564 | } |
| 565 | |
| 566 | // NOTE we need to add the DHCP flow regardless so that the host can be discovered and the MacAddress added |
| 567 | handleSubscriberDhcpFlows(sub.device.id(), sub.port, FlowOperation.ADD, |
| 568 | sub.subscriberAndDeviceInformation); |
| 569 | |
| 570 | if (isMacLearningEnabled(sub.subscriberAndDeviceInformation) |
| 571 | && !isMacAddressAvailable(sub.device.id(), sub.port, |
| 572 | sub.subscriberAndDeviceInformation)) { |
| 573 | log.debug("Awaiting for macAddress on {}", portWithName(sub.port)); |
| 574 | return false; |
| 575 | } |
| 576 | |
Matteo Scandolo | 8a91c0f | 2021-12-03 10:58:14 -0800 | [diff] [blame] | 577 | // NOTE that the EAPOL flows handling is based on the data-plane flows status |
| 578 | // always process them before |
| 579 | handleSubscriberEapolFlows(sub, FlowOperation.ADD, sub.subscriberAndDeviceInformation); |
| 580 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 581 | handleSubscriberPppoeFlows(sub.device.id(), sub.port, FlowOperation.ADD, sub.subscriberAndDeviceInformation); |
| 582 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 583 | handleSubscriberDataFlows(sub.device, sub.port, FlowOperation.ADD, |
| 584 | sub.subscriberAndDeviceInformation, multicastServiceName); |
| 585 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 586 | handleSubscriberIgmpFlows(sub, FlowOperation.ADD); |
| 587 | |
| 588 | log.info("Provisioning of subscriber on {} completed", portWithName(sub.port)); |
| 589 | return true; |
| 590 | } |
| 591 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 592 | protected boolean removeSubscriberFlows(DiscoveredSubscriber sub, String defaultBandwithProfile, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 593 | String multicastServiceName) { |
| 594 | |
| 595 | if (log.isTraceEnabled()) { |
| 596 | log.trace("Removal of subscriber on {} started", |
| 597 | portWithName(sub.port)); |
| 598 | } |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 599 | SubscriberAndDeviceInformation si = sub.subscriberAndDeviceInformation; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 600 | |
| 601 | handleSubscriberDhcpFlows(sub.device.id(), sub.port, FlowOperation.REMOVE, si); |
| 602 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 603 | handleSubscriberPppoeFlows(sub.device.id(), sub.port, FlowOperation.REMOVE, sub.subscriberAndDeviceInformation); |
| 604 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 605 | if (enableEapol) { |
| 606 | // remove the tagged eapol |
| 607 | handleSubscriberEapolFlows(sub, FlowOperation.REMOVE, si); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 608 | } |
| 609 | handleSubscriberDataFlows(sub.device, sub.port, FlowOperation.REMOVE, si, multicastServiceName); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 610 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 611 | handleSubscriberIgmpFlows(sub, FlowOperation.REMOVE); |
| 612 | |
| 613 | if (enableEapol) { |
| 614 | |
| 615 | // if any of the services still has flows, return false |
| 616 | Iterator<UniTagInformation> iter = sub.subscriberAndDeviceInformation.uniTagList().iterator(); |
| 617 | while (iter.hasNext()) { |
| 618 | UniTagInformation entry = iter.next(); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 619 | if (areSubscriberFlowsPendingRemoval(sub.port, entry, enableEapol)) { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 620 | log.info("Subscriber {} still have flows on service {}, postpone default EAPOL installation.", |
| 621 | portWithName(sub.port), entry.getServiceName()); |
| 622 | return false; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | // once the flows are removed add the default one back |
| 627 | // (only if the port is ENABLED and still present on the device) |
Matteo Scandolo | 49c4205 | 2021-11-23 13:12:29 -0800 | [diff] [blame] | 628 | if (sub.port.isEnabled() && deviceService.getPort(sub.device.id(), sub.port.number()) != null) { |
| 629 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 630 | // NOTE we remove the subscriber when the port goes down |
| 631 | // but in that case we don't need to add default eapol |
| 632 | handleEapolFlow(sub, defaultBandwithProfile, defaultBandwithProfile, |
| 633 | FlowOperation.ADD, VlanId.vlanId(EAPOL_DEFAULT_VLAN)); |
| 634 | } |
| 635 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 636 | // FIXME check the return status of the flow and return accordingly |
| 637 | log.info("Removal of subscriber on {} completed", portWithName(sub.port)); |
| 638 | return true; |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public boolean hasDefaultEapol(Port port) { |
| 643 | OltPortStatus status = getOltPortStatus(port, defaultEapolUniTag); |
| 644 | // NOTE we consider ERROR as a present EAPOL flow as ONOS |
| 645 | // will keep trying to add it |
| 646 | return status != null && (status.defaultEapolStatus == OltFlowsStatus.ADDED || |
| 647 | status.defaultEapolStatus == OltFlowsStatus.PENDING_ADD || |
| 648 | status.defaultEapolStatus == OltFlowsStatus.ERROR); |
| 649 | } |
| 650 | |
| 651 | private OltPortStatus getOltPortStatus(Port port, UniTagInformation uniTagInformation) { |
| 652 | try { |
| 653 | cpStatusReadLock.lock(); |
| 654 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uniTagInformation); |
| 655 | OltPortStatus status = cpStatus.get(sk); |
| 656 | return status; |
| 657 | } finally { |
| 658 | cpStatusReadLock.unlock(); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | public boolean isDefaultEapolPendingRemoval(Port port) { |
| 663 | OltPortStatus status = getOltPortStatus(port, defaultEapolUniTag); |
| 664 | if (log.isTraceEnabled()) { |
| 665 | log.trace("Status during EAPOL flow check {} for port {} and UniTagInformation {}", |
| 666 | status, portWithName(port), defaultEapolUniTag); |
| 667 | } |
| 668 | return status != null && status.defaultEapolStatus == OltFlowsStatus.PENDING_REMOVE; |
| 669 | } |
| 670 | |
| 671 | @Override |
| 672 | public boolean hasDhcpFlows(Port port, UniTagInformation uti) { |
| 673 | OltPortStatus status = getOltPortStatus(port, uti); |
| 674 | if (log.isTraceEnabled()) { |
| 675 | log.trace("Status during DHCP flow check {} for port {} and service {}", |
| 676 | status, portWithName(port), uti.getServiceName()); |
| 677 | } |
| 678 | return status != null && |
| 679 | (status.dhcpStatus == OltFlowsStatus.ADDED || |
| 680 | status.dhcpStatus == OltFlowsStatus.PENDING_ADD); |
| 681 | } |
| 682 | |
| 683 | @Override |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 684 | public boolean hasPppoeFlows(Port port, UniTagInformation uti) { |
| 685 | OltPortStatus status = getOltPortStatus(port, uti); |
| 686 | if (log.isTraceEnabled()) { |
| 687 | log.trace("Status during PPPoE flow check {} for port {} and service {}", |
| 688 | status, portWithName(port), uti.getServiceName()); |
| 689 | } |
| 690 | return status != null && |
| 691 | (status.pppoeStatus == OltFlowsStatus.ADDED || |
| 692 | status.pppoeStatus == OltFlowsStatus.PENDING_ADD); |
| 693 | } |
| 694 | |
| 695 | @Override |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 696 | public boolean hasSubscriberFlows(Port port, UniTagInformation uti) { |
| 697 | |
| 698 | OltPortStatus status = getOltPortStatus(port, uti); |
| 699 | if (log.isTraceEnabled()) { |
| 700 | log.trace("Status during subscriber flow check {} for port {} and service {}", |
| 701 | status, portWithName(port), uti.getServiceName()); |
| 702 | } |
| 703 | return status != null && (status.subscriberFlowsStatus == OltFlowsStatus.ADDED || |
| 704 | status.subscriberFlowsStatus == OltFlowsStatus.PENDING_ADD); |
| 705 | } |
| 706 | |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 707 | public boolean areSubscriberFlowsPendingRemoval(Port port, UniTagInformation uti, boolean enableEapol) { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 708 | OltPortStatus status = getOltPortStatus(port, uti); |
| 709 | if (log.isTraceEnabled()) { |
| 710 | log.trace("Status during pending_remove flow check {} for port {} and UniTagInformation {}", |
| 711 | status, portWithName(port), uti); |
| 712 | } |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 713 | return status != null && (status.subscriberFlowsStatus == OltFlowsStatus.PENDING_REMOVE || |
| 714 | (enableEapol && status.subscriberEapolStatus == OltFlowsStatus.PENDING_REMOVE) || |
| 715 | (uti.getIsDhcpRequired() && status.dhcpStatus == OltFlowsStatus.PENDING_REMOVE)); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 716 | } |
| 717 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 718 | @Override |
| 719 | public void purgeDeviceFlows(DeviceId deviceId) { |
| 720 | log.debug("Purging flows on device {}", deviceId); |
Matteo Scandolo | b6981dc | 2021-12-02 16:31:44 -0800 | [diff] [blame] | 721 | flowRuleService.purgeFlowRules(deviceId); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 722 | |
| 723 | // removing the status from the cpStatus map |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 724 | if (log.isTraceEnabled()) { |
| 725 | log.trace("Clearing cp status from device {}", deviceId); |
| 726 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 727 | try { |
| 728 | cpStatusWriteLock.lock(); |
| 729 | Iterator<Map.Entry<ServiceKey, OltPortStatus>> iter = cpStatus.entrySet().iterator(); |
| 730 | while (iter.hasNext()) { |
| 731 | Map.Entry<ServiceKey, OltPortStatus> entry = iter.next(); |
| 732 | if (entry.getKey().getPort().connectPoint().deviceId().equals(deviceId)) { |
| 733 | cpStatus.remove(entry.getKey()); |
| 734 | } |
| 735 | } |
| 736 | } finally { |
| 737 | cpStatusWriteLock.unlock(); |
| 738 | } |
| 739 | |
| 740 | // removing subscribers from the provisioned map |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 741 | if (log.isTraceEnabled()) { |
| 742 | log.trace("Clearing provisioned subscribers from device {}", deviceId); |
| 743 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 744 | try { |
| 745 | provisionedSubscribersWriteLock.lock(); |
| 746 | Iterator<Map.Entry<ServiceKey, Boolean>> iter = provisionedSubscribers.entrySet().iterator(); |
| 747 | while (iter.hasNext()) { |
| 748 | Map.Entry<ServiceKey, Boolean> entry = iter.next(); |
| 749 | if (entry.getKey().getPort().connectPoint().deviceId().equals(deviceId)) { |
| 750 | provisionedSubscribers.remove(entry.getKey()); |
| 751 | } |
| 752 | } |
| 753 | } finally { |
| 754 | provisionedSubscribersWriteLock.unlock(); |
| 755 | } |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 756 | log.debug("Done clearing up device flows and subscribers"); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public boolean isSubscriberServiceProvisioned(AccessDevicePort cp) { |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 761 | Set<Map.Entry<ServiceKey, Boolean>> subs; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 762 | try { |
| 763 | provisionedSubscribersReadLock.lock(); |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 764 | subs = new HashSet<>(provisionedSubscribers.entrySet()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 765 | } finally { |
| 766 | provisionedSubscribersReadLock.unlock(); |
| 767 | } |
Andrea Campanella | 61650a1 | 2022-01-24 18:09:44 -0800 | [diff] [blame] | 768 | |
| 769 | for (Map.Entry<ServiceKey, Boolean> entry : subs) { |
| 770 | if (entry.getKey().getPort().equals(cp) && entry.getValue()) { |
| 771 | return true; |
| 772 | } |
| 773 | } |
| 774 | return false; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | @Override |
| 778 | public boolean isSubscriberServiceProvisioned(ServiceKey sk) { |
| 779 | try { |
| 780 | provisionedSubscribersReadLock.lock(); |
| 781 | Boolean provisioned = provisionedSubscribers.get(sk); |
| 782 | if (provisioned == null || !provisioned) { |
| 783 | return false; |
| 784 | } |
| 785 | } finally { |
| 786 | provisionedSubscribersReadLock.unlock(); |
| 787 | } |
| 788 | return true; |
| 789 | } |
| 790 | |
| 791 | @Override |
| 792 | public void updateProvisionedSubscriberStatus(ServiceKey sk, Boolean status) { |
| 793 | try { |
| 794 | provisionedSubscribersWriteLock.lock(); |
| 795 | provisionedSubscribers.put(sk, status); |
| 796 | } finally { |
| 797 | provisionedSubscribersWriteLock.unlock(); |
| 798 | } |
| 799 | } |
| 800 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 801 | protected boolean handleEapolFlow(DiscoveredSubscriber sub, String bandwidthProfile, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 802 | String oltBandwidthProfile, FlowOperation action, VlanId vlanId) { |
| 803 | |
| 804 | // create a subscriberKey for the EAPOL flow |
| 805 | ServiceKey sk = new ServiceKey(new AccessDevicePort(sub.port), defaultEapolUniTag); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 806 | OltFlowsStatus status = action == FlowOperation.ADD ? |
| 807 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 808 | if (vlanId.id().equals(EAPOL_DEFAULT_VLAN)) { |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 809 | updateConnectPointStatus(sk, status, OltFlowsStatus.NONE, OltFlowsStatus.NONE, |
| 810 | OltFlowsStatus.NONE, OltFlowsStatus.NONE); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 811 | |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 812 | } else { |
| 813 | updateConnectPointStatus(sk, OltFlowsStatus.NONE, status, OltFlowsStatus.NONE, |
| 814 | OltFlowsStatus.NONE, OltFlowsStatus.NONE); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
| 818 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 819 | |
| 820 | int techProfileId = getDefaultTechProfileId(sub.port); |
| 821 | MeterId meterId = oltMeterService.getMeterIdForBandwidthProfile(sub.device.id(), bandwidthProfile); |
| 822 | |
| 823 | // in the delete case the meter should still be there as we remove |
| 824 | // the meters only if no flows are pointing to them |
| 825 | if (meterId == null) { |
| 826 | log.debug("MeterId is null for BandwidthProfile {} on device {}", |
| 827 | bandwidthProfile, sub.device.id()); |
| 828 | return false; |
| 829 | } |
| 830 | |
| 831 | MeterId oltMeterId = oltMeterService.getMeterIdForBandwidthProfile(sub.device.id(), oltBandwidthProfile); |
| 832 | if (oltMeterId == null) { |
| 833 | log.debug("MeterId is null for OltBandwidthProfile {} on device {}", |
| 834 | oltBandwidthProfile, sub.device.id()); |
| 835 | return false; |
| 836 | } |
| 837 | |
| 838 | log.info("{} EAPOL flow for {} with vlanId {} and BandwidthProfile {} (meterId {})", |
| 839 | flowOpToString(action), portWithName(sub.port), vlanId, bandwidthProfile, meterId); |
| 840 | |
| 841 | FilteringObjective.Builder eapolAction; |
| 842 | |
| 843 | if (action == FlowOperation.ADD) { |
| 844 | eapolAction = filterBuilder.permit(); |
| 845 | } else if (action == FlowOperation.REMOVE) { |
| 846 | eapolAction = filterBuilder.deny(); |
| 847 | } else { |
| 848 | log.error("Operation {} not supported", action); |
| 849 | return false; |
| 850 | } |
| 851 | |
| 852 | FilteringObjective.Builder baseEapol = eapolAction |
| 853 | .withKey(Criteria.matchInPort(sub.port.number())) |
| 854 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())); |
| 855 | |
| 856 | // NOTE we only need to add the treatment to install the flow, |
| 857 | // we can remove it based in the match |
| 858 | FilteringObjective.Builder eapol; |
| 859 | |
| 860 | TrafficTreatment treatment = treatmentBuilder |
| 861 | .meter(meterId) |
| 862 | .writeMetadata(createTechProfValueForWriteMetadata( |
| 863 | vlanId, |
| 864 | techProfileId, oltMeterId), 0) |
| 865 | .setOutput(PortNumber.CONTROLLER) |
| 866 | .pushVlan() |
| 867 | .setVlanId(vlanId) |
| 868 | .build(); |
| 869 | eapol = baseEapol |
| 870 | .withMeta(treatment); |
| 871 | |
| 872 | FilteringObjective eapolObjective = eapol |
| 873 | .fromApp(appId) |
| 874 | .withPriority(MAX_PRIORITY) |
| 875 | .add(new ObjectiveContext() { |
| 876 | @Override |
| 877 | public void onSuccess(Objective objective) { |
| 878 | log.info("EAPOL flow objective {} for {}", |
| 879 | completeFlowOpToString(action), portWithName(sub.port)); |
| 880 | if (log.isTraceEnabled()) { |
| 881 | log.trace("EAPOL flow details for port {}: {}", portWithName(sub.port), objective); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | @Override |
| 886 | public void onError(Objective objective, ObjectiveError error) { |
| 887 | log.error("Cannot {} eapol flow for {} : {}", action, |
| 888 | portWithName(sub.port), error); |
| 889 | |
| 890 | if (vlanId.id().equals(EAPOL_DEFAULT_VLAN)) { |
| 891 | updateConnectPointStatus(sk, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 892 | OltFlowsStatus.ERROR, null, null, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | }); |
| 896 | |
| 897 | flowObjectiveService.filter(sub.device.id(), eapolObjective); |
| 898 | |
| 899 | log.info("{} EAPOL filter for {}", completeFlowOpToString(action), portWithName(sub.port)); |
| 900 | return true; |
| 901 | } |
| 902 | |
| 903 | // FIXME it's confusing that si is not necessarily inside the DiscoveredSubscriber |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 904 | protected boolean handleSubscriberEapolFlows(DiscoveredSubscriber sub, FlowOperation action, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 905 | SubscriberAndDeviceInformation si) { |
| 906 | if (!enableEapol) { |
| 907 | return true; |
| 908 | } |
| 909 | // TODO verify we need an EAPOL flow for EACH service |
| 910 | AtomicBoolean success = new AtomicBoolean(true); |
| 911 | si.uniTagList().forEach(u -> { |
| 912 | // we assume that if subscriber flows are installed, tagged EAPOL is installed as well |
| 913 | boolean hasFlows = hasSubscriberFlows(sub.port, u); |
| 914 | |
| 915 | // if the subscriber flows are present the EAPOL flow is present thus we don't need to install it, |
| 916 | // if the subscriber does not have flows the EAPOL flow is not present thus we don't need to remove it |
| 917 | if (action == FlowOperation.ADD && hasFlows || |
| 918 | action == FlowOperation.REMOVE && !hasFlows) { |
| 919 | log.debug("Not {} EAPOL on {}({}) as subscriber flow status is {}", flowOpToString(action), |
| 920 | portWithName(sub.port), u.getServiceName(), hasFlows); |
| 921 | return; |
| 922 | } |
| 923 | log.info("{} EAPOL flows for subscriber {} on {} and service {}", |
| 924 | flowOpToString(action), si.id(), portWithName(sub.port), u.getServiceName()); |
| 925 | if (!handleEapolFlow(sub, u.getUpstreamBandwidthProfile(), |
| 926 | u.getUpstreamOltBandwidthProfile(), |
| 927 | action, u.getPonCTag())) { |
| 928 | // |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 929 | log.error("Failed to {} EAPOL with subscriber tags", action); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 930 | //TODO this sets it for all services, maybe some services succeeded. |
| 931 | success.set(false); |
| 932 | } |
| 933 | }); |
| 934 | return success.get(); |
| 935 | } |
| 936 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 937 | protected void handleSubscriberIgmpFlows(DiscoveredSubscriber sub, FlowOperation action) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 938 | sub.subscriberAndDeviceInformation.uniTagList().forEach(uti -> { |
| 939 | if (uti.getIsIgmpRequired()) { |
| 940 | DeviceId deviceId = sub.device.id(); |
| 941 | // if we reached here a meter already exists |
| 942 | MeterId meterId = oltMeterService |
| 943 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 944 | MeterId oltMeterId = oltMeterService |
| 945 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 946 | |
| 947 | processIgmpFilteringObjectives(deviceId, sub.port, |
| 948 | action, FlowDirection.UPSTREAM, meterId, oltMeterId, uti.getTechnologyProfileId(), |
| 949 | uti.getPonCTag(), uti.getUniTagMatch(), uti.getUsPonCTagPriority()); |
| 950 | } |
| 951 | }); |
| 952 | } |
| 953 | |
| 954 | private boolean checkSadisRunning() { |
| 955 | if (bpService == null) { |
| 956 | log.warn("Sadis is not running"); |
| 957 | return false; |
| 958 | } |
| 959 | return true; |
| 960 | } |
| 961 | |
| 962 | private int getDefaultTechProfileId(Port port) { |
| 963 | if (!checkSadisRunning()) { |
| 964 | return defaultTechProfileId; |
| 965 | } |
| 966 | if (port != null) { |
| 967 | SubscriberAndDeviceInformation info = subsService.get(getPortName(port)); |
| 968 | if (info != null && info.uniTagList().size() == 1) { |
| 969 | return info.uniTagList().get(0).getTechnologyProfileId(); |
| 970 | } |
| 971 | } |
| 972 | return defaultTechProfileId; |
| 973 | } |
| 974 | |
| 975 | protected Long createTechProfValueForWriteMetadata(VlanId cVlan, int techProfileId, MeterId upstreamOltMeterId) { |
| 976 | Long writeMetadata; |
| 977 | |
| 978 | if (cVlan == null || VlanId.NONE.equals(cVlan)) { |
| 979 | writeMetadata = (long) techProfileId << 32; |
| 980 | } else { |
| 981 | writeMetadata = ((long) (cVlan.id()) << 48 | (long) techProfileId << 32); |
| 982 | } |
| 983 | if (upstreamOltMeterId == null) { |
| 984 | return writeMetadata; |
| 985 | } else { |
| 986 | return writeMetadata | upstreamOltMeterId.id(); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | private void processLldpFilteringObjective(DeviceId deviceId, Port port, FlowOperation action) { |
| 991 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 992 | |
| 993 | FilteringObjective lldp = (action == FlowOperation.ADD ? builder.permit() : builder.deny()) |
| 994 | .withKey(Criteria.matchInPort(port.number())) |
| 995 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 996 | .withMeta(DefaultTrafficTreatment.builder() |
| 997 | .setOutput(PortNumber.CONTROLLER).build()) |
| 998 | .fromApp(appId) |
| 999 | .withPriority(MAX_PRIORITY) |
| 1000 | .add(new ObjectiveContext() { |
| 1001 | @Override |
| 1002 | public void onSuccess(Objective objective) { |
| 1003 | log.info("{} LLDP filter for {}.", completeFlowOpToString(action), portWithName(port)); |
| 1004 | } |
| 1005 | |
| 1006 | @Override |
| 1007 | public void onError(Objective objective, ObjectiveError error) { |
| 1008 | log.error("Falied to {} LLDP filter on {} because {}", action, portWithName(port), |
| 1009 | error); |
| 1010 | } |
| 1011 | }); |
| 1012 | |
| 1013 | flowObjectiveService.filter(deviceId, lldp); |
| 1014 | } |
| 1015 | |
| 1016 | protected void handleSubscriberDhcpFlows(DeviceId deviceId, Port port, |
| 1017 | FlowOperation action, |
| 1018 | SubscriberAndDeviceInformation si) { |
| 1019 | si.uniTagList().forEach(uti -> { |
| 1020 | |
| 1021 | if (!uti.getIsDhcpRequired()) { |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | // if it's an ADD skip if flows are there, |
| 1026 | // if it's a DELETE skip if flows are not there |
| 1027 | boolean hasFlows = hasDhcpFlows(port, uti); |
| 1028 | if (action == FlowOperation.ADD && hasFlows || |
| 1029 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1030 | log.debug("Not dealing with DHCP {} on {} as DHCP flow status is {}", action, |
| 1031 | uti.getServiceName(), hasFlows); |
| 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | log.info("{} DHCP flows for subscriber on {} and service {}", |
| 1036 | flowOpToString(action), portWithName(port), uti.getServiceName()); |
| 1037 | |
| 1038 | // if we reached here a meter already exists |
| 1039 | MeterId meterId = oltMeterService |
| 1040 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 1041 | MeterId oltMeterId = oltMeterService |
| 1042 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 1043 | |
| 1044 | if (enableDhcpV4) { |
| 1045 | processDhcpFilteringObjectives(deviceId, port, action, FlowDirection.UPSTREAM, 68, 67, |
| 1046 | EthType.EtherType.IPV4.ethType(), IPv4.PROTOCOL_UDP, meterId, oltMeterId, |
| 1047 | uti); |
| 1048 | } |
| 1049 | if (enableDhcpV6) { |
| 1050 | log.error("DHCP V6 not supported for subscribers"); |
| 1051 | } |
| 1052 | }); |
| 1053 | } |
| 1054 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1055 | protected void handleSubscriberPppoeFlows(DeviceId deviceId, Port port, |
| 1056 | FlowOperation action, |
| 1057 | SubscriberAndDeviceInformation si) { |
| 1058 | si.uniTagList().forEach(uti -> { |
| 1059 | |
| 1060 | if (!uti.getIsPppoeRequired()) { |
| 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | // if it's an ADD skip if flows are there, |
| 1065 | // if it's a DELETE skip if flows are not there |
| 1066 | boolean hasFlows = hasPppoeFlows(port, uti); |
| 1067 | if (action == FlowOperation.ADD && hasFlows || |
| 1068 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1069 | log.debug("Not dealing with PPPoE {} on {} as PPPoE flow status is {}", action, |
| 1070 | uti.getServiceName(), hasFlows); |
| 1071 | return; |
| 1072 | } |
| 1073 | |
| 1074 | log.info("{} PPPoE flows for subscriber on {} and service {}", |
| 1075 | flowOpToString(action), portWithName(port), uti.getServiceName()); |
| 1076 | |
| 1077 | // if we reached here a meter already exists |
| 1078 | MeterId meterId = oltMeterService |
| 1079 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamBandwidthProfile()); |
| 1080 | MeterId oltMeterId = oltMeterService |
| 1081 | .getMeterIdForBandwidthProfile(deviceId, uti.getUpstreamOltBandwidthProfile()); |
| 1082 | |
| 1083 | if (enablePppoe) { |
| 1084 | processPPPoEDFilteringObjectives(deviceId, port, action, FlowDirection.UPSTREAM, meterId, oltMeterId, |
| 1085 | uti.getTechnologyProfileId(), uti.getPonCTag(), uti.getUniTagMatch(), |
| 1086 | (byte) uti.getUsPonCTagPriority()); |
| 1087 | } |
| 1088 | }); |
| 1089 | } |
| 1090 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1091 | // FIXME return boolean, if this fails we need to retry |
| 1092 | protected void handleSubscriberDataFlows(Device device, Port port, |
| 1093 | FlowOperation action, |
| 1094 | SubscriberAndDeviceInformation si, String multicastServiceName) { |
| 1095 | |
| 1096 | Optional<Port> nniPort = oltDeviceService.getNniPort(device); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 1097 | if (nniPort == null || nniPort.isEmpty()) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1098 | log.error("Cannot configure DP flows as upstream port is not configured for subscriber {} on {}", |
| 1099 | si.id(), portWithName(port)); |
| 1100 | return; |
| 1101 | } |
| 1102 | si.uniTagList().forEach(uti -> { |
| 1103 | |
| 1104 | boolean hasFlows = hasSubscriberFlows(port, uti); |
| 1105 | if (action == FlowOperation.ADD && hasFlows || |
| 1106 | action == FlowOperation.REMOVE && !hasFlows) { |
| 1107 | log.debug("Not dealing with DP flows {} on {} as subscriber flow status is {}", action, |
| 1108 | uti.getServiceName(), hasFlows); |
| 1109 | return; |
| 1110 | } |
| 1111 | |
| 1112 | if (multicastServiceName.equals(uti.getServiceName())) { |
| 1113 | log.debug("This is the multicast service ({}) for subscriber {} on {}, " + |
| 1114 | "dataplane flows are not needed", |
| 1115 | uti.getServiceName(), si.id(), portWithName(port)); |
| 1116 | return; |
| 1117 | } |
| 1118 | |
| 1119 | log.info("{} Data plane flows for subscriber {} on {} and service {}", |
| 1120 | flowOpToString(action), si.id(), portWithName(port), uti.getServiceName()); |
Matteo Scandolo | 80f5e97 | 2021-12-02 14:59:15 -0800 | [diff] [blame] | 1121 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
| 1122 | OltFlowsStatus status = action.equals(FlowOperation.ADD) ? |
| 1123 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1124 | updateConnectPointStatus(sk, null, null, status, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1125 | |
| 1126 | // upstream flows |
| 1127 | MeterId usMeterId = oltMeterService |
| 1128 | .getMeterIdForBandwidthProfile(device.id(), uti.getUpstreamBandwidthProfile()); |
| 1129 | MeterId oltUsMeterId = oltMeterService |
| 1130 | .getMeterIdForBandwidthProfile(device.id(), uti.getUpstreamOltBandwidthProfile()); |
| 1131 | processUpstreamDataFilteringObjects(device.id(), port, nniPort.get(), action, usMeterId, |
| 1132 | oltUsMeterId, uti); |
| 1133 | |
| 1134 | // downstream flows |
| 1135 | MeterId dsMeterId = oltMeterService |
| 1136 | .getMeterIdForBandwidthProfile(device.id(), uti.getDownstreamBandwidthProfile()); |
| 1137 | MeterId oltDsMeterId = oltMeterService |
| 1138 | .getMeterIdForBandwidthProfile(device.id(), uti.getDownstreamOltBandwidthProfile()); |
| 1139 | processDownstreamDataFilteringObjects(device.id(), port, nniPort.get(), action, dsMeterId, |
| 1140 | oltDsMeterId, uti, getMacAddress(device.id(), port, uti)); |
| 1141 | }); |
| 1142 | } |
| 1143 | |
| 1144 | private void processDhcpFilteringObjectives(DeviceId deviceId, Port port, |
| 1145 | FlowOperation action, FlowDirection direction, |
| 1146 | int udpSrc, int udpDst, EthType ethType, byte protocol, |
| 1147 | MeterId meterId, MeterId oltMeterId, UniTagInformation uti) { |
| 1148 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
| 1149 | log.debug("{} DHCP filtering objectives on {}", flowOpToString(action), sk); |
| 1150 | |
| 1151 | |
| 1152 | OltFlowsStatus status = action.equals(FlowOperation.ADD) ? |
| 1153 | OltFlowsStatus.PENDING_ADD : OltFlowsStatus.PENDING_REMOVE; |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1154 | updateConnectPointStatus(sk, null, null, null, status, null); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1155 | |
| 1156 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 1157 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1158 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1159 | if (meterId != null) { |
| 1160 | treatmentBuilder.meter(meterId); |
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 | if (uti.getTechnologyProfileId() != NONE_TP_ID) { |
| 1164 | treatmentBuilder.writeMetadata( |
| 1165 | createTechProfValueForWriteMetadata(uti.getUniTagMatch(), |
| 1166 | uti.getTechnologyProfileId(), oltMeterId), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1167 | } |
| 1168 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1169 | FilteringObjective.Builder dhcpBuilder = (action == FlowOperation.ADD ? builder.permit() : builder.deny()) |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1170 | .withKey(Criteria.matchInPort(port.number())) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1171 | .addCondition(Criteria.matchEthType(ethType)) |
| 1172 | .addCondition(Criteria.matchIPProtocol(protocol)) |
| 1173 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(udpSrc))) |
| 1174 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(udpDst))) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1175 | .fromApp(appId) |
| 1176 | .withPriority(MAX_PRIORITY); |
| 1177 | |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1178 | //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] | 1179 | if (direction == FlowDirection.UPSTREAM) { |
| 1180 | treatmentBuilder.setVlanId(uti.getPonCTag()); |
| 1181 | if (!VlanId.vlanId(VlanId.NO_VID).equals(uti.getUniTagMatch())) { |
| 1182 | dhcpBuilder.addCondition(Criteria.matchVlanId(uti.getUniTagMatch())); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1183 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1184 | if (uti.getUsPonCTagPriority() != -1) { |
| 1185 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1186 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1189 | dhcpBuilder.withMeta(treatmentBuilder |
| 1190 | .setOutput(PortNumber.CONTROLLER).build()); |
Andrea Campanella | 0e34f56 | 2020-06-11 10:47:10 +0200 | [diff] [blame] | 1191 | |
| 1192 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1193 | FilteringObjective dhcpUpstream = dhcpBuilder.add(new ObjectiveContext() { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1194 | @Override |
| 1195 | public void onSuccess(Objective objective) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1196 | log.info("{} DHCP {} filter for {}.", |
| 1197 | completeFlowOpToString(action), (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 1198 | portWithName(port)); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | @Override |
| 1202 | public void onError(Objective objective, ObjectiveError error) { |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1203 | log.error("DHCP {} filter for {} failed {} because {}", |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1204 | (ethType.equals(EthType.EtherType.IPV4.ethType())) ? V4 : V6, |
| 1205 | portWithName(port), |
| 1206 | action, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1207 | error); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1208 | updateConnectPointStatus(sk, null, null, null, OltFlowsStatus.ERROR, null); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1209 | } |
| 1210 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1211 | flowObjectiveService.filter(deviceId, dhcpUpstream); |
| 1212 | } |
| 1213 | |
| 1214 | private void processIgmpFilteringObjectives(DeviceId deviceId, Port port, |
| 1215 | FlowOperation action, FlowDirection direction, |
| 1216 | MeterId meterId, MeterId oltMeterId, int techProfileId, |
| 1217 | VlanId cTag, VlanId unitagMatch, int vlanPcp) { |
| 1218 | |
| 1219 | DefaultFilteringObjective.Builder filterBuilder = DefaultFilteringObjective.builder(); |
| 1220 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1221 | if (direction == FlowDirection.UPSTREAM) { |
| 1222 | |
| 1223 | if (techProfileId != NONE_TP_ID) { |
| 1224 | treatmentBuilder.writeMetadata(createTechProfValueForWriteMetadata(null, |
| 1225 | techProfileId, oltMeterId), 0); |
| 1226 | } |
| 1227 | |
| 1228 | |
| 1229 | if (meterId != null) { |
| 1230 | treatmentBuilder.meter(meterId); |
| 1231 | } |
| 1232 | |
| 1233 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 1234 | filterBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 1235 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1236 | if (!VlanId.vlanId(VlanId.NO_VID).equals(cTag)) { |
| 1237 | treatmentBuilder.setVlanId(cTag); |
| 1238 | } |
| 1239 | |
| 1240 | if (vlanPcp != -1) { |
| 1241 | treatmentBuilder.setVlanPcp((byte) vlanPcp); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | filterBuilder = (action == FlowOperation.ADD) ? filterBuilder.permit() : filterBuilder.deny(); |
| 1246 | |
| 1247 | FilteringObjective igmp = filterBuilder |
| 1248 | .withKey(Criteria.matchInPort(port.number())) |
| 1249 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 1250 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 1251 | .withMeta(treatmentBuilder |
| 1252 | .setOutput(PortNumber.CONTROLLER).build()) |
| 1253 | .fromApp(appId) |
| 1254 | .withPriority(MAX_PRIORITY) |
| 1255 | .add(new ObjectiveContext() { |
| 1256 | @Override |
| 1257 | public void onSuccess(Objective objective) { |
| 1258 | log.info("Igmp filter for {} {}.", portWithName(port), action); |
| 1259 | } |
| 1260 | |
| 1261 | @Override |
| 1262 | public void onError(Objective objective, ObjectiveError error) { |
| 1263 | log.error("Igmp filter for {} failed {} because {}.", portWithName(port), action, |
| 1264 | error); |
| 1265 | } |
| 1266 | }); |
| 1267 | |
| 1268 | flowObjectiveService.filter(deviceId, igmp); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1269 | |
| 1270 | } |
| 1271 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1272 | private void processPPPoEDFilteringObjectives(DeviceId deviceId, Port port, |
| 1273 | FlowOperation action, FlowDirection direction, |
| 1274 | MeterId meterId, MeterId oltMeterId, int techProfileId, |
| 1275 | VlanId cTag, VlanId unitagMatch, Byte vlanPcp) { |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1276 | |
| 1277 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 1278 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1279 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1280 | if (meterId != null) { |
| 1281 | treatmentBuilder.meter(meterId); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | if (techProfileId != NONE_TP_ID) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1285 | treatmentBuilder.writeMetadata(createTechProfValueForWriteMetadata(cTag, techProfileId, oltMeterId), 0); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1286 | } |
| 1287 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1288 | DefaultFilteringObjective.Builder pppoedBuilder = ((action == FlowOperation.ADD) |
| 1289 | ? builder.permit() : builder.deny()) |
Tunahan Sezen | f0843b9 | 2021-04-30 07:13:16 +0000 | [diff] [blame] | 1290 | .withKey(Criteria.matchInPort(port.number())) |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1291 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 1292 | .fromApp(appId) |
| 1293 | .withPriority(10000); |
| 1294 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1295 | if (direction == FlowDirection.UPSTREAM) { |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1296 | treatmentBuilder.setVlanId(cTag); |
| 1297 | if (!VlanId.vlanId(VlanId.NO_VID).equals(unitagMatch)) { |
| 1298 | pppoedBuilder.addCondition(Criteria.matchVlanId(unitagMatch)); |
| 1299 | } |
| 1300 | if (vlanPcp != null) { |
| 1301 | treatmentBuilder.setVlanPcp(vlanPcp); |
| 1302 | } |
| 1303 | } |
| 1304 | pppoedBuilder = pppoedBuilder.withMeta(treatmentBuilder.setOutput(PortNumber.CONTROLLER).build()); |
| 1305 | |
| 1306 | FilteringObjective pppoed = pppoedBuilder |
| 1307 | .add(new ObjectiveContext() { |
| 1308 | @Override |
| 1309 | public void onSuccess(Objective objective) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1310 | log.info("PPPoED filter for {} {}.", portWithName(port), action); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | @Override |
| 1314 | public void onError(Objective objective, ObjectiveError error) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1315 | log.info("PPPoED filter for {} failed {} because {}", portWithName(port), |
| 1316 | action, error); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1317 | } |
| 1318 | }); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1319 | flowObjectiveService.filter(deviceId, pppoed); |
Gustavo Silva | 5c492dd | 2021-02-12 10:21:11 -0300 | [diff] [blame] | 1320 | } |
| 1321 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1322 | private void processUpstreamDataFilteringObjects(DeviceId deviceId, Port port, Port nniPort, |
| 1323 | FlowOperation action, |
| 1324 | MeterId upstreamMeterId, |
| 1325 | MeterId upstreamOltMeterId, |
| 1326 | UniTagInformation uti) { |
| 1327 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1328 | TrafficSelector selector = DefaultTrafficSelector.builder() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1329 | .matchInPort(port.number()) |
| 1330 | .matchVlanId(uti.getUniTagMatch()) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1331 | .build(); |
| 1332 | |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1333 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); |
| 1334 | //if the subscriberVlan (cTag) is different than ANY it needs to set. |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1335 | if (uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1336 | treatmentBuilder.pushVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1337 | .setVlanId(uti.getPonCTag()); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1338 | } |
Maria Carmela Cascino | 067ee4d | 2021-11-02 13:14:43 +0100 | [diff] [blame] | 1339 | if (uti.getPonSTag().toShort() == VlanId.ANY_VALUE) { |
| 1340 | treatmentBuilder.popVlan(); |
| 1341 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1342 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1343 | if (uti.getUsPonCTagPriority() != -1) { |
| 1344 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Maria Carmela Cascino | 067ee4d | 2021-11-02 13:14:43 +0100 | [diff] [blame] | 1345 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | treatmentBuilder.pushVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1349 | .setVlanId(uti.getPonSTag()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1350 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1351 | if (uti.getUsPonSTagPriority() != -1) { |
| 1352 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonSTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1355 | treatmentBuilder.setOutput(nniPort.number()) |
| 1356 | .writeMetadata(createMetadata(uti.getPonCTag(), |
| 1357 | uti.getTechnologyProfileId(), nniPort.number()), 0L); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1358 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1359 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
| 1360 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1361 | if (upstreamMeterId != null) { |
| 1362 | treatmentBuilder.meter(upstreamMeterId); |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1363 | annotationBuilder.set(UPSTREAM_ONU, upstreamMeterId.toString()); |
| 1364 | } |
| 1365 | if (upstreamOltMeterId != null) { |
| 1366 | treatmentBuilder.meter(upstreamOltMeterId); |
| 1367 | annotationBuilder.set(UPSTREAM_OLT, upstreamOltMeterId.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1370 | DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selector, |
| 1371 | treatmentBuilder.build(), MIN_PRIORITY, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1372 | annotationBuilder.build()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1373 | |
| 1374 | ObjectiveContext context = new ObjectiveContext() { |
| 1375 | @Override |
| 1376 | public void onSuccess(Objective objective) { |
| 1377 | log.info("{} Upstream Data plane filter for {}.", |
| 1378 | completeFlowOpToString(action), sk); |
| 1379 | } |
| 1380 | |
| 1381 | @Override |
| 1382 | public void onError(Objective objective, ObjectiveError error) { |
| 1383 | log.error("Upstream Data plane filter for {} failed {} because {}.", |
| 1384 | sk, action, error); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1385 | updateConnectPointStatus(sk, null, null, OltFlowsStatus.ERROR, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1386 | } |
| 1387 | }; |
| 1388 | |
| 1389 | ForwardingObjective flow = null; |
| 1390 | if (action == FlowOperation.ADD) { |
| 1391 | flow = flowBuilder.add(context); |
| 1392 | } else if (action == FlowOperation.REMOVE) { |
| 1393 | flow = flowBuilder.remove(context); |
| 1394 | } else { |
| 1395 | log.error("Flow action not supported: {}", action); |
| 1396 | } |
| 1397 | |
| 1398 | if (flow != null) { |
| 1399 | flowObjectiveService.forward(deviceId, flow); |
| 1400 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1403 | private void processDownstreamDataFilteringObjects(DeviceId deviceId, Port port, Port nniPort, |
| 1404 | FlowOperation action, |
| 1405 | MeterId downstreamMeterId, |
| 1406 | MeterId downstreamOltMeterId, |
| 1407 | UniTagInformation uti, |
| 1408 | MacAddress macAddress) { |
| 1409 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), uti); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1410 | //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] | 1411 | TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1412 | .matchVlanId(uti.getPonSTag()) |
| 1413 | .matchInPort(nniPort.number()) |
| 1414 | .matchInnerVlanId(uti.getPonCTag()); |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 1415 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1416 | if (uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 1417 | selectorBuilder.matchMetadata(uti.getPonCTag().toShort()); |
Andrea Campanella | 090e4a0 | 2020-02-05 13:53:55 +0100 | [diff] [blame] | 1418 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1419 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1420 | if (uti.getDsPonCTagPriority() != -1) { |
| 1421 | selectorBuilder.matchVlanPcp((byte) uti.getDsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1424 | if (macAddress != null) { |
| 1425 | selectorBuilder.matchEthDst(macAddress); |
| 1426 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1427 | |
| 1428 | TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder() |
| 1429 | .popVlan() |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1430 | .setOutput(port.number()); |
Andrea Campanella | 327c572 | 2020-01-30 11:34:13 +0100 | [diff] [blame] | 1431 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1432 | treatmentBuilder.writeMetadata(createMetadata(uti.getPonCTag(), |
| 1433 | uti.getTechnologyProfileId(), |
| 1434 | port.number()), 0); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1435 | |
Andrea Campanella | 981e86c | 2021-03-12 11:35:33 +0100 | [diff] [blame] | 1436 | // Upstream pbit is used to remark inner vlan pbit. |
| 1437 | // Upstream is used to avoid trusting the BNG to send the packet with correct pbit. |
| 1438 | // this is done because ds mode 0 is used because ds mode 3 or 6 that allow for |
| 1439 | // all pbit acceptance are not widely supported by vendors even though present in |
| 1440 | // the OMCI spec. |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1441 | if (uti.getUsPonCTagPriority() != -1) { |
| 1442 | treatmentBuilder.setVlanPcp((byte) uti.getUsPonCTagPriority()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1445 | if (!VlanId.NONE.equals(uti.getUniTagMatch()) && |
| 1446 | uti.getPonCTag().toShort() != VlanId.ANY_VALUE) { |
| 1447 | treatmentBuilder.setVlanId(uti.getUniTagMatch()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1450 | DefaultAnnotations.Builder annotationBuilder = DefaultAnnotations.builder(); |
| 1451 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1452 | if (downstreamMeterId != null) { |
| 1453 | treatmentBuilder.meter(downstreamMeterId); |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1454 | annotationBuilder.set(DOWNSTREAM_ONU, downstreamMeterId.toString()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1457 | if (downstreamOltMeterId != null) { |
| 1458 | treatmentBuilder.meter(downstreamOltMeterId); |
| 1459 | annotationBuilder.set(DOWNSTREAM_OLT, downstreamOltMeterId.toString()); |
| 1460 | } |
| 1461 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1462 | DefaultForwardingObjective.Builder flowBuilder = createForwardingObjectiveBuilder(selectorBuilder.build(), |
| 1463 | treatmentBuilder.build(), MIN_PRIORITY, annotationBuilder.build()); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1464 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1465 | ObjectiveContext context = new ObjectiveContext() { |
| 1466 | @Override |
| 1467 | public void onSuccess(Objective objective) { |
| 1468 | log.info("{} Downstream Data plane filter for {}.", |
| 1469 | completeFlowOpToString(action), sk); |
| 1470 | } |
| 1471 | |
| 1472 | @Override |
| 1473 | public void onError(Objective objective, ObjectiveError error) { |
| 1474 | log.info("Downstream Data plane filter for {} failed {} because {}.", |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1475 | sk, action, error); |
| 1476 | updateConnectPointStatus(sk, null, null, OltFlowsStatus.ERROR, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1477 | } |
| 1478 | }; |
| 1479 | |
| 1480 | ForwardingObjective flow = null; |
| 1481 | if (action == FlowOperation.ADD) { |
| 1482 | flow = flowBuilder.add(context); |
| 1483 | } else if (action == FlowOperation.REMOVE) { |
| 1484 | flow = flowBuilder.remove(context); |
| 1485 | } else { |
| 1486 | log.error("Flow action not supported: {}", action); |
| 1487 | } |
| 1488 | |
| 1489 | if (flow != null) { |
| 1490 | if (log.isTraceEnabled()) { |
| 1491 | log.trace("Forwarding rule {}", flow); |
| 1492 | } |
| 1493 | flowObjectiveService.forward(deviceId, flow); |
| 1494 | } |
Andrea Campanella | 600d2e2 | 2020-06-22 11:00:31 +0200 | [diff] [blame] | 1495 | } |
| 1496 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1497 | private DefaultForwardingObjective.Builder createForwardingObjectiveBuilder(TrafficSelector selector, |
| 1498 | TrafficTreatment treatment, |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1499 | Integer priority, |
| 1500 | Annotations annotations) { |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1501 | return DefaultForwardingObjective.builder() |
| 1502 | .withFlag(ForwardingObjective.Flag.VERSATILE) |
| 1503 | .withPriority(priority) |
| 1504 | .makePermanent() |
| 1505 | .withSelector(selector) |
yasin sapli | b4b8ee1 | 2021-06-13 18:25:20 +0000 | [diff] [blame] | 1506 | .withAnnotations(annotations) |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1507 | .fromApp(appId) |
| 1508 | .withTreatment(treatment); |
| 1509 | } |
| 1510 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1511 | private Long createMetadata(VlanId innerVlan, int techProfileId, PortNumber egressPort) { |
| 1512 | if (techProfileId == NONE_TP_ID) { |
Andrea Campanella | 7c49b79 | 2020-05-11 11:36:53 +0200 | [diff] [blame] | 1513 | techProfileId = DEFAULT_TP_ID_DEFAULT; |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | return ((long) (innerVlan.id()) << 48 | (long) techProfileId << 32) | egressPort.toLong(); |
| 1517 | } |
| 1518 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1519 | private boolean isMacLearningEnabled(SubscriberAndDeviceInformation si) { |
| 1520 | AtomicBoolean requiresMacLearning = new AtomicBoolean(); |
| 1521 | requiresMacLearning.set(false); |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1522 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1523 | si.uniTagList().forEach(uniTagInfo -> { |
| 1524 | if (uniTagInfo.getEnableMacLearning()) { |
| 1525 | requiresMacLearning.set(true); |
| 1526 | } |
| 1527 | }); |
| 1528 | |
| 1529 | return requiresMacLearning.get(); |
| 1530 | } |
| 1531 | |
| 1532 | /** |
| 1533 | * Checks whether the subscriber has the MacAddress configured or discovered. |
| 1534 | * |
| 1535 | * @param deviceId DeviceId for this subscriber |
| 1536 | * @param port Port for this subscriber |
| 1537 | * @param si SubscriberAndDeviceInformation |
| 1538 | * @return boolean |
| 1539 | */ |
| 1540 | protected boolean isMacAddressAvailable(DeviceId deviceId, Port port, SubscriberAndDeviceInformation si) { |
| 1541 | AtomicBoolean isConfigured = new AtomicBoolean(); |
| 1542 | isConfigured.set(true); |
| 1543 | |
| 1544 | si.uniTagList().forEach(uniTagInfo -> { |
| 1545 | boolean isMacLearningEnabled = uniTagInfo.getEnableMacLearning(); |
| 1546 | boolean configureMac = isMacAddressValid(uniTagInfo); |
| 1547 | boolean discoveredMac = false; |
| 1548 | Optional<Host> optHost = hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())) |
| 1549 | .stream().filter(host -> host.vlan().equals(uniTagInfo.getPonCTag())).findFirst(); |
| 1550 | if (optHost.isPresent() && optHost.get().mac() != null) { |
| 1551 | discoveredMac = true; |
| 1552 | } |
| 1553 | if (isMacLearningEnabled && !configureMac && !discoveredMac) { |
| 1554 | log.debug("Awaiting for macAddress on {} for service {}", |
| 1555 | portWithName(port), uniTagInfo.getServiceName()); |
| 1556 | isConfigured.set(false); |
| 1557 | } |
| 1558 | }); |
| 1559 | |
| 1560 | return isConfigured.get(); |
| 1561 | } |
| 1562 | |
| 1563 | protected MacAddress getMacAddress(DeviceId deviceId, Port port, UniTagInformation uniTagInfo) { |
| 1564 | boolean configuredMac = isMacAddressValid(uniTagInfo); |
| 1565 | if (configuredMac) { |
| 1566 | return MacAddress.valueOf(uniTagInfo.getConfiguredMacAddress()); |
| 1567 | } else if (uniTagInfo.getEnableMacLearning()) { |
| 1568 | Optional<Host> optHost = hostService.getConnectedHosts(new ConnectPoint(deviceId, port.number())) |
| 1569 | .stream().filter(host -> host.vlan().equals(uniTagInfo.getPonCTag())).findFirst(); |
| 1570 | if (optHost.isPresent() && optHost.get().mac() != null) { |
| 1571 | return optHost.get().mac(); |
| 1572 | } |
| 1573 | } |
| 1574 | return null; |
| 1575 | } |
| 1576 | |
| 1577 | private boolean isMacAddressValid(UniTagInformation tagInformation) { |
| 1578 | return tagInformation.getConfiguredMacAddress() != null && |
| 1579 | !tagInformation.getConfiguredMacAddress().trim().equals("") && |
| 1580 | !MacAddress.NONE.equals(MacAddress.valueOf(tagInformation.getConfiguredMacAddress())); |
| 1581 | } |
| 1582 | |
| 1583 | protected void updateConnectPointStatus(ServiceKey key, OltFlowsStatus eapolStatus, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1584 | OltFlowsStatus subscriberEapolStatus, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1585 | OltFlowsStatus subscriberFlowsStatus, OltFlowsStatus dhcpStatus, |
| 1586 | OltFlowsStatus pppoeStatus) { |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1587 | if (log.isTraceEnabled()) { |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1588 | log.trace("Updating cpStatus {} with values: eapolFlow={}, " + |
| 1589 | "subscriberEapolStatus={}, subscriberFlows={}, dhcpFlow={}", |
| 1590 | key, eapolStatus, subscriberEapolStatus, subscriberFlowsStatus, dhcpStatus); |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1591 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1592 | try { |
| 1593 | cpStatusWriteLock.lock(); |
| 1594 | OltPortStatus status = cpStatus.get(key); |
| 1595 | |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1596 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1597 | if (status == null) { |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 1598 | // if we don't have status for the connectPoint |
| 1599 | // and we're only updating status to PENDING_REMOVE or ERROR |
| 1600 | // do not create it. This is because this case will only happen when a device is removed |
| 1601 | // and it's status cleaned |
| 1602 | List<OltFlowsStatus> statusesToIgnore = new ArrayList<>(); |
| 1603 | statusesToIgnore.add(OltFlowsStatus.PENDING_REMOVE); |
| 1604 | statusesToIgnore.add(OltFlowsStatus.ERROR); |
| 1605 | |
| 1606 | if ( |
| 1607 | (statusesToIgnore.contains(subscriberFlowsStatus) && dhcpStatus == null) || |
| 1608 | (subscriberFlowsStatus == null && statusesToIgnore.contains(dhcpStatus)) |
| 1609 | ) { |
| 1610 | if (log.isTraceEnabled()) { |
| 1611 | log.trace("Ignoring cpStatus update as status is meaningless"); |
| 1612 | } |
| 1613 | return; |
| 1614 | } |
| 1615 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1616 | status = new OltPortStatus( |
| 1617 | eapolStatus != null ? eapolStatus : OltFlowsStatus.NONE, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1618 | subscriberEapolStatus != null ? subscriberEapolStatus : OltFlowsStatus.NONE, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1619 | subscriberFlowsStatus != null ? subscriberFlowsStatus : OltFlowsStatus.NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1620 | dhcpStatus != null ? dhcpStatus : OltFlowsStatus.NONE, |
| 1621 | pppoeStatus != null ? pppoeStatus : OltFlowsStatus.NONE |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1622 | ); |
| 1623 | } else { |
| 1624 | if (eapolStatus != null) { |
| 1625 | status.defaultEapolStatus = eapolStatus; |
| 1626 | } |
| 1627 | if (subscriberFlowsStatus != null) { |
| 1628 | status.subscriberFlowsStatus = subscriberFlowsStatus; |
| 1629 | } |
| 1630 | if (dhcpStatus != null) { |
| 1631 | status.dhcpStatus = dhcpStatus; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | cpStatus.put(key, status); |
| 1636 | } finally { |
| 1637 | cpStatusWriteLock.unlock(); |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | protected class InternalFlowListener implements FlowRuleListener { |
| 1642 | @Override |
| 1643 | public void event(FlowRuleEvent event) { |
| 1644 | if (appId.id() != (event.subject().appId())) { |
| 1645 | return; |
| 1646 | } |
| 1647 | |
| 1648 | if (!oltDeviceService.isLocalLeader(event.subject().deviceId())) { |
| 1649 | if (log.isTraceEnabled()) { |
| 1650 | log.trace("ignoring flow event {} " + |
| 1651 | "as not leader for {}", event, event.subject().deviceId()); |
| 1652 | } |
| 1653 | return; |
| 1654 | } |
| 1655 | |
| 1656 | switch (event.type()) { |
| 1657 | case RULE_ADDED: |
| 1658 | case RULE_REMOVED: |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1659 | DeviceId deviceId = event.subject().deviceId(); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1660 | Port port = getCpFromFlowRule(event.subject()); |
| 1661 | if (port == null) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1662 | log.warn("Port is gone in ONOS, " + |
| 1663 | "manually creating it {}", event.subject()); |
| 1664 | PortNumber inPort = getPortNumberFromFlowRule(event.subject()); |
| 1665 | cpStatusReadLock.lock(); |
| 1666 | Optional<ServiceKey> keyWithPort = cpStatus.keySet() |
| 1667 | .stream().filter(key -> key.getPort().connectPoint() |
| 1668 | .deviceId().equals(deviceId) |
| 1669 | && key.getPort().connectPoint().port() |
| 1670 | .equals(inPort)).findFirst(); |
| 1671 | cpStatusReadLock.unlock(); |
| 1672 | if (keyWithPort.isPresent()) { |
| 1673 | port = new DefaultPort(deviceService.getDevice(deviceId), |
| 1674 | inPort, false, |
| 1675 | DefaultAnnotations.builder() |
| 1676 | .set(AnnotationKeys.PORT_NAME, |
| 1677 | keyWithPort.get().getPort().name()) |
| 1678 | .build()); |
| 1679 | } else { |
| 1680 | log.warn("Can't find corresponding status for {}/{}", deviceId, inPort); |
| 1681 | return; |
| 1682 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1683 | } |
| 1684 | if (log.isTraceEnabled()) { |
| 1685 | log.trace("flow event {} on cp {}: {}", event.type(), |
| 1686 | portWithName(port), event.subject()); |
| 1687 | } |
| 1688 | updateCpStatus(event.type(), port, event.subject()); |
| 1689 | return; |
| 1690 | case RULE_ADD_REQUESTED: |
| 1691 | case RULE_REMOVE_REQUESTED: |
| 1692 | // NOTE that PENDING_ADD/REMOVE is set when we create the flowObjective |
| 1693 | return; |
| 1694 | default: |
| 1695 | return; |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | protected void updateCpStatus(FlowRuleEvent.Type type, Port port, FlowRule flowRule) { |
| 1700 | OltFlowsStatus status = flowRuleStatusToOltFlowStatus(type); |
| 1701 | if (isDefaultEapolFlow(flowRule)) { |
| 1702 | ServiceKey sk = new ServiceKey(new AccessDevicePort(port), |
| 1703 | defaultEapolUniTag); |
| 1704 | if (log.isTraceEnabled()) { |
| 1705 | log.trace("update defaultEapolStatus {} on {}", status, sk); |
| 1706 | } |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1707 | updateConnectPointStatus(sk, status, null, null, null, null); |
| 1708 | } else if (isSubscriberEapolFlow(flowRule)) { |
| 1709 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
| 1710 | if (sk == null) { |
| 1711 | return; |
| 1712 | } |
| 1713 | if (log.isTraceEnabled()) { |
| 1714 | log.trace("update subscriberEapolStatus {} on {}", status, sk); |
| 1715 | } |
| 1716 | updateConnectPointStatus(sk, null, status, null, status, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1717 | } else if (isDhcpFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1718 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1719 | if (sk == null) { |
| 1720 | return; |
| 1721 | } |
| 1722 | if (log.isTraceEnabled()) { |
| 1723 | log.trace("update dhcpStatus {} on {}", status, sk); |
| 1724 | } |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1725 | updateConnectPointStatus(sk, null, null, null, status, null); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1726 | } else if (isPppoeFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1727 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1728 | if (sk == null) { |
| 1729 | return; |
| 1730 | } |
| 1731 | if (log.isTraceEnabled()) { |
| 1732 | log.trace("update pppoeStatus {} on {}", status, sk); |
| 1733 | } |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1734 | updateConnectPointStatus(sk, null, null, null, null, status); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1735 | } else if (isDataFlow(flowRule)) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1736 | PortNumber number = getPortNumberFromFlowRule(flowRule); |
| 1737 | if (number == null) { |
| 1738 | log.error("Can't capture the port number from flow {}", flowRule); |
| 1739 | return; |
| 1740 | } |
| 1741 | if (oltDeviceService.isNniPort(deviceService.getDevice(flowRule.deviceId()), number)) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1742 | // the NNI has data-plane for every subscriber, doesn't make sense to track them |
| 1743 | return; |
| 1744 | } |
| 1745 | |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1746 | ServiceKey sk = getSubscriberKeyFromFlowRule(flowRule, port); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1747 | if (sk == null) { |
| 1748 | return; |
| 1749 | } |
| 1750 | if (log.isTraceEnabled()) { |
| 1751 | log.trace("update dataplaneStatus {} on {}", status, sk); |
| 1752 | } |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1753 | updateConnectPointStatus(sk, null, null, status, null, null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | private boolean isDefaultEapolFlow(FlowRule flowRule) { |
| 1758 | EthTypeCriterion c = (EthTypeCriterion) flowRule.selector().getCriterion(Criterion.Type.ETH_TYPE); |
| 1759 | if (c == null) { |
| 1760 | return false; |
| 1761 | } |
| 1762 | if (c.ethType().equals(EthType.EtherType.EAPOL.ethType())) { |
| 1763 | AtomicBoolean isDefault = new AtomicBoolean(false); |
| 1764 | flowRule.treatment().allInstructions().forEach(instruction -> { |
| 1765 | if (instruction.type() == L2MODIFICATION) { |
| 1766 | L2ModificationInstruction modificationInstruction = (L2ModificationInstruction) instruction; |
| 1767 | if (modificationInstruction.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { |
| 1768 | L2ModificationInstruction.ModVlanIdInstruction vlanInstruction = |
| 1769 | (L2ModificationInstruction.ModVlanIdInstruction) modificationInstruction; |
| 1770 | if (vlanInstruction.vlanId().id().equals(EAPOL_DEFAULT_VLAN)) { |
| 1771 | isDefault.set(true); |
| 1772 | return; |
| 1773 | } |
| 1774 | } |
| 1775 | } |
| 1776 | }); |
| 1777 | return isDefault.get(); |
| 1778 | } |
| 1779 | return false; |
| 1780 | } |
| 1781 | |
| 1782 | /** |
| 1783 | * Returns true if the flow is a DHCP flow. |
| 1784 | * Matches both upstream and downstream flows. |
| 1785 | * |
| 1786 | * @param flowRule The FlowRule to evaluate |
| 1787 | * @return boolean |
| 1788 | */ |
| 1789 | private boolean isDhcpFlow(FlowRule flowRule) { |
| 1790 | IPProtocolCriterion ipCriterion = (IPProtocolCriterion) flowRule.selector() |
| 1791 | .getCriterion(Criterion.Type.IP_PROTO); |
| 1792 | if (ipCriterion == null) { |
| 1793 | return false; |
| 1794 | } |
| 1795 | |
| 1796 | UdpPortCriterion src = (UdpPortCriterion) flowRule.selector().getCriterion(Criterion.Type.UDP_SRC); |
| 1797 | |
| 1798 | if (src == null) { |
| 1799 | return false; |
| 1800 | } |
| 1801 | return ipCriterion.protocol() == IPv4.PROTOCOL_UDP && |
| 1802 | (src.udpPort().toInt() == 68 || src.udpPort().toInt() == 67); |
| 1803 | } |
| 1804 | |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 1805 | private boolean isPppoeFlow(FlowRule flowRule) { |
| 1806 | EthTypeCriterion ethTypeCriterion = (EthTypeCriterion) flowRule.selector() |
| 1807 | .getCriterion(Criterion.Type.ETH_TYPE); |
| 1808 | |
| 1809 | if (ethTypeCriterion == null) { |
| 1810 | return false; |
| 1811 | } |
| 1812 | return EthType.EtherType.PPPoED.ethType().equals(ethTypeCriterion.ethType()); |
| 1813 | } |
| 1814 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1815 | private boolean isDataFlow(FlowRule flowRule) { |
| 1816 | // we consider subscriber flows the one that matches on VLAN_VID |
| 1817 | // method is valid only because it's the last check after EAPOL and DHCP. |
| 1818 | // this matches mcast flows as well, if we want to avoid that we can |
| 1819 | // filter out the elements that have groups in the treatment or |
| 1820 | // mcastIp in the selector |
| 1821 | // IPV4_DST:224.0.0.22/32 |
| 1822 | // treatment=[immediate=[GROUP:0x1]] |
| 1823 | |
| 1824 | return flowRule.selector().getCriterion(Criterion.Type.VLAN_VID) != null; |
| 1825 | } |
| 1826 | |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1827 | private boolean isSubscriberEapolFlow(FlowRule flowRule) { |
| 1828 | EthTypeCriterion c = (EthTypeCriterion) flowRule.selector().getCriterion(Criterion.Type.ETH_TYPE); |
| 1829 | if (c == null) { |
| 1830 | return false; |
| 1831 | } |
| 1832 | if (c.ethType().equals(EthType.EtherType.EAPOL.ethType())) { |
| 1833 | AtomicBoolean isSubscriber = new AtomicBoolean(false); |
| 1834 | flowRule.treatment().allInstructions().forEach(instruction -> { |
| 1835 | if (instruction.type() == L2MODIFICATION) { |
| 1836 | L2ModificationInstruction modificationInstruction = (L2ModificationInstruction) instruction; |
| 1837 | if (modificationInstruction.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) { |
| 1838 | L2ModificationInstruction.ModVlanIdInstruction vlanInstruction = |
| 1839 | (L2ModificationInstruction.ModVlanIdInstruction) modificationInstruction; |
| 1840 | if (!vlanInstruction.vlanId().id().equals(EAPOL_DEFAULT_VLAN)) { |
| 1841 | isSubscriber.set(true); |
| 1842 | return; |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | }); |
| 1847 | return isSubscriber.get(); |
| 1848 | } |
| 1849 | return false; |
| 1850 | } |
| 1851 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1852 | private Port getCpFromFlowRule(FlowRule flowRule) { |
| 1853 | DeviceId deviceId = flowRule.deviceId(); |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1854 | PortNumber inPort = getPortNumberFromFlowRule(flowRule); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1855 | if (inPort != null) { |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1856 | return deviceService.getPort(deviceId, inPort); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1857 | } |
| 1858 | return null; |
| 1859 | } |
| 1860 | |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 1861 | private PortNumber getPortNumberFromFlowRule(FlowRule flowRule) { |
| 1862 | PortCriterion inPort = (PortCriterion) flowRule.selector().getCriterion(Criterion.Type.IN_PORT); |
| 1863 | if (inPort != null) { |
| 1864 | return inPort.port(); |
| 1865 | } |
| 1866 | return null; |
| 1867 | } |
| 1868 | |
| 1869 | private ServiceKey getSubscriberKeyFromFlowRule(FlowRule flowRule, Port flowPort) { |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1870 | SubscriberAndDeviceInformation si = subsService.get(getPortName(flowPort)); |
| 1871 | |
| 1872 | Boolean isNni = oltDeviceService.isNniPort(deviceService.getDevice(flowRule.deviceId()), flowPort.number()); |
| 1873 | if (si == null && !isNni) { |
| 1874 | log.error("Subscriber information not found in sadis for port {}", portWithName(flowPort)); |
| 1875 | return null; |
| 1876 | } |
| 1877 | |
| 1878 | if (isNni) { |
| 1879 | return new ServiceKey(new AccessDevicePort(flowPort), nniUniTag); |
| 1880 | } |
| 1881 | |
| 1882 | Optional<UniTagInformation> found = Optional.empty(); |
| 1883 | VlanId flowVlan = null; |
| 1884 | if (isDhcpFlow(flowRule)) { |
| 1885 | // we need to make a special case for DHCP as in the ATT workflow DHCP flows don't match on tags |
| 1886 | L2ModificationInstruction.ModVlanIdInstruction instruction = |
| 1887 | (L2ModificationInstruction.ModVlanIdInstruction) flowRule.treatment().immediate().get(1); |
| 1888 | flowVlan = instruction.vlanId(); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 1889 | } else if (isSubscriberEapolFlow(flowRule)) { |
| 1890 | // we need to make a special case for EAPOL as in the ATT workflow EAPOL flows don't match on tags |
| 1891 | L2ModificationInstruction.ModVlanIdInstruction instruction = |
| 1892 | (L2ModificationInstruction.ModVlanIdInstruction) flowRule.treatment().immediate().get(2); |
| 1893 | flowVlan = instruction.vlanId(); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1894 | } else { |
| 1895 | // for now we assume that if it's not DHCP it's dataplane (or at least tagged) |
| 1896 | VlanIdCriterion vlanIdCriterion = |
| 1897 | (VlanIdCriterion) flowRule.selector().getCriterion(Criterion.Type.VLAN_VID); |
| 1898 | if (vlanIdCriterion == null) { |
| 1899 | log.warn("cannot match the flow to a subscriber service as it does not carry vlans"); |
| 1900 | return null; |
| 1901 | } |
| 1902 | flowVlan = vlanIdCriterion.vlanId(); |
| 1903 | } |
| 1904 | |
| 1905 | VlanId finalFlowVlan = flowVlan; |
| 1906 | found = si.uniTagList().stream().filter(uti -> |
| 1907 | uti.getPonCTag().equals(finalFlowVlan) || |
| 1908 | uti.getPonSTag().equals(finalFlowVlan) || |
| 1909 | uti.getUniTagMatch().equals(finalFlowVlan) |
| 1910 | ).findFirst(); |
| 1911 | |
| 1912 | |
| 1913 | if (found.isEmpty()) { |
| 1914 | log.warn("Cannot map flow rule {} to Service in {}", flowRule, si); |
| 1915 | } |
| 1916 | |
| 1917 | return found.isPresent() ? new ServiceKey(new AccessDevicePort(flowPort), found.get()) : null; |
| 1918 | |
| 1919 | } |
| 1920 | |
| 1921 | private OltFlowsStatus flowRuleStatusToOltFlowStatus(FlowRuleEvent.Type type) { |
| 1922 | switch (type) { |
| 1923 | case RULE_ADD_REQUESTED: |
| 1924 | return OltFlowsStatus.PENDING_ADD; |
| 1925 | case RULE_ADDED: |
| 1926 | return OltFlowsStatus.ADDED; |
| 1927 | case RULE_REMOVE_REQUESTED: |
| 1928 | return OltFlowsStatus.PENDING_REMOVE; |
| 1929 | case RULE_REMOVED: |
| 1930 | return OltFlowsStatus.REMOVED; |
| 1931 | default: |
| 1932 | return OltFlowsStatus.NONE; |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | protected void bindSadisService(SadisService service) { |
| 1938 | this.subsService = service.getSubscriberInfoService(); |
| 1939 | this.bpService = service.getBandwidthProfileService(); |
| 1940 | log.info("Sadis service is loaded"); |
| 1941 | } |
| 1942 | |
| 1943 | protected void unbindSadisService(SadisService service) { |
| 1944 | this.subsService = null; |
| 1945 | this.bpService = null; |
| 1946 | log.info("Sadis service is unloaded"); |
| 1947 | } |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 1948 | } |