blob: 84eb986ccd5ffa2bbeece7e84ab27d36740c7ceb [file] [log] [blame]
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +00001/*
2 * Copyright 2016-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 */
Daniele Moro8ea9e102020-03-24 18:56:52 +010016package org.opencord.cordmcast.impl;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000017
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000018import static org.easymock.EasyMock.expect;
19import static org.easymock.EasyMock.replay;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000020
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000021import org.easymock.EasyMock;
22import org.junit.After;
23import org.junit.Before;
24import org.junit.Test;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000025import org.onlab.junit.TestUtils;
26import org.onlab.packet.IpAddress;
27import org.onlab.packet.VlanId;
28import org.onosproject.cfg.ComponentConfigAdapter;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000029import org.onosproject.cfg.ComponentConfigService;
30import org.onosproject.mcast.api.McastEvent;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000031import org.onosproject.mcast.api.McastRoute;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000032import org.onosproject.mcast.api.McastRouteUpdate;
33import org.onosproject.mcast.api.MulticastRouteService;
34import org.onosproject.net.ConnectPoint;
35import org.onosproject.net.DeviceId;
36import org.onosproject.net.HostId;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000037import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
Esin Karamane4890012020-04-19 11:58:54 +000039import org.onosproject.net.flow.criteria.Criterion;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000040import org.onosproject.net.flow.criteria.IPCriterion;
Esin Karamane4890012020-04-19 11:58:54 +000041import org.onosproject.net.flow.criteria.VlanIdCriterion;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000042import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
43import org.onosproject.net.flowobjective.Objective;
44import org.onosproject.store.service.StorageServiceAdapter;
45import org.onosproject.store.service.TestConsistentMap;
Daniele Moro8ea9e102020-03-24 18:56:52 +010046import org.opencord.cordmcast.CordMcastStatistics;
47import org.opencord.cordmcast.CordMcastStatisticsEvent;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000048import org.osgi.service.component.ComponentContext;
49import com.google.common.collect.ImmutableMap;
50import com.google.common.collect.Sets;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000051
52import java.util.Dictionary;
53import java.util.HashSet;
54import java.util.Hashtable;
55import java.util.Set;
56import java.util.Map;
57import java.util.Arrays;
58import java.util.Collection;
59
60import static org.junit.Assert.*;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000061import static org.onlab.junit.TestTools.assertAfter;
62
63public class McastTest extends McastTestBase {
64
65 private CordMcast cordMcast;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000066 private CordMcastStatisticsManager cordMcastStatisticsManager;
67
68 private MockCordMcastStatisticsEventListener mockListener = new MockCordMcastStatisticsEventListener();
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000069
70 private static final int WAIT_TIMEOUT = 1000;
71 private static final int WAIT = 250;
72 McastRouteUpdate previousSubject, currentSubject;
73
74 @Before
75 public void setUp() {
Esin Karamane4890012020-04-19 11:58:54 +000076 //setup operation is handled by init() method in each test
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000077 }
78
79 @After
80 public void tearDown() {
81 cordMcast.deactivate();
82 forwardMap.clear();
83 nextMap.clear();
84 }
85
Esin Karamane4890012020-04-19 11:58:54 +000086 private void init(boolean vlanEnabled, VlanId egressVlan, VlanId egressInnerVlan) {
87 cordMcast = new CordMcast();
88 cordMcastStatisticsManager = new CordMcastStatisticsManager();
89 cordMcast.coreService = new MockCoreService();
90
91 TestNetworkConfigRegistry testNetworkConfigRegistry = new TestNetworkConfigRegistry();
92 testNetworkConfigRegistry.setEgressVlan(egressVlan);
93 testNetworkConfigRegistry.setEgressInnerVlan(egressInnerVlan);
94 cordMcast.networkConfig = testNetworkConfigRegistry;
95
96 cordMcast.flowObjectiveService = new MockFlowObjectiveService();
97 cordMcast.mastershipService = new TestMastershipService();
98 cordMcast.deviceService = new MockDeviceService();
99 cordMcast.componentConfigService = new ComponentConfigAdapter();
100 cordMcastStatisticsManager.componentConfigService = new ComponentConfigAdapter();
101 cordMcastStatisticsManager.addListener(mockListener);
102 cordMcast.sadisService = new MockSadisService();
103 cordMcast.cordMcastStatisticsService = cordMcastStatisticsManager;
104
105 cordMcast.storageService = EasyMock.createMock(StorageServiceAdapter.class);
106 expect(cordMcast.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>());
107 replay(cordMcast.storageService);
108
109 Dictionary<String, Object> cfgDict = new Hashtable<String, Object>();
110 cfgDict.put("vlanEnabled", vlanEnabled);
111 cfgDict.put("eventGenerationPeriodInSeconds", EVENT_GENERATION_PERIOD);
112
113 cordMcast.componentConfigService = EasyMock.createNiceMock(ComponentConfigService.class);
114 replay(cordMcast.componentConfigService);
115
116 Set<McastRoute> route1Set = new HashSet<McastRoute>();
117 route1Set.add(route1);
118
119 cordMcast.mcastService = EasyMock.createNiceMock(MulticastRouteService.class);
120 expect(cordMcast.mcastService.getRoutes()).andReturn(Sets.newHashSet());
121 replay(cordMcast.mcastService);
122
123 cordMcastStatisticsManager.mcastService = EasyMock.createNiceMock(MulticastRouteService.class);
124 expect(cordMcastStatisticsManager.mcastService.getRoutes()).andReturn(route1Set).times(2);
125 replay(cordMcastStatisticsManager.mcastService);
126
127 TestUtils.setField(cordMcastStatisticsManager, "eventDispatcher", new TestEventDispatcher());
128
129 ComponentContext componentContext = EasyMock.createMock(ComponentContext.class);
130 expect(componentContext.getProperties()).andReturn(cfgDict).times(2);
131 replay(componentContext);
132 cordMcast.cordMcastStatisticsService = cordMcastStatisticsManager;
133 cordMcastStatisticsManager.activate(componentContext);
134
135 cordMcast.activate(componentContext);
136 }
137
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000138 @Test
139 public void testAddingSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000140 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000141
142 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
143 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
144
145 //Adding the details to create different routes
146 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
147 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
148 // Creating new mcast event for adding sink
149 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
150 cordMcast.listener.event(event);
151 synchronized (forwardMap) {
152 forwardMap.wait(WAIT_TIMEOUT);
153 }
154
155 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
156 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
157 assertTrue(forwardMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.ADD);
158
159 // Output port number will be PORT_B i.e. 16
160 Collection<TrafficTreatment> traffictreatMentCollection =
161 nextMap.get(DEVICE_ID_OF_A).next();
162 assertTrue(1 == traffictreatMentCollection.size());
163 OutputInstruction output = null;
164 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
165 output = outputPort(trafficTreatment);
166 }
167 assertNotNull(output);
168 assertTrue(PORT_B == output.port());
169 // Checking the group ip address
170 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
171 IPCriterion ipCriterion = ipAddress(trafficSelector);
172 assertNotNull(ipCriterion);
173 assertTrue(MULTICAST_IP.equals(ipCriterion.ip().address()));
Esin Karamane4890012020-04-19 11:58:54 +0000174 //checking the vlan criterion
175 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
176 VlanIdCriterion vlanId = vlanId(meta, Criterion.Type.VLAN_VID);
177 assertNull(vlanId); //since vlanEnabled flag is false
178 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
179 assertNull(innerVlanIdCriterion);
180 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000181
Esin Karamane4890012020-04-19 11:58:54 +0000182 @Test
183 public void testAddingSinkEventVlanEnabled() throws InterruptedException {
184 // vlanEnabled is set to true and just egressVlan is set
185 init(true, VlanId.vlanId("4000"), null);
186
187 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
188 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
189
190 //Adding the details to create different routes
191 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
192 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
193 // Creating new mcast event for adding sink
194 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
195 cordMcast.listener.event(event);
196 synchronized (forwardMap) {
197 forwardMap.wait(WAIT_TIMEOUT);
198 }
199 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
200 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
201 assertTrue(forwardMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.ADD);
202
203 // Output port number will be PORT_B i.e. 16
204 Collection<TrafficTreatment> traffictreatMentCollection =
205 nextMap.get(DEVICE_ID_OF_A).next();
206 assertTrue(1 == traffictreatMentCollection.size());
207 OutputInstruction output = null;
208 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
209 output = outputPort(trafficTreatment);
210 }
211 assertNotNull(output);
212 assertTrue(PORT_B == output.port());
213 // Checking the group ip address
214 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
215 IPCriterion ipCriterion = ipAddress(trafficSelector);
216 assertNotNull(ipCriterion);
217 assertTrue(MULTICAST_IP.equals(ipCriterion.ip().address()));
218 //checking the vlan criteria
219 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
220 VlanIdCriterion vlanIdCriterion = vlanId(meta, Criterion.Type.VLAN_VID);
221 assertNotNull(vlanIdCriterion); //since vlanEnabled flag is true
222 assertEquals(cordMcast.assignedVlan(), vlanIdCriterion.vlanId());
223 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
224 assertNull(innerVlanIdCriterion);
225 }
226
227 @Test
228 public void testAddingSinkEventInnerVlanEnabled() throws InterruptedException {
229 // vlanEnabled is set to true and egressVlan & egressInnerVlan are set
230 init(true, VlanId.vlanId("4000"), VlanId.vlanId("1000"));
231
232 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
233 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
234
235 //Adding the details to create different routes
236 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
237 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
238 // Creating new mcast event for adding sink
239 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
240 cordMcast.listener.event(event);
241 synchronized (forwardMap) {
242 forwardMap.wait(WAIT_TIMEOUT);
243 }
244
245 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
246 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
247 assertTrue(forwardMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.ADD);
248
249 // Output port number will be PORT_B i.e. 16
250 Collection<TrafficTreatment> traffictreatMentCollection =
251 nextMap.get(DEVICE_ID_OF_A).next();
252 assertTrue(1 == traffictreatMentCollection.size());
253 OutputInstruction output = null;
254 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
255 output = outputPort(trafficTreatment);
256 }
257 assertNotNull(output);
258 assertTrue(PORT_B == output.port());
259 // Checking the group ip address
260 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
261 IPCriterion ipCriterion = ipAddress(trafficSelector);
262 assertNotNull(ipCriterion);
263 assertTrue(MULTICAST_IP.equals(ipCriterion.ip().address()));
264 //checking the vlan criteria
265 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
266 VlanIdCriterion vlanIdCriterion = vlanId(meta, Criterion.Type.VLAN_VID);
267 assertNotNull(vlanIdCriterion); //since vlanEnabled flag is true
268 assertEquals(cordMcast.assignedVlan(), vlanIdCriterion.vlanId());
269 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
270 assertNotNull(innerVlanIdCriterion);
271 assertEquals(cordMcast.assignedInnerVlan(), innerVlanIdCriterion.vlanId());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000272 }
273
274 @Test
275 public void testAddToExistingSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000276 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000277 // Adding first sink (none --> CP_B)
278 testAddingSinkEvent();
279
280 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
281 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
282 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
283 sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B, CONNECT_POINT_C));
284 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
285 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
286 // Again listening the mcast event with different output port ( none --> CP_B, CP_C)
287 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
288 cordMcast.listener.event(event);
289
290 // NextMap will contain the operation "ADD_TO_EXISTING" in the DefaultNextObjective.
291 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
292 assertTrue(nextMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.ADD_TO_EXISTING));
293 // Output port number will be changed to 24 i.e. PORT_C
294 Collection<TrafficTreatment> traffictreatMentCollection = nextMap.get(DEVICE_ID_OF_A).next();
295 assertTrue(1 == traffictreatMentCollection.size());
296 OutputInstruction output = null;
297 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
298 output = outputPort(trafficTreatment);
299 }
300 assertNotNull(output);
301 assertTrue(PORT_C == output.port());
302 }
303
304 @Test
305 public void testRemoveSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000306 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000307 testAddToExistingSinkEvent();
308 // Handling the mcast event for removing sink.
309 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B, CONNECT_POINT_C));
310 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
311 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
312 sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_C));
313 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
314 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
315 McastEvent event = new McastEvent(McastEvent.Type.SINKS_REMOVED, previousSubject, currentSubject);
316 cordMcast.listener.event(event);
317 // Operation will be REMOVE_FROM_EXISTING and nextMap will be updated. ( None --> CP_C)
318 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
319 assertTrue(nextMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.REMOVE_FROM_EXISTING));
320
321 // Output port number will be PORT_B i.e. 16
322 // Port_B is removed from the group.
323 Collection<TrafficTreatment> traffictreatMentCollection =
324 nextMap.get(DEVICE_ID_OF_A).next();
325 assertTrue(1 == traffictreatMentCollection.size());
326 OutputInstruction output = null;
327 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
328 output = outputPort(trafficTreatment);
329 }
330 assertNotNull(output);
331 assertTrue(PORT_B == output.port());
332
333 }
334
335 @Test
336 public void testRemoveLastSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000337 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000338 testRemoveSinkEvent();
339 // Handling the mcast event for removing sink.
340 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_C));
341 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
342 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
343 sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
344 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
345 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
346 McastEvent event = new McastEvent(McastEvent.Type.SINKS_REMOVED, previousSubject, currentSubject);
347 cordMcast.listener.event(event);
348
Andrea Campanella03652352020-05-06 16:12:00 +0200349 // Operation will be REMOVE and nextMap will be updated. None --> { }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000350 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
Andrea Campanella03652352020-05-06 16:12:00 +0200351 assertTrue(nextMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.REMOVE));
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000352 }
353
354 @Test
355 public void testUnkownOltDevice() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000356 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000357 // Configuration of mcast event for unknown olt device
358 final DeviceId deviceIdOfB = DeviceId.deviceId("of:1");
359
360 ConnectPoint connectPointA = new ConnectPoint(deviceIdOfB, PORT_A);
361 ConnectPoint connectPointB = new ConnectPoint(deviceIdOfB, PORT_B);
362 Set<ConnectPoint> sourcesCp = new HashSet<ConnectPoint>(Arrays.asList(connectPointA));
363 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
364 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(connectPointB));
365 Map<HostId, Set<ConnectPoint>> sources = ImmutableMap.of(HOST_ID_NONE, sourcesCp);
366
367 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
368 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
369 //Adding the details to create different routes
370 McastRouteUpdate previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
371 McastRouteUpdate currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
372 // Creating new mcast event for adding sink
373 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
374 cordMcast.listener.event(event);
375 // OltInfo flag is set to true when olt device is unkown
376 assertAfter(WAIT, WAIT * 2, () -> assertTrue(knownOltFlag));
377 assertTrue(0 == forwardMap.size());
378 assertTrue(0 == nextMap.size());
379
380 }
381
382 @Test
383 public void testRouteAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000384 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000385 //Adding the details to create different routes
386 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
387 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
388 // Creating new mcast event for route adding
389 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_ADDED, previousSubject, currentSubject);
390 cordMcast.listener.event(event);
391 // There will be no forwarding objective
392 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
393 assertTrue(0 == nextMap.size());
394
395 }
396
397
398 @Test
399 public void testRouteRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000400 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000401 testRouteAddedEvent();
402
403 //Adding the details to create different routes
404 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
405 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
406 // Creating new mcast event for route removing
407 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_REMOVED, previousSubject, currentSubject);
408 cordMcast.listener.event(event);
409 // There will be no forwarding objective
410 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
411 assertTrue(0 == nextMap.size());
412
413 }
414
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000415 @Test
416 public void testSourceAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000417 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000418 // Adding route before adding source.
419 testRouteAddedEvent();
420
421 //Adding the details to create different routes
422 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
423 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
424 // Creating new mcast event for source adding
425 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_ADDED, previousSubject, currentSubject);
426 cordMcast.listener.event(event);
427 // There will be no forwarding objective
428 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
429 assertTrue(0 == nextMap.size());
430
431 }
432
433 @Test
434 public void testSourcesRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000435 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000436 testSourceAddedEvent();
437
438 //Adding the details to create different routes
439 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
440 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
441 // Creating new mcast event for removing source
442 // Warning message of unknown event will be displayed.
443 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_REMOVED, previousSubject, currentSubject);
444 cordMcast.listener.event(event);
445 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
446 assertTrue(0 == nextMap.size());
447 }
448
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000449 @Test
450 public void mcastTestEventGeneration() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000451 init(false, VlanId.vlanId("4000"), VlanId.NONE);
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000452 //fetching route details used to push CordMcastStatisticsEvent.
453 IpAddress testGroup = route1.group();
454 String testSource = route1.source().isEmpty() ? "*" : route1.source().get().toString();
455 VlanId testVlan = cordMcast.assignedVlan();
456
457 // Thread is scheduled without any delay
458 assertAfter(WAIT, WAIT * 2, () ->
459 assertEquals(1, mockListener.mcastEventList.size()));
460
461 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
462 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
463 }
464
465 CordMcastStatistics cordMcastStatistics = mockListener.mcastEventList.get(0).subject().get(0);
466 assertEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
467 assertEquals(testVlan, cordMcastStatistics.getVlanId());
468 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
469 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
470
471 // Test for vlanEnabled
472 Dictionary<String, Object> cfgDict = new Hashtable<>();
473 cfgDict.put("vlanEnabled", true);
474
475 ComponentContext componentContext = EasyMock.createMock(ComponentContext.class);
476 expect(componentContext.getProperties()).andReturn(cfgDict);
477 replay(componentContext);
478 cordMcast.modified(componentContext);
479 testVlan = cordMcast.assignedVlan();
480
481 assertAfter(EVENT_GENERATION_PERIOD, EVENT_GENERATION_PERIOD * 1000, () ->
482 assertEquals(2, mockListener.mcastEventList.size()));
483
484 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
485 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
486 }
487
488 cordMcastStatistics = mockListener.mcastEventList.get(1).subject().get(0);
489 assertNotEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
490 assertEquals(testVlan, cordMcastStatistics.getVlanId());
491 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
492 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
493 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000494}