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