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