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