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