blob: dc220f8405fb980ab6b571b7c2a29b59e4ce0f4a [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
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
Shubham Sharma47f2caf2020-02-18 12:13:40 +000021import org.onlab.junit.TestUtils;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000022import org.onlab.packet.Ethernet;
23import org.onosproject.core.CoreServiceAdapter;
24import org.onosproject.net.flow.FlowRuleServiceAdapter;
25import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter;
developere400c582020-03-24 19:42:08 +010026import org.opencord.igmpproxy.impl.IgmpManagerBase.MockComponentContext;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000027
28import static org.junit.Assert.*;
29
Shubham Sharma47f2caf2020-02-18 12:13:40 +000030/**
31 * Set of tests of the ONOS application component.
32 */
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000033public class IgmpManagerTest extends IgmpManagerBase {
34
35 private static final int WAIT_TIMEOUT = 1000;
36
37 private IgmpManager igmpManager;
38
Shubham Sharma47f2caf2020-02-18 12:13:40 +000039 private IgmpStatisticsManager igmpStatisticsManager;
40
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000041 // Set up the IGMP application.
42 @Before
43 public void setUp() {
44 igmpManager = new IgmpManager();
45 igmpManager.coreService = new CoreServiceAdapter();
46 igmpManager.mastershipService = new MockMastershipService();
47 igmpManager.flowObjectiveService = new FlowObjectiveServiceAdapter();
48 igmpManager.deviceService = new MockDeviceService();
49 igmpManager.packetService = new MockPacketService();
50 igmpManager.flowRuleService = new FlowRuleServiceAdapter();
51 igmpManager.multicastService = new TestMulticastRouteService();
Matteo Scandolo7482bbe2020-02-12 14:37:09 -080052 igmpManager.sadisService = new MockSadisService();
Shubham Sharma47f2caf2020-02-18 12:13:40 +000053 igmpStatisticsManager = new IgmpStatisticsManager();
54 igmpStatisticsManager.cfgService = new MockCfgService();
55 TestUtils.setField(igmpStatisticsManager, "eventDispatcher", new TestEventDispatcher());
56 igmpStatisticsManager.activate(new MockComponentContext());
57 igmpManager.igmpStatisticsManager = this.igmpStatisticsManager;
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +000058 // By default - we send query messages
59 SingleStateMachine.sendQuery = true;
60 }
61
62 // Tear Down the IGMP application.
63 @After
64 public void tearDown() {
65 igmpManager.deactivate();
66 IgmpManager.groupMemberMap.clear();
67 StateMachine.clearMap();
68 }
69
70 // Checking the Default value of IGMP_ON_POD_BASIS.
71 @Test
72 public void testIsIgmpOnPodBasisDefaultValue() {
73 igmpManager.networkConfig = new TestNetworkConfigRegistry(false);
74 igmpManager.activate();
75 assertFalse(IgmpManager.isIgmpOnPodBasis());
76 }
77
78
79 // Checking the value of IGMP_ON_POD_BASIS.
80 @Test
81 public void testIsIgmpOnPodBasisTrueValue() {
82 igmpManager.networkConfig = new TestNetworkConfigRegistry(true);
83 igmpManager.activate();
84 assertTrue(IgmpManager.isIgmpOnPodBasis());
85 }
86
87 // Testing the flow of packet when isIgmpOnPodBasis value is false.
88 @Test
89 public void testIgmpOnPodBasisDefaultValue() throws InterruptedException {
90 // We need to count join messages sent on the upstream
91 SingleStateMachine.sendQuery = false;
92
93 igmpManager.networkConfig = new TestNetworkConfigRegistry(false);
94 igmpManager.activate();
95
96 Ethernet firstPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_A);
97 Ethernet secondPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_B);
98 // Sending first packet and here shouldSendjoin flag will be true
Sonal Kasliwalf11c0672020-03-18 11:11:50 +000099 sendPacket(firstPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000100 // Emitted packet is stored in list savedPackets
101 assertNotNull(savedPackets);
102 synchronized (savedPackets) {
103 savedPackets.wait(WAIT_TIMEOUT);
104 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000105
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000106 assertNotNull(savedPackets);
107 assertEquals(1, savedPackets.size());
108 // Sending the second packet with same group ip address
Sonal Kasliwalf11c0672020-03-18 11:11:50 +0000109 sendPacket(secondPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000110 synchronized (savedPackets) {
111 savedPackets.wait(WAIT_TIMEOUT);
112 }
113 // Emitted packet is stored in list savedPackets as shouldSendJoin flag is true
114 assertEquals(2, savedPackets.size());
115 }
116
117 // Testing IGMP_ON_POD_BASIS value by sending two packets.
118 @Test
119 public void testIgmpOnPodBasisTrueValue() throws InterruptedException {
120 // We need to count join messages
121 SingleStateMachine.sendQuery = false;
122
123 igmpManager.networkConfig = new TestNetworkConfigRegistry(true);
124 igmpManager.activate();
125
126 Ethernet firstPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_A);
127 Ethernet secondPacket = IgmpSender.getInstance().buildIgmpV3Join(GROUP_IP, SOURCE_IP_OF_B);
128 // Sending first packet and here shouldSendjoin flag will be true
Sonal Kasliwalf11c0672020-03-18 11:11:50 +0000129 sendPacket(firstPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000130 // Emitted packet is stored in list savedPackets
131 synchronized (savedPackets) {
132 savedPackets.wait(WAIT_TIMEOUT);
133 }
134 assertNotNull(savedPackets);
135 assertEquals(1, savedPackets.size());
136 // Sending the second packet with same group ip address which will not be emitted
137 // shouldSendJoin flag will be false.
Sonal Kasliwalf11c0672020-03-18 11:11:50 +0000138 sendPacket(secondPacket);
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000139 synchronized (savedPackets) {
140 savedPackets.wait(WAIT_TIMEOUT);
141 }
142 assertEquals(1, savedPackets.size());
143 }
Shubham Sharma47f2caf2020-02-18 12:13:40 +0000144
Sonal Kasliwalddc3ff22019-11-18 11:52:49 +0000145}