Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | */ |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 16 | package org.opencord.cordvtn.impl.handler; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 17 | |
| 18 | import com.google.common.base.Strings; |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
| 26 | import org.onlab.packet.Ethernet; |
| 27 | import org.onlab.packet.IpAddress; |
| 28 | import org.onlab.packet.IpPrefix; |
| 29 | import org.onlab.packet.MacAddress; |
| 30 | import org.onlab.packet.VlanId; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 31 | import org.opencord.cordvtn.api.InstanceService; |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 32 | import org.opencord.cordvtn.impl.AbstractInstanceHandler; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 33 | import org.opencord.cordvtn.api.Instance; |
| 34 | import org.opencord.cordvtn.api.InstanceHandler; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 35 | import org.onosproject.net.DefaultAnnotations; |
| 36 | import org.onosproject.net.HostId; |
| 37 | import org.onosproject.net.PortNumber; |
| 38 | import org.onosproject.net.flow.DefaultFlowRule; |
| 39 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 40 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 41 | import org.onosproject.net.flow.FlowRule; |
| 42 | import org.onosproject.net.flow.FlowRuleService; |
| 43 | import org.onosproject.net.flow.TrafficSelector; |
| 44 | import org.onosproject.net.flow.TrafficTreatment; |
| 45 | import org.onosproject.net.flow.criteria.Criterion; |
| 46 | import org.onosproject.net.flow.criteria.IPCriterion; |
| 47 | import org.onosproject.net.flow.instructions.Instruction; |
| 48 | import org.onosproject.net.flow.instructions.Instructions; |
| 49 | import org.onosproject.net.flow.instructions.L2ModificationInstruction; |
| 50 | import org.onosproject.net.host.DefaultHostDescription; |
| 51 | import org.onosproject.net.host.HostDescription; |
| 52 | import org.onosproject.xosclient.api.VtnPort; |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 53 | import org.opencord.cordvtn.impl.CordVtnNodeManager; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 54 | import org.opencord.cordvtn.impl.CordVtnPipeline; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 55 | |
| 56 | import java.util.Map; |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 57 | import java.util.Optional; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 58 | import java.util.Set; |
| 59 | |
| 60 | import static com.google.common.base.Preconditions.checkNotNull; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 61 | import static org.onosproject.net.flow.criteria.Criterion.Type.IPV4_DST; |
| 62 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_PUSH; |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 63 | import static org.onosproject.xosclient.api.VtnServiceApi.ServiceType.VSG; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Provides network connectivity for vSG instances. |
| 67 | */ |
| 68 | @Component(immediate = true) |
| 69 | @Service(value = VsgInstanceHandler.class) |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 70 | public final class VsgInstanceHandler extends AbstractInstanceHandler implements InstanceHandler { |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 71 | |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 73 | protected CordVtnPipeline pipeline; |
| 74 | |
| 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 76 | protected CordVtnNodeManager nodeManager; |
| 77 | |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 78 | private static final String STAG = "stag"; |
| 79 | private static final String VSG_VM = "vsgVm"; |
| 80 | |
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 82 | protected FlowRuleService flowRuleService; |
| 83 | |
| 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 85 | protected InstanceService instanceService; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 86 | |
| 87 | @Activate |
| 88 | protected void activate() { |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 89 | serviceType = Optional.of(VSG); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 90 | super.activate(); |
| 91 | } |
| 92 | |
| 93 | @Deactivate |
| 94 | protected void deactivate() { |
| 95 | super.deactivate(); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void instanceDetected(Instance instance) { |
| 100 | if (isVsgContainer(instance)) { |
| 101 | log.info("vSG container detected {}", instance); |
| 102 | |
| 103 | // find vsg vm for this vsg container |
| 104 | String vsgVmId = instance.getAnnotation(VSG_VM); |
| 105 | if (Strings.isNullOrEmpty(vsgVmId)) { |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 106 | log.warn("Failed to find vSG VM for {}", instance); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 107 | return; |
| 108 | } |
| 109 | |
| 110 | Instance vsgVm = Instance.of(hostService.getHost(HostId.hostId(vsgVmId))); |
| 111 | VtnPort vtnPort = getVtnPort(vsgVm); |
| 112 | if (vtnPort == null || getStag(vtnPort) == null) { |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 113 | log.warn("Failed to get vSG information {}", vsgVm); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 114 | return; |
| 115 | } |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 116 | populateVsgRules(vsgVm, getStag(vtnPort), |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 117 | nodeManager.dataPort(vsgVm.deviceId()), |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 118 | vtnPort.addressPairs().keySet(), |
| 119 | true); |
| 120 | |
| 121 | } else { |
| 122 | VtnPort vtnPort = getVtnPort(instance); |
| 123 | if (vtnPort == null || getStag(vtnPort) == null) { |
| 124 | return; |
| 125 | } |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 126 | log.info("vSG VM detected {}", instance); |
| 127 | |
| 128 | // insert vSG containers inside the vSG VM as a host |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 129 | vtnPort.addressPairs().entrySet().stream() |
| 130 | .forEach(pair -> addVsgContainer( |
| 131 | instance, |
| 132 | pair.getKey(), |
| 133 | pair.getValue(), |
| 134 | getStag(vtnPort).toString() |
| 135 | )); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void instanceRemoved(Instance instance) { |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 141 | if (!isVsgContainer(instance)) { |
| 142 | // nothing to do for the vSG VM itself |
| 143 | return; |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 144 | } |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 145 | |
| 146 | log.info("vSG container vanished {}", instance); |
| 147 | |
| 148 | // find vsg vm for this vsg container |
| 149 | String vsgVmId = instance.getAnnotation(VSG_VM); |
| 150 | if (Strings.isNullOrEmpty(vsgVmId)) { |
| 151 | log.warn("Failed to find vSG VM for {}", instance); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | Instance vsgVm = Instance.of(hostService.getHost(HostId.hostId(vsgVmId))); |
| 156 | VtnPort vtnPort = getVtnPort(vsgVm); |
| 157 | if (vtnPort == null || getStag(vtnPort) == null) { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | populateVsgRules(vsgVm, getStag(vtnPort), |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 162 | nodeManager.dataPort(vsgVm.deviceId()), |
Hyunsun Moon | 60a1067 | 2016-06-12 17:39:12 -0700 | [diff] [blame] | 163 | vtnPort.addressPairs().keySet(), |
| 164 | false); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Updates set of vSGs in a given vSG VM. |
| 169 | * |
| 170 | * @param vsgVmId vsg vm host id |
| 171 | * @param stag stag |
| 172 | * @param vsgInstances full set of vsg wan ip and mac address pairs in this vsg vm |
| 173 | */ |
| 174 | public void updateVsgInstances(HostId vsgVmId, String stag, Map<IpAddress, MacAddress> vsgInstances) { |
| 175 | if (hostService.getHost(vsgVmId) == null) { |
| 176 | log.debug("vSG VM {} is not added yet, ignore this update", vsgVmId); |
| 177 | return; |
| 178 | } |
| 179 | |
| 180 | Instance vsgVm = Instance.of(hostService.getHost(vsgVmId)); |
| 181 | if (vsgVm == null) { |
| 182 | log.warn("Failed to find existing vSG VM for STAG: {}", stag); |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | log.info("Updates vSGs in {} with STAG: {}", vsgVm, stag); |
| 187 | |
| 188 | // adds vSGs in the address pair |
| 189 | vsgInstances.entrySet().stream() |
| 190 | .filter(addr -> hostService.getHostsByMac(addr.getValue()).isEmpty()) |
| 191 | .forEach(addr -> addVsgContainer( |
| 192 | vsgVm, |
| 193 | addr.getKey(), |
| 194 | addr.getValue(), |
| 195 | stag)); |
| 196 | |
| 197 | // removes vSGs not listed in the address pair |
| 198 | hostService.getConnectedHosts(vsgVm.host().location()).stream() |
| 199 | .filter(host -> !host.mac().equals(vsgVm.mac())) |
| 200 | .filter(host -> !vsgInstances.values().contains(host.mac())) |
| 201 | .forEach(host -> { |
| 202 | log.info("Removed vSG {}", host.toString()); |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 203 | instanceService.removeNestedInstance(host.id()); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 204 | }); |
| 205 | } |
| 206 | |
| 207 | private boolean isVsgContainer(Instance instance) { |
| 208 | return !Strings.isNullOrEmpty(instance.host().annotations().value(STAG)); |
| 209 | } |
| 210 | |
| 211 | private void addVsgContainer(Instance vsgVm, IpAddress vsgWanIp, MacAddress vsgMac, |
| 212 | String stag) { |
| 213 | HostId hostId = HostId.hostId(vsgMac); |
| 214 | DefaultAnnotations.Builder annotations = DefaultAnnotations.builder() |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 215 | .set(Instance.SERVICE_TYPE, vsgVm.serviceType().toString()) |
| 216 | .set(Instance.SERVICE_ID, vsgVm.serviceId().id()) |
| 217 | .set(Instance.PORT_ID, vsgVm.portId().id()) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 218 | .set(STAG, stag) |
| 219 | .set(VSG_VM, vsgVm.host().id().toString()) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 220 | .set(Instance.CREATE_TIME, String.valueOf(System.currentTimeMillis())); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 221 | |
| 222 | HostDescription hostDesc = new DefaultHostDescription( |
| 223 | vsgMac, |
| 224 | VlanId.NONE, |
| 225 | vsgVm.host().location(), |
| 226 | Sets.newHashSet(vsgWanIp), |
| 227 | annotations.build()); |
| 228 | |
Hyunsun Moon | 5401aaa | 2016-06-12 17:40:34 -0700 | [diff] [blame] | 229 | instanceService.addNestedInstance(hostId, hostDesc); |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 232 | private void populateVsgRules(Instance vsgVm, VlanId stag, PortNumber dataPort, |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 233 | Set<IpAddress> vsgWanIps, boolean install) { |
| 234 | // for traffics with s-tag, strip the tag and take through the vSG VM |
| 235 | TrafficSelector selector = DefaultTrafficSelector.builder() |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 236 | .matchInPort(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 237 | .matchVlanId(stag) |
| 238 | .build(); |
| 239 | |
| 240 | TrafficTreatment treatment = DefaultTrafficTreatment.builder() |
| 241 | .setOutput(vsgVm.portNumber()) |
| 242 | .build(); |
| 243 | |
| 244 | FlowRule flowRule = DefaultFlowRule.builder() |
| 245 | .fromApp(appId) |
| 246 | .withSelector(selector) |
| 247 | .withTreatment(treatment) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 248 | .withPriority(CordVtnPipeline.PRIORITY_DEFAULT) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 249 | .forDevice(vsgVm.deviceId()) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 250 | .forTable(CordVtnPipeline.TABLE_VLAN) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 251 | .makePermanent() |
| 252 | .build(); |
| 253 | |
| 254 | pipeline.processFlowRule(install, flowRule); |
| 255 | |
| 256 | // for traffics with customer vlan, tag with the service vlan based on input port with |
| 257 | // lower priority to avoid conflict with WAN tag |
| 258 | selector = DefaultTrafficSelector.builder() |
| 259 | .matchInPort(vsgVm.portNumber()) |
| 260 | .matchVlanId(stag) |
| 261 | .build(); |
| 262 | |
| 263 | treatment = DefaultTrafficTreatment.builder() |
Hyunsun Moon | 81a1356 | 2016-08-04 13:48:08 -0700 | [diff] [blame] | 264 | .setOutput(dataPort) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 265 | .build(); |
| 266 | |
| 267 | flowRule = DefaultFlowRule.builder() |
| 268 | .fromApp(appId) |
| 269 | .withSelector(selector) |
| 270 | .withTreatment(treatment) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 271 | .withPriority(CordVtnPipeline.PRIORITY_DEFAULT) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 272 | .forDevice(vsgVm.deviceId()) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 273 | .forTable(CordVtnPipeline.TABLE_VLAN) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 274 | .makePermanent() |
| 275 | .build(); |
| 276 | |
| 277 | pipeline.processFlowRule(install, flowRule); |
| 278 | |
| 279 | // for traffic coming from WAN, tag 500 and take through the vSG VM |
| 280 | // based on destination ip |
| 281 | vsgWanIps.stream().forEach(ip -> { |
| 282 | TrafficSelector downstream = DefaultTrafficSelector.builder() |
| 283 | .matchEthType(Ethernet.TYPE_IPV4) |
| 284 | .matchIPDst(ip.toIpPrefix()) |
| 285 | .build(); |
| 286 | |
| 287 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
| 288 | .pushVlan() |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 289 | .setVlanId(CordVtnPipeline.VLAN_WAN) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 290 | .setEthDst(vsgVm.mac()) |
| 291 | .setOutput(vsgVm.portNumber()) |
| 292 | .build(); |
| 293 | |
| 294 | FlowRule downstreamFlowRule = DefaultFlowRule.builder() |
| 295 | .fromApp(appId) |
| 296 | .withSelector(downstream) |
| 297 | .withTreatment(downstreamTreatment) |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 298 | .withPriority(CordVtnPipeline.PRIORITY_DEFAULT) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 299 | .forDevice(vsgVm.deviceId()) |
Hyunsun Moon | 1e88fef | 2016-08-04 14:00:35 -0700 | [diff] [blame] | 300 | .forTable(CordVtnPipeline.TABLE_DST) |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 301 | .makePermanent() |
| 302 | .build(); |
| 303 | |
| 304 | pipeline.processFlowRule(install, downstreamFlowRule); |
| 305 | }); |
| 306 | |
| 307 | // remove downstream flow rules for the vSG not shown in vsgWanIps |
| 308 | for (FlowRule rule : flowRuleService.getFlowRulesById(appId)) { |
| 309 | if (!rule.deviceId().equals(vsgVm.deviceId())) { |
| 310 | continue; |
| 311 | } |
| 312 | PortNumber output = getOutputFromTreatment(rule); |
| 313 | if (output == null || !output.equals(vsgVm.portNumber()) || |
| 314 | !isVlanPushFromTreatment(rule)) { |
| 315 | continue; |
| 316 | } |
| 317 | |
| 318 | IpPrefix dstIp = getDstIpFromSelector(rule); |
| 319 | if (dstIp != null && !vsgWanIps.contains(dstIp.address())) { |
| 320 | pipeline.processFlowRule(false, rule); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | |
Hyunsun Moon | e7e4bb3 | 2016-05-16 04:32:45 -0700 | [diff] [blame] | 325 | // TODO get stag from XOS when XOS provides it, extract if from port name for now |
| 326 | private VlanId getStag(VtnPort vtnPort) { |
| 327 | checkNotNull(vtnPort); |
| 328 | |
| 329 | String portName = vtnPort.name(); |
| 330 | if (portName != null && portName.startsWith(STAG)) { |
| 331 | return VlanId.vlanId(portName.split("-")[1]); |
| 332 | } else { |
| 333 | return null; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | private PortNumber getOutputFromTreatment(FlowRule flowRule) { |
| 338 | Instruction instruction = flowRule.treatment().allInstructions().stream() |
| 339 | .filter(inst -> inst instanceof Instructions.OutputInstruction) |
| 340 | .findFirst() |
| 341 | .orElse(null); |
| 342 | if (instruction == null) { |
| 343 | return null; |
| 344 | } |
| 345 | return ((Instructions.OutputInstruction) instruction).port(); |
| 346 | } |
| 347 | |
| 348 | private IpPrefix getDstIpFromSelector(FlowRule flowRule) { |
| 349 | Criterion criterion = flowRule.selector().getCriterion(IPV4_DST); |
| 350 | if (criterion != null && criterion instanceof IPCriterion) { |
| 351 | IPCriterion ip = (IPCriterion) criterion; |
| 352 | return ip.ip(); |
| 353 | } else { |
| 354 | return null; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | private boolean isVlanPushFromTreatment(FlowRule flowRule) { |
| 359 | Instruction instruction = flowRule.treatment().allInstructions().stream() |
| 360 | .filter(inst -> inst instanceof L2ModificationInstruction) |
| 361 | .filter(inst -> ((L2ModificationInstruction) inst).subtype().equals(VLAN_PUSH)) |
| 362 | .findAny() |
| 363 | .orElse(null); |
| 364 | return instruction != null; |
| 365 | } |
| 366 | } |