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