blob: acd85f3432c78b4e95f291064ef558dd012abb0f [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;
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +000030import org.onosproject.cluster.ClusterServiceAdapter;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000031import org.onosproject.mcast.api.McastEvent;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000032import org.onosproject.mcast.api.McastRoute;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000033import org.onosproject.mcast.api.McastRouteUpdate;
34import org.onosproject.mcast.api.MulticastRouteService;
35import org.onosproject.net.ConnectPoint;
36import org.onosproject.net.DeviceId;
37import org.onosproject.net.HostId;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000038import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
Esin Karamane4890012020-04-19 11:58:54 +000040import org.onosproject.net.flow.criteria.Criterion;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000041import org.onosproject.net.flow.criteria.IPCriterion;
Esin Karamane4890012020-04-19 11:58:54 +000042import org.onosproject.net.flow.criteria.VlanIdCriterion;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000043import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
44import org.onosproject.net.flowobjective.Objective;
45import org.onosproject.store.service.StorageServiceAdapter;
46import org.onosproject.store.service.TestConsistentMap;
Daniele Moro8ea9e102020-03-24 18:56:52 +010047import org.opencord.cordmcast.CordMcastStatistics;
48import org.opencord.cordmcast.CordMcastStatisticsEvent;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000049import org.osgi.service.component.ComponentContext;
50import com.google.common.collect.ImmutableMap;
51import com.google.common.collect.Sets;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000052
53import java.util.Dictionary;
54import java.util.HashSet;
55import java.util.Hashtable;
56import java.util.Set;
57import java.util.Map;
58import java.util.Arrays;
59import java.util.Collection;
60
61import static org.junit.Assert.*;
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000062import static org.onlab.junit.TestTools.assertAfter;
63
64public class McastTest extends McastTestBase {
65
66 private CordMcast cordMcast;
Arjun E Kabf9e6e2020-03-02 10:15:21 +000067 private CordMcastStatisticsManager cordMcastStatisticsManager;
68
69 private MockCordMcastStatisticsEventListener mockListener = new MockCordMcastStatisticsEventListener();
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000070
71 private static final int WAIT_TIMEOUT = 1000;
72 private static final int WAIT = 250;
73 McastRouteUpdate previousSubject, currentSubject;
74
75 @Before
76 public void setUp() {
Esin Karamane4890012020-04-19 11:58:54 +000077 //setup operation is handled by init() method in each test
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +000078 }
79
80 @After
81 public void tearDown() {
82 cordMcast.deactivate();
83 forwardMap.clear();
84 nextMap.clear();
85 }
86
Esin Karamane4890012020-04-19 11:58:54 +000087 private void init(boolean vlanEnabled, VlanId egressVlan, VlanId egressInnerVlan) {
88 cordMcast = new CordMcast();
89 cordMcastStatisticsManager = new CordMcastStatisticsManager();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +000090 cordMcastStatisticsManager.clusterService = new ClusterServiceAdapter();
91 cordMcastStatisticsManager.leadershipService = new LeadershipServiceMcastAdapter();
Esin Karamane4890012020-04-19 11:58:54 +000092 cordMcast.coreService = new MockCoreService();
93
94 TestNetworkConfigRegistry testNetworkConfigRegistry = new TestNetworkConfigRegistry();
95 testNetworkConfigRegistry.setEgressVlan(egressVlan);
96 testNetworkConfigRegistry.setEgressInnerVlan(egressInnerVlan);
97 cordMcast.networkConfig = testNetworkConfigRegistry;
98
99 cordMcast.flowObjectiveService = new MockFlowObjectiveService();
100 cordMcast.mastershipService = new TestMastershipService();
101 cordMcast.deviceService = new MockDeviceService();
102 cordMcast.componentConfigService = new ComponentConfigAdapter();
103 cordMcastStatisticsManager.componentConfigService = new ComponentConfigAdapter();
104 cordMcastStatisticsManager.addListener(mockListener);
105 cordMcast.sadisService = new MockSadisService();
106 cordMcast.cordMcastStatisticsService = cordMcastStatisticsManager;
107
108 cordMcast.storageService = EasyMock.createMock(StorageServiceAdapter.class);
109 expect(cordMcast.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>());
110 replay(cordMcast.storageService);
111
112 Dictionary<String, Object> cfgDict = new Hashtable<String, Object>();
113 cfgDict.put("vlanEnabled", vlanEnabled);
114 cfgDict.put("eventGenerationPeriodInSeconds", EVENT_GENERATION_PERIOD);
115
116 cordMcast.componentConfigService = EasyMock.createNiceMock(ComponentConfigService.class);
117 replay(cordMcast.componentConfigService);
118
119 Set<McastRoute> route1Set = new HashSet<McastRoute>();
120 route1Set.add(route1);
121
122 cordMcast.mcastService = EasyMock.createNiceMock(MulticastRouteService.class);
123 expect(cordMcast.mcastService.getRoutes()).andReturn(Sets.newHashSet());
124 replay(cordMcast.mcastService);
125
126 cordMcastStatisticsManager.mcastService = EasyMock.createNiceMock(MulticastRouteService.class);
127 expect(cordMcastStatisticsManager.mcastService.getRoutes()).andReturn(route1Set).times(2);
128 replay(cordMcastStatisticsManager.mcastService);
129
130 TestUtils.setField(cordMcastStatisticsManager, "eventDispatcher", new TestEventDispatcher());
131
132 ComponentContext componentContext = EasyMock.createMock(ComponentContext.class);
133 expect(componentContext.getProperties()).andReturn(cfgDict).times(2);
134 replay(componentContext);
135 cordMcast.cordMcastStatisticsService = cordMcastStatisticsManager;
136 cordMcastStatisticsManager.activate(componentContext);
137
138 cordMcast.activate(componentContext);
139 }
140
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000141 @Test
142 public void testAddingSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000143 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000144
145 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
146 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
147
148 //Adding the details to create different routes
149 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
150 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
151 // Creating new mcast event for adding sink
152 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
153 cordMcast.listener.event(event);
154 synchronized (forwardMap) {
155 forwardMap.wait(WAIT_TIMEOUT);
156 }
157
158 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
159 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000160 assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000161
162 // Output port number will be PORT_B i.e. 16
163 Collection<TrafficTreatment> traffictreatMentCollection =
164 nextMap.get(DEVICE_ID_OF_A).next();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000165 assertEquals(1, traffictreatMentCollection.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000166 OutputInstruction output = null;
167 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
168 output = outputPort(trafficTreatment);
169 }
170 assertNotNull(output);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000171 assertEquals(PORT_B, output.port());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000172 // Checking the group ip address
173 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
174 IPCriterion ipCriterion = ipAddress(trafficSelector);
175 assertNotNull(ipCriterion);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000176 assertEquals(MULTICAST_IP, ipCriterion.ip().address());
Esin Karamane4890012020-04-19 11:58:54 +0000177 //checking the vlan criterion
178 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
179 VlanIdCriterion vlanId = vlanId(meta, Criterion.Type.VLAN_VID);
180 assertNull(vlanId); //since vlanEnabled flag is false
181 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
182 assertNull(innerVlanIdCriterion);
183 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000184
Esin Karamane4890012020-04-19 11:58:54 +0000185 @Test
186 public void testAddingSinkEventVlanEnabled() throws InterruptedException {
187 // vlanEnabled is set to true and just egressVlan is set
188 init(true, VlanId.vlanId("4000"), null);
189
190 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
191 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
192
193 //Adding the details to create different routes
194 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
195 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
196 // Creating new mcast event for adding sink
197 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
198 cordMcast.listener.event(event);
199 synchronized (forwardMap) {
200 forwardMap.wait(WAIT_TIMEOUT);
201 }
202 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
203 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000204 assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD);
Esin Karamane4890012020-04-19 11:58:54 +0000205
206 // Output port number will be PORT_B i.e. 16
207 Collection<TrafficTreatment> traffictreatMentCollection =
208 nextMap.get(DEVICE_ID_OF_A).next();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000209 assertEquals(1, traffictreatMentCollection.size());
Esin Karamane4890012020-04-19 11:58:54 +0000210 OutputInstruction output = null;
211 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
212 output = outputPort(trafficTreatment);
213 }
214 assertNotNull(output);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000215 assertEquals(PORT_B, output.port());
Esin Karamane4890012020-04-19 11:58:54 +0000216 // Checking the group ip address
217 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
218 IPCriterion ipCriterion = ipAddress(trafficSelector);
219 assertNotNull(ipCriterion);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000220 assertEquals(MULTICAST_IP, ipCriterion.ip().address());
Esin Karamane4890012020-04-19 11:58:54 +0000221 //checking the vlan criteria
222 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
223 VlanIdCriterion vlanIdCriterion = vlanId(meta, Criterion.Type.VLAN_VID);
224 assertNotNull(vlanIdCriterion); //since vlanEnabled flag is true
225 assertEquals(cordMcast.assignedVlan(), vlanIdCriterion.vlanId());
226 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
227 assertNull(innerVlanIdCriterion);
228 }
229
230 @Test
231 public void testAddingSinkEventInnerVlanEnabled() throws InterruptedException {
232 // vlanEnabled is set to true and egressVlan & egressInnerVlan are set
233 init(true, VlanId.vlanId("4000"), VlanId.vlanId("1000"));
234
235 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
236 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
237
238 //Adding the details to create different routes
239 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
240 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
241 // Creating new mcast event for adding sink
242 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
243 cordMcast.listener.event(event);
244 synchronized (forwardMap) {
245 forwardMap.wait(WAIT_TIMEOUT);
246 }
247
248 // ForwardMap will contain the operation "Add" in the flowObjective. None -> CP_B
249 assertNotNull(forwardMap.get(DEVICE_ID_OF_A));
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000250 assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD);
Esin Karamane4890012020-04-19 11:58:54 +0000251
252 // Output port number will be PORT_B i.e. 16
253 Collection<TrafficTreatment> traffictreatMentCollection =
254 nextMap.get(DEVICE_ID_OF_A).next();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000255 assertEquals(1, traffictreatMentCollection.size());
Esin Karamane4890012020-04-19 11:58:54 +0000256 OutputInstruction output = null;
257 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
258 output = outputPort(trafficTreatment);
259 }
260 assertNotNull(output);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000261 assertEquals(PORT_B, output.port());
Esin Karamane4890012020-04-19 11:58:54 +0000262 // Checking the group ip address
263 TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector();
264 IPCriterion ipCriterion = ipAddress(trafficSelector);
265 assertNotNull(ipCriterion);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000266 assertEquals(MULTICAST_IP, ipCriterion.ip().address());
Esin Karamane4890012020-04-19 11:58:54 +0000267 //checking the vlan criteria
268 TrafficSelector meta = forwardMap.get(DEVICE_ID_OF_A).meta();
269 VlanIdCriterion vlanIdCriterion = vlanId(meta, Criterion.Type.VLAN_VID);
270 assertNotNull(vlanIdCriterion); //since vlanEnabled flag is true
271 assertEquals(cordMcast.assignedVlan(), vlanIdCriterion.vlanId());
272 VlanIdCriterion innerVlanIdCriterion = vlanId(meta, Criterion.Type.INNER_VLAN_VID);
273 assertNotNull(innerVlanIdCriterion);
274 assertEquals(cordMcast.assignedInnerVlan(), innerVlanIdCriterion.vlanId());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000275 }
276
277 @Test
278 public void testAddToExistingSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000279 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000280 // Adding first sink (none --> CP_B)
281 testAddingSinkEvent();
282
283 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B));
284 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
285 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
286 sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B, CONNECT_POINT_C));
287 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
288 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
289 // Again listening the mcast event with different output port ( none --> CP_B, CP_C)
290 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
291 cordMcast.listener.event(event);
292
293 // NextMap will contain the operation "ADD_TO_EXISTING" in the DefaultNextObjective.
294 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000295 assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD_TO_EXISTING));
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000296 // Output port number will be changed to 24 i.e. PORT_C
297 Collection<TrafficTreatment> traffictreatMentCollection = nextMap.get(DEVICE_ID_OF_A).next();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000298 assertEquals(1, traffictreatMentCollection.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000299 OutputInstruction output = null;
300 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
301 output = outputPort(trafficTreatment);
302 }
303 assertNotNull(output);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000304 assertEquals(PORT_C, output.port());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000305 }
306
307 @Test
308 public void testRemoveSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000309 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000310 testAddToExistingSinkEvent();
311 // Handling the mcast event for removing sink.
312 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_B, CONNECT_POINT_C));
313 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
314 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
315 sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_C));
316 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
317 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
318 McastEvent event = new McastEvent(McastEvent.Type.SINKS_REMOVED, previousSubject, currentSubject);
319 cordMcast.listener.event(event);
320 // Operation will be REMOVE_FROM_EXISTING and nextMap will be updated. ( None --> CP_C)
321 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000322 assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.REMOVE_FROM_EXISTING));
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000323
324 // Output port number will be PORT_B i.e. 16
325 // Port_B is removed from the group.
326 Collection<TrafficTreatment> traffictreatMentCollection =
327 nextMap.get(DEVICE_ID_OF_A).next();
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000328 assertEquals(1, traffictreatMentCollection.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000329 OutputInstruction output = null;
330 for (TrafficTreatment trafficTreatment : traffictreatMentCollection) {
331 output = outputPort(trafficTreatment);
332 }
333 assertNotNull(output);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000334 assertEquals(PORT_B, output.port());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000335
336 }
337
338 @Test
339 public void testRemoveLastSinkEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000340 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000341 testRemoveSinkEvent();
342 // Handling the mcast event for removing sink.
343 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_C));
344 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
345 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
346 sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
347 sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
348 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
349 McastEvent event = new McastEvent(McastEvent.Type.SINKS_REMOVED, previousSubject, currentSubject);
350 cordMcast.listener.event(event);
351
Andrea Campanella03652352020-05-06 16:12:00 +0200352 // Operation will be REMOVE and nextMap will be updated. None --> { }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000353 assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () ->
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000354 assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.REMOVE));
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000355 }
356
357 @Test
358 public void testUnkownOltDevice() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000359 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000360 // Configuration of mcast event for unknown olt device
361 final DeviceId deviceIdOfB = DeviceId.deviceId("of:1");
362
363 ConnectPoint connectPointA = new ConnectPoint(deviceIdOfB, PORT_A);
364 ConnectPoint connectPointB = new ConnectPoint(deviceIdOfB, PORT_B);
365 Set<ConnectPoint> sourcesCp = new HashSet<ConnectPoint>(Arrays.asList(connectPointA));
366 Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList());
367 Set<ConnectPoint> sinks2Cp = new HashSet<ConnectPoint>(Arrays.asList(connectPointB));
368 Map<HostId, Set<ConnectPoint>> sources = ImmutableMap.of(HOST_ID_NONE, sourcesCp);
369
370 Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp);
371 Map<HostId, Set<ConnectPoint>> sinks2 = ImmutableMap.of(HOST_ID_NONE, sinks2Cp);
372 //Adding the details to create different routes
373 McastRouteUpdate previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
374 McastRouteUpdate currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks2);
375 // Creating new mcast event for adding sink
376 McastEvent event = new McastEvent(McastEvent.Type.SINKS_ADDED, previousSubject, currentSubject);
377 cordMcast.listener.event(event);
378 // OltInfo flag is set to true when olt device is unkown
379 assertAfter(WAIT, WAIT * 2, () -> assertTrue(knownOltFlag));
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000380 assertEquals(0, forwardMap.size());
381 assertEquals(0, nextMap.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000382
383 }
384
385 @Test
386 public void testRouteAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000387 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000388 //Adding the details to create different routes
389 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
390 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
391 // Creating new mcast event for route adding
392 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_ADDED, previousSubject, currentSubject);
393 cordMcast.listener.event(event);
394 // There will be no forwarding objective
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000395 assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size()));
396 assertEquals(0, nextMap.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000397
398 }
399
400
401 @Test
402 public void testRouteRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000403 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000404 testRouteAddedEvent();
405
406 //Adding the details to create different routes
407 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
408 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
409 // Creating new mcast event for route removing
410 McastEvent event = new McastEvent(McastEvent.Type.ROUTE_REMOVED, previousSubject, currentSubject);
411 cordMcast.listener.event(event);
412 // There will be no forwarding objective
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000413 assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size()));
414 assertEquals(0, nextMap.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000415
416 }
417
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000418 @Test
419 public void testSourceAddedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000420 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000421 // Adding route before adding source.
422 testRouteAddedEvent();
423
424 //Adding the details to create different routes
425 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
426 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
427 // Creating new mcast event for source adding
428 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_ADDED, previousSubject, currentSubject);
429 cordMcast.listener.event(event);
430 // There will be no forwarding objective
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000431 assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size()));
432 assertEquals(0, nextMap.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000433
434 }
435
436 @Test
437 public void testSourcesRemovedEvent() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000438 init(false, null, null);
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000439 testSourceAddedEvent();
440
441 //Adding the details to create different routes
442 previousSubject = McastRouteUpdate.mcastRouteUpdate(route1, sources, sinks);
443 currentSubject = McastRouteUpdate.mcastRouteUpdate(route1, emptySource, sinks);
444 // Creating new mcast event for removing source
445 // Warning message of unknown event will be displayed.
446 McastEvent event = new McastEvent(McastEvent.Type.SOURCES_REMOVED, previousSubject, currentSubject);
447 cordMcast.listener.event(event);
Ilayda Ozdemir0414dde2020-06-27 23:18:07 +0000448 assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size()));
449 assertEquals(0, nextMap.size());
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000450 }
451
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000452 @Test
453 public void mcastTestEventGeneration() throws InterruptedException {
Esin Karamane4890012020-04-19 11:58:54 +0000454 init(false, VlanId.vlanId("4000"), VlanId.NONE);
Arjun E Kabf9e6e2020-03-02 10:15:21 +0000455 //fetching route details used to push CordMcastStatisticsEvent.
456 IpAddress testGroup = route1.group();
457 String testSource = route1.source().isEmpty() ? "*" : route1.source().get().toString();
458 VlanId testVlan = cordMcast.assignedVlan();
459
460 // Thread is scheduled without any delay
461 assertAfter(WAIT, WAIT * 2, () ->
462 assertEquals(1, mockListener.mcastEventList.size()));
463
464 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
465 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
466 }
467
468 CordMcastStatistics cordMcastStatistics = mockListener.mcastEventList.get(0).subject().get(0);
469 assertEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
470 assertEquals(testVlan, cordMcastStatistics.getVlanId());
471 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
472 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
473
474 // Test for vlanEnabled
475 Dictionary<String, Object> cfgDict = new Hashtable<>();
476 cfgDict.put("vlanEnabled", true);
477
478 ComponentContext componentContext = EasyMock.createMock(ComponentContext.class);
479 expect(componentContext.getProperties()).andReturn(cfgDict);
480 replay(componentContext);
481 cordMcast.modified(componentContext);
482 testVlan = cordMcast.assignedVlan();
483
484 assertAfter(EVENT_GENERATION_PERIOD, EVENT_GENERATION_PERIOD * 1000, () ->
485 assertEquals(2, mockListener.mcastEventList.size()));
486
487 for (CordMcastStatisticsEvent event: mockListener.mcastEventList) {
488 assertEquals(event.type(), CordMcastStatisticsEvent.Type.STATUS_UPDATE);
489 }
490
491 cordMcastStatistics = mockListener.mcastEventList.get(1).subject().get(0);
492 assertNotEquals(VlanId.NONE, cordMcastStatistics.getVlanId());
493 assertEquals(testVlan, cordMcastStatistics.getVlanId());
494 assertEquals(testSource, cordMcastStatistics.getSourceAddress());
495 assertEquals(testGroup, cordMcastStatistics.getGroupAddress());
496 }
Sonal Kasliwala0bbe6c2020-01-06 10:46:30 +0000497}