Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 17 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame^] | 19 | import com.google.common.collect.Lists; |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 20 | import com.google.common.collect.Maps; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 21 | import org.onlab.packet.Ethernet; |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 22 | import org.onlab.packet.IGMP; |
| 23 | import org.onlab.packet.IGMPMembership; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 24 | import org.onlab.packet.Ip4Address; |
| 25 | import org.onlab.packet.IpAddress; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 26 | import org.onlab.packet.MacAddress; |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 27 | import org.onlab.packet.VlanId; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 28 | import org.onosproject.cfg.ComponentConfigService; |
| 29 | import org.onosproject.cfg.ConfigProperty; |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame^] | 30 | import org.onosproject.cluster.Leader; |
| 31 | import org.onosproject.cluster.Leadership; |
| 32 | import org.onosproject.cluster.NodeId; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 34 | import org.onosproject.event.DefaultEventSinkRegistry; |
| 35 | import org.onosproject.event.Event; |
| 36 | import org.onosproject.event.EventDeliveryService; |
| 37 | import org.onosproject.event.EventSink; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 38 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 39 | import org.onosproject.mcast.api.McastListener; |
| 40 | import org.onosproject.mcast.api.McastRoute; |
| 41 | import org.onosproject.mcast.api.McastRouteData; |
| 42 | import org.onosproject.mcast.api.MulticastRouteService; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 43 | import org.onosproject.net.AnnotationKeys; |
| 44 | import org.onosproject.net.Annotations; |
| 45 | import org.onosproject.net.ConnectPoint; |
| 46 | import org.onosproject.net.DefaultAnnotations; |
| 47 | import org.onosproject.net.DefaultDevice; |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 48 | import org.onosproject.net.DefaultPort; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 49 | import org.onosproject.net.Device; |
| 50 | import org.onosproject.net.DeviceId; |
| 51 | import org.onosproject.net.HostId; |
| 52 | import org.onosproject.net.Port; |
| 53 | import org.onosproject.net.PortNumber; |
| 54 | import org.onosproject.net.SparseAnnotations; |
| 55 | import org.onosproject.net.config.Config; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 56 | import org.onosproject.net.config.ConfigFactory; |
| 57 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 58 | import org.onosproject.net.config.basics.McastConfig; |
| 59 | import org.onosproject.net.config.basics.SubjectFactories; |
| 60 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 61 | import org.onosproject.net.packet.DefaultInboundPacket; |
| 62 | import org.onosproject.net.packet.DefaultPacketContext; |
| 63 | import org.onosproject.net.packet.InboundPacket; |
| 64 | import org.onosproject.net.packet.OutboundPacket; |
| 65 | import org.onosproject.net.packet.PacketContext; |
| 66 | import org.onosproject.net.packet.PacketProcessor; |
| 67 | import org.onosproject.net.packet.PacketServiceAdapter; |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 68 | import org.opencord.igmpproxy.IgmpLeadershipService; |
| 69 | import org.opencord.igmpproxy.impl.store.groupmember.AbstractGroupMemberStore; |
| 70 | import org.opencord.igmpproxy.impl.store.machine.AbstractStateMachineStore; |
| 71 | import org.opencord.igmpproxy.statemachine.StateMachine; |
| 72 | import org.opencord.igmpproxy.statemachine.StateMachineId; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 73 | import org.opencord.sadis.BandwidthProfileInformation; |
| 74 | import org.opencord.sadis.BaseInformationService; |
| 75 | import org.opencord.sadis.SadisService; |
| 76 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 77 | import org.osgi.framework.Bundle; |
| 78 | import org.osgi.framework.BundleContext; |
| 79 | import org.osgi.framework.ServiceReference; |
| 80 | import org.osgi.service.component.ComponentContext; |
| 81 | import org.osgi.service.component.ComponentInstance; |
| 82 | |
| 83 | import static com.google.common.base.Preconditions.checkState; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 84 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 85 | import java.nio.ByteBuffer; |
| 86 | import java.util.ArrayList; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 87 | import java.util.Dictionary; |
| 88 | import java.util.Hashtable; |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 89 | import java.util.LinkedList; |
| 90 | import java.util.List; |
| 91 | import java.util.Set; |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 92 | import java.util.Map; |
| 93 | import java.util.concurrent.atomic.AtomicLong; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 94 | |
| 95 | public class IgmpManagerBase { |
| 96 | |
| 97 | // Device configuration |
| 98 | protected static final DeviceId DEVICE_ID_OF_A = DeviceId.deviceId("of:1"); |
| 99 | protected static final DeviceId DEVICE_ID_OF_B = DeviceId.deviceId("of:2"); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 100 | protected static final DeviceId DEVICE_ID_OF_C = DeviceId.deviceId("of:00000000000000003"); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 101 | |
| 102 | //Multicast ip address |
| 103 | protected static final Ip4Address GROUP_IP = Ip4Address.valueOf("224.0.0.0"); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 104 | //Unknown group Ip address |
| 105 | protected static final Ip4Address UNKNOWN_GRP_IP = Ip4Address.valueOf("124.0.0.0"); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 106 | // Source ip address of two different device. |
| 107 | protected static final Ip4Address SOURCE_IP_OF_A = Ip4Address.valueOf("10.177.125.4"); |
| 108 | protected static final Ip4Address SOURCE_IP_OF_B = Ip4Address.valueOf("10.177.125.5"); |
| 109 | |
| 110 | // Common connect point of aggregation switch used by all devices. |
| 111 | protected static final ConnectPoint COMMON_CONNECT_POINT = |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 112 | ConnectPoint.deviceConnectPoint("of:00000000000000003/3"); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 113 | // Uplink ports for two olts A and B |
| 114 | protected static final PortNumber PORT_A = PortNumber.portNumber(1); |
| 115 | protected static final PortNumber PORT_B = PortNumber.portNumber(2); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 116 | protected static final PortNumber PORT_C = PortNumber.portNumber(3); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 117 | protected static final PortNumber PORT_NNI = PortNumber.portNumber(65536); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 118 | |
| 119 | // Connect Point mode for two olts |
| 120 | protected static final ConnectPoint CONNECT_POINT_A = new ConnectPoint(DEVICE_ID_OF_A, PORT_A); |
| 121 | protected static final ConnectPoint CONNECT_POINT_B = new ConnectPoint(DEVICE_ID_OF_B, PORT_B); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 122 | protected static final ConnectPoint CONNECT_POINT_C = new ConnectPoint(DEVICE_ID_OF_C, PORT_C); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 123 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 124 | protected static final String CLIENT_NAS_PORT_ID = "PON 1/1"; |
| 125 | protected static final String CLIENT_CIRCUIT_ID = "CIR-PON 1/1"; |
| 126 | protected String dsBpId = "HSIA-DS"; |
| 127 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 128 | private static final int STATISTICS_GEN_PERIOD_IN_SEC = 2; |
| 129 | |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 130 | private static final String NNI_PREFIX = "nni"; |
| 131 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 132 | protected List<Port> lsPorts = new ArrayList<Port>(); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 133 | protected List<Device> lsDevices = new ArrayList<Device>(); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 134 | // Flag for adding two different devices in oltData |
| 135 | protected boolean flagForDevice = true; |
| 136 | PacketContext context; |
| 137 | // Flag for sending two different packets |
| 138 | protected boolean flagForPacket = true; |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 139 | // Flag for sending two different packets |
| 140 | protected boolean flagForQueryPacket = false; |
| 141 | // Flag to check permission |
| 142 | boolean flagForPermission = false; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 143 | // List to store the packets emitted |
| 144 | protected List<OutboundPacket> savedPackets; |
| 145 | protected PacketProcessor packetProcessor; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 146 | |
| 147 | class MockDeviceService extends DeviceServiceAdapter { |
| 148 | |
| 149 | @Override |
| 150 | public Device getDevice(DeviceId deviceId) { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 151 | if (flagForDevice) { |
| 152 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
| 153 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, SOURCE_IP_OF_A.toString()); |
| 154 | SparseAnnotations annotations = annotationsBuilder.build(); |
| 155 | Annotations[] da = {annotations}; |
| 156 | Device deviceA = new DefaultDevice(null, DEVICE_ID_OF_A, Device.Type.OTHER, "", "", "", "", null, da); |
| 157 | flagForDevice = false; |
| 158 | return deviceA; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 159 | } else { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 160 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
| 161 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, SOURCE_IP_OF_B.toString()); |
| 162 | SparseAnnotations annotations = annotationsBuilder.build(); |
| 163 | Annotations[] da = {annotations}; |
| 164 | Device deviceB = new DefaultDevice(null, DEVICE_ID_OF_B, Device.Type.OTHER, "", "", "", "", null, da); |
| 165 | return deviceB; |
| 166 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 167 | } |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 168 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 169 | @Override |
| 170 | public List<Port> getPorts(DeviceId deviceId) { |
| 171 | return lsPorts; |
| 172 | } |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 173 | |
| 174 | @Override |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 175 | public Iterable<Device> getAvailableDevices() { |
| 176 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
| 177 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, SOURCE_IP_OF_A.toString()); |
| 178 | SparseAnnotations annotations = annotationsBuilder.build(); |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 179 | Annotations[] da = {annotations}; |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 180 | Device deviceA = new DefaultDevice(null, DEVICE_ID_OF_C, Device.Type.OTHER, "", "", "", "", null, da); |
| 181 | lsDevices.add(deviceA); |
| 182 | return lsDevices; |
| 183 | } |
| 184 | |
| 185 | @Override |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 186 | public Port getPort(DeviceId deviceId, PortNumber portNumber) { |
| 187 | if (portNumber.equals(PORT_NNI)) { |
| 188 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
| 189 | .set(AnnotationKeys.PORT_NAME, NNI_PREFIX); |
| 190 | Port nni = new DefaultPort(null, portNumber, true, annotationsBuilder.build()); |
| 191 | return nni; |
| 192 | } |
| 193 | return super.getPort(deviceId, portNumber); |
| 194 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 197 | static final Class<IgmpproxyConfig> IGMPPROXY_CONFIG_CLASS = IgmpproxyConfig.class; |
| 198 | static final Class<IgmpproxySsmTranslateConfig> IGMPPROXY_SSM_CONFIG_CLASS = IgmpproxySsmTranslateConfig.class; |
| 199 | static final Class<McastConfig> MCAST_CONFIG_CLASS = McastConfig.class; |
| 200 | ConfigFactory<ApplicationId, IgmpproxyConfig> igmpproxyConfigFactory = |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 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 | }; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 208 | |
| 209 | ConfigFactory<ApplicationId, IgmpproxySsmTranslateConfig> igmpproxySsmConfigFactory = |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 210 | new ConfigFactory<ApplicationId, IgmpproxySsmTranslateConfig>( |
| 211 | SubjectFactories.APP_SUBJECT_FACTORY, IGMPPROXY_SSM_CONFIG_CLASS, "ssmTranslate", true) { |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 212 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 213 | @Override |
| 214 | public IgmpproxySsmTranslateConfig createConfig() { |
| 215 | return new IgmpproxySsmTranslateConfig(); |
| 216 | } |
| 217 | }; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 218 | |
| 219 | |
| 220 | class MockIgmpProxyConfig extends IgmpproxyConfig { |
| 221 | boolean igmpOnPodBasis = true; |
| 222 | |
| 223 | MockIgmpProxyConfig(boolean igmpFlagValue) { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 224 | igmpOnPodBasis = igmpFlagValue; |
| 225 | } |
| 226 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 227 | @Override |
| 228 | public boolean igmpOnPodBasis() { |
| 229 | return igmpOnPodBasis; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public ConnectPoint getSourceDeviceAndPort() { |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 234 | if (flagForPermission) { |
| 235 | return null; |
| 236 | } |
| 237 | return COMMON_CONNECT_POINT; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public ConnectPoint connectPoint() { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 242 | return COMMON_CONNECT_POINT; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
| 246 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 247 | class TestNetworkConfigRegistry extends NetworkConfigRegistryAdapter { |
| 248 | Boolean igmpOnPodFlag = false; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 249 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 250 | TestNetworkConfigRegistry(Boolean igmpFlag) { |
| 251 | igmpOnPodFlag = igmpFlag; |
| 252 | } |
| 253 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 254 | @SuppressWarnings("unchecked") |
| 255 | @Override |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 256 | public <S> Set<S> getSubjects(Class<S> subjectClass) { |
| 257 | if (subjectClass.getName().equalsIgnoreCase("org.onosproject.net.DeviceId")) { |
| 258 | return (Set<S>) ImmutableSet.of(DEVICE_ID_OF_A, DEVICE_ID_OF_B); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 259 | } |
| 260 | return null; |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 261 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 262 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 263 | @SuppressWarnings("unchecked") |
| 264 | @Override |
| 265 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
| 266 | if (configClass.getName().equalsIgnoreCase("org.opencord.igmpproxy.impl.IgmpproxyConfig")) { |
| 267 | IgmpproxyConfig igmpproxyConfig = new MockIgmpProxyConfig(igmpOnPodFlag); |
| 268 | return (C) igmpproxyConfig; |
| 269 | } else { |
| 270 | super.getConfig(subject, configClass); |
| 271 | } |
| 272 | return null; |
| 273 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
| 277 | /** |
| 278 | * Keeps a reference to the PacketProcessor and saves the OutboundPackets. Adds |
| 279 | * the emitted packet in savedPackets list |
| 280 | */ |
| 281 | class MockPacketService extends PacketServiceAdapter { |
| 282 | |
| 283 | public MockPacketService() { |
| 284 | savedPackets = new LinkedList<>(); |
| 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public void addProcessor(PacketProcessor processor, int priority) { |
| 289 | packetProcessor = processor; |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void emit(OutboundPacket packet) { |
| 294 | synchronized (savedPackets) { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 295 | savedPackets.add(packet); |
| 296 | savedPackets.notify(); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 299 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 300 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 301 | class TestIgmpLeaderShipService implements IgmpLeadershipService { |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame^] | 302 | private NodeId nodeId = NodeId.nodeId("test-id"); |
| 303 | private Leader leader = new Leader(nodeId, 0, 0); |
| 304 | private static final String TEST_TOPIC = "igmp-statistics"; |
| 305 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 306 | @Override |
| 307 | public boolean isLocalLeader(DeviceId deviceId) { |
| 308 | return true; |
| 309 | } |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame^] | 310 | |
| 311 | @Override |
| 312 | public NodeId getLocalNodeId() { |
| 313 | return nodeId; |
| 314 | } |
| 315 | |
| 316 | @Override |
| 317 | public NodeId getLeader(String topic) { |
| 318 | return nodeId; |
| 319 | } |
| 320 | |
| 321 | @Override |
| 322 | public Leadership runForLeadership(String topic) { |
| 323 | return new Leadership(TEST_TOPIC, leader, Lists.newArrayList(nodeId)); |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public void withdraw(String topic) { |
| 328 | |
| 329 | } |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 330 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 331 | |
| 332 | class MockMastershipService extends MastershipServiceAdapter { |
| 333 | @Override |
| 334 | public boolean isLocalMaster(DeviceId deviceId) { |
| 335 | return true; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | final class TestMulticastRouteService implements MulticastRouteService { |
| 340 | @Override |
| 341 | public void addListener(McastListener listener) { |
| 342 | } |
| 343 | |
| 344 | @Override |
| 345 | public void removeListener(McastListener listener) { |
| 346 | } |
| 347 | |
| 348 | @Override |
| 349 | public void add(McastRoute route) { |
| 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public void remove(McastRoute route) { |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public Set<McastRoute> getRoutes() { |
| 358 | return null; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public Set<McastRoute> getRoute(IpAddress groupIp, IpAddress sourceIp) { |
| 363 | return null; |
| 364 | } |
| 365 | |
| 366 | @Override |
| 367 | public void addSource(McastRoute route, HostId source) { |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void addSources(McastRoute route, HostId hostId, Set<ConnectPoint> connectPoints) { |
| 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void addSources(McastRoute route, Set<ConnectPoint> sources) { |
| 376 | |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public void removeSources(McastRoute route) { |
| 381 | |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void removeSource(McastRoute route, HostId source) { |
| 386 | |
| 387 | } |
| 388 | |
| 389 | @Override |
Esin Karaman | 09b41e5 | 2020-06-01 10:52:55 +0000 | [diff] [blame] | 390 | public void removeSources(McastRoute route, Set<ConnectPoint> sources) { |
| 391 | |
| 392 | } |
| 393 | |
| 394 | @Override |
| 395 | public void removeSources(McastRoute route, HostId hostId, Set<ConnectPoint> connectPoints) { |
| 396 | |
| 397 | } |
| 398 | |
| 399 | @Override |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 400 | public void addSink(McastRoute route, HostId hostId) { |
| 401 | |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public void addSinks(McastRoute route, HostId hostId, Set<ConnectPoint> connectPoints) { |
| 406 | |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public void addSinks(McastRoute route, Set<ConnectPoint> sinks) { |
| 411 | |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void removeSinks(McastRoute route) { |
| 416 | |
| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | public void removeSink(McastRoute route, HostId hostId) { |
| 421 | |
| 422 | } |
| 423 | |
| 424 | @Override |
| 425 | public void removeSinks(McastRoute route, Set<ConnectPoint> sink) { |
| 426 | |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public McastRouteData routeData(McastRoute route) { |
| 431 | return null; |
| 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public Set<ConnectPoint> sources(McastRoute route) { |
| 436 | return null; |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public Set<ConnectPoint> sources(McastRoute route, HostId hostId) { |
| 441 | return null; |
| 442 | } |
| 443 | |
| 444 | @Override |
| 445 | public Set<ConnectPoint> sinks(McastRoute route) { |
| 446 | return null; |
| 447 | } |
| 448 | |
| 449 | @Override |
| 450 | public Set<ConnectPoint> sinks(McastRoute route, HostId hostId) { |
| 451 | return null; |
| 452 | } |
| 453 | |
| 454 | @Override |
| 455 | public Set<ConnectPoint> nonHostSinks(McastRoute route) { |
| 456 | return null; |
| 457 | } |
| 458 | |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /** |
| 463 | * Mocks the DefaultPacketContext. |
| 464 | */ |
| 465 | final class TestPacketContext extends DefaultPacketContext { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 466 | TestPacketContext(long time, InboundPacket inPkt, OutboundPacket outPkt, boolean block) { |
| 467 | super(time, inPkt, outPkt, block); |
| 468 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 469 | |
| 470 | @Override |
| 471 | public void send() { |
| 472 | // We don't send anything out. |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /** |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 477 | * Sends Ethernet packet to the process method of the Packet Processor. |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 478 | * |
| 479 | * @param reply Ethernet packet |
| 480 | * @throws InterruptedException |
| 481 | */ |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 482 | void sendPacket(Ethernet reply) { |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 483 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 484 | if (reply != null) { |
| 485 | final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize()); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 486 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 487 | if (flagForQueryPacket) { |
| 488 | InboundPacket inBoundPacket = new DefaultInboundPacket(CONNECT_POINT_C, reply, byteBuffer); |
| 489 | context = new TestPacketContext(127L, inBoundPacket, null, false); |
| 490 | packetProcessor.process(context); |
| 491 | } else { |
| 492 | if (flagForPacket) { |
| 493 | InboundPacket inPacket = new DefaultInboundPacket(CONNECT_POINT_A, reply, byteBuffer); |
| 494 | context = new TestPacketContext(127L, inPacket, null, false); |
| 495 | flagForPacket = false; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 496 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 497 | packetProcessor.process(context); |
| 498 | } else { |
| 499 | InboundPacket inBoundPacket = new DefaultInboundPacket(CONNECT_POINT_B, reply, byteBuffer); |
| 500 | context = new TestPacketContext(127L, inBoundPacket, null, false); |
| 501 | flagForPacket = true; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 502 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 503 | packetProcessor.process(context); |
| 504 | } |
| 505 | } |
| 506 | } |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 507 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 508 | |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 509 | protected class MockSadisService implements SadisService { |
| 510 | |
| 511 | @Override |
| 512 | public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() { |
| 513 | return new MockSubService(); |
| 514 | } |
| 515 | |
| 516 | @Override |
| 517 | public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() { |
| 518 | return new MockBpService(); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | private class MockBpService implements BaseInformationService<BandwidthProfileInformation> { |
| 523 | |
| 524 | @Override |
| 525 | public void invalidateAll() { |
| 526 | |
| 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public void invalidateId(String id) { |
| 531 | |
| 532 | } |
| 533 | |
| 534 | @Override |
| 535 | public BandwidthProfileInformation get(String id) { |
| 536 | if (id.equals(dsBpId)) { |
| 537 | BandwidthProfileInformation bpInfo = new BandwidthProfileInformation(); |
| 538 | bpInfo.setAssuredInformationRate(0); |
| 539 | bpInfo.setCommittedInformationRate(10000); |
| 540 | bpInfo.setCommittedBurstSize(1000L); |
| 541 | bpInfo.setExceededBurstSize(2000L); |
| 542 | bpInfo.setExceededInformationRate(20000); |
| 543 | return bpInfo; |
| 544 | } |
| 545 | return null; |
| 546 | } |
| 547 | |
| 548 | @Override |
| 549 | public BandwidthProfileInformation getfromCache(String id) { |
| 550 | return null; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> { |
| 555 | MockSubscriberAndDeviceInformation sub = |
| 556 | new MockSubscriberAndDeviceInformation(CLIENT_NAS_PORT_ID, |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 557 | CLIENT_NAS_PORT_ID, CLIENT_CIRCUIT_ID, null, null); |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 558 | |
| 559 | @Override |
| 560 | public SubscriberAndDeviceInformation get(String id) { |
| 561 | return sub; |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void invalidateAll() { |
| 566 | } |
| 567 | |
| 568 | @Override |
| 569 | public void invalidateId(String id) { |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public SubscriberAndDeviceInformation getfromCache(String id) { |
| 574 | return null; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation { |
| 579 | |
| 580 | MockSubscriberAndDeviceInformation(String id, String nasPortId, |
| 581 | String circuitId, MacAddress hardId, |
| 582 | Ip4Address ipAddress) { |
| 583 | this.setHardwareIdentifier(hardId); |
| 584 | this.setId(id); |
| 585 | this.setIPAddress(ipAddress); |
| 586 | this.setNasPortId(nasPortId); |
| 587 | this.setCircuitId(circuitId); |
Esin Karaman | 00e16b7 | 2020-02-21 10:32:39 +0000 | [diff] [blame] | 588 | this.setUplinkPort((int) PORT_NNI.toLong()); |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 592 | protected class MockCfgService implements ComponentConfigService { |
| 593 | |
| 594 | @Override |
| 595 | public Set<String> getComponentNames() { |
| 596 | return null; |
| 597 | } |
| 598 | |
| 599 | @Override |
| 600 | public void registerProperties(Class<?> componentClass) { |
| 601 | |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | public void unregisterProperties(Class<?> componentClass, boolean clear) { |
| 606 | |
| 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public Set<ConfigProperty> getProperties(String componentName) { |
| 611 | return null; |
| 612 | } |
| 613 | |
| 614 | @Override |
| 615 | public void setProperty(String componentName, String name, String value) { |
| 616 | |
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public void preSetProperty(String componentName, String name, String value) { |
| 621 | |
| 622 | } |
| 623 | |
| 624 | @Override |
| 625 | public void preSetProperty(String componentName, String name, String value, boolean override) { |
| 626 | |
| 627 | } |
| 628 | |
| 629 | @Override |
| 630 | public void unsetProperty(String componentName, String name) { |
| 631 | |
| 632 | } |
| 633 | |
| 634 | @Override |
| 635 | public ConfigProperty getProperty(String componentName, String attribute) { |
| 636 | return null; |
| 637 | } |
| 638 | |
| 639 | } |
| 640 | |
| 641 | public static class TestEventDispatcher extends DefaultEventSinkRegistry implements EventDeliveryService { |
| 642 | |
| 643 | @Override |
| 644 | @SuppressWarnings("unchecked") |
| 645 | public synchronized void post(Event event) { |
| 646 | EventSink sink = getSink(event.getClass()); |
| 647 | checkState(sink != null, "No sink for event %s", event); |
| 648 | sink.process(event); |
| 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public void setDispatchTimeLimit(long millis) { |
| 653 | } |
| 654 | |
| 655 | @Override |
| 656 | public long getDispatchTimeLimit() { |
| 657 | return 0; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | class MockComponentContext implements ComponentContext { |
| 662 | |
| 663 | @Override |
| 664 | public Dictionary<String, Object> getProperties() { |
| 665 | Dictionary<String, Object> cfgDict = new Hashtable<String, Object>(); |
| 666 | cfgDict.put("statisticsGenerationPeriodInSeconds", STATISTICS_GEN_PERIOD_IN_SEC); |
| 667 | return cfgDict; |
| 668 | } |
| 669 | |
| 670 | @Override |
| 671 | public Object locateService(String name) { |
| 672 | // TODO Auto-generated method stub |
| 673 | return null; |
| 674 | } |
| 675 | |
| 676 | @Override |
| 677 | public Object locateService(String name, ServiceReference reference) { |
| 678 | // TODO Auto-generated method stub |
| 679 | return null; |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public Object[] locateServices(String name) { |
| 684 | // TODO Auto-generated method stub |
| 685 | return null; |
| 686 | } |
| 687 | |
| 688 | @Override |
| 689 | public BundleContext getBundleContext() { |
| 690 | // TODO Auto-generated method stub |
| 691 | return null; |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public Bundle getUsingBundle() { |
| 696 | // TODO Auto-generated method stub |
| 697 | return null; |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public ComponentInstance getComponentInstance() { |
| 702 | // TODO Auto-generated method stub |
| 703 | return null; |
| 704 | } |
| 705 | |
| 706 | @Override |
| 707 | public void enableComponent(String name) { |
| 708 | // TODO Auto-generated method stub |
| 709 | } |
| 710 | |
| 711 | @Override |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 712 | public void disableComponent(String name) { |
| 713 | // TODO Auto-generated method stub |
| 714 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 715 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 716 | @Override |
| 717 | public ServiceReference getServiceReference() { |
| 718 | // TODO Auto-generated method stub |
| 719 | return null; |
| 720 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 721 | } |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 722 | |
| 723 | Ethernet buildWrongIgmpPacket(Ip4Address groupIp, Ip4Address sourceIp) { |
| 724 | IGMPMembership igmpMembership = new IGMPMembership(groupIp); |
| 725 | igmpMembership.setRecordType((byte) 0x33); |
| 726 | |
| 727 | return IgmpSender.getInstance().buildIgmpPacket(IGMP.TYPE_IGMPV3_MEMBERSHIP_REPORT, groupIp, |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 728 | igmpMembership, sourceIp, false, VlanId.ANY_VALUE, VlanId.NO_VID, IgmpSender.DEFAULT_COS); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | Ethernet buildUnknownIgmpPacket(Ip4Address groupIp, Ip4Address sourceIp) { |
| 732 | IGMPMembership igmpMembership = new IGMPMembership(groupIp); |
| 733 | igmpMembership.setRecordType((byte) 0x33); |
| 734 | |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 735 | return IgmpSender.getInstance().buildIgmpPacket((byte) 0x44, groupIp, igmpMembership, sourceIp, false, |
| 736 | VlanId.ANY_VALUE, VlanId.NO_VID, IgmpSender.DEFAULT_COS); |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 739 | class TestStateMachineStoreService extends AbstractStateMachineStore { |
| 740 | private static final int DEFAULT_COUNT = 0; |
| 741 | private Map<StateMachineId, AtomicLong> countsMap; |
| 742 | |
| 743 | public TestStateMachineStoreService(Map<StateMachineId, StateMachine> map) { |
| 744 | super(); |
| 745 | stateMachineMap = Maps.newConcurrentMap(); |
| 746 | countsMap = Maps.newConcurrentMap(); |
| 747 | } |
| 748 | |
| 749 | @Override |
| 750 | public long increaseAndGetCounter(StateMachineId stateMachineId) { |
| 751 | AtomicLong count = countsMap.get(stateMachineId); |
| 752 | if (count == null) { |
| 753 | count = new AtomicLong(DEFAULT_COUNT); |
| 754 | countsMap.put(stateMachineId, count); |
| 755 | } |
| 756 | return count.incrementAndGet(); |
| 757 | } |
| 758 | |
| 759 | @Override |
| 760 | public long decreaseAndGetCounter(StateMachineId stateMachineId) { |
| 761 | AtomicLong count = countsMap.get(stateMachineId); |
| 762 | if (count.get() > 0) { |
| 763 | return count.decrementAndGet(); |
| 764 | } else { |
| 765 | return count.get(); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public boolean removeCounter(StateMachineId stateMachineId) { |
| 771 | countsMap.remove(stateMachineId); |
| 772 | return true; |
| 773 | } |
| 774 | |
| 775 | @Override |
| 776 | public long getCounter(StateMachineId stateMachineId) { |
| 777 | return countsMap.get(stateMachineId).get(); |
| 778 | } |
| 779 | |
| 780 | } |
| 781 | |
| 782 | |
| 783 | class TestGroupMemberStoreService extends AbstractGroupMemberStore { |
| 784 | public TestGroupMemberStoreService() { |
| 785 | super(Maps.newConcurrentMap()); |
| 786 | } |
| 787 | } |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 788 | } |