Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 1 | /* |
Joey Armstrong | 517afab | 2023-01-09 14:22:22 -0500 | [diff] [blame] | 2 | * Copyright 2017-2023 Open Networking Foundation (ONF) and the ONF Contributors |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
developer | e400c58 | 2020-03-24 19:42:08 +0100 | [diff] [blame] | 16 | package org.opencord.igmpproxy.impl; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 17 | |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 22 | import org.onlab.junit.TestUtils; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 23 | import org.onlab.packet.Ethernet; |
| 24 | import org.onosproject.core.CoreServiceAdapter; |
| 25 | import org.onosproject.net.flow.FlowRuleServiceAdapter; |
| 26 | import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter; |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 27 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
| 28 | import org.onosproject.store.service.TestStorageService; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 29 | |
| 30 | import static org.junit.Assert.*; |
| 31 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 32 | /** |
| 33 | * Set of tests of the ONOS application component. |
| 34 | */ |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 35 | public class IgmpManagerTest extends IgmpManagerBase { |
| 36 | |
| 37 | private static final int WAIT_TIMEOUT = 1000; |
| 38 | |
| 39 | private IgmpManager igmpManager; |
| 40 | |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 41 | private IgmpStatisticsManager igmpStatisticsManager; |
| 42 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 43 | // Set up the IGMP application. |
| 44 | @Before |
| 45 | public void setUp() { |
| 46 | igmpManager = new IgmpManager(); |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 47 | igmpManager.igmpLeadershipService = new TestIgmpLeaderShipService(); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 48 | igmpManager.coreService = new CoreServiceAdapter(); |
| 49 | igmpManager.mastershipService = new MockMastershipService(); |
| 50 | igmpManager.flowObjectiveService = new FlowObjectiveServiceAdapter(); |
| 51 | igmpManager.deviceService = new MockDeviceService(); |
| 52 | igmpManager.packetService = new MockPacketService(); |
| 53 | igmpManager.flowRuleService = new FlowRuleServiceAdapter(); |
| 54 | igmpManager.multicastService = new TestMulticastRouteService(); |
Matteo Scandolo | 7482bbe | 2020-02-12 14:37:09 -0800 | [diff] [blame] | 55 | igmpManager.sadisService = new MockSadisService(); |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 56 | igmpStatisticsManager = new IgmpStatisticsManager(); |
| 57 | igmpStatisticsManager.cfgService = new MockCfgService(); |
| 58 | TestUtils.setField(igmpStatisticsManager, "eventDispatcher", new TestEventDispatcher()); |
Ilayda Ozdemir | 0872abd | 2020-06-03 20:20:20 +0300 | [diff] [blame] | 59 | igmpStatisticsManager.storageService = new TestStorageService(); |
| 60 | igmpStatisticsManager.leadershipManager = new TestIgmpLeaderShipService(); |
| 61 | igmpStatisticsManager.clusterCommunicationService = new ClusterCommunicationServiceAdapter(); |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 62 | igmpStatisticsManager.activate(new MockComponentContext()); |
| 63 | igmpManager.igmpStatisticsManager = this.igmpStatisticsManager; |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 64 | |
| 65 | igmpManager.groupMemberStore = new TestGroupMemberStoreService(); |
| 66 | StateMachineManager stateMachineManager = new StateMachineManager(); |
| 67 | stateMachineManager.stateMachineStore = new TestStateMachineStoreService(Maps.newConcurrentMap()); |
| 68 | stateMachineManager.activate(new MockComponentContext()); |
| 69 | igmpManager.stateMachineService = stateMachineManager; |
| 70 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 71 | // By default - we send query messages |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 72 | StateMachineManager.sendQuery = true; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | // Tear Down the IGMP application. |
| 76 | @After |
| 77 | public void tearDown() { |
| 78 | igmpManager.deactivate(); |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 79 | igmpManager.stateMachineService.clearAllMaps(); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | // Checking the Default value of IGMP_ON_POD_BASIS. |
| 83 | @Test |
| 84 | public void testIsIgmpOnPodBasisDefaultValue() { |
| 85 | igmpManager.networkConfig = new TestNetworkConfigRegistry(false); |
| 86 | igmpManager.activate(); |
| 87 | assertFalse(IgmpManager.isIgmpOnPodBasis()); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | // Checking the value of IGMP_ON_POD_BASIS. |
| 92 | @Test |
| 93 | public void testIsIgmpOnPodBasisTrueValue() { |
| 94 | igmpManager.networkConfig = new TestNetworkConfigRegistry(true); |
| 95 | igmpManager.activate(); |
| 96 | assertTrue(IgmpManager.isIgmpOnPodBasis()); |
| 97 | } |
| 98 | |
| 99 | // Testing the flow of packet when isIgmpOnPodBasis value is false. |
| 100 | @Test |
| 101 | public void testIgmpOnPodBasisDefaultValue() throws InterruptedException { |
| 102 | // We need to count join messages sent on the upstream |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 103 | StateMachineManager.sendQuery = false; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 104 | |
| 105 | igmpManager.networkConfig = new TestNetworkConfigRegistry(false); |
| 106 | igmpManager.activate(); |
| 107 | |
| 108 | Ethernet firstPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_A); |
| 109 | Ethernet secondPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_B); |
| 110 | // Sending first packet and here shouldSendjoin flag will be true |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 111 | sendPacket(firstPacket); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 112 | // Emitted packet is stored in list savedPackets |
| 113 | assertNotNull(savedPackets); |
| 114 | synchronized (savedPackets) { |
| 115 | savedPackets.wait(WAIT_TIMEOUT); |
| 116 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 117 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 118 | assertNotNull(savedPackets); |
| 119 | assertEquals(1, savedPackets.size()); |
| 120 | // Sending the second packet with same group ip address |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 121 | sendPacket(secondPacket); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 122 | synchronized (savedPackets) { |
| 123 | savedPackets.wait(WAIT_TIMEOUT); |
| 124 | } |
| 125 | // Emitted packet is stored in list savedPackets as shouldSendJoin flag is true |
| 126 | assertEquals(2, savedPackets.size()); |
| 127 | } |
| 128 | |
| 129 | // Testing IGMP_ON_POD_BASIS value by sending two packets. |
| 130 | @Test |
| 131 | public void testIgmpOnPodBasisTrueValue() throws InterruptedException { |
| 132 | // We need to count join messages |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 133 | StateMachineManager.sendQuery = false; |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 134 | |
| 135 | igmpManager.networkConfig = new TestNetworkConfigRegistry(true); |
| 136 | igmpManager.activate(); |
| 137 | |
| 138 | Ethernet firstPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_A); |
| 139 | Ethernet secondPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_B); |
| 140 | // Sending first packet and here shouldSendjoin flag will be true |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 141 | sendPacket(firstPacket); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 142 | // Emitted packet is stored in list savedPackets |
| 143 | synchronized (savedPackets) { |
Ilayda Ozdemir | 4c5947c | 2020-05-05 13:14:32 +0000 | [diff] [blame] | 144 | savedPackets.wait(WAIT_TIMEOUT); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 145 | } |
| 146 | assertNotNull(savedPackets); |
| 147 | assertEquals(1, savedPackets.size()); |
| 148 | // Sending the second packet with same group ip address which will not be emitted |
| 149 | // shouldSendJoin flag will be false. |
Sonal Kasliwal | f11c067 | 2020-03-18 11:11:50 +0000 | [diff] [blame] | 150 | sendPacket(secondPacket); |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 151 | synchronized (savedPackets) { |
| 152 | savedPackets.wait(WAIT_TIMEOUT); |
| 153 | } |
| 154 | assertEquals(1, savedPackets.size()); |
| 155 | } |
Shubham Sharma | 47f2caf | 2020-02-18 12:13:40 +0000 | [diff] [blame] | 156 | |
Sonal Kasliwal | ddc3ff2 | 2019-11-18 11:52:49 +0000 | [diff] [blame] | 157 | } |