X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=interfacemgr%2Finterfacemgr-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Finterfacemgr%2Fservicebindings%2Fflowbased%2Fstatehelpers%2FFlowBasedServicesStateBindHelper.java;h=3f6cac015d07afed60f5222a3676ba7511afc224;hb=64b73ec2d82a489b159a41513df93b3cc59c321e;hp=25812cdf24236ae21885898364fbd9e42d79d832;hpb=acac66d2b4b29eab99b2604965680f50da9eb9ef;p=vpnservice.git diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java index 25812cdf..3f6cac01 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateBindHelper.java @@ -8,6 +8,7 @@ package org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.statehelpers; import com.google.common.util.concurrent.ListenableFuture; + import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.vpnservice.interfacemgr.IfmConstants; @@ -30,6 +31,9 @@ import org.slf4j.LoggerFactory; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.List; public class FlowBasedServicesStateBindHelper { @@ -38,7 +42,6 @@ public class FlowBasedServicesStateBindHelper { public static List> bindServicesOnInterface(Interface ifaceState, DataBroker dataBroker) { List> futures = new ArrayList<>(); - WriteTransaction t = dataBroker.newWriteOnlyTransaction(); ServicesInfo servicesInfo = FlowBasedServicesUtils.getServicesInfoForInterface(ifaceState.getName(), dataBroker); if (servicesInfo == null) { return futures; @@ -49,41 +52,74 @@ public class FlowBasedServicesStateBindHelper { return futures; } - BoundServices highestPriorityBoundService = null; - short highestPriority = 0xFF; - for (BoundServices boundService : allServices) { - if (boundService.getServicePriority() < highestPriority) { - highestPriorityBoundService = boundService; - highestPriority = boundService.getServicePriority(); - } - } - InterfaceKey interfaceKey = new InterfaceKey(ifaceState.getName()); org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker); - NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); - long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); - BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - List matches = null; if (iface.getType().isAssignableFrom(L2vlan.class)) { - matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, iface); + return bindServiceOnVlan(allServices, iface, ifaceState.getIfIndex(), dataBroker); } else if (iface.getType().isAssignableFrom(Tunnel.class)){ - matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); + return bindServiceOnTunnel(allServices, iface, ifaceState.getIfIndex(), dataBroker); } + return futures; + } + private static List> bindServiceOnTunnel( + List allServices, + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface, + Integer ifIndex, DataBroker dataBroker) { + List> futures = new ArrayList<>(); + NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); + long portNo = Long.parseLong(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); + BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); + List matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); + BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices); + WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (matches != null) { FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, highestPriorityBoundService, - t, matches, ifaceState.getIfIndex(), NwConstants.VLAN_INTERFACE_INGRESS_TABLE); + t, matches, ifIndex, NwConstants.VLAN_INTERFACE_INGRESS_TABLE); } for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, t, ifaceState.getIfIndex()); + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, boundService, iface, t, ifIndex, boundService.getServicePriority(), (short) (boundService.getServicePriority()+1)); } } futures.add(t.submit()); return futures; } + + private static List> bindServiceOnVlan( + List allServices, + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface, + Integer ifIndex, DataBroker dataBroker) { + List> futures = new ArrayList<>(); + NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); + BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); + WriteTransaction t = dataBroker.newWriteOnlyTransaction(); + Collections.sort(allServices, new Comparator() { + @Override + public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) { + return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority()); + } + }); + BoundServices highestPriority = allServices.remove(0); + short nextServiceIndex = (short) (allServices.size() > 0 ? allServices.get(0).getServicePriority() : highestPriority.getServicePriority() + 1); + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, highestPriority, iface, t, ifIndex, IfmConstants.DEFAULT_SERVICE_INDEX, nextServiceIndex); + BoundServices prev = null; + for (BoundServices boundService : allServices) { + if (prev!=null) { + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, iface, t, ifIndex, prev.getServicePriority(), boundService.getServicePriority()); + } + prev = boundService; + } + if (prev!=null) { + FlowBasedServicesUtils.installLPortDispatcherFlow(dpId, prev, iface, t, ifIndex, prev.getServicePriority(), (short) (prev.getServicePriority()+1)); + } + futures.add(t.submit()); + return futures; + + } + } \ No newline at end of file