Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 1 | /* |
| 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 Moro | 8ea9e10 | 2020-03-24 18:56:52 +0100 | [diff] [blame] | 16 | package org.opencord.cordmcast.impl; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 17 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 18 | import static org.easymock.EasyMock.expect; |
| 19 | import static org.easymock.EasyMock.replay; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 20 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 21 | import org.easymock.EasyMock; |
| 22 | import org.junit.After; |
| 23 | import org.junit.Before; |
| 24 | import org.junit.Test; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 25 | import org.onlab.junit.TestUtils; |
| 26 | import org.onlab.packet.IpAddress; |
| 27 | import org.onlab.packet.VlanId; |
| 28 | import org.onosproject.cfg.ComponentConfigAdapter; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 29 | import org.onosproject.cfg.ComponentConfigService; |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 30 | import org.onosproject.cluster.ClusterServiceAdapter; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 31 | import org.onosproject.mcast.api.McastEvent; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 32 | import org.onosproject.mcast.api.McastRoute; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 33 | import org.onosproject.mcast.api.McastRouteUpdate; |
| 34 | import org.onosproject.mcast.api.MulticastRouteService; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DeviceId; |
| 37 | import org.onosproject.net.HostId; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 38 | import org.onosproject.net.flow.TrafficSelector; |
| 39 | import org.onosproject.net.flow.TrafficTreatment; |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 40 | import org.onosproject.net.flow.criteria.Criterion; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 41 | import org.onosproject.net.flow.criteria.IPCriterion; |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 42 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 43 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 44 | import org.onosproject.net.flowobjective.Objective; |
| 45 | import org.onosproject.store.service.StorageServiceAdapter; |
| 46 | import org.onosproject.store.service.TestConsistentMap; |
Daniele Moro | 8ea9e10 | 2020-03-24 18:56:52 +0100 | [diff] [blame] | 47 | import org.opencord.cordmcast.CordMcastStatistics; |
| 48 | import org.opencord.cordmcast.CordMcastStatisticsEvent; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 49 | import org.osgi.service.component.ComponentContext; |
| 50 | import com.google.common.collect.ImmutableMap; |
| 51 | import com.google.common.collect.Sets; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 52 | |
| 53 | import java.util.Dictionary; |
| 54 | import java.util.HashSet; |
| 55 | import java.util.Hashtable; |
| 56 | import java.util.Set; |
| 57 | import java.util.Map; |
| 58 | import java.util.Arrays; |
| 59 | import java.util.Collection; |
| 60 | |
| 61 | import static org.junit.Assert.*; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 62 | import static org.onlab.junit.TestTools.assertAfter; |
| 63 | |
| 64 | public class McastTest extends McastTestBase { |
| 65 | |
| 66 | private CordMcast cordMcast; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 67 | private CordMcastStatisticsManager cordMcastStatisticsManager; |
| 68 | |
| 69 | private MockCordMcastStatisticsEventListener mockListener = new MockCordMcastStatisticsEventListener(); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 70 | |
| 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 Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 77 | //setup operation is handled by init() method in each test |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @After |
| 81 | public void tearDown() { |
| 82 | cordMcast.deactivate(); |
| 83 | forwardMap.clear(); |
| 84 | nextMap.clear(); |
| 85 | } |
| 86 | |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 87 | private void init(boolean vlanEnabled, VlanId egressVlan, VlanId egressInnerVlan) { |
| 88 | cordMcast = new CordMcast(); |
| 89 | cordMcastStatisticsManager = new CordMcastStatisticsManager(); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 90 | cordMcastStatisticsManager.clusterService = new ClusterServiceAdapter(); |
| 91 | cordMcastStatisticsManager.leadershipService = new LeadershipServiceMcastAdapter(); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 92 | 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 Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 141 | @Test |
| 142 | public void testAddingSinkEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 143 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 144 | |
| 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 160 | assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 161 | |
| 162 | // Output port number will be PORT_B i.e. 16 |
| 163 | Collection<TrafficTreatment> traffictreatMentCollection = |
| 164 | nextMap.get(DEVICE_ID_OF_A).next(); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 165 | assertEquals(1, traffictreatMentCollection.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 166 | OutputInstruction output = null; |
| 167 | for (TrafficTreatment trafficTreatment : traffictreatMentCollection) { |
| 168 | output = outputPort(trafficTreatment); |
| 169 | } |
| 170 | assertNotNull(output); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 171 | assertEquals(PORT_B, output.port()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 172 | // Checking the group ip address |
| 173 | TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector(); |
| 174 | IPCriterion ipCriterion = ipAddress(trafficSelector); |
| 175 | assertNotNull(ipCriterion); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 176 | assertEquals(MULTICAST_IP, ipCriterion.ip().address()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 177 | //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 Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 184 | |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 185 | @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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 204 | assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 205 | |
| 206 | // Output port number will be PORT_B i.e. 16 |
| 207 | Collection<TrafficTreatment> traffictreatMentCollection = |
| 208 | nextMap.get(DEVICE_ID_OF_A).next(); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 209 | assertEquals(1, traffictreatMentCollection.size()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 210 | OutputInstruction output = null; |
| 211 | for (TrafficTreatment trafficTreatment : traffictreatMentCollection) { |
| 212 | output = outputPort(trafficTreatment); |
| 213 | } |
| 214 | assertNotNull(output); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 215 | assertEquals(PORT_B, output.port()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 216 | // Checking the group ip address |
| 217 | TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector(); |
| 218 | IPCriterion ipCriterion = ipAddress(trafficSelector); |
| 219 | assertNotNull(ipCriterion); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 220 | assertEquals(MULTICAST_IP, ipCriterion.ip().address()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 221 | //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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 250 | assertEquals(forwardMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 251 | |
| 252 | // Output port number will be PORT_B i.e. 16 |
| 253 | Collection<TrafficTreatment> traffictreatMentCollection = |
| 254 | nextMap.get(DEVICE_ID_OF_A).next(); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 255 | assertEquals(1, traffictreatMentCollection.size()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 256 | OutputInstruction output = null; |
| 257 | for (TrafficTreatment trafficTreatment : traffictreatMentCollection) { |
| 258 | output = outputPort(trafficTreatment); |
| 259 | } |
| 260 | assertNotNull(output); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 261 | assertEquals(PORT_B, output.port()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 262 | // Checking the group ip address |
| 263 | TrafficSelector trafficSelector = forwardMap.get(DEVICE_ID_OF_A).selector(); |
| 264 | IPCriterion ipCriterion = ipAddress(trafficSelector); |
| 265 | assertNotNull(ipCriterion); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 266 | assertEquals(MULTICAST_IP, ipCriterion.ip().address()); |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 267 | //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 Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | @Test |
| 278 | public void testAddToExistingSinkEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 279 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 280 | // 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 295 | assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.ADD_TO_EXISTING)); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 296 | // Output port number will be changed to 24 i.e. PORT_C |
| 297 | Collection<TrafficTreatment> traffictreatMentCollection = nextMap.get(DEVICE_ID_OF_A).next(); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 298 | assertEquals(1, traffictreatMentCollection.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 299 | OutputInstruction output = null; |
| 300 | for (TrafficTreatment trafficTreatment : traffictreatMentCollection) { |
| 301 | output = outputPort(trafficTreatment); |
| 302 | } |
| 303 | assertNotNull(output); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 304 | assertEquals(PORT_C, output.port()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | @Test |
| 308 | public void testRemoveSinkEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 309 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 310 | 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 322 | assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.REMOVE_FROM_EXISTING)); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 323 | |
| 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 328 | assertEquals(1, traffictreatMentCollection.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 329 | OutputInstruction output = null; |
| 330 | for (TrafficTreatment trafficTreatment : traffictreatMentCollection) { |
| 331 | output = outputPort(trafficTreatment); |
| 332 | } |
| 333 | assertNotNull(output); |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 334 | assertEquals(PORT_B, output.port()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 335 | |
| 336 | } |
| 337 | |
| 338 | @Test |
| 339 | public void testRemoveLastSinkEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 340 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 341 | 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 Campanella | 0365235 | 2020-05-06 16:12:00 +0200 | [diff] [blame] | 352 | // Operation will be REMOVE and nextMap will be updated. None --> { } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 353 | assertAfter(WAIT_TIMEOUT, WAIT_TIMEOUT * 2, () -> |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 354 | assertEquals(nextMap.get(DEVICE_ID_OF_A).op(), Objective.Operation.REMOVE)); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Test |
| 358 | public void testUnkownOltDevice() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 359 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 360 | // 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 380 | assertEquals(0, forwardMap.size()); |
| 381 | assertEquals(0, nextMap.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 382 | |
| 383 | } |
| 384 | |
| 385 | @Test |
| 386 | public void testRouteAddedEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 387 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 388 | //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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 395 | assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size())); |
| 396 | assertEquals(0, nextMap.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 397 | |
| 398 | } |
| 399 | |
| 400 | |
| 401 | @Test |
| 402 | public void testRouteRemovedEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 403 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 404 | 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 413 | assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size())); |
| 414 | assertEquals(0, nextMap.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 415 | |
| 416 | } |
| 417 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 418 | @Test |
| 419 | public void testSourceAddedEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 420 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 421 | // 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 431 | assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size())); |
| 432 | assertEquals(0, nextMap.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 433 | |
| 434 | } |
| 435 | |
| 436 | @Test |
| 437 | public void testSourcesRemovedEvent() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 438 | init(false, null, null); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 439 | 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 Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 448 | assertAfter(WAIT, WAIT * 2, () -> assertEquals(0, forwardMap.size())); |
| 449 | assertEquals(0, nextMap.size()); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 452 | @Test |
| 453 | public void mcastTestEventGeneration() throws InterruptedException { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 454 | init(false, VlanId.vlanId("4000"), VlanId.NONE); |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 455 | //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 Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 497 | } |