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