blob: 3ce776073c17308e317d2e577ca77e6d556864ab [file] [log] [blame]
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +00001/*
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 */
developere400c582020-03-24 19:42:08 +010016package org.opencord.igmpproxy.impl;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000017
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +000018import com.google.common.collect.Maps;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000019import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
Shubham Sharma47f2caf2020-02-18 12:13:40 +000022import org.onlab.junit.TestUtils;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000023import org.onlab.packet.Ethernet;
24import org.onosproject.core.CoreServiceAdapter;
25import org.onosproject.net.flow.FlowRuleServiceAdapter;
26import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030027import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter;
28import org.onosproject.store.service.TestStorageService;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000029
30import static org.junit.Assert.*;
31
Shubham Sharma47f2caf2020-02-18 12:13:40 +000032/**
33 * Set of tests of the ONOS application component.
34 */
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000035public class IgmpManagerTest extends IgmpManagerBase {
36
37 private static final int WAIT_TIMEOUT = 1000;
38
39 private IgmpManager igmpManager;
40
Shubham Sharma47f2caf2020-02-18 12:13:40 +000041 private IgmpStatisticsManager igmpStatisticsManager;
42
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000043 // Set up the IGMP application.
44 @Before
45 public void setUp() {
46 igmpManager = new IgmpManager();
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +000047 igmpManager.igmpLeadershipService = new TestIgmpLeaderShipService();
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000048 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 Scandolo7482bbe2020-02-12 14:37:09 -080055 igmpManager.sadisService = new MockSadisService();
Shubham Sharma47f2caf2020-02-18 12:13:40 +000056 igmpStatisticsManager = new IgmpStatisticsManager();
57 igmpStatisticsManager.cfgService = new MockCfgService();
58 TestUtils.setField(igmpStatisticsManager, "eventDispatcher", new TestEventDispatcher());
Ilayda Ozdemir0872abd2020-06-03 20:20:20 +030059 igmpStatisticsManager.storageService = new TestStorageService();
60 igmpStatisticsManager.leadershipManager = new TestIgmpLeaderShipService();
61 igmpStatisticsManager.clusterCommunicationService = new ClusterCommunicationServiceAdapter();
Shubham Sharma47f2caf2020-02-18 12:13:40 +000062 igmpStatisticsManager.activate(new MockComponentContext());
63 igmpManager.igmpStatisticsManager = this.igmpStatisticsManager;
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +000064
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 Kasliwalddc3ff22019-11-18 11:52:49 +000071 // By default - we send query messages
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +000072 StateMachineManager.sendQuery = true;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000073 }
74
75 // Tear Down the IGMP application.
76 @After
77 public void tearDown() {
78 igmpManager.deactivate();
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +000079 igmpManager.stateMachineService.clearAllMaps();
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000080 }
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 Ozdemir4c5947c2020-05-05 13:14:32 +0000103 StateMachineManager.sendQuery = false;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000104
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 Kasliwalf11c0672020-03-18 11:11:50 +0000111 sendPacket(firstPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000112 // Emitted packet is stored in list savedPackets
113 assertNotNull(savedPackets);
114 synchronized (savedPackets) {
115 savedPackets.wait(WAIT_TIMEOUT);
116 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000117
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000118 assertNotNull(savedPackets);
119 assertEquals(1, savedPackets.size());
120 // Sending the second packet with same group ip address
Sonal Kasliwalf11c0672020-03-18 11:11:50 +0000121 sendPacket(secondPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000122 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 Ozdemir4c5947c2020-05-05 13:14:32 +0000133 StateMachineManager.sendQuery = false;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000134
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 Kasliwalf11c0672020-03-18 11:11:50 +0000141 sendPacket(firstPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000142 // Emitted packet is stored in list savedPackets
143 synchronized (savedPackets) {
Ilayda Ozdemir4c5947c2020-05-05 13:14:32 +0000144 savedPackets.wait(WAIT_TIMEOUT);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000145 }
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 Kasliwalf11c0672020-03-18 11:11:50 +0000150 sendPacket(secondPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000151 synchronized (savedPackets) {
152 savedPackets.wait(WAIT_TIMEOUT);
153 }
154 assertEquals(1, savedPackets.size());
155 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000156
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000157}