blob: 9e64dca0280ef14852e05a4bc61deaea9705045a [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
349 // Operation will be REMOVE_FROM_EXISTING and nextMap will be updated. None --> { }
350 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
351 assertTrue(nextMap.get(DEVICE_ID_OF_A).op() == Objective.Operation.REMOVE_FROM_EXISTING));
352
353 // Output port number will be changed to 24 i.e. PORT_C
354 Collection<TrafficTreatment> traffictreatMentCollection = nextMap.get(DEVICE_ID_OF_A).next();
355 assertTrue(1 == traffictreatMentCollection.size());
356 OutputInstruction output = null;
357 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
358 output = outputPort(trafficTreatment);
359 }
360 assertNotNull(output);
361 assertTrue(PORT_C == output.port());
362 }
363
364 @Test
365 public void testUnkownOltDevice() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000366 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000367 // Configuration of mcast event for unknown olt device
368 final DeviceId deviceIdOfB = DeviceId.deviceId("of:1");
369
370 ConnectPoint connectPointA = new ConnectPoint(deviceIdOfB, PORT_A);
371 ConnectPoint connectPointB = new ConnectPoint(deviceIdOfB, PORT_B);
372 Set<ConnectPoint> sourcesCp = new HashSet<ConnectPoint>(Arrays.asList(connectPointA));
373 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
374 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(connectPointB));
375 Map<HostId, Set<ConnectPoint>> sources = ImmutableMap.of(HOST_ID_NONE, sourcesCp);
376
377 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
378 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
379 //Adding the details to create different routes
380 McastRouteUpdate previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
381 McastRouteUpdate currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
382 // Creating new mcast event for adding sink
383 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
384 cordMcast.listener.event(event);
385 // OltInfo flag is set to true when olt device is unkown
386 assertAfter(WAIT, WAIT * 2, () -> assertTrue(knownOltFlag));
387 assertTrue(0 == forwardMap.size());
388 assertTrue(0 == nextMap.size());
389
390 }
391
392 @Test
393 public void testRouteAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000394 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000395 //Adding the details to create different routes
396 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
397 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
398 // Creating new mcast event for route adding
399 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_ADDED, previousSubject, currentSubject);
400 cordMcast.listener.event(event);
401 // There will be no forwarding objective
402 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
403 assertTrue(0 == nextMap.size());
404
405 }
406
407
408 @Test
409 public void testRouteRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000410 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000411 testRouteAddedEvent();
412
413 //Adding the details to create different routes
414 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
415 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
416 // Creating new mcast event for route removing
417 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_REMOVED, previousSubject, currentSubject);
418 cordMcast.listener.event(event);
419 // There will be no forwarding objective
420 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
421 assertTrue(0 == nextMap.size());
422
423 }
424
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000425 @Test
426 public void testSourceAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000427 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000428 // Adding route before adding source.
429 testRouteAddedEvent();
430
431 //Adding the details to create different routes
432 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
433 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
434 // Creating new mcast event for source adding
435 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_ADDED, previousSubject, currentSubject);
436 cordMcast.listener.event(event);
437 // There will be no forwarding objective
438 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
439 assertTrue(0 == nextMap.size());
440
441 }
442
443 @Test
444 public void testSourcesRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000445 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000446 testSourceAddedEvent();
447
448 //Adding the details to create different routes
449 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
450 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
451 // Creating new mcast event for removing source
452 // Warning message of unknown event will be displayed.
453 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_REMOVED, previousSubject, currentSubject);
454 cordMcast.listener.event(event);
455 assertAfter(WAIT, WAIT * 2, () -> assertTrue(0 == forwardMap.size()));
456 assertTrue(0 == nextMap.size());
457 }
458
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000459 @Test
460 public void mcastTestEventGeneration() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000461 init(false, VlanId.vlanId("4000"), VlanId.NONE);
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000462 //fetching route details used to push CordMcastStatisticsEvent.
463 IpAddress testGroup = route1.group();
464 String testSource = route1.source().isEmpty() ? "*" : route1.source().get().toString();
465 VlanId testVlan = cordMcast.assignedVlan();
466
467 // Thread is scheduled without any delay
468 assertAfter(WAIT, WAIT * 2, () ->
469 assertEquals(1, mockListener.mcastEventList.size()));
470
471 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
472 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
473 }
474
475 CordMcastStatistics cordMcastStatistics = mockListener.mcastEventList.get(0).subject().get(0);
476 assertEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
477 assertEquals(testVlan, cordMcastStatistics.getVlanId());
478 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
479 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
480
481 // Test for vlanEnabled
482 Dictionary<String, Object> cfgDict = new Hashtable<>();
483 cfgDict.put("vlanEnabled", true);
484
485 ComponentContext componentContext = EasyMock.createMock(ComponentContext.class);
486 expect(componentContext.getProperties()).andReturn(cfgDict);
487 replay(componentContext);
488 cordMcast.modified(componentContext);
489 testVlan = cordMcast.assignedVlan();
490
491 assertAfter(EVENT_GENERATION_PERIOD, EVENT_GENERATION_PERIOD * 1000, () ->
492 assertEquals(2, mockListener.mcastEventList.size()));
493
494 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
495 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
496 }
497
498 cordMcastStatistics = mockListener.mcastEventList.get(1).subject().get(0);
499 assertNotEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
500 assertEquals(testVlan, cordMcastStatistics.getVlanId());
501 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
502 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
503 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000504}