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