Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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 | */ |
| 16 | |
| 17 | package org.opencord.olt.impl; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Assert; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.mockito.Mockito; |
| 24 | import org.onlab.packet.ChassisId; |
| 25 | import org.onlab.packet.EthType; |
| 26 | import org.onlab.packet.IPv4; |
| 27 | import org.onlab.packet.IPv6; |
| 28 | import org.onlab.packet.MacAddress; |
| 29 | import org.onlab.packet.TpPort; |
| 30 | import org.onlab.packet.VlanId; |
| 31 | import org.onosproject.cfg.ComponentConfigAdapter; |
| 32 | import org.onosproject.core.ApplicationId; |
| 33 | import org.onosproject.core.CoreServiceAdapter; |
| 34 | import org.onosproject.core.DefaultApplicationId; |
| 35 | import org.onosproject.net.ConnectPoint; |
| 36 | import org.onosproject.net.DefaultAnnotations; |
| 37 | import org.onosproject.net.DefaultDevice; |
| 38 | import org.onosproject.net.DefaultHost; |
| 39 | import org.onosproject.net.DefaultPort; |
| 40 | import org.onosproject.net.Device; |
| 41 | import org.onosproject.net.DeviceId; |
| 42 | import org.onosproject.net.Host; |
| 43 | import org.onosproject.net.HostId; |
| 44 | import org.onosproject.net.HostLocation; |
| 45 | import org.onosproject.net.Port; |
| 46 | import org.onosproject.net.PortNumber; |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 47 | import org.onosproject.net.device.DeviceService; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 48 | import org.onosproject.net.flow.DefaultFlowRule; |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 49 | import org.onosproject.net.flow.DefaultTrafficSelector; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 50 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 51 | import org.onosproject.net.flow.FlowRule; |
| 52 | import org.onosproject.net.flow.FlowRuleEvent; |
| 53 | import org.onosproject.net.flow.FlowRuleService; |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 54 | import org.onosproject.net.flow.TrafficSelector; |
| 55 | import org.onosproject.net.flow.TrafficTreatment; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 56 | import org.onosproject.net.flow.criteria.Criteria; |
| 57 | import org.onosproject.net.flowobjective.DefaultFilteringObjective; |
| 58 | import org.onosproject.net.flowobjective.FilteringObjective; |
| 59 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
| 60 | import org.onosproject.net.host.HostService; |
| 61 | import org.onosproject.net.meter.MeterId; |
| 62 | import org.onosproject.net.provider.ProviderId; |
| 63 | import org.onosproject.store.service.TestStorageService; |
| 64 | import org.opencord.sadis.BaseInformationService; |
| 65 | import org.opencord.sadis.SadisService; |
| 66 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
| 67 | import org.opencord.sadis.UniTagInformation; |
| 68 | |
| 69 | import java.util.Arrays; |
| 70 | import java.util.HashSet; |
| 71 | import java.util.LinkedList; |
| 72 | import java.util.List; |
| 73 | import java.util.Set; |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 74 | import java.util.concurrent.TimeUnit; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 75 | |
| 76 | import static org.mockito.Matchers.any; |
| 77 | import static org.mockito.Matchers.argThat; |
| 78 | import static org.mockito.Matchers.eq; |
| 79 | import static org.mockito.Mockito.doReturn; |
| 80 | import static org.mockito.Mockito.never; |
| 81 | import static org.mockito.Mockito.spy; |
| 82 | import static org.mockito.Mockito.times; |
| 83 | import static org.mockito.Mockito.verify; |
| 84 | import static org.onosproject.net.AnnotationKeys.PORT_NAME; |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 85 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.ERROR; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 86 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.NONE; |
| 87 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.ADDED; |
| 88 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.PENDING_ADD; |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 89 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.PENDING_REMOVE; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 90 | import static org.opencord.olt.impl.OltFlowService.OltFlowsStatus.REMOVED; |
| 91 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_BP_ID_DEFAULT; |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 92 | import static org.opencord.olt.impl.OsgiPropertyConstants.DEFAULT_MCAST_SERVICE_NAME; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 93 | |
| 94 | public class OltFlowServiceTest extends OltTestHelpers { |
| 95 | |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 96 | public static final String PORT_1 = "port-1"; |
| 97 | public static final String PORT_2 = "port-2"; |
| 98 | public static final String PORT_3 = "port-3"; |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 99 | private OltFlowService component; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 100 | private OltFlowService oltFlowService; |
| 101 | OltFlowService.InternalFlowListener internalFlowListener; |
| 102 | private final ApplicationId testAppId = new DefaultApplicationId(1, "org.opencord.olt.test"); |
| 103 | private final short eapolDefaultVlan = 4091; |
| 104 | |
| 105 | private final DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 106 | private final Device testDevice = new DefaultDevice(ProviderId.NONE, deviceId, Device.Type.OLT, |
| 107 | "testManufacturer", "1.0", "1.0", "SN", new ChassisId(1)); |
| 108 | Port nniPort = new OltPort(testDevice, true, PortNumber.portNumber(1048576), |
| 109 | DefaultAnnotations.builder().set(PORT_NAME, "nni-1").build()); |
| 110 | Port nniPortDisabled = new OltPort(testDevice, false, PortNumber.portNumber(1048576), |
| 111 | DefaultAnnotations.builder().set(PORT_NAME, "nni-1").build()); |
| 112 | Port uniUpdateEnabled = new OltPort(testDevice, true, PortNumber.portNumber(16), |
| 113 | DefaultAnnotations.builder().set(PORT_NAME, "uni-1").build()); |
| 114 | |
| 115 | @Before |
| 116 | public void setUp() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 117 | component = new OltFlowService(); |
| 118 | component.cfgService = new ComponentConfigAdapter(); |
| 119 | component.sadisService = Mockito.mock(SadisService.class); |
| 120 | component.coreService = Mockito.spy(new CoreServiceAdapter()); |
| 121 | component.oltMeterService = Mockito.mock(OltMeterService.class); |
| 122 | component.flowObjectiveService = Mockito.mock(FlowObjectiveService.class); |
| 123 | component.hostService = Mockito.mock(HostService.class); |
| 124 | component.flowRuleService = Mockito.mock(FlowRuleService.class); |
| 125 | component.storageService = new TestStorageService(); |
| 126 | component.oltDeviceService = Mockito.mock(OltDeviceService.class); |
| 127 | component.appId = testAppId; |
| 128 | component.deviceService = Mockito.mock(DeviceService.class); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 129 | |
| 130 | doReturn(Mockito.mock(BaseInformationService.class)) |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 131 | .when(component.sadisService).getSubscriberInfoService(); |
| 132 | doReturn(testAppId).when(component.coreService).registerApplication("org.opencord.olt"); |
| 133 | component.activate(null); |
| 134 | component.bindSadisService(component.sadisService); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 135 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 136 | internalFlowListener = spy(component.internalFlowListener); |
| 137 | |
| 138 | oltFlowService = spy(component); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @After |
| 142 | public void tearDown() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 143 | component.deactivate(null); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | @Test |
| 147 | public void testUpdateConnectPointStatus() { |
| 148 | |
| 149 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 150 | ProviderId pid = new ProviderId("of", "foo"); |
| 151 | Device device = |
| 152 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 153 | Port port1 = new DefaultPort(device, PortNumber.portNumber(1), true, |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 154 | DefaultAnnotations.builder().set(PORT_NAME, PORT_1).build()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 155 | Port port2 = new DefaultPort(device, PortNumber.portNumber(2), true, |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 156 | DefaultAnnotations.builder().set(PORT_NAME, PORT_2).build()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 157 | Port port3 = new DefaultPort(device, PortNumber.portNumber(3), true, |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 158 | DefaultAnnotations.builder().set(PORT_NAME, PORT_3).build()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 159 | |
| 160 | ServiceKey sk1 = new ServiceKey(new AccessDevicePort(port1), new UniTagInformation()); |
| 161 | ServiceKey sk2 = new ServiceKey(new AccessDevicePort(port2), new UniTagInformation()); |
| 162 | ServiceKey sk3 = new ServiceKey(new AccessDevicePort(port3), new UniTagInformation()); |
| 163 | |
| 164 | // cpStatus map for the test |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 165 | component.cpStatus = component.storageService. |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 166 | <ServiceKey, OltPortStatus>consistentMapBuilder().build().asJavaMap(); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 167 | OltPortStatus cp1Status = new OltPortStatus(PENDING_ADD, NONE, NONE, NONE, NONE); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 168 | component.cpStatus.put(sk1, cp1Status); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 169 | |
| 170 | //check that we only update the provided value |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 171 | component.updateConnectPointStatus(sk1, ADDED, null, null, null, null); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 172 | OltPortStatus updated = component.cpStatus.get(sk1); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 173 | Assert.assertEquals(ADDED, updated.defaultEapolStatus); |
| 174 | Assert.assertEquals(NONE, updated.subscriberFlowsStatus); |
| 175 | Assert.assertEquals(NONE, updated.dhcpStatus); |
| 176 | |
| 177 | // check that it creates an entry if it does not exist |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 178 | component.updateConnectPointStatus(sk2, PENDING_ADD, NONE, NONE, NONE, NONE); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 179 | Assert.assertNotNull(component.cpStatus.get(sk2)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 180 | |
| 181 | // check that if we create a new entry with null values they're converted to NONE |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 182 | component.updateConnectPointStatus(sk3, null, null, null, null, null); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 183 | updated = component.cpStatus.get(sk3); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 184 | Assert.assertEquals(NONE, updated.defaultEapolStatus); |
| 185 | Assert.assertEquals(NONE, updated.subscriberFlowsStatus); |
| 186 | Assert.assertEquals(NONE, updated.dhcpStatus); |
| 187 | } |
| 188 | |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 189 | /** |
| 190 | * If the flow status is PENDING_REMOVE or ERROR and there is no |
| 191 | * previous state in the map that don't update it. |
| 192 | * In case of a device disconnection we immediately wipe out the status, |
| 193 | * but then flows might update the cpStatus map. That result |
| 194 | */ |
| 195 | @Test |
| 196 | public void doNotUpdateConnectPointStatus() { |
| 197 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 198 | ProviderId pid = new ProviderId("of", "foo"); |
| 199 | Device device = |
| 200 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 201 | Port port1 = new DefaultPort(device, PortNumber.portNumber(1), true, |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 202 | DefaultAnnotations.builder().set(PORT_NAME, PORT_1).build()); |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 203 | |
| 204 | ServiceKey sk1 = new ServiceKey(new AccessDevicePort(port1), new UniTagInformation()); |
| 205 | |
| 206 | // cpStatus map for the test |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 207 | component.cpStatus = component.storageService. |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 208 | <ServiceKey, OltPortStatus>consistentMapBuilder().build().asJavaMap(); |
| 209 | |
| 210 | // check that an entry is not created if the only status is pending remove |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 211 | component.updateConnectPointStatus(sk1, null, null, null, PENDING_REMOVE, null); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 212 | OltPortStatus entry = component.cpStatus.get(sk1); |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 213 | Assert.assertNull(entry); |
| 214 | |
| 215 | // check that an entry is not created if the only status is ERROR |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 216 | component.updateConnectPointStatus(sk1, null, null, null, ERROR, null); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 217 | entry = component.cpStatus.get(sk1); |
Matteo Scandolo | 2542e5d | 2021-12-01 16:53:41 -0800 | [diff] [blame] | 218 | Assert.assertNull(entry); |
| 219 | } |
| 220 | |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 221 | @Test |
| 222 | public void testHasDefaultEapol() { |
| 223 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 224 | ProviderId pid = new ProviderId("of", "foo"); |
| 225 | |
| 226 | Device device = |
| 227 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 228 | |
| 229 | Port port = new DefaultPort(device, PortNumber.portNumber(16), true, |
| 230 | DefaultAnnotations.builder().set(PORT_NAME, "name-1").build()); |
| 231 | ServiceKey skWithStatus = new ServiceKey(new AccessDevicePort(port), |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 232 | component.defaultEapolUniTag); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 233 | |
| 234 | Port port17 = new DefaultPort(device, PortNumber.portNumber(17), true, |
| 235 | DefaultAnnotations.builder().set(PORT_NAME, "name-1").build()); |
| 236 | |
| 237 | OltPortStatus portStatusAdded = new OltPortStatus( |
| 238 | OltFlowService.OltFlowsStatus.ADDED, |
| 239 | NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 240 | null, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 241 | null, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 242 | null |
| 243 | ); |
| 244 | |
| 245 | OltPortStatus portStatusRemoved = new OltPortStatus( |
| 246 | REMOVED, |
| 247 | NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 248 | null, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 249 | null, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 250 | null |
| 251 | ); |
| 252 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 253 | component.cpStatus.put(skWithStatus, portStatusAdded); |
| 254 | Assert.assertTrue(component.hasDefaultEapol(port)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 255 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 256 | component.cpStatus.put(skWithStatus, portStatusRemoved); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 257 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 258 | Assert.assertFalse(component.hasDefaultEapol(port17)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Test |
| 262 | public void testHasSubscriberFlows() { |
| 263 | // TODO test with multiple services |
| 264 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 265 | ProviderId pid = new ProviderId("of", "foo"); |
| 266 | |
| 267 | Device device = |
| 268 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 269 | |
| 270 | Port port = new DefaultPort(device, PortNumber.portNumber(16), true, |
| 271 | DefaultAnnotations.builder().set(PORT_NAME, "name-1").build()); |
| 272 | |
| 273 | UniTagInformation uti = new UniTagInformation.Builder().setServiceName("test").build(); |
| 274 | ServiceKey skWithStatus = new ServiceKey(new AccessDevicePort(port), |
| 275 | uti); |
| 276 | |
| 277 | OltPortStatus withDefaultEapol = new OltPortStatus( |
| 278 | ADDED, |
| 279 | NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 280 | NONE, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 281 | NONE, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 282 | NONE |
| 283 | ); |
| 284 | |
| 285 | OltPortStatus withDhcp = new OltPortStatus( |
| 286 | REMOVED, |
| 287 | NONE, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 288 | NONE, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 289 | ADDED, |
| 290 | NONE |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 291 | ); |
| 292 | |
| 293 | OltPortStatus withSubFlow = new OltPortStatus( |
| 294 | REMOVED, |
| 295 | ADDED, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 296 | ADDED, |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 297 | ADDED, |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 298 | NONE |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 299 | ); |
| 300 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 301 | component.cpStatus.put(skWithStatus, withDefaultEapol); |
| 302 | Assert.assertFalse(component.hasSubscriberFlows(port, uti)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 303 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 304 | component.cpStatus.put(skWithStatus, withDhcp); |
| 305 | Assert.assertTrue(component.hasDhcpFlows(port, uti)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 306 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 307 | component.cpStatus.put(skWithStatus, withSubFlow); |
| 308 | Assert.assertTrue(component.hasSubscriberFlows(port, uti)); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | @Test |
| 312 | public void testHandleBasicPortFlowsNoEapol() throws Exception { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 313 | component.enableEapol = false; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 314 | // create empty service for testing |
| 315 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 316 | UniTagInformation empty = new UniTagInformation.Builder().build(); |
| 317 | uniTagInformationList.add(empty); |
| 318 | |
| 319 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 320 | si.setUniTagList(uniTagInformationList); |
| 321 | |
| 322 | final DiscoveredSubscriber addedSub = |
| 323 | new DiscoveredSubscriber(testDevice, |
| 324 | uniUpdateEnabled, DiscoveredSubscriber.Status.ADDED, |
| 325 | false, si); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 326 | component.handleBasicPortFlows(addedSub, DEFAULT_BP_ID_DEFAULT, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 327 | // if eapol is not enabled there's nothing we need to do, |
| 328 | // so make sure we don't even call sadis |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 329 | verify(component.subsService, never()).get(any()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Test |
| 333 | public void testHandleBasicPortFlowsWithEapolNoMeter() throws Exception { |
| 334 | // create empty service for testing |
| 335 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 336 | UniTagInformation empty = new UniTagInformation.Builder().build(); |
| 337 | uniTagInformationList.add(empty); |
| 338 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 339 | si.setUniTagList(uniTagInformationList); |
| 340 | final DiscoveredSubscriber addedSub = |
| 341 | new DiscoveredSubscriber(testDevice, |
| 342 | uniUpdateEnabled, DiscoveredSubscriber.Status.ADDED, |
| 343 | false, si); |
| 344 | // whether the meter is pending or not is up to the createMeter method to handle |
| 345 | // we just don't proceed with the subscriber till it's ready |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 346 | doReturn(false).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 347 | .createMeter(addedSub.device.id(), DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 348 | boolean res = component.handleBasicPortFlows(addedSub, DEFAULT_BP_ID_DEFAULT, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 349 | |
| 350 | Assert.assertFalse(res); |
| 351 | |
| 352 | // we do not create flows |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 353 | verify(component.flowObjectiveService, never()) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 354 | .filter(eq(addedSub.device.id()), any()); |
| 355 | } |
| 356 | |
| 357 | @Test |
| 358 | public void testHandleBasicPortFlowsWithEapolAddedMeter() throws Exception { |
| 359 | // create empty service for testing |
| 360 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 361 | UniTagInformation empty = new UniTagInformation.Builder().build(); |
| 362 | uniTagInformationList.add(empty); |
| 363 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 364 | si.setUniTagList(uniTagInformationList); |
| 365 | final DiscoveredSubscriber addedSub = |
| 366 | new DiscoveredSubscriber(testDevice, |
| 367 | uniUpdateEnabled, DiscoveredSubscriber.Status.ADDED, |
| 368 | false, si); |
| 369 | // this is the happy case, we have the meter so we check that the default EAPOL flow |
| 370 | // is installed |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 371 | doReturn(true).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 372 | .createMeter(deviceId, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 373 | doReturn(true).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 374 | .hasMeterByBandwidthProfile(deviceId, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 375 | doReturn(MeterId.meterId(1)).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 376 | .getMeterIdForBandwidthProfile(deviceId, DEFAULT_BP_ID_DEFAULT); |
| 377 | |
| 378 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 379 | .permit() |
| 380 | .withKey(Criteria.matchInPort(uniUpdateEnabled.number())) |
| 381 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 382 | .fromApp(testAppId) |
| 383 | .withPriority(10000) |
| 384 | .withMeta( |
| 385 | DefaultTrafficTreatment.builder() |
| 386 | .meter(MeterId.meterId(1)) |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 387 | .writeMetadata(component.createTechProfValueForWriteMetadata( |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 388 | VlanId.vlanId(eapolDefaultVlan), |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 389 | component.defaultTechProfileId, MeterId.meterId(1)), 0) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 390 | .setOutput(PortNumber.CONTROLLER) |
| 391 | .pushVlan() |
| 392 | .setVlanId(VlanId.vlanId(eapolDefaultVlan)).build() |
| 393 | ) |
| 394 | .add(); |
| 395 | |
| 396 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 397 | component.handleBasicPortFlows(addedSub, DEFAULT_BP_ID_DEFAULT, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 398 | |
| 399 | // we check for an existing meter (present) |
| 400 | // FIXME understand why the above test invokes this call and this one doesn't |
| 401 | // verify(oltFlowService.oltMeterService, times(1)) |
| 402 | // .hasMeterByBandwidthProfile(eq(addedSub.device.id()), eq(DEFAULT_BP_ID_DEFAULT)); |
| 403 | |
| 404 | // the meter exist, no need to check for PENDING or to create it |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 405 | verify(component.oltMeterService, never()) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 406 | .hasPendingMeterByBandwidthProfile(eq(deviceId), eq(DEFAULT_BP_ID_DEFAULT)); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 407 | verify(component.oltMeterService, never()) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 408 | .createMeterForBp(eq(deviceId), eq(DEFAULT_BP_ID_DEFAULT)); |
| 409 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 410 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 411 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 412 | } |
| 413 | |
| 414 | @Test |
| 415 | public void testHandleBasicPortFlowsRemovedSub() throws Exception { |
| 416 | // create empty service for testing |
| 417 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 418 | UniTagInformation empty = new UniTagInformation.Builder().build(); |
| 419 | uniTagInformationList.add(empty); |
| 420 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 421 | si.setUniTagList(uniTagInformationList); |
| 422 | final DiscoveredSubscriber removedSub = |
| 423 | new DiscoveredSubscriber(testDevice, |
| 424 | uniUpdateEnabled, DiscoveredSubscriber.Status.REMOVED, |
| 425 | false, si); |
| 426 | // we are testing that when a port goes down we remove the default EAPOL flow |
| 427 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 428 | doReturn(MeterId.meterId(1)).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 429 | .getMeterIdForBandwidthProfile(deviceId, DEFAULT_BP_ID_DEFAULT); |
| 430 | |
| 431 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 432 | .deny() |
| 433 | .withKey(Criteria.matchInPort(uniUpdateEnabled.number())) |
| 434 | .addCondition(Criteria.matchEthType(EthType.EtherType.EAPOL.ethType())) |
| 435 | .fromApp(testAppId) |
| 436 | .withPriority(10000) |
| 437 | .withMeta( |
| 438 | DefaultTrafficTreatment.builder() |
| 439 | .meter(MeterId.meterId(1)) |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 440 | .writeMetadata(component.createTechProfValueForWriteMetadata( |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 441 | VlanId.vlanId(eapolDefaultVlan), |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 442 | component.defaultTechProfileId, MeterId.meterId(1)), 0) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 443 | .setOutput(PortNumber.CONTROLLER) |
| 444 | .pushVlan() |
| 445 | .setVlanId(VlanId.vlanId(eapolDefaultVlan)).build() |
| 446 | ) |
| 447 | .add(); |
| 448 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 449 | component.handleBasicPortFlows(removedSub, DEFAULT_BP_ID_DEFAULT, DEFAULT_BP_ID_DEFAULT); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 450 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 451 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 452 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 453 | } |
| 454 | |
| 455 | @Test |
| 456 | public void testHandleNniFlowsOnlyLldp() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 457 | component.enableDhcpOnNni = false; |
| 458 | component.handleNniFlows(testDevice, nniPort, OltFlowService.FlowOperation.ADD); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 459 | |
| 460 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 461 | .permit() |
| 462 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 463 | .addCondition(Criteria.matchEthType(EthType.EtherType.LLDP.ethType())) |
| 464 | .fromApp(testAppId) |
| 465 | .withPriority(10000) |
| 466 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 467 | .add(); |
| 468 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 469 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 470 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 471 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 472 | .filter(eq(deviceId), any()); |
| 473 | } |
| 474 | |
| 475 | @Test |
| 476 | public void testHandleNniFlowsDhcpV4() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 477 | component.enableDhcpOnNni = true; |
| 478 | component.enableDhcpV4 = true; |
| 479 | component.handleNniFlows(testDevice, nniPort, OltFlowService.FlowOperation.ADD); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 480 | |
| 481 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 482 | .permit() |
| 483 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 484 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 485 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 486 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(67))) |
| 487 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(68))) |
| 488 | .fromApp(testAppId) |
| 489 | .withPriority(10000) |
| 490 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 491 | .add(); |
| 492 | |
| 493 | // invoked with the correct DHCP filtering objective |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 494 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 495 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 496 | // invoked only twice, LLDP and DHCP |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 497 | verify(component.flowObjectiveService, times(2)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 498 | .filter(eq(deviceId), any()); |
| 499 | } |
| 500 | |
| 501 | @Test |
| 502 | public void testRemoveNniFlowsDhcpV4() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 503 | component.enableDhcpOnNni = true; |
| 504 | component.enableDhcpV4 = true; |
| 505 | component.handleNniFlows(testDevice, nniPortDisabled, OltFlowService.FlowOperation.REMOVE); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 506 | |
| 507 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 508 | .deny() |
| 509 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 510 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 511 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 512 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(67))) |
| 513 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(68))) |
| 514 | .fromApp(testAppId) |
| 515 | .withPriority(10000) |
| 516 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 517 | .add(); |
| 518 | |
| 519 | // invoked with the correct DHCP filtering objective |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 520 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 521 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 522 | // invoked only twice, LLDP and DHCP |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 523 | verify(component.flowObjectiveService, times(2)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 524 | .filter(eq(deviceId), any()); |
| 525 | } |
| 526 | |
| 527 | @Test |
| 528 | public void testHandleNniFlowsDhcpV6() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 529 | component.enableDhcpOnNni = true; |
| 530 | component.enableDhcpV4 = false; |
| 531 | component.enableDhcpV6 = true; |
| 532 | component.handleNniFlows(testDevice, nniPort, OltFlowService.FlowOperation.ADD); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 533 | |
| 534 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 535 | .permit() |
| 536 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 537 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV6.ethType())) |
| 538 | .addCondition(Criteria.matchIPProtocol(IPv6.PROTOCOL_UDP)) |
| 539 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(546))) |
| 540 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(547))) |
| 541 | .fromApp(testAppId) |
| 542 | .withPriority(10000) |
| 543 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 544 | .add(); |
| 545 | |
| 546 | // invoked with the correct DHCP filtering objective |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 547 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 548 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 549 | // invoked only twice, LLDP and DHCP |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 550 | verify(component.flowObjectiveService, times(2)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 551 | .filter(eq(deviceId), any()); |
| 552 | } |
| 553 | |
| 554 | @Test |
| 555 | public void testHandleNniFlowsIgmp() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 556 | component.enableDhcpOnNni = false; |
| 557 | component.enableIgmpOnNni = true; |
| 558 | component.handleNniFlows(testDevice, nniPort, OltFlowService.FlowOperation.ADD); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 559 | |
| 560 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 561 | .permit() |
| 562 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 563 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 564 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_IGMP)) |
| 565 | .fromApp(testAppId) |
| 566 | .withPriority(10000) |
| 567 | .add(); |
| 568 | |
| 569 | // invoked with the correct DHCP filtering objective |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 570 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 571 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 572 | // invoked only twice, LLDP and DHCP |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 573 | verify(component.flowObjectiveService, times(2)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 574 | .filter(eq(deviceId), any()); |
| 575 | } |
| 576 | |
| 577 | @Test |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 578 | public void testHandleNniFlowsPppoe() { |
| 579 | component.enablePppoeOnNni = true; |
| 580 | component.enablePppoe = true; |
| 581 | component.handleNniFlows(testDevice, nniPort, OltFlowService.FlowOperation.ADD); |
| 582 | |
| 583 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 584 | .permit() |
| 585 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 586 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 587 | .fromApp(testAppId) |
| 588 | .withPriority(10000) |
| 589 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 590 | .add(); |
| 591 | |
| 592 | // invoked with the correct Pppoe filtering objective |
| 593 | verify(component.flowObjectiveService, times(1)) |
| 594 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 595 | // invoked only twice, LLDP and DHCP |
| 596 | verify(component.flowObjectiveService, times(2)) |
| 597 | .filter(eq(deviceId), any()); |
| 598 | } |
| 599 | |
| 600 | @Test |
| 601 | public void testRemoveNniFlowsPppoe() { |
| 602 | component.enablePppoeOnNni = true; |
| 603 | component.enablePppoe = true; |
| 604 | component.handleNniFlows(testDevice, nniPortDisabled, OltFlowService.FlowOperation.REMOVE); |
| 605 | |
| 606 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 607 | .deny() |
| 608 | .withKey(Criteria.matchInPort(nniPort.number())) |
| 609 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 610 | .fromApp(testAppId) |
| 611 | .withPriority(10000) |
| 612 | .withMeta(DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build()) |
| 613 | .add(); |
| 614 | |
| 615 | // invoked with the correct Pppoe filtering objective |
| 616 | verify(component.flowObjectiveService, times(1)) |
| 617 | .filter(eq(deviceId), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 618 | // invoked only twice, LLDP and DHCP |
| 619 | verify(component.flowObjectiveService, times(2)) |
| 620 | .filter(eq(deviceId), any()); |
| 621 | } |
| 622 | |
| 623 | @Test |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 624 | public void testMacAddressNotRequired() { |
| 625 | // create a single service that doesn't require mac address |
| 626 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 627 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 628 | .setEnableMacLearning(false) |
| 629 | .build(); |
| 630 | uniTagInformationList.add(hsia); |
| 631 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 632 | si.setUniTagList(uniTagInformationList); |
| 633 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 634 | boolean isMacAvailable = component.isMacAddressAvailable(testDevice.id(), uniUpdateEnabled, si); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 635 | // we return true as we don't care wether it's available or not |
| 636 | Assert.assertTrue(isMacAvailable); |
| 637 | } |
| 638 | |
| 639 | @Test |
| 640 | public void testIsMacAddressAvailableViaMacLearning() { |
| 641 | |
| 642 | // create a single service that requires macLearning to be enabled |
| 643 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 644 | VlanId hsiaCtag = VlanId.vlanId((short) 11); |
| 645 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 646 | .setPonCTag(hsiaCtag) |
| 647 | .setEnableMacLearning(true).build(); |
| 648 | uniTagInformationList.add(hsia); |
| 649 | |
| 650 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 651 | si.setUniTagList(uniTagInformationList); |
| 652 | |
| 653 | // with no hosts discovered, return false |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 654 | boolean isMacAvailable = component.isMacAddressAvailable(testDevice.id(), uniUpdateEnabled, si); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 655 | Assert.assertFalse(isMacAvailable); |
| 656 | |
| 657 | // with a discovered host, return true |
| 658 | Host fakeHost = new DefaultHost(ProviderId.NONE, HostId.hostId(MacAddress.NONE), MacAddress.ZERO, |
| 659 | hsiaCtag, HostLocation.NONE, new HashSet<>(), DefaultAnnotations.builder().build()); |
| 660 | Set<Host> hosts = new HashSet<>(Arrays.asList(fakeHost)); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 661 | doReturn(hosts).when(component.hostService).getConnectedHosts((ConnectPoint) any()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 662 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 663 | isMacAvailable = component.isMacAddressAvailable(testDevice.id(), uniUpdateEnabled, si); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 664 | Assert.assertTrue(isMacAvailable); |
| 665 | } |
| 666 | |
| 667 | @Test |
| 668 | public void testIsMacAddressAvailableViaConfiguration() { |
| 669 | // create a single service that has a macAddress configured |
| 670 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 671 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 672 | .setConfiguredMacAddress("2e:0a:00:01:00:00") |
| 673 | .build(); |
| 674 | uniTagInformationList.add(hsia); |
| 675 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 676 | si.setUniTagList(uniTagInformationList); |
| 677 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 678 | boolean isMacAvailable = component.isMacAddressAvailable(testDevice.id(), uniUpdateEnabled, si); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 679 | Assert.assertTrue(isMacAvailable); |
| 680 | } |
| 681 | |
| 682 | @Test |
| 683 | public void testHandleSubscriberDhcpFlowsAdd() { |
| 684 | |
| 685 | String usBp = "usBp"; |
| 686 | String usOltBp = "usOltBp"; |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 687 | component.enableDhcpV4 = true; |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 688 | |
| 689 | // create two services, one requires DHCP the other doesn't |
| 690 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 691 | VlanId hsiaCtag = VlanId.vlanId((short) 11); |
| 692 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 693 | .setPonCTag(hsiaCtag) |
| 694 | .setTechnologyProfileId(64) |
| 695 | .setUniTagMatch(VlanId.vlanId(VlanId.NO_VID)) |
| 696 | .setUpstreamBandwidthProfile(usBp) |
| 697 | .setUpstreamOltBandwidthProfile(usOltBp) |
| 698 | .setIsDhcpRequired(true).build(); |
| 699 | UniTagInformation mc = new UniTagInformation.Builder() |
| 700 | .setIsDhcpRequired(false).build(); |
| 701 | uniTagInformationList.add(hsia); |
| 702 | uniTagInformationList.add(mc); |
| 703 | |
| 704 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 705 | si.setUniTagList(uniTagInformationList); |
| 706 | |
| 707 | final DiscoveredSubscriber addedSub = |
| 708 | new DiscoveredSubscriber(testDevice, |
| 709 | uniUpdateEnabled, DiscoveredSubscriber.Status.ADDED, |
| 710 | false, si); |
| 711 | |
| 712 | // return meter IDs |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 713 | doReturn(MeterId.meterId(2)).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 714 | .getMeterIdForBandwidthProfile(addedSub.device.id(), usBp); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 715 | doReturn(MeterId.meterId(3)).when(component.oltMeterService) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 716 | .getMeterIdForBandwidthProfile(addedSub.device.id(), usOltBp); |
| 717 | |
| 718 | // TODO improve the matches on the filter |
| 719 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 720 | .permit() |
| 721 | .withKey(Criteria.matchInPort(addedSub.port.number())) |
| 722 | .addCondition(Criteria.matchEthType(EthType.EtherType.IPV4.ethType())) |
| 723 | .addCondition(Criteria.matchIPProtocol(IPv4.PROTOCOL_UDP)) |
| 724 | .addCondition(Criteria.matchUdpSrc(TpPort.tpPort(68))) |
| 725 | .addCondition(Criteria.matchUdpDst(TpPort.tpPort(67))) |
| 726 | .fromApp(testAppId) |
| 727 | .withPriority(10000) |
| 728 | .add(); |
| 729 | |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 730 | component.handleSubscriberDhcpFlows(addedSub.device.id(), addedSub.port, |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 731 | OltFlowService.FlowOperation.ADD, si); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 732 | verify(component.flowObjectiveService, times(1)) |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 733 | .filter(eq(addedSub.device.id()), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 734 | } |
| 735 | |
| 736 | @Test |
yasin sapli | 0823c93 | 2022-01-26 11:26:09 +0000 | [diff] [blame] | 737 | public void testHandleSubscriberPppoeFlowsAdd() { |
| 738 | |
| 739 | String usBp = "usBp"; |
| 740 | String usOltBp = "usOltBp"; |
| 741 | component.enablePppoe = true; |
| 742 | |
| 743 | // create two services, one requires Pppoe the other doesn't |
| 744 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 745 | VlanId hsiaCtag = VlanId.vlanId((short) 11); |
| 746 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 747 | .setPonCTag(hsiaCtag) |
| 748 | .setTechnologyProfileId(64) |
| 749 | .setUniTagMatch(VlanId.vlanId(VlanId.NO_VID)) |
| 750 | .setUpstreamBandwidthProfile(usBp) |
| 751 | .setUpstreamOltBandwidthProfile(usOltBp) |
| 752 | .setIsPppoeRequired(true).build(); |
| 753 | UniTagInformation mc = new UniTagInformation.Builder() |
| 754 | .setIsPppoeRequired(false).build(); |
| 755 | uniTagInformationList.add(hsia); |
| 756 | uniTagInformationList.add(mc); |
| 757 | |
| 758 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 759 | si.setUniTagList(uniTagInformationList); |
| 760 | |
| 761 | final DiscoveredSubscriber addedSub = |
| 762 | new DiscoveredSubscriber(testDevice, |
| 763 | uniUpdateEnabled, DiscoveredSubscriber.Status.ADDED, |
| 764 | false, si); |
| 765 | |
| 766 | // return meter IDs |
| 767 | doReturn(MeterId.meterId(2)).when(component.oltMeterService) |
| 768 | .getMeterIdForBandwidthProfile(addedSub.device.id(), usBp); |
| 769 | doReturn(MeterId.meterId(3)).when(component.oltMeterService) |
| 770 | .getMeterIdForBandwidthProfile(addedSub.device.id(), usOltBp); |
| 771 | |
| 772 | FilteringObjective expectedFilter = DefaultFilteringObjective.builder() |
| 773 | .permit() |
| 774 | .withKey(Criteria.matchInPort(addedSub.port.number())) |
| 775 | .addCondition(Criteria.matchEthType(EthType.EtherType.PPPoED.ethType())) |
| 776 | .fromApp(testAppId) |
| 777 | .withPriority(10000) |
| 778 | .add(); |
| 779 | |
| 780 | component.handleSubscriberPppoeFlows(addedSub.device.id(), addedSub.port, |
| 781 | OltFlowService.FlowOperation.ADD, si); |
| 782 | verify(component.flowObjectiveService, times(1)) |
| 783 | .filter(eq(addedSub.device.id()), argThat(new FilteringObjectiveMatcher(expectedFilter))); |
| 784 | } |
| 785 | |
| 786 | @Test |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 787 | public void testInternalFlowListenerNotMaster() { |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 788 | doReturn(false).when(component.oltDeviceService).isLocalLeader(any()); |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 789 | |
| 790 | FlowRule flowRule = DefaultFlowRule.builder() |
| 791 | .forDevice(DeviceId.deviceId("foo")) |
| 792 | .fromApp(testAppId) |
| 793 | .makePermanent() |
| 794 | .withPriority(1000) |
| 795 | .build(); |
| 796 | FlowRuleEvent event = new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, |
| 797 | flowRule); |
| 798 | |
| 799 | internalFlowListener.event(event); |
| 800 | |
| 801 | // if we're not master of the device, we should not update |
| 802 | verify(internalFlowListener, never()).updateCpStatus(any(), any(), any()); |
| 803 | } |
| 804 | |
| 805 | @Test |
| 806 | public void testInternalFlowListenerDifferentApp() { |
| 807 | ApplicationId someAppId = new DefaultApplicationId(1, "org.opencord.olt.not-test"); |
| 808 | FlowRule flowRule = DefaultFlowRule.builder() |
| 809 | .forDevice(DeviceId.deviceId("foo")) |
| 810 | .fromApp(someAppId) |
| 811 | .makePermanent() |
| 812 | .withPriority(1000) |
| 813 | .build(); |
| 814 | FlowRuleEvent event = new FlowRuleEvent(FlowRuleEvent.Type.RULE_ADDED, |
| 815 | flowRule); |
| 816 | |
| 817 | internalFlowListener.event(event); |
| 818 | |
| 819 | // if we're not master of the device, we should not update |
| 820 | verify(internalFlowListener, never()).updateCpStatus(any(), any(), any()); |
| 821 | } |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 822 | |
| 823 | @Test |
| 824 | public void testRemoveSubscriberFlows() { |
| 825 | // test that if we have EAPOL we wait till the tagged flow is removed |
| 826 | // before installing the default one |
| 827 | |
| 828 | // setup |
| 829 | component.enableEapol = true; |
| 830 | |
| 831 | // mock data |
| 832 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 833 | ProviderId pid = new ProviderId("of", "foo"); |
| 834 | Device device = |
| 835 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 836 | Port port = new DefaultPort(device, PortNumber.portNumber(1), true, |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 837 | DefaultAnnotations.builder().set(PORT_NAME, PORT_1).build()); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 838 | |
| 839 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 840 | UniTagInformation hsia = new UniTagInformation.Builder() |
| 841 | .setUpstreamBandwidthProfile("usbp") |
| 842 | .setDownstreamBandwidthProfile("dsbp") |
| 843 | .setPonCTag(VlanId.vlanId((short) 900)).build(); |
| 844 | uniTagInformationList.add(hsia); |
| 845 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 846 | si.setUniTagList(uniTagInformationList); |
| 847 | |
| 848 | DiscoveredSubscriber sub = new DiscoveredSubscriber( |
| 849 | device, port, DiscoveredSubscriber.Status.REMOVED, true, si); |
| 850 | |
| 851 | // first test that when we remove the EAPOL flow we return false so that the |
| 852 | // subscriber is not removed from the queue |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 853 | doReturn(true).when(oltFlowService).areSubscriberFlowsPendingRemoval(any(), any(), eq(true)); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 854 | boolean res = oltFlowService.removeSubscriberFlows(sub, DEFAULT_BP_ID_DEFAULT, DEFAULT_MCAST_SERVICE_NAME); |
| 855 | verify(oltFlowService, times(1)) |
| 856 | .handleSubscriberDhcpFlows(deviceId, port, OltFlowService.FlowOperation.REMOVE, si); |
| 857 | verify(oltFlowService, times(1)) |
| 858 | .handleSubscriberEapolFlows(sub, OltFlowService.FlowOperation.REMOVE, si); |
| 859 | verify(oltFlowService, times(1)) |
| 860 | .handleSubscriberDataFlows(device, port, OltFlowService.FlowOperation.REMOVE, |
| 861 | si, DEFAULT_MCAST_SERVICE_NAME); |
| 862 | verify(oltFlowService, times(1)) |
| 863 | .handleSubscriberIgmpFlows(sub, OltFlowService.FlowOperation.REMOVE); |
| 864 | verify(oltFlowService, never()) |
| 865 | .handleEapolFlow(any(), any(), any(), |
| 866 | eq(OltFlowService.FlowOperation.ADD), eq(VlanId.vlanId(OltFlowService.EAPOL_DEFAULT_VLAN))); |
| 867 | Assert.assertFalse(res); |
| 868 | |
| 869 | // then test that if the tagged EAPOL is not there we install the default EAPOL |
| 870 | // and return true so we remove the subscriber from the queue |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 871 | doReturn(false).when(oltFlowService).areSubscriberFlowsPendingRemoval(any(), any(), eq(true)); |
Matteo Scandolo | 97449bb | 2021-12-09 15:33:46 -0800 | [diff] [blame] | 872 | doReturn(port).when(oltFlowService.deviceService).getPort(deviceId, port.number()); |
| 873 | res = oltFlowService.removeSubscriberFlows(sub, DEFAULT_BP_ID_DEFAULT, DEFAULT_MCAST_SERVICE_NAME); |
| 874 | verify(oltFlowService, times(1)) |
| 875 | .handleEapolFlow(any(), any(), any(), |
| 876 | eq(OltFlowService.FlowOperation.ADD), eq(VlanId.vlanId(OltFlowService.EAPOL_DEFAULT_VLAN))); |
| 877 | Assert.assertTrue(res); |
| 878 | } |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 879 | |
| 880 | @Test |
| 881 | public void testRemovedFlowEvent() throws InterruptedException { |
| 882 | // test that we update the status in case of REMOVED flow even with non |
| 883 | // existing port in the onos device manager |
| 884 | |
| 885 | DeviceId deviceId = DeviceId.deviceId("test-device"); |
| 886 | ProviderId pid = new ProviderId("of", "foo"); |
| 887 | Device device = |
| 888 | new DefaultDevice(pid, deviceId, Device.Type.OLT, "", "", "", "", null); |
| 889 | |
| 890 | Port port1 = new DefaultPort(device, PortNumber.portNumber(1), true, |
| 891 | DefaultAnnotations.builder().set(PORT_NAME, PORT_1).build()); |
| 892 | // create empty service for testing |
| 893 | List<UniTagInformation> uniTagInformationList = new LinkedList<>(); |
| 894 | UniTagInformation vlanUniTag = new UniTagInformation.Builder().setPonCTag(VlanId.vlanId((short) 60)) |
| 895 | .build(); |
| 896 | uniTagInformationList.add(vlanUniTag); |
| 897 | SubscriberAndDeviceInformation si = new SubscriberAndDeviceInformation(); |
| 898 | si.setUniTagList(uniTagInformationList); |
| 899 | ServiceKey sk1 = new ServiceKey(new AccessDevicePort(port1), vlanUniTag); |
| 900 | |
| 901 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 902 | .matchInPort(port1.number()) |
| 903 | .matchVlanId(VlanId.vlanId((short) 60)) |
| 904 | .build(); |
| 905 | |
| 906 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 907 | .immediate() |
| 908 | .setOutput(port1.number()) |
| 909 | .build(); |
| 910 | |
| 911 | FlowRule flowRule = DefaultFlowRule.builder() |
| 912 | .makePermanent() |
| 913 | .withPriority(1000) |
| 914 | .forTable(0) |
| 915 | .forDevice(deviceId) |
| 916 | .fromApp(testAppId) |
| 917 | .withSelector(selector) |
| 918 | .withTreatment(treatment) |
| 919 | .build(); |
| 920 | |
| 921 | // cpStatus map for the test |
| 922 | component.cpStatus = component.storageService. |
| 923 | <ServiceKey, OltPortStatus>consistentMapBuilder().build().asJavaMap(); |
Andrea Campanella | 87241ae | 2022-03-11 11:20:24 +0100 | [diff] [blame^] | 924 | OltPortStatus cp1Status = new OltPortStatus(NONE, NONE, PENDING_REMOVE, NONE, NONE); |
Andrea Campanella | 40d2b34 | 2022-02-04 18:13:37 +0100 | [diff] [blame] | 925 | component.cpStatus.put(sk1, cp1Status); |
| 926 | |
| 927 | FlowRuleEvent event = new FlowRuleEvent(FlowRuleEvent.Type.RULE_REMOVED, flowRule); |
| 928 | doReturn(true).when(component.oltDeviceService).isLocalLeader(any()); |
| 929 | doReturn(device).when(component.deviceService).getDevice(deviceId); |
| 930 | doReturn(si).when(component.subsService).get(PORT_1); |
| 931 | |
| 932 | oltFlowService.internalFlowListener.event(event); |
| 933 | |
| 934 | //Some time to finish the operation |
| 935 | TimeUnit.MILLISECONDS.sleep(200); |
| 936 | |
| 937 | OltPortStatus status = component.cpStatus.get(sk1); |
| 938 | Assert.assertEquals(REMOVED, status.subscriberFlowsStatus); |
| 939 | } |
Matteo Scandolo | aa2adde | 2021-09-13 12:45:32 -0700 | [diff] [blame] | 940 | } |