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