David K. Bainbridge | d77028f | 2017-08-01 12:47:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4d08470 | 2017-08-03 22:45:58 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
David K. Bainbridge | d77028f | 2017-08-01 12:47:55 -0700 | [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 | */ |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 16 | package org.opencord.igmpproxy; |
| 17 | |
| 18 | import com.google.common.collect.Maps; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 19 | import com.google.common.collect.Sets; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 20 | import org.onosproject.net.Device; |
| 21 | import org.opencord.sadis.BaseInformationService; |
| 22 | import org.opencord.sadis.SadisService; |
| 23 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 29 | import org.onlab.packet.EthType; |
| 30 | import org.onlab.packet.Ethernet; |
| 31 | import org.onlab.packet.IGMP; |
| 32 | import org.onlab.packet.IGMPGroup; |
| 33 | import org.onlab.packet.IGMPMembership; |
| 34 | import org.onlab.packet.IGMPQuery; |
| 35 | import org.onlab.packet.IPv4; |
| 36 | import org.onlab.packet.Ip4Address; |
| 37 | import org.onlab.packet.IpAddress; |
| 38 | import org.onlab.packet.VlanId; |
| 39 | import org.onosproject.core.ApplicationId; |
| 40 | import org.onosproject.core.CoreService; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 41 | import org.onosproject.mastership.MastershipService; |
| 42 | import org.onosproject.net.AnnotationKeys; |
| 43 | import org.onosproject.net.ConnectPoint; |
| 44 | import org.onosproject.net.DeviceId; |
| 45 | import org.onosproject.net.Port; |
| 46 | import org.onosproject.net.PortNumber; |
| 47 | import org.onosproject.net.config.ConfigFactory; |
| 48 | import org.onosproject.net.config.NetworkConfigEvent; |
| 49 | import org.onosproject.net.config.NetworkConfigListener; |
| 50 | import org.onosproject.net.config.NetworkConfigRegistry; |
Jonathan Hart | 488e114 | 2018-05-02 17:30:05 -0700 | [diff] [blame] | 51 | import org.onosproject.net.config.basics.McastConfig; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 52 | import org.onosproject.net.config.basics.SubjectFactories; |
| 53 | import org.onosproject.net.device.DeviceEvent; |
| 54 | import org.onosproject.net.device.DeviceListener; |
| 55 | import org.onosproject.net.device.DeviceService; |
| 56 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 57 | import org.onosproject.net.flow.FlowRuleService; |
| 58 | import org.onosproject.net.flow.criteria.Criteria; |
| 59 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 60 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 61 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 62 | import org.onosproject.net.flowobjective.Objective; |
| 63 | import org.onosproject.net.flowobjective.ObjectiveContext; |
| 64 | import org.onosproject.net.flowobjective.ObjectiveError; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 65 | import org.onosproject.mcast.api.McastRoute; |
| 66 | import org.onosproject.mcast.api.MulticastRouteService; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 67 | import org.onosproject.net.packet.InboundPacket; |
| 68 | import org.onosproject.net.packet.PacketContext; |
| 69 | import org.onosproject.net.packet.PacketProcessor; |
| 70 | import org.onosproject.net.packet.PacketService; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 71 | import org.slf4j.Logger; |
| 72 | import org.slf4j.LoggerFactory; |
| 73 | |
| 74 | import java.util.ArrayList; |
| 75 | import java.util.Collection; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 76 | import java.util.HashSet; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 77 | import java.util.Iterator; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 78 | import java.util.Map; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 79 | import java.util.Optional; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 80 | import java.util.Set; |
| 81 | import java.util.TimerTask; |
| 82 | import java.util.concurrent.ConcurrentHashMap; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 83 | import java.util.concurrent.ExecutorService; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 84 | import java.util.concurrent.Executors; |
| 85 | import java.util.concurrent.ScheduledExecutorService; |
| 86 | import java.util.concurrent.TimeUnit; |
| 87 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 88 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 89 | import static org.onlab.util.Tools.groupedThreads; |
| 90 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 91 | /** |
| 92 | * Igmp process application, use proxy mode, support first join/ last leave , fast leave |
| 93 | * period query and keep alive, packet out igmp message to uplink port features. |
| 94 | */ |
| 95 | @Component(immediate = true) |
| 96 | public class IgmpManager { |
| 97 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 98 | private static final String APP_NAME = "org.opencord.igmpproxy"; |
| 99 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 100 | private static final Class<IgmpproxyConfig> IGMPPROXY_CONFIG_CLASS = |
| 101 | IgmpproxyConfig.class; |
| 102 | private static final Class<IgmpproxySsmTranslateConfig> IGMPPROXY_SSM_CONFIG_CLASS = |
| 103 | IgmpproxySsmTranslateConfig.class; |
| 104 | private static final Class<McastConfig> MCAST_CONFIG_CLASS = |
| 105 | McastConfig.class; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 106 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 107 | public static Map<String, GroupMember> groupMemberMap = Maps.newConcurrentMap(); |
| 108 | private static ApplicationId appId; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 109 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 110 | private static int unSolicitedTimeout = 3; // unit is 1 sec |
| 111 | private static int keepAliveCount = 3; |
| 112 | private static int lastQueryInterval = 2; //unit is 1 sec |
| 113 | private static int lastQueryCount = 2; |
| 114 | private static boolean fastLeave = true; |
| 115 | private static boolean withRAUplink = true; |
| 116 | private static boolean withRADownlink = false; |
| 117 | private static boolean periodicQuery = true; |
| 118 | private static short mvlan = 4000; |
| 119 | private static byte igmpCos = 7; |
| 120 | public static boolean connectPointMode = true; |
| 121 | public static ConnectPoint connectPoint = null; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 122 | private static ConnectPoint sourceDeviceAndPort = null; |
| 123 | private static boolean enableIgmpProvisioning = false; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 124 | private static boolean igmpOnPodBasis = false; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 125 | |
| 126 | private static final Integer MAX_PRIORITY = 10000; |
| 127 | private static final String INSTALLED = "installed"; |
| 128 | private static final String REMOVED = "removed"; |
| 129 | private static final String INSTALLATION = "installation"; |
| 130 | private static final String REMOVAL = "removal"; |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 131 | private static final String NNI_PREFIX = "nni"; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 132 | |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 133 | private static boolean pimSSmInterworking = false; |
| 134 | private static final String DEFAULT_PIMSSM_HOST = "127.0.0.1"; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 135 | private final ScheduledExecutorService scheduledExecutorService = |
| 136 | Executors.newScheduledThreadPool(1); |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 137 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 138 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 139 | protected CoreService coreService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 140 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 141 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 142 | protected PacketService packetService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 143 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 144 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 145 | protected MastershipService mastershipService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 146 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 147 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 148 | protected FlowRuleService flowRuleService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 149 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 150 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 151 | protected DeviceService deviceService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 152 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 153 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 154 | protected FlowObjectiveService flowObjectiveService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 155 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 156 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 157 | protected NetworkConfigRegistry networkConfig; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 158 | |
Carmelo Cascone | bef302e | 2019-11-14 19:58:20 -0800 | [diff] [blame] | 159 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 160 | protected MulticastRouteService multicastService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 161 | |
| 162 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 163 | protected SadisService sadisService; |
| 164 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 165 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 166 | protected IgmpStatisticsService igmpStatisticsManager; |
| 167 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 168 | private IgmpPacketProcessor processor = new IgmpPacketProcessor(); |
| 169 | private Logger log = LoggerFactory.getLogger(getClass()); |
| 170 | private ApplicationId coreAppId; |
| 171 | private Map<Ip4Address, Ip4Address> ssmTranslateTable = new ConcurrentHashMap<>(); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 172 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 173 | private InternalNetworkConfigListener configListener = |
| 174 | new InternalNetworkConfigListener(); |
| 175 | private DeviceListener deviceListener = new InternalDeviceListener(); |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 176 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 177 | private ConfigFactory<ApplicationId, IgmpproxyConfig> igmpproxyConfigFactory = |
| 178 | new ConfigFactory<ApplicationId, IgmpproxyConfig>( |
| 179 | SubjectFactories.APP_SUBJECT_FACTORY, IGMPPROXY_CONFIG_CLASS, "igmpproxy") { |
| 180 | @Override |
| 181 | public IgmpproxyConfig createConfig() { |
| 182 | return new IgmpproxyConfig(); |
| 183 | } |
| 184 | }; |
| 185 | private ConfigFactory<ApplicationId, IgmpproxySsmTranslateConfig> igmpproxySsmConfigFactory = |
| 186 | new ConfigFactory<ApplicationId, IgmpproxySsmTranslateConfig>( |
| 187 | SubjectFactories.APP_SUBJECT_FACTORY, IGMPPROXY_SSM_CONFIG_CLASS, "ssmTranslate", true) { |
| 188 | @Override |
| 189 | public IgmpproxySsmTranslateConfig createConfig() { |
| 190 | return new IgmpproxySsmTranslateConfig(); |
| 191 | } |
| 192 | }; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 193 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 194 | private int maxResp = 10; //unit is 1 sec |
| 195 | private int keepAliveInterval = 120; //unit is 1 sec |
| 196 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 197 | private ExecutorService eventExecutor; |
| 198 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 199 | public static int getUnsolicitedTimeout() { |
| 200 | return unSolicitedTimeout; |
| 201 | } |
| 202 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 203 | protected BaseInformationService<SubscriberAndDeviceInformation> subsService; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 204 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 205 | @Activate |
| 206 | protected void activate() { |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 207 | appId = coreService.registerApplication(APP_NAME); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 208 | coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME); |
| 209 | packetService.addProcessor(processor, PacketProcessor.director(4)); |
| 210 | IgmpSender.init(packetService, mastershipService); |
| 211 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 212 | networkConfig.registerConfigFactory(igmpproxySsmConfigFactory); |
| 213 | networkConfig.registerConfigFactory(igmpproxyConfigFactory); |
| 214 | networkConfig.addListener(configListener); |
| 215 | |
| 216 | configListener.reconfigureNetwork(networkConfig.getConfig(appId, IGMPPROXY_CONFIG_CLASS)); |
| 217 | configListener.reconfigureSsmTable(networkConfig.getConfig(appId, IGMPPROXY_SSM_CONFIG_CLASS)); |
| 218 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 219 | subsService = sadisService.getSubscriberInfoService(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 220 | if (connectPointMode) { |
| 221 | provisionConnectPointFlows(); |
| 222 | } else { |
| 223 | provisionUplinkFlows(); |
| 224 | } |
| 225 | |
| 226 | McastConfig config = networkConfig.getConfig(coreAppId, MCAST_CONFIG_CLASS); |
| 227 | if (config != null) { |
| 228 | mvlan = config.egressVlan().toShort(); |
Deepa Vaddireddy | 88134a4 | 2017-07-05 12:16:03 +0530 | [diff] [blame] | 229 | IgmpSender.getInstance().setMvlan(mvlan); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 230 | } |
| 231 | deviceService.addListener(deviceListener); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 232 | scheduledExecutorService.scheduleAtFixedRate(new IgmpProxyTimerTask(), 1000, 1000, TimeUnit.MILLISECONDS); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 233 | eventExecutor = newSingleThreadScheduledExecutor(groupedThreads("cord/igmpproxy", |
| 234 | "events-igmp-%d", log)); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 235 | log.info("Started"); |
| 236 | } |
| 237 | |
| 238 | @Deactivate |
| 239 | protected void deactivate() { |
| 240 | scheduledExecutorService.shutdown(); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 241 | eventExecutor.shutdown(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 242 | |
| 243 | // de-register and null our handler |
| 244 | networkConfig.removeListener(configListener); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 245 | networkConfig.unregisterConfigFactory(igmpproxyConfigFactory); |
| 246 | networkConfig.unregisterConfigFactory(igmpproxySsmConfigFactory); |
| 247 | deviceService.removeListener(deviceListener); |
| 248 | packetService.removeProcessor(processor); |
| 249 | flowRuleService.removeFlowRulesById(appId); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 250 | log.info("Stopped"); |
| 251 | } |
| 252 | |
| 253 | protected Ip4Address getDeviceIp(DeviceId ofDeviceId) { |
| 254 | try { |
| 255 | String[] mgmtAddress = deviceService.getDevice(ofDeviceId) |
| 256 | .annotations().value(AnnotationKeys.MANAGEMENT_ADDRESS).split(":"); |
| 257 | return Ip4Address.valueOf(mgmtAddress[0]); |
| 258 | } catch (Exception ex) { |
| 259 | log.info("No valid Ipaddress for " + ofDeviceId.toString()); |
| 260 | return null; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | private void processIgmpQuery(IGMPQuery igmpQuery, ConnectPoint cp, int maxResp) { |
| 265 | |
| 266 | DeviceId deviceId = cp.deviceId(); |
| 267 | Ip4Address gAddr = igmpQuery.getGaddr().getIp4Address(); |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 268 | maxResp = calculateMaxResp(maxResp); |
| 269 | if (gAddr != null && !gAddr.isZero()) { |
| 270 | StateMachine.specialQuery(deviceId, gAddr, maxResp); |
| 271 | } else { |
| 272 | StateMachine.generalQuery(deviceId, maxResp); |
| 273 | } |
| 274 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 275 | |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 276 | private void processIgmpConnectPointQuery(IGMPQuery igmpQuery, ConnectPoint cp, int maxResp) { |
| 277 | |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 278 | Ip4Address gAddr = igmpQuery.getGaddr().getIp4Address(); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 279 | final int maxResponseTime = calculateMaxResp(maxResp); |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 280 | //The query is received on the ConnectPoint |
| 281 | // send query accordingly to the registered OLT devices. |
| 282 | if (gAddr != null && !gAddr.isZero()) { |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 283 | deviceService.getAvailableDevices().forEach(device -> { |
| 284 | Optional<SubscriberAndDeviceInformation> accessDevice = getSubscriberAndDeviceInformation(device.id()); |
| 285 | if (accessDevice.isPresent()) { |
| 286 | StateMachine.specialQuery(device.id(), gAddr, maxResponseTime); |
| 287 | } |
| 288 | }); |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 289 | } else { |
| 290 | //Don't know which group is targeted by the query |
| 291 | //So query all the members(in all the OLTs) and proxy their reports |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 292 | StateMachine.generalQuery(maxResponseTime); |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | |
| 297 | private int calculateMaxResp(int maxResp) { |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 298 | if (maxResp >= 128) { |
| 299 | int mant = maxResp & 0xf; |
| 300 | int exp = (maxResp >> 4) & 0x7; |
| 301 | maxResp = (mant | 0x10) << (exp + 3); |
| 302 | } |
| 303 | |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 304 | return (maxResp + 5) / 10; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | private Ip4Address ssmTranslateRoute(IpAddress group) { |
| 308 | return ssmTranslateTable.get(group); |
| 309 | } |
| 310 | |
| 311 | private void processIgmpReport(IGMPMembership igmpGroup, VlanId vlan, ConnectPoint cp, byte igmpType) { |
| 312 | DeviceId deviceId = cp.deviceId(); |
| 313 | PortNumber portNumber = cp.port(); |
| 314 | |
| 315 | Ip4Address groupIp = igmpGroup.getGaddr().getIp4Address(); |
| 316 | if (!groupIp.isMulticast()) { |
| 317 | log.info(groupIp.toString() + " is not a valid group address"); |
| 318 | return; |
| 319 | } |
| 320 | Ip4Address srcIp = getDeviceIp(deviceId); |
| 321 | |
| 322 | byte recordType = igmpGroup.getRecordType(); |
| 323 | boolean join = false; |
| 324 | |
| 325 | ArrayList<Ip4Address> sourceList = new ArrayList<>(); |
| 326 | |
| 327 | if (igmpGroup.getSources().size() > 0) { |
| 328 | igmpGroup.getSources().forEach(source -> sourceList.add(source.getIp4Address())); |
| 329 | if (recordType == IGMPMembership.CHANGE_TO_EXCLUDE_MODE || |
| 330 | recordType == IGMPMembership.MODE_IS_EXCLUDE || |
| 331 | recordType == IGMPMembership.BLOCK_OLD_SOURCES) { |
| 332 | join = false; |
| 333 | } else if (recordType == IGMPMembership.CHANGE_TO_INCLUDE_MODE || |
| 334 | recordType == IGMPMembership.MODE_IS_INCLUDE || |
| 335 | recordType == IGMPMembership.ALLOW_NEW_SOURCES) { |
| 336 | join = true; |
| 337 | } |
| 338 | } else { |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 339 | IpAddress src = null; |
| 340 | if (pimSSmInterworking) { |
| 341 | src = ssmTranslateRoute(groupIp); |
| 342 | if (src == null) { |
| 343 | log.info("no ssm translate for group " + groupIp.toString()); |
| 344 | return; |
| 345 | } |
| 346 | } else { |
| 347 | src = IpAddress.valueOf(DEFAULT_PIMSSM_HOST); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 348 | } |
| 349 | sourceList.add(src.getIp4Address()); |
| 350 | if (recordType == IGMPMembership.CHANGE_TO_EXCLUDE_MODE || |
| 351 | recordType == IGMPMembership.MODE_IS_EXCLUDE || |
| 352 | recordType == IGMPMembership.BLOCK_OLD_SOURCES) { |
| 353 | join = true; |
| 354 | } else if (recordType == IGMPMembership.CHANGE_TO_INCLUDE_MODE || |
| 355 | recordType == IGMPMembership.MODE_IS_INCLUDE || |
| 356 | recordType == IGMPMembership.ALLOW_NEW_SOURCES) { |
| 357 | join = false; |
| 358 | } |
| 359 | } |
| 360 | String groupMemberKey = GroupMember.getkey(groupIp, deviceId, portNumber); |
| 361 | GroupMember groupMember = groupMemberMap.get(groupMemberKey); |
| 362 | |
| 363 | if (join) { |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 364 | igmpStatisticsManager.getIgmpStats().increaseIgmpJoinReq(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 365 | if (groupMember == null) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 366 | Optional<ConnectPoint> sourceConfigured = getSource(); |
| 367 | if (!sourceConfigured.isPresent()) { |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 368 | igmpStatisticsManager.getIgmpStats().increaseIgmpFailJoinReq(); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 369 | log.warn("Unable to process IGMP Join from {} since no source " + |
| 370 | "configuration is found.", deviceId); |
| 371 | return; |
| 372 | } |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 373 | |
| 374 | Optional<PortNumber> deviceUplink = getDeviceUplink(deviceId); |
| 375 | if (deviceUplink.isEmpty()) { |
| 376 | log.warn("Unable to process IGMP Join since uplink port " + |
| 377 | "of the device {} is not found.", deviceId); |
| 378 | return; |
| 379 | } |
| 380 | |
| 381 | if (igmpType == IGMP.TYPE_IGMPV2_MEMBERSHIP_REPORT) { |
| 382 | groupMember = new GroupMember(groupIp, vlan, deviceId, portNumber, true); |
| 383 | } else { |
| 384 | groupMember = new GroupMember(groupIp, vlan, deviceId, portNumber, false); |
| 385 | } |
| 386 | |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 387 | HashSet<ConnectPoint> sourceConnectPoints = Sets.newHashSet(sourceConfigured.get()); |
| 388 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 389 | boolean isJoined = StateMachine.join(deviceId, groupIp, srcIp, deviceUplink.get()); |
| 390 | if (isJoined) { |
| 391 | igmpStatisticsManager.getIgmpStats().increaseIgmpSuccessJoinRejoinReq(); |
| 392 | } else { |
| 393 | igmpStatisticsManager.getIgmpStats().increaseIgmpFailJoinReq(); |
| 394 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 395 | groupMemberMap.put(groupMemberKey, groupMember); |
| 396 | groupMember.updateList(recordType, sourceList); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 397 | groupMember.getSourceList().forEach(source -> { |
| 398 | McastRoute route = new McastRoute(source, groupIp, McastRoute.Type.IGMP); |
| 399 | //add route |
| 400 | multicastService.add(route); |
| 401 | //add source to the route |
| 402 | multicastService.addSources(route, Sets.newHashSet(sourceConnectPoints)); |
| 403 | //add sink to the route |
| 404 | multicastService.addSinks(route, Sets.newHashSet(cp)); |
| 405 | }); |
| 406 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 407 | } |
| 408 | groupMember.resetAllTimers(); |
| 409 | groupMember.updateList(recordType, sourceList); |
| 410 | groupMember.setLeave(false); |
| 411 | } else { |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 412 | igmpStatisticsManager.getIgmpStats().increaseIgmpLeaveReq(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 413 | if (groupMember == null) { |
| 414 | log.info("receive leave but no instance, group " + groupIp.toString() + |
| 415 | " device:" + deviceId.toString() + " port:" + portNumber.toString()); |
| 416 | return; |
| 417 | } else { |
| 418 | groupMember.setLeave(true); |
| 419 | if (fastLeave) { |
| 420 | leaveAction(groupMember); |
| 421 | } else { |
| 422 | sendQuery(groupMember); |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | private void leaveAction(GroupMember groupMember) { |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 429 | igmpStatisticsManager.getIgmpStats().increaseIgmpDisconnect(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 430 | ConnectPoint cp = new ConnectPoint(groupMember.getDeviceId(), groupMember.getPortNumber()); |
| 431 | StateMachine.leave(groupMember.getDeviceId(), groupMember.getGroupIp()); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 432 | groupMember.getSourceList().forEach(source -> multicastService.removeSinks( |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 433 | new McastRoute(source, groupMember.getGroupIp(), |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 434 | McastRoute.Type.IGMP), Sets.newHashSet(cp))); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 435 | groupMemberMap.remove(groupMember.getId()); |
| 436 | } |
| 437 | |
| 438 | private void sendQuery(GroupMember groupMember) { |
| 439 | Ethernet ethpkt; |
| 440 | Ip4Address srcIp = getDeviceIp(groupMember.getDeviceId()); |
| 441 | if (groupMember.getv2()) { |
| 442 | ethpkt = IgmpSender.getInstance().buildIgmpV2Query(groupMember.getGroupIp(), srcIp); |
| 443 | } else { |
| 444 | ethpkt = IgmpSender.getInstance().buildIgmpV3Query(groupMember.getGroupIp(), srcIp); |
| 445 | } |
| 446 | IgmpSender.getInstance().sendIgmpPacket(ethpkt, groupMember.getDeviceId(), groupMember.getPortNumber()); |
| 447 | } |
| 448 | |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 449 | /** |
| 450 | * @return connect point of the source if configured; and empty Optional otherwise. |
| 451 | */ |
| 452 | public static Optional<ConnectPoint> getSource() { |
| 453 | return sourceDeviceAndPort == null ? Optional.empty() : |
| 454 | Optional.of(sourceDeviceAndPort); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Packet processor responsible for forwarding packets along their paths. |
| 459 | */ |
| 460 | private class IgmpPacketProcessor implements PacketProcessor { |
| 461 | @Override |
| 462 | public void process(PacketContext context) { |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 463 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 464 | eventExecutor.execute(() -> { |
| 465 | try { |
| 466 | InboundPacket pkt = context.inPacket(); |
| 467 | Ethernet ethPkt = pkt.parsed(); |
| 468 | if (ethPkt == null) { |
| 469 | return; |
| 470 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 471 | igmpStatisticsManager.getIgmpStats().increaseTotalMsgReceived(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 472 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 473 | if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) { |
| 474 | return; |
| 475 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 476 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 477 | IPv4 ipv4Pkt = (IPv4) ethPkt.getPayload(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 478 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 479 | if (ipv4Pkt.getProtocol() != IPv4.PROTOCOL_IGMP) { |
| 480 | return; |
| 481 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 482 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 483 | short vlan = ethPkt.getVlanID(); |
| 484 | DeviceId deviceId = pkt.receivedFrom().deviceId(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 485 | |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 486 | if (!isConnectPoint(deviceId, pkt.receivedFrom().port()) && |
| 487 | !getSubscriberAndDeviceInformation(deviceId).isPresent()) { |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 488 | log.error("Device not registered in netcfg :" + deviceId.toString()); |
| 489 | return; |
| 490 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 491 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 492 | IGMP igmp = (IGMP) ipv4Pkt.getPayload(); |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 493 | |
| 494 | Optional<PortNumber> deviceUpLinkOpt = getDeviceUplink(deviceId); |
| 495 | PortNumber upLinkPort = deviceUpLinkOpt.isPresent() ? deviceUpLinkOpt.get() : null; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 496 | switch (igmp.getIgmpType()) { |
| 497 | case IGMP.TYPE_IGMPV3_MEMBERSHIP_QUERY: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 498 | igmpStatisticsManager.getIgmpStats().increaseIgmpv3MembershipQuery(); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 499 | //Discard Query from OLT’s non-uplink port’s |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 500 | if (!pkt.receivedFrom().port().equals(upLinkPort)) { |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 501 | if (isConnectPoint(deviceId, pkt.receivedFrom().port())) { |
| 502 | log.info("IGMP Picked up query from connectPoint"); |
| 503 | //OK to process packet |
| 504 | processIgmpConnectPointQuery((IGMPQuery) igmp.getGroups().get(0), |
| 505 | pkt.receivedFrom(), |
| 506 | 0xff & igmp.getMaxRespField()); |
| 507 | break; |
| 508 | } else { |
| 509 | //Not OK to process packet |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 510 | log.warn("IGMP Picked up query from non-uplink port {}", upLinkPort); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 511 | return; |
| 512 | } |
| 513 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 514 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 515 | processIgmpQuery((IGMPQuery) igmp.getGroups().get(0), pkt.receivedFrom(), |
| 516 | 0xff & igmp.getMaxRespField()); |
| 517 | break; |
| 518 | case IGMP.TYPE_IGMPV1_MEMBERSHIP_REPORT: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 519 | igmpStatisticsManager.getIgmpStats().increaseIgmpv1MembershipReport(); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 520 | log.debug("IGMP version 1 message types are not currently supported."); |
| 521 | break; |
| 522 | case IGMP.TYPE_IGMPV3_MEMBERSHIP_REPORT: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 523 | igmpStatisticsManager.getIgmpStats().increaseIgmpv3MembershipReport(); |
| 524 | processIgmpMessage(pkt, igmp, upLinkPort, vlan); |
| 525 | break; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 526 | case IGMP.TYPE_IGMPV2_MEMBERSHIP_REPORT: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 527 | igmpStatisticsManager.getIgmpStats().increaseIgmpv2MembershipReport(); |
| 528 | processIgmpMessage(pkt, igmp, upLinkPort, vlan); |
| 529 | break; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 530 | case IGMP.TYPE_IGMPV2_LEAVE_GROUP: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 531 | igmpStatisticsManager.getIgmpStats().increaseIgmpv2LeaveGroup(); |
| 532 | processIgmpMessage(pkt, igmp, upLinkPort, vlan); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 533 | break; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 534 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 535 | default: |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 536 | log.warn("wrong IGMP v3 type:" + igmp.getIgmpType()); |
| 537 | igmpStatisticsManager.getIgmpStats().increaseInvalidIgmpMsgReceived(); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 538 | break; |
| 539 | } |
| 540 | |
| 541 | } catch (Exception ex) { |
| 542 | log.error("igmp process error : {} ", ex); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 543 | } |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 544 | }); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 548 | private void processIgmpMessage(InboundPacket pkt, IGMP igmp, PortNumber upLinkPort, short vlan) { |
| 549 | //Discard join/leave from OLT’s uplink port’s |
| 550 | if (pkt.receivedFrom().port().equals(upLinkPort) || |
| 551 | isConnectPoint(pkt.receivedFrom().deviceId(), pkt.receivedFrom().port())) { |
| 552 | log.info("IGMP Picked up join/leave from uplink/connectPoint port"); |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | Iterator<IGMPGroup> itr = igmp.getGroups().iterator(); |
| 557 | while (itr.hasNext()) { |
| 558 | IGMPGroup group = itr.next(); |
| 559 | if (group instanceof IGMPMembership) { |
| 560 | processIgmpReport((IGMPMembership) group, VlanId.vlanId(vlan), |
| 561 | pkt.receivedFrom(), igmp.getIgmpType()); |
| 562 | } else { |
| 563 | IGMPMembership mgroup = new IGMPMembership(group.getGaddr().getIp4Address()); |
| 564 | mgroup.setRecordType(igmp.getIgmpType() == IGMP.TYPE_IGMPV2_MEMBERSHIP_REPORT ? |
| 565 | IGMPMembership.MODE_IS_EXCLUDE : |
| 566 | IGMPMembership.MODE_IS_INCLUDE); |
| 567 | processIgmpReport(mgroup, VlanId.vlanId(vlan), |
| 568 | pkt.receivedFrom(), igmp.getIgmpType()); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | } |
| 573 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 574 | private class IgmpProxyTimerTask extends TimerTask { |
| 575 | public void run() { |
| 576 | try { |
| 577 | IgmpTimer.timeOut1s(); |
| 578 | queryMembers(); |
| 579 | } catch (Exception ex) { |
| 580 | log.warn("Igmp timer task error : {}", ex.getMessage()); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | private void queryMembers() { |
| 585 | GroupMember groupMember; |
| 586 | Set groupMemberSet = groupMemberMap.entrySet(); |
| 587 | Iterator itr = groupMemberSet.iterator(); |
| 588 | while (itr.hasNext()) { |
| 589 | Map.Entry entry = (Map.Entry) itr.next(); |
| 590 | groupMember = (GroupMember) entry.getValue(); |
| 591 | DeviceId did = groupMember.getDeviceId(); |
| 592 | if (mastershipService.isLocalMaster(did)) { |
| 593 | if (groupMember.isLeave()) { |
| 594 | lastQuery(groupMember); |
| 595 | } else if (periodicQuery) { |
| 596 | periodicQuery(groupMember); |
| 597 | } |
| 598 | } |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | private void lastQuery(GroupMember groupMember) { |
| 603 | if (groupMember.getLastQueryInterval() < lastQueryInterval) { |
| 604 | groupMember.lastQueryInterval(true); // count times |
| 605 | } else if (groupMember.getLastQueryCount() < lastQueryCount - 1) { |
| 606 | sendQuery(groupMember); |
| 607 | groupMember.lastQueryInterval(false); // reset count number |
| 608 | groupMember.lastQueryCount(true); //count times |
| 609 | } else if (groupMember.getLastQueryCount() == lastQueryCount - 1) { |
| 610 | leaveAction(groupMember); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | private void periodicQuery(GroupMember groupMember) { |
| 615 | if (groupMember.getKeepAliveQueryInterval() < keepAliveInterval) { |
| 616 | groupMember.keepAliveInterval(true); |
| 617 | } else if (groupMember.getKeepAliveQueryCount() < keepAliveCount) { |
| 618 | sendQuery(groupMember); |
| 619 | groupMember.keepAliveInterval(false); |
| 620 | groupMember.keepAliveQueryCount(true); |
| 621 | } else if (groupMember.getKeepAliveQueryCount() == keepAliveCount) { |
| 622 | leaveAction(groupMember); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | } |
| 627 | |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 628 | public Optional<PortNumber> getDeviceUplink(DeviceId devId) { |
| 629 | Device device = deviceService.getDevice(devId); |
| 630 | if (device == null || device.serialNumber() == null) { |
| 631 | return Optional.empty(); |
Deepa Vaddireddy | bcd5235 | 2017-09-21 05:04:48 +0000 | [diff] [blame] | 632 | } |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 633 | Optional<SubscriberAndDeviceInformation> olt = getSubscriberAndDeviceInformation(device.serialNumber()); |
| 634 | if (olt.isEmpty()) { |
| 635 | return Optional.empty(); |
| 636 | } |
| 637 | PortNumber portNumber = PortNumber.portNumber(olt.get().uplinkPort()); |
| 638 | return validateUpLinkPort(device.id(), portNumber) ? |
| 639 | Optional.of(portNumber) : Optional.empty(); |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * |
| 644 | * @param deviceId device id |
| 645 | * @param portNumber port number |
| 646 | * @return true if the port name starts with NNI_PREFIX; false otherwise. |
| 647 | */ |
| 648 | public boolean validateUpLinkPort(DeviceId deviceId, PortNumber portNumber) { |
| 649 | Port port = deviceService.getPort(deviceId, portNumber); |
| 650 | if (port == null) { |
| 651 | //port is not discovered by ONOS; so cannot validate it. |
| 652 | return false; |
| 653 | } |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 654 | boolean isValid = port.annotations().value(AnnotationKeys.PORT_NAME) != null && |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 655 | port.annotations().value(AnnotationKeys.PORT_NAME).startsWith(NNI_PREFIX); |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 656 | if (!isValid) { |
| 657 | log.warn("Port cannot be validated; it is not configured as an NNI port." + |
| 658 | "Device/port: {}/{}", deviceId, portNumber); |
| 659 | } |
| 660 | return isValid; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 661 | } |
| 662 | |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 663 | public static boolean isIgmpOnPodBasis() { |
| 664 | return igmpOnPodBasis; |
| 665 | } |
| 666 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 667 | private void processFilterObjective(DeviceId devId, PortNumber port, boolean remove) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 668 | if (!enableIgmpProvisioning) { |
| 669 | log.debug("IGMP trap rules won't be installed since enableIgmpProvisioning flag is not set"); |
| 670 | return; |
| 671 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 672 | //TODO migrate to packet requests when packet service uses filtering objectives |
| 673 | DefaultFilteringObjective.Builder builder = DefaultFilteringObjective.builder(); |
| 674 | |
| 675 | builder = remove ? builder.deny() : builder.permit(); |
| 676 | |
| 677 | FilteringObjective igmp = builder |
| 678 | .withKey(Criteria.matchInPort(port)) |
| 679 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 680 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 681 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 682 | .fromApp(appId) |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 683 | .withPriority(MAX_PRIORITY) |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 684 | .add(new ObjectiveContext() { |
| 685 | @Override |
| 686 | public void onSuccess(Objective objective) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 687 | log.info("Igmp filter for {} on {} {}.", |
| 688 | devId, port, (remove) ? REMOVED : INSTALLED); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | @Override |
| 692 | public void onError(Objective objective, ObjectiveError error) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 693 | log.info("Igmp filter {} for device {} on port {} failed because of {}", |
| 694 | (remove) ? INSTALLATION : REMOVAL, devId, port, |
| 695 | error); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 696 | } |
| 697 | }); |
| 698 | |
| 699 | flowObjectiveService.filter(devId, igmp); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 700 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | private boolean isConnectPoint(DeviceId device, PortNumber port) { |
Deepa Vaddireddy | 01f33b4 | 2017-07-02 13:26:53 +0530 | [diff] [blame] | 704 | if (connectPoint != null) { |
| 705 | return (connectPointMode && connectPoint.deviceId().equals(device) |
| 706 | && connectPoint.port().equals(port)); |
| 707 | } else { |
| 708 | log.info("connectPoint not configured for device {}", device); |
| 709 | return false; |
| 710 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 711 | } |
Deepa Vaddireddy | 01f33b4 | 2017-07-02 13:26:53 +0530 | [diff] [blame] | 712 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 713 | private boolean isUplink(DeviceId device, PortNumber port) { |
Esin Karaman | ce5ce51 | 2020-02-25 15:58:14 +0000 | [diff] [blame] | 714 | if (connectPointMode) { |
| 715 | return false; |
| 716 | } |
| 717 | Optional<PortNumber> upLinkPort = getDeviceUplink(device); |
| 718 | return upLinkPort.isPresent() && upLinkPort.get().equals(port); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 719 | } |
| 720 | |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 721 | /** |
| 722 | * Fetches device information associated with the device serial number from SADIS. |
| 723 | * |
| 724 | * @param serialNumber serial number of a device |
| 725 | * @return device information; an empty Optional otherwise. |
| 726 | */ |
| 727 | private Optional<SubscriberAndDeviceInformation> getSubscriberAndDeviceInformation(String serialNumber) { |
| 728 | long start = System.currentTimeMillis(); |
| 729 | try { |
| 730 | return Optional.ofNullable(sadisService.getSubscriberInfoService().get(serialNumber)); |
| 731 | } finally { |
| 732 | if (log.isDebugEnabled()) { |
| 733 | // SADIS can call remote systems to fetch device data and this calls can take a long time. |
| 734 | // This measurement is just for monitoring these kinds of situations. |
| 735 | log.debug("Device fetched from SADIS. Elapsed {} msec", System.currentTimeMillis() - start); |
| 736 | } |
| 737 | |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * Fetches device information associated with the device serial number from SADIS. |
| 743 | * |
| 744 | * @param deviceId device id |
| 745 | * @return device information; an empty Optional otherwise. |
| 746 | */ |
| 747 | private Optional<SubscriberAndDeviceInformation> getSubscriberAndDeviceInformation(DeviceId deviceId) { |
| 748 | Device device = deviceService.getDevice(deviceId); |
| 749 | if (device == null || device.serialNumber() == null) { |
| 750 | return Optional.empty(); |
| 751 | } |
| 752 | return getSubscriberAndDeviceInformation(device.serialNumber()); |
| 753 | } |
| 754 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 755 | private class InternalDeviceListener implements DeviceListener { |
| 756 | @Override |
| 757 | public void event(DeviceEvent event) { |
| 758 | DeviceId devId = event.subject().id(); |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 759 | Port p = event.port(); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 760 | if (getSubscriberAndDeviceInformation(devId).isEmpty() && |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 761 | !(p != null && isConnectPoint(devId, p.number()))) { |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 762 | return; |
| 763 | } |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 764 | PortNumber port; |
| 765 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 766 | switch (event.type()) { |
| 767 | |
| 768 | case DEVICE_ADDED: |
| 769 | case DEVICE_UPDATED: |
| 770 | case DEVICE_REMOVED: |
| 771 | case DEVICE_SUSPENDED: |
| 772 | case DEVICE_AVAILABILITY_CHANGED: |
| 773 | case PORT_STATS_UPDATED: |
| 774 | break; |
| 775 | case PORT_ADDED: |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 776 | port = p.number(); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 777 | if (getSubscriberAndDeviceInformation(devId).isPresent() && |
| 778 | !isUplink(devId, port) && !isConnectPoint(devId, port)) { |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 779 | processFilterObjective(devId, port, false); |
| 780 | } else if (isUplink(devId, port)) { |
| 781 | provisionUplinkFlows(); |
| 782 | } else if (isConnectPoint(devId, port)) { |
| 783 | provisionConnectPointFlows(); |
| 784 | } |
| 785 | break; |
| 786 | case PORT_UPDATED: |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 787 | port = p.number(); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 788 | if (getSubscriberAndDeviceInformation(devId).isPresent() && |
| 789 | !isUplink(devId, port) && !isConnectPoint(devId, port)) { |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 790 | if (event.port().isEnabled()) { |
| 791 | processFilterObjective(devId, port, false); |
| 792 | } else { |
| 793 | processFilterObjective(devId, port, true); |
| 794 | } |
| 795 | } else if (isUplink(devId, port)) { |
| 796 | if (event.port().isEnabled()) { |
| 797 | provisionUplinkFlows(devId); |
| 798 | } else { |
| 799 | processFilterObjective(devId, port, true); |
| 800 | } |
| 801 | } else if (isConnectPoint(devId, port)) { |
| 802 | if (event.port().isEnabled()) { |
| 803 | provisionConnectPointFlows(); |
| 804 | } else { |
| 805 | unprovisionConnectPointFlows(); |
| 806 | } |
| 807 | } |
| 808 | break; |
| 809 | case PORT_REMOVED: |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 810 | port = p.number(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 811 | processFilterObjective(devId, port, true); |
| 812 | break; |
| 813 | default: |
| 814 | log.info("Unknown device event {}", event.type()); |
| 815 | break; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public boolean isRelevant(DeviceEvent event) { |
| 821 | return true; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | private class InternalNetworkConfigListener implements NetworkConfigListener { |
| 826 | |
| 827 | private void reconfigureNetwork(IgmpproxyConfig cfg) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 828 | IgmpproxyConfig newCfg = cfg == null ? new IgmpproxyConfig() : cfg; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 829 | |
| 830 | unSolicitedTimeout = newCfg.unsolicitedTimeOut(); |
| 831 | maxResp = newCfg.maxResp(); |
| 832 | keepAliveInterval = newCfg.keepAliveInterval(); |
| 833 | keepAliveCount = newCfg.keepAliveCount(); |
| 834 | lastQueryInterval = newCfg.lastQueryInterval(); |
| 835 | lastQueryCount = newCfg.lastQueryCount(); |
| 836 | withRAUplink = newCfg.withRAUplink(); |
| 837 | withRADownlink = newCfg.withRADownlink(); |
| 838 | igmpCos = newCfg.igmpCos(); |
| 839 | periodicQuery = newCfg.periodicQuery(); |
| 840 | fastLeave = newCfg.fastLeave(); |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 841 | pimSSmInterworking = newCfg.pimSsmInterworking(); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 842 | enableIgmpProvisioning = newCfg.enableIgmpProvisioning(); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 843 | igmpOnPodBasis = newCfg.igmpOnPodBasis(); |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 844 | |
| 845 | if (connectPointMode != newCfg.connectPointMode() || |
| 846 | connectPoint != newCfg.connectPoint()) { |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 847 | connectPointMode = newCfg.connectPointMode(); |
Deepa Vaddireddy | ca7b25d | 2017-09-28 13:47:18 +0000 | [diff] [blame] | 848 | connectPoint = newCfg.connectPoint(); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 849 | if (connectPointMode) { |
| 850 | unprovisionUplinkFlows(); |
| 851 | provisionConnectPointFlows(); |
| 852 | } else { |
| 853 | unprovisionConnectPointFlows(); |
| 854 | provisionUplinkFlows(); |
| 855 | } |
| 856 | } |
| 857 | if (connectPoint != null) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 858 | log.info("connect point : {}", connectPoint); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 859 | } |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 860 | log.info("mode: {}", connectPointMode); |
| 861 | |
| 862 | getSourceConnectPoint(newCfg); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 863 | |
| 864 | IgmpSender.getInstance().setIgmpCos(igmpCos); |
| 865 | IgmpSender.getInstance().setMaxResp(maxResp); |
| 866 | IgmpSender.getInstance().setMvlan(mvlan); |
| 867 | IgmpSender.getInstance().setWithRADownlink(withRADownlink); |
| 868 | IgmpSender.getInstance().setWithRAUplink(withRAUplink); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 869 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 870 | |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 871 | void getSourceConnectPoint(IgmpproxyConfig cfg) { |
| 872 | sourceDeviceAndPort = cfg.getSourceDeviceAndPort(); |
| 873 | if (sourceDeviceAndPort != null) { |
| 874 | log.debug("source parameter configured to {}", sourceDeviceAndPort); |
| 875 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | public void reconfigureSsmTable(IgmpproxySsmTranslateConfig cfg) { |
| 879 | if (cfg == null) { |
| 880 | return; |
| 881 | } |
| 882 | Collection<McastRoute> translations = cfg.getSsmTranslations(); |
| 883 | for (McastRoute route : translations) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 884 | ssmTranslateTable.put(route.group().getIp4Address(), route.source().get().getIp4Address()); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 885 | } |
| 886 | } |
| 887 | |
| 888 | @Override |
| 889 | public void event(NetworkConfigEvent event) { |
| 890 | switch (event.type()) { |
| 891 | case CONFIG_ADDED: |
| 892 | case CONFIG_UPDATED: |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 893 | // NOTE how to know if something has changed in sadis? |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 894 | |
| 895 | if (event.configClass().equals(IGMPPROXY_CONFIG_CLASS)) { |
| 896 | IgmpproxyConfig config = networkConfig.getConfig(appId, IGMPPROXY_CONFIG_CLASS); |
| 897 | if (config != null) { |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 898 | log.info("igmpproxy config received. {}", config); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 899 | reconfigureNetwork(config); |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | if (event.configClass().equals(IGMPPROXY_SSM_CONFIG_CLASS)) { |
| 904 | IgmpproxySsmTranslateConfig config = networkConfig.getConfig(appId, IGMPPROXY_SSM_CONFIG_CLASS); |
| 905 | if (config != null) { |
| 906 | reconfigureSsmTable(config); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | if (event.configClass().equals(MCAST_CONFIG_CLASS)) { |
| 911 | McastConfig config = networkConfig.getConfig(coreAppId, MCAST_CONFIG_CLASS); |
| 912 | if (config != null && mvlan != config.egressVlan().toShort()) { |
| 913 | mvlan = config.egressVlan().toShort(); |
Deepa Vaddireddy | 88134a4 | 2017-07-05 12:16:03 +0530 | [diff] [blame] | 914 | IgmpSender.getInstance().setMvlan(mvlan); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 915 | groupMemberMap.values().forEach(m -> leaveAction(m)); |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | log.info("Reconfigured"); |
| 920 | break; |
| 921 | case CONFIG_REGISTERED: |
| 922 | case CONFIG_UNREGISTERED: |
| 923 | break; |
| 924 | case CONFIG_REMOVED: |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 925 | // NOTE how to know if something has changed in sadis? |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 926 | default: |
| 927 | break; |
| 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 932 | private void provisionUplinkFlows(DeviceId deviceId) { |
| 933 | if (connectPointMode) { |
| 934 | return; |
| 935 | } |
| 936 | |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 937 | Optional<PortNumber> upLink = getDeviceUplink(deviceId); |
| 938 | if (upLink.isPresent()) { |
| 939 | processFilterObjective(deviceId, upLink.get(), false); |
| 940 | } |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | private void provisionUplinkFlows() { |
| 944 | if (connectPointMode) { |
| 945 | return; |
| 946 | } |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 947 | deviceService.getAvailableDevices().forEach(device -> { |
| 948 | Optional<SubscriberAndDeviceInformation> accessDevice = getSubscriberAndDeviceInformation(device.id()); |
| 949 | if (accessDevice.isPresent()) { |
| 950 | provisionUplinkFlows(device.id()); |
| 951 | } |
| 952 | }); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 953 | } |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 954 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 955 | private void unprovisionUplinkFlows() { |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 956 | deviceService.getAvailableDevices().forEach(device -> { |
| 957 | Optional<SubscriberAndDeviceInformation> accessDevices = getSubscriberAndDeviceInformation(device.id()); |
| 958 | if (accessDevices.isPresent()) { |
| 959 | Optional<PortNumber> upLink = getDeviceUplink(device.id()); |
| 960 | if (upLink.isPresent()) { |
| 961 | processFilterObjective(device.id(), upLink.get(), true); |
| 962 | } |
| 963 | } |
| 964 | }); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | private void provisionConnectPointFlows() { |
| 968 | if ((!connectPointMode) || connectPoint == null) { |
| 969 | return; |
| 970 | } |
| 971 | |
| 972 | processFilterObjective(connectPoint.deviceId(), connectPoint.port(), false); |
| 973 | } |
| 974 | private void unprovisionConnectPointFlows() { |
| 975 | if (connectPoint == null) { |
| 976 | return; |
| 977 | } |
| 978 | processFilterObjective(connectPoint.deviceId(), connectPoint.port(), true); |
| 979 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame^] | 980 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 981 | } |