From c614ed6714caaaa0268f27f9dbe579e85deb95bf Mon Sep 17 00:00:00 2001 From: Kency Date: Mon, 8 Feb 2016 19:55:15 +0530 Subject: [PATCH] Bug 5199 : Fixed unbind & other issues in intrface Change-Id: I823d12bfd8f1d3a921acb054ac3e980f54d24ee7 Signed-off-by: Kency (cherry picked from commit b530354942c4f4e4d507ebf1ecc9be76ddd59852) --- .../commons/InterfaceManagerCommonUtils.java | 72 ++++++++++++------- .../OvsInterfaceConfigAddHelper.java | 20 +++--- .../OvsInterfaceConfigRemoveHelper.java | 1 + .../OvsVlanMemberConfigAddHelper.java | 49 ++----------- .../OvsInterfaceStateAddHelper.java | 16 ++--- .../FlowBasedServicesConfigBindHelper.java | 2 +- .../FlowBasedServicesConfigUnbindHelper.java | 16 ++--- .../FlowBasedServicesStateBindHelper.java | 2 +- .../FlowBasedServicesStateUnbindHelper.java | 33 ++++----- .../utilities/FlowBasedServicesUtils.java | 17 +++-- 10 files changed, 102 insertions(+), 126 deletions(-) diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java index 6339f5f3..aa350d6c 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/commons/InterfaceManagerCommonUtils.java @@ -8,16 +8,24 @@ package org.opendaylight.vpnservice.interfacemgr.commons; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.ListenableFuture; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.idmanager.IdManager; import org.opendaylight.vpnservice.interfacemgr.IfmConstants; import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils; -import org.opendaylight.vpnservice.mdsalutil.*; +import org.opendaylight.vpnservice.mdsalutil.FlowEntity; +import org.opendaylight.vpnservice.mdsalutil.InstructionInfo; +import org.opendaylight.vpnservice.mdsalutil.InstructionType; +import org.opendaylight.vpnservice.mdsalutil.MDSALUtil; +import org.opendaylight.vpnservice.mdsalutil.MatchFieldType; +import org.opendaylight.vpnservice.mdsalutil.MatchInfo; +import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil; +import org.opendaylight.vpnservice.mdsalutil.NwConstants; import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; @@ -46,9 +54,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.ListenableFuture; public class InterfaceManagerCommonUtils { private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerCommonUtils.class); @@ -145,24 +152,6 @@ public class InterfaceManagerCommonUtils { MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, id, ifaceBuilder.build()); } - public static void createInterfaceParentEntryIfNotPresent(DataBroker dataBroker, WriteTransaction t, - String parentInterface){ - InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface); - InstanceIdentifier interfaceParentEntryIdentifier = - InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey); - InterfaceParentEntry interfaceParentEntry = - InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker); - - if(interfaceParentEntry != null){ - LOG.info("Not Found entry for Parent Interface: {} in Vlan Trunk-Member Interface Renderer ConfigDS. " + - "Creating...", parentInterface); - InterfaceParentEntryBuilder interfaceParentEntryBuilder = new InterfaceParentEntryBuilder() - .setKey(interfaceParentEntryKey).setParentInterface(parentInterface); - t.put(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier, - interfaceParentEntryBuilder.build(), true); - } - } - public static void createInterfaceChildEntry( WriteTransaction t, String parentInterface, String childInterface){ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface); @@ -292,4 +281,37 @@ public class InterfaceManagerCommonUtils { IfmUtil.buildStateInterfaceId(interfaceName); transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId); } + + // For trunk interfaces, binding to a parent interface which is already bound to another trunk interface should not + // be allowed + public static boolean createInterfaceChildEntryIfNotPresent( DataBroker dataBroker, WriteTransaction t, + String parentInterface, String childInterface){ + InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface); + InstanceIdentifier interfaceParentEntryIdentifier = + InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey); + InterfaceParentEntry interfaceParentEntry = + InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker); + + if(interfaceParentEntry != null){ + LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface); + return false; + } + + LOG.info("First vlan trunk {} bound on parent-interface {}", childInterface, parentInterface); + InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface); + InstanceIdentifier intfId = + InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey); + InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey) + .setChildInterface(childInterface); + t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true); + return true; + } + + public static boolean deleteParentInterfaceEntry( WriteTransaction t, String parentInterface){ + InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface); + InstanceIdentifier interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey); + t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier); + return true; + } + } \ No newline at end of file diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java index e98e6d6a..fecf3cf7 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigAddHelper.java @@ -7,12 +7,13 @@ */ package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers; -import com.google.common.base.Optional; -import com.google.common.util.concurrent.ListenableFuture; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.idmanager.IdManager; import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; @@ -39,9 +40,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; +import com.google.common.base.Optional; +import com.google.common.util.concurrent.ListenableFuture; public class OvsInterfaceConfigAddHelper { private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigAddHelper.class); @@ -69,10 +69,12 @@ public class OvsInterfaceConfigAddHelper { if (ifL2vlan == null || IfL2vlan.L2vlanMode.Trunk != ifL2vlan.getL2vlanMode()) { return; } - LOG.debug("adding vlan configuration for {}",interfaceNew.getName()); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); - InterfaceManagerCommonUtils.createInterfaceChildEntry(transaction, - parentRefs.getParentInterface(), interfaceNew.getName()); + if(!InterfaceManagerCommonUtils.createInterfaceChildEntryIfNotPresent(dataBroker, transaction, + parentRefs.getParentInterface(), interfaceNew.getName())){ + return; + } + LOG.debug("adding vlan configuration for {}",interfaceNew.getName()); org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java index 64e79571..fe929204 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsInterfaceConfigRemoveHelper.java @@ -92,6 +92,7 @@ public class OvsInterfaceConfigRemoveHelper { NodeConnectorId ncId = new NodeConnectorId(ifState.getLowerLayerIf().get(0)); BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(ncId)); FlowBasedServicesUtils.removeIngressFlow(interfaceOld.getName(), dpId, transaction); + InterfaceManagerCommonUtils.deleteParentInterfaceEntry(transaction, parentRefs.getParentInterface()); // For Vlan-Trunk Interface, remove the trunk-member operstates as well... InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(interfaceOld.getName()); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigAddHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigAddHelper.java index c4e7a9db..e0086804 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigAddHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/confighelpers/OvsVlanMemberConfigAddHelper.java @@ -7,34 +7,21 @@ */ package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers; -import com.google.common.util.concurrent.ListenableFuture; +import java.util.ArrayList; +import java.util.List; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.vpnservice.interfacemgr.IfmConstants; -import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; -import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; -import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils; -import org.opendaylight.vpnservice.mdsalutil.MatchInfo; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan; import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; +import com.google.common.util.concurrent.ListenableFuture; public class OvsVlanMemberConfigAddHelper { private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class); @@ -45,7 +32,6 @@ public class OvsVlanMemberConfigAddHelper { List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - InterfaceManagerCommonUtils.createInterfaceParentEntryIfNotPresent(dataBroker, t, parentRefs.getParentInterface()); InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName()); InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface()); @@ -68,35 +54,8 @@ public class OvsVlanMemberConfigAddHelper { InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker); if (ifState != null) { LOG.debug("add interface state info for vlan member {}",interfaceNew.getName()); - OperStatus operStatus = ifState.getOperStatus(); - AdminStatus adminStatus = ifState.getAdminStatus(); - PhysAddress physAddress = ifState.getPhysAddress(); - - if (!interfaceNew.isEnabled()) { - operStatus = OperStatus.Down; - } + InterfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), t, dataBroker, idManager, ifState); - InstanceIdentifier ifStateId = - IfmUtil.buildStateInterfaceId(interfaceNew.getName()); - List lowerLayerIfList = new ArrayList<>(); - lowerLayerIfList.add(ifState.getLowerLayerIf().get(0)); - //lowerLayerIfList.add(parentRefs.getParentInterface()); - Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceNew.getName()); - InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus).setOperStatus(operStatus) - .setPhysAddress(physAddress).setLowerLayerIf(lowerLayerIfList).setIfIndex(ifIndex); - ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName())); - t.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true); - - // create lportTag Interface Map - InterfaceMetaUtils.createLportTagInterfaceMap(t, interfaceNew.getName(), ifIndex); - //Installing vlan flow for vlan member - NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0)); - BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); - if (operStatus == OperStatus.Up) { - List matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceNew); - FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceNew, t, matches, ifIndex); - } // FIXME: Maybe, add the new interface to the higher-layer if of the parent interface-state. // That may not serve any purpose though for interface manager.... Unless some external parties are interested in it. diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateAddHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateAddHelper.java index 7d90a44a..24832638 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateAddHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/renderer/ovs/statehelpers/OvsInterfaceStateAddHelper.java @@ -7,16 +7,16 @@ */ package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.statehelpers; -import com.google.common.util.concurrent.ListenableFuture; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.vpnservice.interfacemgr.IfmConstants; import org.opendaylight.vpnservice.interfacemgr.IfmUtil; import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils; -import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils; -import org.opendaylight.vpnservice.mdsalutil.MatchInfo; import org.opendaylight.vpnservice.mdsalutil.NwConstants; import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; @@ -33,9 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; +import com.google.common.util.concurrent.ListenableFuture; /** * This worker is responsible for adding the openflow-interfaces/of-port-info container @@ -73,12 +71,12 @@ public class OvsInterfaceStateAddHelper { Interface ifState = InterfaceManagerCommonUtils.addStateEntry(iface, portName, transaction, idManager, physAddress, operStatus, adminStatus, nodeConnectorId); - BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); // If this interface is a tunnel interface, create the tunnel ingress flow if(iface != null) { IfTunnel tunnel = iface.getAugmentation(IfTunnel.class); if (tunnel != null) { + BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); + long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId)); InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface, ifState.getIfIndex(), NwConstants.ADD_FLOW); futures.add(transaction.submit()); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java index 5bc4219e..1308221d 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigBindHelper.java @@ -125,7 +125,7 @@ public class FlowBasedServicesConfigBindHelper { if (matches != null) { WriteTransaction removeFlowTransaction = dataBroker.newWriteOnlyTransaction(); - FlowBasedServicesUtils.removeIngressFlow(iface, serviceToReplace, dpId, removeFlowTransaction); + FlowBasedServicesUtils.removeIngressFlow(iface.getName(), serviceToReplace, dpId, removeFlowTransaction); futures.add(removeFlowTransaction.submit()); WriteTransaction installFlowTransaction = dataBroker.newWriteOnlyTransaction(); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java index 6984e784..25b93c24 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/confighelpers/FlowBasedServicesConfigUnbindHelper.java @@ -82,7 +82,7 @@ public class FlowBasedServicesConfigUnbindHelper { BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); if (boundServices.isEmpty()) { // Remove default entry from Lport Dispatcher Table. - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX); if (t != null) { futures.add(t.submit()); } @@ -94,11 +94,11 @@ public class FlowBasedServicesConfigUnbindHelper { // This means the one removed was the highest priority service if (high == null) { LOG.trace("Deleting table entry for service {}, match service index {}", boundServiceOld, IfmConstants.DEFAULT_SERVICE_INDEX); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, IfmConstants.DEFAULT_SERVICE_INDEX); if (low != null) { //delete the lower services flow entry. LOG.trace("Deleting table entry for lower service {}, match service index {}", low, low.getServicePriority()); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, low, t, low.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), low, t, low.getServicePriority()); BoundServices lower = FlowBasedServicesUtils.getHighAndLowPriorityService(boundServices, low)[0]; short lowerServiceIndex = (short) ((lower!=null) ? lower.getServicePriority() : low.getServicePriority() + 1); LOG.trace("Installing new entry for lower service {}, match service index {}, update service index {}", low, IfmConstants.DEFAULT_SERVICE_INDEX, lowerServiceIndex); @@ -106,7 +106,7 @@ public class FlowBasedServicesConfigUnbindHelper { } } else { LOG.trace("Deleting table entry for service {}, match service index {}", boundServiceOld, boundServiceOld.getServicePriority()); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, boundServiceOld.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, boundServiceOld.getServicePriority()); short lowerServiceIndex = (short) ((low!=null) ? low.getServicePriority() : boundServiceOld.getServicePriority() + 1); BoundServices highest = FlowBasedServicesUtils.getHighestPriorityService(boundServices); if (high.equals(highest)) { @@ -134,7 +134,7 @@ public class FlowBasedServicesConfigUnbindHelper { if (boundServices.isEmpty()) { // Remove entry from Ingress Table. - FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t); + FlowBasedServicesUtils.removeIngressFlow(iface.getName(), boundServiceOld, dpId, t); if (t != null) { futures.add(t.submit()); } @@ -151,7 +151,7 @@ public class FlowBasedServicesConfigUnbindHelper { } if (highestPriority < boundServiceOld.getServicePriority()) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundServiceOld, t, boundServiceOld.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundServiceOld, t, boundServiceOld.getServicePriority()); if (t != null) { futures.add(t.submit()); } @@ -162,10 +162,10 @@ public class FlowBasedServicesConfigUnbindHelper { matches = FlowBasedServicesUtils.getMatchInfoForTunnelPortAtIngressTable (dpId, portNo, iface); BoundServices toBeMoved = tmpServicesMap.get(highestPriority); - FlowBasedServicesUtils.removeIngressFlow(iface, boundServiceOld, dpId, t); + FlowBasedServicesUtils.removeIngressFlow(iface.getName(), boundServiceOld, dpId, t); FlowBasedServicesUtils.installInterfaceIngressFlow(dpId, iface, toBeMoved, t, matches, ifIndex, NwConstants.VLAN_INTERFACE_INGRESS_TABLE); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, toBeMoved, t, toBeMoved.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), toBeMoved, t, toBeMoved.getServicePriority()); if (t != null) { futures.add(t.submit()); 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 6186802f..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 @@ -101,7 +101,7 @@ public class FlowBasedServicesStateBindHelper { Collections.sort(allServices, new Comparator() { @Override public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) { - return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority()); + return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority()); } }); BoundServices highestPriority = allServices.remove(0); diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java index ede481e1..619c6bf5 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/statehelpers/FlowBasedServicesStateUnbindHelper.java @@ -17,11 +17,9 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.vpnservice.interfacemgr.IfmConstants; import org.opendaylight.vpnservice.interfacemgr.IfmUtil; -import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils; import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo; @@ -48,37 +46,34 @@ public class FlowBasedServicesStateUnbindHelper { return futures; } - 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); - if (ifaceState.getType().isAssignableFrom(L2vlan.class)) { - return unbindServiceOnVlan(allServices, iface, ifaceState.getIfIndex(), dataBroker); + return unbindServiceOnVlan(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker); } else if (ifaceState.getType().isAssignableFrom(Tunnel.class)){ - return unbindServiceOnTunnel(allServices, iface, ifaceState.getIfIndex(), dataBroker); + return unbindServiceOnTunnel(allServices, ifaceState, ifaceState.getIfIndex(), dataBroker); } return futures; } private static List> unbindServiceOnTunnel( List allServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface, + Interface iface, Integer ifIndex, DataBroker dataBroker) { List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); + List ofportIds = iface.getLowerLayerIf(); + NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); if(nodeConnectorId == null){ return futures; } BoundServices highestPriorityBoundService = FlowBasedServicesUtils.getHighestPriorityService(allServices); BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); - FlowBasedServicesUtils.removeIngressFlow(iface, highestPriorityBoundService, dpId, t); + FlowBasedServicesUtils.removeIngressFlow(iface.getName(), highestPriorityBoundService, dpId, t); for (BoundServices boundService : allServices) { if (!boundService.equals(highestPriorityBoundService)) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t, boundService.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface.getName(), boundService, t, boundService.getServicePriority()); } } @@ -87,26 +82,26 @@ public class FlowBasedServicesStateUnbindHelper { } private static List> unbindServiceOnVlan( - List allServices, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface, + List allServices, Interface ifaceState, Integer ifIndex, DataBroker dataBroker) { List> futures = new ArrayList<>(); WriteTransaction t = dataBroker.newWriteOnlyTransaction(); - NodeConnectorId nodeConnectorId = FlowBasedServicesUtils.getNodeConnectorIdFromInterface(iface, dataBroker); - if (nodeConnectorId == null) { + List ofportIds = ifaceState.getLowerLayerIf(); + NodeConnectorId nodeConnectorId = new NodeConnectorId(ofportIds.get(0)); + if(nodeConnectorId == null){ return futures; } BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId)); Collections.sort(allServices, new Comparator() { @Override public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) { - return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority()); + return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority()); } }); BoundServices highestPriority = allServices.remove(0); - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, highestPriority, t, IfmConstants.DEFAULT_SERVICE_INDEX); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), highestPriority, t, IfmConstants.DEFAULT_SERVICE_INDEX); for (BoundServices boundService : allServices) { - FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, iface, boundService, t, boundService.getServicePriority()); + FlowBasedServicesUtils.removeLPortDispatcherFlow(dpId, ifaceState.getName(), boundService, t, boundService.getServicePriority()); } futures.add(t.submit()); return futures; diff --git a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java index 36730e4c..787ad51c 100644 --- a/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java +++ b/interfacemgr/interfacemgr-impl/src/main/java/org/opendaylight/vpnservice/interfacemgr/servicebindings/flowbased/utilities/FlowBasedServicesUtils.java @@ -39,7 +39,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.ServiceBindings; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.StypeOpenflow; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo; @@ -243,9 +242,9 @@ public class FlowBasedServicesUtils { installFlow(dpId, ingressFlow, t); } - public static void removeIngressFlow(Interface iface, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) { + public static void removeIngressFlow(String name, BoundServices serviceOld, BigInteger dpId, WriteTransaction t) { LOG.debug("Removing Ingress Flows"); - String flowKeyStr = getFlowRef(dpId, iface.getName(), serviceOld, serviceOld.getServicePriority()); + String flowKeyStr = getFlowRef(dpId, name, serviceOld, serviceOld.getServicePriority()); FlowKey flowKey = new FlowKey(new FlowId(flowKeyStr)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) @@ -255,17 +254,17 @@ public class FlowBasedServicesUtils { t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } - public static void removeLPortDispatcherFlow(BigInteger dpId, Interface iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) { + public static void removeLPortDispatcherFlow(BigInteger dpId, String iface, BoundServices boundServicesOld, WriteTransaction t, short currentServiceIndex) { LOG.debug("Removing LPort Dispatcher Flows {}, {}", dpId, iface); StypeOpenflow stypeOpenFlow = boundServicesOld.getAugmentation(StypeOpenflow.class); // build the flow and install it - String flowRef = getFlowRef(dpId, iface.getName(), boundServicesOld, currentServiceIndex); + String flowRef = getFlowRef(dpId, iface, boundServicesOld, currentServiceIndex); FlowKey flowKey = new FlowKey(new FlowId(flowRef)); Node nodeDpn = buildInventoryDpnNode(dpId); InstanceIdentifier flowInstanceId = InstanceIdentifier.builder(Nodes.class) .child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey(stypeOpenFlow.getDispatcherTableId())).child(Flow.class, flowKey).build(); + .child(Table.class, new TableKey(NwConstants.LPORT_DISPATCHER_TABLE)).child(Flow.class, flowKey).build(); t.delete(LogicalDatastoreType.CONFIGURATION, flowInstanceId); } @@ -295,11 +294,11 @@ public class FlowBasedServicesUtils { Collections.sort(availableServiceInfos, new Comparator() { @Override public int compare(BoundServices serviceInfo1, BoundServices serviceInfo2) { - return serviceInfo2.getServicePriority().compareTo(serviceInfo1.getServicePriority()); + return serviceInfo1.getServicePriority().compareTo(serviceInfo2.getServicePriority()); } }); for (BoundServices availableServiceInfo: availableServiceInfos) { - if (currentServiceInfo.getServicePriority() > availableServiceInfo.getServicePriority()) { + if (currentServiceInfo.getServicePriority() < availableServiceInfo.getServicePriority()) { lower = availableServiceInfo; break; } else { @@ -317,7 +316,7 @@ public class FlowBasedServicesUtils { BoundServices highPriorityService = availableServiceInfos.get(0); availableServiceInfos.remove(0); for (BoundServices availableServiceInfo: availableServiceInfos) { - if (availableServiceInfo.getServicePriority() > highPriorityService.getServicePriority()) { + if (availableServiceInfo.getServicePriority() < highPriorityService.getServicePriority()) { highPriorityService = availableServiceInfo; } } -- 2.36.6