X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=interfacemanager%2Finterfacemanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fgenius%2Finterfacemanager%2Frenderer%2Fovs%2Fconfighelpers%2FOvsInterfaceConfigUpdateHelper.java;h=cfd3eabcb1ab27c29d0cafad41c81170a5f0f038;hb=9cf3f1b8989ff0ffb08326c382814254a36f671e;hp=e3dc181f15c9e7a010b20551272baf24113f6f86;hpb=c406f3523dde2d8eb776a6f7ed18e9cf7ab795c5;p=genius.git diff --git a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigUpdateHelper.java b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigUpdateHelper.java index e3dc181f1..cfd3eabcb 100644 --- a/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigUpdateHelper.java +++ b/interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/renderer/ovs/confighelpers/OvsInterfaceConfigUpdateHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -8,6 +8,9 @@ package org.opendaylight.genius.interfacemanager.renderer.ovs.confighelpers; import com.google.common.util.concurrent.ListenableFuture; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator; @@ -31,40 +34,41 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; - -public class OvsInterfaceConfigUpdateHelper{ +public class OvsInterfaceConfigUpdateHelper { private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceConfigUpdateHelper.class); - public static List> updateConfiguration(DataBroker dataBroker, AlivenessMonitorService alivenessMonitorService, - IdManagerService idManager, IMdsalApiManager mdsalApiManager, - Interface interfaceNew, Interface interfaceOld) { + public static List> updateConfiguration(DataBroker dataBroker, + AlivenessMonitorService alivenessMonitorService, IdManagerService idManager, + IMdsalApiManager mdsalApiManager, Interface interfaceNew, Interface interfaceOld) { List> futures = new ArrayList<>(); - - // If any of the port attributes are modified, treat it as a delete and recreate scenario - if(portAttributesModified(interfaceOld, interfaceNew)) { - futures.addAll(OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService, interfaceOld, idManager, - mdsalApiManager, interfaceOld.getAugmentation(ParentRefs.class))); + LOG.info("updating configuration for interface {}", interfaceNew.getName()); + // If any of the port attributes are modified, treat it as a delete and + // recreate scenario + if (portAttributesModified(interfaceOld, interfaceNew)) { + futures.addAll(OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService, + interfaceOld, idManager, mdsalApiManager, interfaceOld.getAugmentation(ParentRefs.class))); futures.addAll(OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, - interfaceNew.getAugmentation(ParentRefs.class), interfaceNew, idManager,alivenessMonitorService,mdsalApiManager)); + interfaceNew.getAugmentation(ParentRefs.class), interfaceNew, idManager, alivenessMonitorService, + mdsalApiManager)); return futures; } - // If there is no operational state entry for the interface, treat it as create - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = - InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceNew.getName(), dataBroker); + // If there is no operational state entry for the interface, treat it as + // create + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState = InterfaceManagerCommonUtils + .getInterfaceState(interfaceNew.getName(), dataBroker); if (ifState == null) { futures.addAll(OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, - interfaceNew.getAugmentation(ParentRefs.class), interfaceNew, idManager, alivenessMonitorService, mdsalApiManager)); + interfaceNew.getAugmentation(ParentRefs.class), interfaceNew, idManager, alivenessMonitorService, + mdsalApiManager)); return futures; } WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); - if(TunnelMonitoringAttributesModified(interfaceOld, interfaceNew)){ - handleTunnelMonitorUpdates(futures, transaction, alivenessMonitorService, interfaceNew, - interfaceOld, dataBroker); + if (tunnelMonitoringAttributesModified(interfaceOld, interfaceNew)) { + handleTunnelMonitorUpdates(futures, transaction, alivenessMonitorService, interfaceNew, interfaceOld, + dataBroker); return futures; } @@ -91,11 +95,11 @@ public class OvsInterfaceConfigUpdateHelper{ IfTunnel ifTunnelOld = interfaceOld.getAugmentation(IfTunnel.class); IfTunnel ifTunnelNew = interfaceNew.getAugmentation(IfTunnel.class); - if (checkAugmentations(ifTunnelOld,ifTunnelNew)) { - if(!ifTunnelNew.getTunnelDestination().equals(ifTunnelOld.getTunnelDestination()) || - !ifTunnelNew.getTunnelSource().equals(ifTunnelOld.getTunnelSource()) || - ( ifTunnelNew.getTunnelGateway() !=null && ifTunnelOld.getTunnelGateway() !=null && - !ifTunnelNew.getTunnelGateway().equals(ifTunnelOld.getTunnelGateway()))) { + if (checkAugmentations(ifTunnelOld, ifTunnelNew)) { + if (!ifTunnelNew.getTunnelDestination().equals(ifTunnelOld.getTunnelDestination()) + || !ifTunnelNew.getTunnelSource().equals(ifTunnelOld.getTunnelSource()) + || ifTunnelNew.getTunnelGateway() != null && ifTunnelOld.getTunnelGateway() != null + && !ifTunnelNew.getTunnelGateway().equals(ifTunnelOld.getTunnelGateway())) { return true; } } @@ -103,48 +107,52 @@ public class OvsInterfaceConfigUpdateHelper{ return false; } - private static boolean TunnelMonitoringAttributesModified(Interface interfaceOld, Interface interfaceNew) { + private static boolean tunnelMonitoringAttributesModified(Interface interfaceOld, Interface interfaceNew) { IfTunnel ifTunnelOld = interfaceOld.getAugmentation(IfTunnel.class); IfTunnel ifTunnelNew = interfaceNew.getAugmentation(IfTunnel.class); return checkAugmentations(ifTunnelOld, ifTunnelNew); } /* - * if the tunnel monitoring attributes have changed, handle it based on the tunnel type. - * As of now internal vxlan tunnels use LLDP monitoring and external tunnels use BFD monitoring. + * if the tunnel monitoring attributes have changed, handle it based on the + * tunnel type. As of now internal vxlan tunnels use LLDP monitoring and + * external tunnels use BFD monitoring. */ private static void handleTunnelMonitorUpdates(List> futures, WriteTransaction transaction, - AlivenessMonitorService alivenessMonitorService, - Interface interfaceNew, Interface interfaceOld, DataBroker dataBroker){ + AlivenessMonitorService alivenessMonitorService, Interface interfaceNew, Interface interfaceOld, + DataBroker dataBroker) { LOG.debug("tunnel monitoring attributes modified for interface {}", interfaceNew.getName()); // update termination point on switch, if switch is connected - BridgeRefEntry bridgeRefEntry = - InterfaceMetaUtils.getBridgeReferenceForInterface(interfaceNew, dataBroker); + BridgeRefEntry bridgeRefEntry = InterfaceMetaUtils.getBridgeReferenceForInterface(interfaceNew, dataBroker); IfTunnel ifTunnel = interfaceNew.getAugmentation(IfTunnel.class); - if(SouthboundUtils.isMonitorProtocolBfd(ifTunnel) && InterfaceMetaUtils.bridgeExists(bridgeRefEntry, dataBroker)) { + if (SouthboundUtils.isMonitorProtocolBfd(ifTunnel) + && InterfaceMetaUtils.bridgeExists(bridgeRefEntry, dataBroker)) { SouthboundUtils.updateBfdParamtersForTerminationPoint(bridgeRefEntry.getBridgeReference().getValue(), - interfaceNew.getAugmentation(IfTunnel.class), - interfaceNew.getName(), transaction); - }else { - // update lldp tunnel monitoring attributes for an internal vxlan tunnel interface - AlivenessMonitorUtils.handleTunnelMonitorUpdates(alivenessMonitorService, dataBroker, interfaceOld, interfaceNew); + interfaceNew.getAugmentation(IfTunnel.class), interfaceNew.getName(), transaction); + } else { + // update lldp tunnel monitoring attributes for an internal vxlan + // tunnel interface + AlivenessMonitorUtils.handleTunnelMonitorUpdates(alivenessMonitorService, dataBroker, interfaceOld, + interfaceNew); } futures.add(transaction.submit()); } - private static void handleInterfaceAdminStateUpdates(List> futures, WriteTransaction transaction, - Interface interfaceNew, DataBroker dataBroker, - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState){ - OperStatus operStatus = InterfaceManagerCommonUtils.updateStateEntry(interfaceNew, dataBroker, transaction, ifState); - + private static void handleInterfaceAdminStateUpdates(List> futures, + WriteTransaction transaction, Interface interfaceNew, DataBroker dataBroker, + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang + .ietf.interfaces.rev140508.interfaces.state.Interface ifState) { IfL2vlan ifL2vlan = interfaceNew.getAugmentation(IfL2vlan.class); - if (ifL2vlan == null || (IfL2vlan.L2vlanMode.Trunk != ifL2vlan.getL2vlanMode() && IfL2vlan.L2vlanMode.Transparent != ifL2vlan.getL2vlanMode())) { + if (ifL2vlan == null || IfL2vlan.L2vlanMode.Trunk != ifL2vlan.getL2vlanMode() + && IfL2vlan.L2vlanMode.Transparent != ifL2vlan.getL2vlanMode()) { return; } - + LOG.info("admin-state modified for interface {}", interfaceNew.getName()); + OperStatus operStatus = InterfaceManagerCommonUtils.updateStateEntry(interfaceNew, dataBroker, transaction, + ifState); InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(interfaceNew.getName()); - InterfaceParentEntry interfaceParentEntry = - InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker); + InterfaceParentEntry interfaceParentEntry = InterfaceMetaUtils + .getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker); if (interfaceParentEntry == null || interfaceParentEntry.getInterfaceChildEntry() == null) { return; } @@ -155,9 +163,8 @@ public class OvsInterfaceConfigUpdateHelper{ coordinator.enqueueJob(interfaceNew.getName(), vlanMemberStateUpdateWorker, IfmConstants.JOB_MAX_RETRIES); } - private static boolean checkAugmentations(T oldAug, T newAug) { - if ((oldAug != null && newAug == null) || - (oldAug == null && newAug != null)) { + private static boolean checkAugmentations(T oldAug, T newAug) { + if (oldAug != null && newAug == null || oldAug == null && newAug != null) { return true; } @@ -166,11 +173,11 @@ public class OvsInterfaceConfigUpdateHelper{ private static class VlanMemberStateUpdateWorker implements Callable>> { - private DataBroker dataBroker; - private OperStatus operStatus; - private List interfaceChildEntries; + private final DataBroker dataBroker; + private final OperStatus operStatus; + private final List interfaceChildEntries; - public VlanMemberStateUpdateWorker(DataBroker dataBroker, OperStatus operStatus, + VlanMemberStateUpdateWorker(DataBroker dataBroker, OperStatus operStatus, List interfaceChildEntries) { this.dataBroker = dataBroker; this.operStatus = operStatus; @@ -178,7 +185,7 @@ public class OvsInterfaceConfigUpdateHelper{ } @Override - public List> call() throws Exception { + public List> call() { List> futures = new ArrayList<>(); WriteTransaction operShardTransaction = dataBroker.newWriteOnlyTransaction(); for (InterfaceChildEntry interfaceChildEntry : interfaceChildEntries) { @@ -197,4 +204,3 @@ public class OvsInterfaceConfigUpdateHelper{ } } } -