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 java.util.List; |
| 19 | import java.util.Map; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 20 | import java.util.HashMap; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 21 | import java.util.Set; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 22 | import java.util.HashSet; |
| 23 | import java.util.Arrays; |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.Iterator; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 26 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 27 | import org.onlab.packet.Ip4Address; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 28 | import org.onlab.packet.IpAddress; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 29 | import org.onlab.packet.VlanId; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 30 | import org.onosproject.TestApplicationId; |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 31 | import org.onosproject.cluster.LeadershipServiceAdapter; |
| 32 | import org.onosproject.cluster.NodeId; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.CoreServiceAdapter; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 35 | import org.onosproject.event.DefaultEventSinkRegistry; |
| 36 | import org.onosproject.event.Event; |
| 37 | import org.onosproject.event.EventDeliveryService; |
| 38 | import org.onosproject.event.EventSink; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 39 | import org.onosproject.mastership.MastershipServiceAdapter; |
| 40 | import org.onosproject.mcast.api.McastRoute; |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 41 | import org.onosproject.net.AnnotationKeys; |
| 42 | import org.onosproject.net.Annotations; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 43 | import org.onosproject.net.ConnectPoint; |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 44 | import org.onosproject.net.DefaultAnnotations; |
| 45 | import org.onosproject.net.DefaultDevice; |
| 46 | import org.onosproject.net.Device; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 47 | import org.onosproject.net.DeviceId; |
| 48 | import org.onosproject.net.HostId; |
| 49 | import org.onosproject.net.PortNumber; |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 50 | import org.onosproject.net.SparseAnnotations; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 51 | import org.onosproject.net.config.Config; |
| 52 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
| 53 | import org.onosproject.net.config.basics.McastConfig; |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 54 | import org.onosproject.net.device.DeviceServiceAdapter; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 55 | import org.onosproject.net.flow.TrafficSelector; |
| 56 | import org.onosproject.net.flow.TrafficTreatment; |
| 57 | import org.onosproject.net.flow.criteria.Criterion; |
| 58 | import org.onosproject.net.flow.criteria.IPCriterion; |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 59 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 60 | import org.onosproject.net.flow.instructions.Instruction; |
| 61 | import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; |
| 62 | import org.onosproject.net.flowobjective.FlowObjectiveServiceAdapter; |
| 63 | import org.onosproject.net.flowobjective.ForwardingObjective; |
| 64 | import org.onosproject.net.flowobjective.NextObjective; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 65 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 66 | import com.google.common.collect.ImmutableMap; |
Daniele Moro | 8ea9e10 | 2020-03-24 18:56:52 +0100 | [diff] [blame] | 67 | import org.opencord.cordmcast.CordMcastStatisticsEvent; |
| 68 | import org.opencord.cordmcast.CordMcastStatisticsEventListener; |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 69 | import org.opencord.sadis.BandwidthProfileInformation; |
| 70 | import org.opencord.sadis.BaseInformationService; |
| 71 | import org.opencord.sadis.SadisService; |
| 72 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 73 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 74 | import static com.google.common.base.Preconditions.checkState; |
| 75 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 76 | public class McastTestBase { |
| 77 | |
| 78 | // Map to store the forwardingObjective in flowObjectiveService.forward() |
| 79 | Map<DeviceId, ForwardingObjective> forwardMap = new HashMap<>(); |
| 80 | // Map to store the nextObjective in flowObjectiveService.next() |
| 81 | Map<DeviceId, NextObjective> nextMap = new HashMap<>(); |
| 82 | // Device configuration |
| 83 | protected static final DeviceId DEVICE_ID_OF_A = DeviceId.deviceId("of:00000a0a0a0a0a00"); |
| 84 | // Port number |
| 85 | protected static final PortNumber PORT_A = PortNumber.portNumber(1048576); |
| 86 | protected static final PortNumber PORT_B = PortNumber.portNumber(16); |
| 87 | protected static final PortNumber PORT_C = PortNumber.portNumber(24); |
| 88 | |
| 89 | // Connect Point for creating source and sink |
| 90 | protected static final ConnectPoint CONNECT_POINT_A = new ConnectPoint(DEVICE_ID_OF_A, PORT_A); |
| 91 | protected static final ConnectPoint CONNECT_POINT_B = new ConnectPoint(DEVICE_ID_OF_A, PORT_B); |
| 92 | protected static final ConnectPoint CONNECT_POINT_C = new ConnectPoint(DEVICE_ID_OF_A, PORT_C); |
| 93 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 94 | // serial number of the device A |
| 95 | protected static final String SERIAL_NUMBER_OF_DEVICE_A = "serialNumberOfDevA"; |
| 96 | // Management ip address of the device A |
| 97 | protected static final Ip4Address MANAGEMENT_IP_OF_A = Ip4Address.valueOf("10.177.125.4"); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 98 | //Host id configuration |
| 99 | protected static final HostId HOST_ID_NONE = HostId.NONE; |
| 100 | // Source connect point |
| 101 | protected static final Set<ConnectPoint> SOURCES_CP = new HashSet<ConnectPoint>(Arrays.asList(CONNECT_POINT_A)); |
| 102 | Map<HostId, Set<ConnectPoint>> sources = ImmutableMap.of(HOST_ID_NONE, SOURCES_CP); |
| 103 | |
| 104 | protected static final IpAddress MULTICAST_IP = IpAddress.valueOf("224.0.0.22"); |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 105 | protected static final IpAddress SOURCE_IP = IpAddress.valueOf("192.168.1.1"); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 106 | // Creating dummy route with IGMP type. |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 107 | McastRoute route1 = new McastRoute(SOURCE_IP, MULTICAST_IP, McastRoute.Type.IGMP); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 108 | |
| 109 | // Creating empty sink used in prevRoute |
| 110 | Set<ConnectPoint> sinksCp = new HashSet<ConnectPoint>(Arrays.asList()); |
| 111 | Map<HostId, Set<ConnectPoint>> sinks = ImmutableMap.of(HOST_ID_NONE, sinksCp); |
| 112 | |
| 113 | // Creating empty source |
| 114 | Set<ConnectPoint> sourceCp = new HashSet<ConnectPoint>(Arrays.asList()); |
| 115 | Map<HostId, Set<ConnectPoint>> emptySource = ImmutableMap.of(HOST_ID_NONE, sourceCp); |
| 116 | |
| 117 | // Flag to check unknown olt device |
| 118 | boolean knownOltFlag = false; |
| 119 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 120 | // For the tests reduce events period to 1s |
| 121 | protected static final int EVENT_GENERATION_PERIOD = 1; |
| 122 | |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 123 | class MockCoreService extends CoreServiceAdapter { |
| 124 | @Override |
| 125 | public ApplicationId registerApplication(String name) { |
| 126 | ApplicationId testApplicationId = TestApplicationId.create("org.opencord.cordmcast"); |
| 127 | return testApplicationId; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | class MockFlowObjectiveService extends FlowObjectiveServiceAdapter { |
| 132 | @Override |
| 133 | public void forward(DeviceId deviceId, ForwardingObjective forwardingObjective) { |
| 134 | synchronized (forwardMap) { |
| 135 | forwardMap.put(deviceId, forwardingObjective); |
Andrea Campanella | 0365235 | 2020-05-06 16:12:00 +0200 | [diff] [blame] | 136 | forwardingObjective.context().ifPresent(context -> { |
| 137 | context.onSuccess(forwardingObjective); |
| 138 | }); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 139 | forwardMap.notify(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public void next(DeviceId deviceId, NextObjective nextObjective) { |
| 145 | nextMap.put(deviceId, nextObjective); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | class TestMastershipService extends MastershipServiceAdapter { |
| 150 | @Override |
| 151 | public boolean isLocalMaster(DeviceId deviceId) { |
| 152 | return true; |
| 153 | } |
| 154 | } |
| 155 | |
Ilayda Ozdemir | 0414dde | 2020-06-27 23:18:07 +0000 | [diff] [blame] | 156 | class LeadershipServiceMcastAdapter extends LeadershipServiceAdapter { |
| 157 | @Override |
| 158 | public NodeId getLeader(String path) { |
| 159 | return NodeId.nodeId("local"); |
| 160 | } |
| 161 | } |
| 162 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 163 | protected class MockSadisService implements SadisService { |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 164 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 165 | @Override |
| 166 | public BaseInformationService<SubscriberAndDeviceInformation> getSubscriberInfoService() { |
| 167 | return new MockSubService(); |
| 168 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 169 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 170 | @Override |
| 171 | public BaseInformationService<BandwidthProfileInformation> getBandwidthProfileService() { |
| 172 | return null; |
| 173 | } |
| 174 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 175 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 176 | /** |
| 177 | * Mocks the McastConfig class to return vlan id value. |
| 178 | */ |
| 179 | static class MockMcastConfig extends McastConfig { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 180 | private VlanId egressVlan; |
| 181 | private VlanId egressInnerVlan; |
| 182 | |
| 183 | public MockMcastConfig(VlanId egressVlan, VlanId egressInnerVlan) { |
| 184 | this.egressVlan = egressVlan; |
| 185 | this.egressInnerVlan = egressInnerVlan; |
| 186 | } |
| 187 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 188 | @Override |
| 189 | public VlanId egressVlan() { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 190 | return egressVlan; |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 191 | } |
Esin Karaman | bb35a3b | 2020-03-18 13:53:24 +0000 | [diff] [blame] | 192 | |
| 193 | @Override |
| 194 | public VlanId egressInnerVlan() { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 195 | return egressInnerVlan; |
Esin Karaman | bb35a3b | 2020-03-18 13:53:24 +0000 | [diff] [blame] | 196 | } |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Mocks the network config registry. |
| 201 | */ |
| 202 | @SuppressWarnings("unchecked") |
| 203 | static final class TestNetworkConfigRegistry |
| 204 | extends NetworkConfigRegistryAdapter { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 205 | |
| 206 | private VlanId egressVlan = VlanId.vlanId("4000"); |
| 207 | private VlanId egressInnerVlan = VlanId.NONE; |
| 208 | |
| 209 | public void setEgressVlan(VlanId egressVlan) { |
| 210 | this.egressVlan = egressVlan; |
| 211 | } |
| 212 | |
| 213 | public void setEgressInnerVlan(VlanId egressInnerVlan) { |
| 214 | this.egressInnerVlan = egressInnerVlan; |
| 215 | } |
| 216 | |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 217 | @Override |
| 218 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 219 | McastConfig mcastConfig = new MockMcastConfig(egressVlan, egressInnerVlan); |
Arjun E K | abf9e6e | 2020-03-02 10:15:21 +0000 | [diff] [blame] | 220 | return (C) mcastConfig; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | public static class TestEventDispatcher extends DefaultEventSinkRegistry |
| 225 | implements EventDeliveryService { |
| 226 | |
| 227 | @Override |
| 228 | @SuppressWarnings("unchecked") |
| 229 | public synchronized void post(Event event) { |
| 230 | EventSink sink = getSink(event.getClass()); |
| 231 | checkState(sink != null, "No sink for event %s", event); |
| 232 | sink.process(event); |
| 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void setDispatchTimeLimit(long millis) { |
| 237 | |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public long getDispatchTimeLimit() { |
| 242 | return 0; |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | public static class MockCordMcastStatisticsEventListener implements CordMcastStatisticsEventListener { |
| 247 | protected List<CordMcastStatisticsEvent> mcastEventList = new ArrayList<CordMcastStatisticsEvent>(); |
| 248 | |
| 249 | @Override |
| 250 | public void event(CordMcastStatisticsEvent event) { |
| 251 | mcastEventList.add(event); |
| 252 | } |
| 253 | } |
| 254 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 255 | private class MockSubService implements BaseInformationService<SubscriberAndDeviceInformation> { |
| 256 | MockSubscriberAndDeviceInformation deviceA = |
| 257 | new MockSubscriberAndDeviceInformation(SERIAL_NUMBER_OF_DEVICE_A, MANAGEMENT_IP_OF_A); |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 258 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 259 | @Override |
| 260 | public SubscriberAndDeviceInformation get(String id) { |
| 261 | return SERIAL_NUMBER_OF_DEVICE_A.equals(id) ? deviceA : null; |
| 262 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 263 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 264 | @Override |
Ilayda Ozdemir | 2fccbce | 2021-02-23 15:36:47 +0000 | [diff] [blame] | 265 | public void clearLocalData() { |
| 266 | } |
| 267 | |
| 268 | @Override |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 269 | public void invalidateAll() { |
| 270 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 271 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 272 | @Override |
| 273 | public void invalidateId(String id) { |
| 274 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 275 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 276 | @Override |
| 277 | public SubscriberAndDeviceInformation getfromCache(String id) { |
| 278 | return null; |
| 279 | } |
| 280 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 281 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 282 | private class MockSubscriberAndDeviceInformation extends SubscriberAndDeviceInformation { |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 283 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 284 | MockSubscriberAndDeviceInformation(String id, Ip4Address ipAddress) { |
| 285 | this.setId(id); |
| 286 | this.setIPAddress(ipAddress); |
| 287 | this.setUplinkPort((int) PORT_A.toLong()); |
| 288 | } |
| 289 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 290 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 291 | class MockDeviceService extends DeviceServiceAdapter { |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 292 | |
Esin Karaman | 996177c | 2020-03-05 13:21:09 +0000 | [diff] [blame] | 293 | @Override |
| 294 | public Device getDevice(DeviceId deviceId) { |
| 295 | if (DEVICE_ID_OF_A.equals(deviceId)) { |
| 296 | DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder() |
| 297 | .set(AnnotationKeys.MANAGEMENT_ADDRESS, MANAGEMENT_IP_OF_A.toString()); |
| 298 | SparseAnnotations annotations = annotationsBuilder.build(); |
| 299 | Annotations[] da = {annotations}; |
| 300 | |
| 301 | Device deviceA = new DefaultDevice(null, DEVICE_ID_OF_A, Device.Type.OTHER, "", "", |
| 302 | "", SERIAL_NUMBER_OF_DEVICE_A, null, da); |
| 303 | return deviceA; |
| 304 | } else { |
| 305 | knownOltFlag = true; |
| 306 | } |
| 307 | return null; |
| 308 | } |
| 309 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 310 | |
| 311 | public OutputInstruction outputPort(TrafficTreatment trafficTreatment) { |
| 312 | List<Instruction> listOfInstructions = trafficTreatment.allInstructions(); |
| 313 | OutputInstruction output = null; |
| 314 | for (Instruction intruction : listOfInstructions) { |
| 315 | output = (OutputInstruction) intruction; |
| 316 | } |
| 317 | return output; |
| 318 | } |
| 319 | |
| 320 | public IPCriterion ipAddress(TrafficSelector trafficSelector) { |
| 321 | Set<Criterion> criterionSet = trafficSelector.criteria(); |
| 322 | Iterator<Criterion> it = criterionSet.iterator(); |
| 323 | IPCriterion ipCriterion = null; |
| 324 | while (it.hasNext()) { |
| 325 | Criterion criteria = it.next(); |
| 326 | if (Criterion.Type.IPV4_DST == criteria.type()) { |
| 327 | ipCriterion = (IPCriterion) criteria; |
| 328 | } |
| 329 | } |
| 330 | return (IPCriterion) ipCriterion; |
| 331 | } |
| 332 | |
Esin Karaman | e489001 | 2020-04-19 11:58:54 +0000 | [diff] [blame] | 333 | public VlanIdCriterion vlanId(TrafficSelector trafficSelector, Criterion.Type type) { |
| 334 | Set<Criterion> criterionSet = trafficSelector.criteria(); |
| 335 | Iterator<Criterion> it = criterionSet.iterator(); |
| 336 | VlanIdCriterion criterion = null; |
| 337 | while (it.hasNext()) { |
| 338 | Criterion criteria = it.next(); |
| 339 | if (type == criteria.type()) { |
| 340 | criterion = (VlanIdCriterion) criteria; |
| 341 | } |
| 342 | } |
| 343 | return criterion; |
| 344 | } |
Sonal Kasliwal | a0bbe6c | 2020-01-06 10:46:30 +0000 | [diff] [blame] | 345 | } |