X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=qosservice%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Fqosservice%2FQosNeutronUtils.java;h=7ffe635a1eebb60fccb3f0a43933b41df3ec1adc;hb=2f0569ed75ef8a1fb60f992d19c8bbdf92ff45bf;hp=086167b8849ad55afc3a31972b03af2b9b67daaa;hpb=cb90410a3fa82fb18d817d2d62ed5ec55c2e2961;p=netvirt.git diff --git a/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java b/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java index 086167b884..7ffe635a1e 100644 --- a/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java +++ b/qosservice/impl/src/main/java/org/opendaylight/netvirt/qosservice/QosNeutronUtils.java @@ -7,27 +7,29 @@ */ package org.opendaylight.netvirt.qosservice; -import com.google.common.base.Optional; -import java.math.BigInteger; +import static java.util.Collections.emptyList; +import static org.opendaylight.genius.infra.Datastore.CONFIGURATION; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; -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.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker; +import org.opendaylight.genius.infra.Datastore; import org.opendaylight.genius.infra.ManagedNewTransactionRunner; import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl; +import org.opendaylight.genius.infra.TypedWriteTransaction; import org.opendaylight.genius.mdsalutil.ActionInfo; import org.opendaylight.genius.mdsalutil.FlowEntity; import org.opendaylight.genius.mdsalutil.InstructionInfo; @@ -43,6 +45,8 @@ import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType; import org.opendaylight.genius.mdsalutil.matches.MatchMetadata; import org.opendaylight.genius.utils.ServiceIndex; import org.opendaylight.infrautils.jobcoordinator.JobCoordinator; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager; import org.opendaylight.ovsdb.utils.southbound.utils.SouthboundUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; @@ -98,6 +102,7 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.Uint64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -147,7 +152,7 @@ public class QosNeutronUtils { public Collection getQosPorts(Uuid qosUuid) { final ConcurrentMap portMap = qosPortsMap.get(qosUuid); - return portMap != null ? portMap.values() : Collections.emptyList(); + return portMap != null ? portMap.values() : emptyList(); } public void addToQosPortsCache(Uuid qosUuid, Port port) { @@ -171,38 +176,41 @@ public class QosNeutronUtils { } } - @Nonnull + @NonNull public Collection getQosNetworks(Uuid qosUuid) { final ConcurrentMap networkMap = qosNetworksMap.get(qosUuid); - return networkMap != null ? networkMap.values() : Collections.emptyList(); + return networkMap != null ? networkMap.values() : emptyList(); } - @Nonnull + @NonNull public List getSubnetIdsFromNetworkId(Uuid networkId) { InstanceIdentifier networkMapId = InstanceIdentifier.builder(NetworkMaps.class) .child(NetworkMap.class, new NetworkMapKey(networkId)).build(); Optional optionalNetworkMap = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, networkMapId, dataBroker); - return optionalNetworkMap.isPresent() ? optionalNetworkMap.get().getSubnetIdList() : Collections.emptyList(); + return (optionalNetworkMap.isPresent() && optionalNetworkMap.get().getSubnetIdList() != null) + ? optionalNetworkMap.get().getSubnetIdList() : emptyList(); } - @Nonnull + @NonNull protected List getPortIdsFromSubnetId(Uuid subnetId) { InstanceIdentifier subnetMapId = InstanceIdentifier .builder(Subnetmaps.class) .child(Subnetmap.class, new SubnetmapKey(subnetId)).build(); Optional optionalSubnetmap = MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, subnetMapId,dataBroker); - return optionalSubnetmap.isPresent() ? optionalSubnetmap.get().getPortList() : Collections.emptyList(); + return (optionalSubnetmap.isPresent() && optionalSubnetmap.get().getPortList() != null) + ? optionalSubnetmap.get().getPortList() : emptyList(); } public void handleNeutronPortQosAdd(Port port, Uuid qosUuid) { - LOG.trace("Handling Port add and QoS associated: port: {} qos: {}", port.getUuid(), qosUuid); + LOG.debug("Handling Port add and QoS associated: port: {} qos: {}", port.getUuid().getValue(), + qosUuid.getValue()); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), - () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { + () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> { // handle Bandwidth Limit Rules update if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null && !qosPolicy.getBandwidthLimitRules().isEmpty()) { @@ -217,7 +225,8 @@ public class QosNeutronUtils { } public void handleQosInterfaceAdd(Port port, Uuid qosUuid) { - LOG.trace("Handling Port add and QoS associated: port: {} qos: {}", port.getUuid(), qosUuid); + LOG.debug("Handling Port add and QoS associated: port: {} qos: {}", port.getUuid().getValue(), + qosUuid.getValue()); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); @@ -227,18 +236,19 @@ public class QosNeutronUtils { && !qosPolicy.getDscpmarkingRules().isEmpty()) { setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0)); } - return Collections.emptyList(); + return emptyList(); }); } public void handleNeutronPortQosUpdate(Port port, Uuid qosUuidNew, Uuid qosUuidOld) { - LOG.trace("Handling Port QoS update: port: {} qosservice: {}", port.getUuid(), qosUuidNew); + LOG.debug("Handling Port QoS update: port: {} qosservice: {}", port.getUuid().getValue(), + qosUuidNew.getValue()); QosPolicy qosPolicyNew = qosPolicyMap.get(qosUuidNew); QosPolicy qosPolicyOld = qosPolicyMap.get(qosUuidOld); jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), - () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { + () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> { // handle Bandwidth Limit Rules update if (qosPolicyNew != null && qosPolicyNew.getBandwidthLimitRules() != null && !qosPolicyNew.getBandwidthLimitRules().isEmpty()) { @@ -248,8 +258,8 @@ public class QosNeutronUtils { && !qosPolicyOld.getBandwidthLimitRules().isEmpty()) { BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder(); setPortBandwidthLimits(port, bwLimitBuilder - .setMaxBurstKbps(BigInteger.ZERO) - .setMaxKbps(BigInteger.ZERO).build(), tx); + .setMaxBurstKbps(Uint64.ZERO) + .setMaxKbps(Uint64.ZERO).build(), tx); } } //handle DSCP Mark Rules update @@ -266,7 +276,7 @@ public class QosNeutronUtils { } public void handleNeutronPortQosRemove(Port port, Uuid qosUuid) { - LOG.trace("Handling Port QoS removal: port: {} qosservice: {}", port.getUuid(), qosUuid); + LOG.debug("Handling Port QoS removal: port: {} qosservice: {}", port.getUuid().getValue(), qosUuid.getValue()); // check for network qosservice to apply Network network = neutronVpnManager.getNeutronNetwork(port.getNetworkId()); @@ -279,14 +289,14 @@ public class QosNeutronUtils { QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), - () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { + () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> { // handle Bandwidth Limit Rules removal if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null && !qosPolicy.getBandwidthLimitRules().isEmpty()) { BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder(); setPortBandwidthLimits(port, bwLimitBuilder - .setMaxBurstKbps(BigInteger.ZERO) - .setMaxKbps(BigInteger.ZERO).build(), tx); + .setMaxBurstKbps(Uint64.ZERO) + .setMaxKbps(Uint64.ZERO).build(), tx); } // handle DSCP MArk Rules removal if (qosPolicy != null && qosPolicy.getDscpmarkingRules() != null @@ -298,7 +308,8 @@ public class QosNeutronUtils { } public void handleNeutronPortRemove(Port port, Uuid qosUuid) { - LOG.trace("Handling Port removal and Qos associated: port: {} qos: {}", port.getUuid(), qosUuid); + LOG.debug("Handling Port removal and Qos associated: port: {} qos: {}", port.getUuid().getValue(), + qosUuid.getValue()); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), () -> { @@ -307,12 +318,13 @@ public class QosNeutronUtils { && !qosPolicy.getDscpmarkingRules().isEmpty()) { unsetPortDscpMark(port); } - return Collections.emptyList(); + return emptyList(); }); } public void handleNeutronPortRemove(Port port, Uuid qosUuid, Interface intrf) { - LOG.trace("Handling Port removal and Qos associated: port: {} qos: {}", port.getUuid(), qosUuid); + LOG.debug("Handling Port removal and Qos associated: port: {} qos: {}", port.getUuid().getValue(), + qosUuid.getValue()); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); jobCoordinator.enqueueJob("QosPort-" + port.getUuid().getValue(), () -> { @@ -320,13 +332,13 @@ public class QosNeutronUtils { && !qosPolicy.getDscpmarkingRules().isEmpty()) { unsetPortDscpMark(port, intrf); } - return Collections.emptyList(); + return emptyList(); }); } public void handleNeutronNetworkQosUpdate(Network network, Uuid qosUuid) { - LOG.trace("Handling Network QoS update: net: {} qosservice: {}", network.getUuid(), qosUuid); + LOG.debug("Handling Network QoS update: net: {} qosservice: {}", network.getUuid().getValue(), qosUuid); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); if (qosPolicy == null || (qosPolicy.getBandwidthLimitRules() == null || qosPolicy.getBandwidthLimitRules().isEmpty()) @@ -342,23 +354,25 @@ public class QosNeutronUtils { if (port != null && (port.augmentation(QosPortExtension.class) == null || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) { jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), - () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { - if (qosPolicy.getBandwidthLimitRules() != null - && !qosPolicy.getBandwidthLimitRules().isEmpty()) { - setPortBandwidthLimits(port, qosPolicy.getBandwidthLimitRules().get(0), tx); - } - if (qosPolicy.getDscpmarkingRules() != null - && !qosPolicy.getDscpmarkingRules().isEmpty()) { - setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0)); - } - }))); + () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit( + CONFIGURATION, tx -> { + if (qosPolicy.getBandwidthLimitRules() != null + && !qosPolicy.getBandwidthLimitRules().isEmpty()) { + setPortBandwidthLimits(port, qosPolicy.getBandwidthLimitRules().get(0), tx); + } + if (qosPolicy.getDscpmarkingRules() != null + && !qosPolicy.getDscpmarkingRules().isEmpty()) { + setPortDscpMarking(port, qosPolicy.getDscpmarkingRules().get(0)); + } + }))); } } } } public void handleNeutronNetworkQosRemove(Network network, Uuid qosUuid) { - LOG.trace("Handling Network QoS removal: net: {} qosservice: {}", network.getUuid(), qosUuid); + LOG.debug("Handling Network QoS removal: net: {} qosservice: {}", network.getUuid().getValue(), + qosUuid.getValue()); QosPolicy qosPolicy = qosPolicyMap.get(qosUuid); List subnetIds = getSubnetIdsFromNetworkId(network.getUuid()); @@ -369,26 +383,27 @@ public class QosNeutronUtils { if (port != null && (port.augmentation(QosPortExtension.class) == null || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) { jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), - () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> { - if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null - && !qosPolicy.getBandwidthLimitRules().isEmpty()) { - BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder(); - setPortBandwidthLimits(port, bwLimitBuilder - .setMaxBurstKbps(BigInteger.ZERO) - .setMaxKbps(BigInteger.ZERO).build(), tx); - } - if (qosPolicy != null && qosPolicy.getDscpmarkingRules() != null - && !qosPolicy.getDscpmarkingRules().isEmpty()) { - unsetPortDscpMark(port); - } - }))); + () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit( + CONFIGURATION, tx -> { + if (qosPolicy != null && qosPolicy.getBandwidthLimitRules() != null + && !qosPolicy.getBandwidthLimitRules().isEmpty()) { + BandwidthLimitRulesBuilder bwLimitBuilder = new BandwidthLimitRulesBuilder(); + setPortBandwidthLimits(port, bwLimitBuilder + .setMaxBurstKbps(Uint64.ZERO) + .setMaxKbps(Uint64.ZERO).build(), tx); + } + if (qosPolicy != null && qosPolicy.getDscpmarkingRules() != null + && !qosPolicy.getDscpmarkingRules().isEmpty()) { + unsetPortDscpMark(port); + } + }))); } } } } public void handleNeutronNetworkQosBwRuleRemove(Network network, BandwidthLimitRules zeroBwLimitRule) { - LOG.trace("Handling Qos Bandwidth Rule Remove, net: {}", network.getUuid()); + LOG.debug("Handling Qos Bandwidth Rule Remove, net: {}", network.getUuid().getValue()); List subnetIds = getSubnetIdsFromNetworkId(network.getUuid()); @@ -399,7 +414,7 @@ public class QosNeutronUtils { if (port != null && (port.augmentation(QosPortExtension.class) == null || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) { jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), () -> Collections.singletonList( - txRunner.callWithNewWriteOnlyTransactionAndSubmit( + txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> setPortBandwidthLimits(port, zeroBwLimitRule, tx)))); } } @@ -407,7 +422,7 @@ public class QosNeutronUtils { } public void handleNeutronNetworkQosDscpRuleRemove(Network network) { - LOG.trace("Handling Qos Dscp Rule Remove, net: {}", network.getUuid()); + LOG.debug("Handling Qos Dscp Rule Remove, net: {}", network.getUuid().getValue()); List subnetIds = getSubnetIdsFromNetworkId(network.getUuid()); @@ -419,7 +434,7 @@ public class QosNeutronUtils { || port.augmentation(QosPortExtension.class).getQosPolicyId() == null)) { jobCoordinator.enqueueJob("QosPort-" + portId.getValue(), () -> { unsetPortDscpMark(port); - return Collections.emptyList(); + return emptyList(); }); } } @@ -428,26 +443,36 @@ public class QosNeutronUtils { // TODO Clean up the exception handling @SuppressWarnings("checkstyle:IllegalCatch") - public void setPortBandwidthLimits(Port port, BandwidthLimitRules bwLimit, WriteTransaction writeConfigTxn) { + public void setPortBandwidthLimits(Port port, BandwidthLimitRules bwLimit, + TypedWriteTransaction writeConfigTxn) { if (!qosEosHandler.isQosClusterOwner()) { - LOG.trace("Not Qos Cluster Owner. Ignoring setting bandwidth limits"); + LOG.debug("Not Qos Cluster Owner. Ignoring setting bandwidth limits"); return; } - LOG.trace("Setting bandwidth limits {} on Port {}", port, bwLimit); - - BigInteger dpId = getDpnForInterface(port.getUuid().getValue()); - if (dpId.equals(BigInteger.ZERO)) { + Uint64 dpId = getDpnForInterface(port.getUuid().getValue()); + if (dpId.equals(Uint64.ZERO)) { LOG.info("DPN ID for interface {} not found", port.getUuid().getValue()); return; } + LOG.trace("Setting bandwidth limits {} on Port {}", port.getUuid().getValue(), bwLimit); OvsdbBridgeRef bridgeRefEntry = getBridgeRefEntryFromOperDS(dpId); Optional bridgeNode = MDSALUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeRefEntry.getValue().firstIdentifierOf(Node.class), dataBroker); - + if (!bridgeNode.isPresent()) { + LOG.error("bridge not found for dpn {} port {} in operational datastore", dpId, port.getUuid().getValue()); + return; + } + LOG.debug("bridgeNode {}", bridgeNode.get().getNodeId().getValue()); TerminationPoint tp = SouthboundUtils.getTerminationPointByExternalId(bridgeNode.get(), port.getUuid().getValue()); + if (tp == null) { + LOG.debug("Skipping setting of bandwidth limit rules for subport {}", + port.getUuid().getValue()); + return; + } + LOG.debug("tp: {}", tp.getTpId().getValue()); OvsdbTerminationPointAugmentation ovsdbTp = tp.augmentation(OvsdbTerminationPointAugmentation.class); OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); @@ -460,7 +485,7 @@ public class QosNeutronUtils { tpBuilder.addAugmentation(OvsdbTerminationPointAugmentation.class, tpAugmentationBuilder.build()); try { if (writeConfigTxn != null) { - writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier + writeConfigTxn.merge(InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundUtils.OVSDB_TOPOLOGY_ID)) .child(Node.class, bridgeNode.get().key()) @@ -473,108 +498,121 @@ public class QosNeutronUtils { .child(TerminationPoint.class, new TerminationPointKey(tp.key())), tpBuilder.build()); } } catch (Exception e) { - LOG.error("Failure while setting BwLimitRule {} to port {}", bwLimit, port, e); + if (LOG.isDebugEnabled()) { + LOG.debug("Failure while setting BwLimitRule {} to port {} exception ", bwLimit, + port.getUuid().getValue(), e); + } else { + LOG.error("Failure while setting BwLimitRule {} to port {}", bwLimit, port.getUuid().getValue()); + } } } public void setPortDscpMarking(Port port, DscpmarkingRules dscpMark) { - if (!qosEosHandler.isQosClusterOwner()) { - LOG.trace("Not Qos Cluster Owner. Ignoring setting DSCP marking"); - return; - } - LOG.trace("Setting DSCP value {} on Port {}", port, dscpMark); - BigInteger dpnId = getDpnForInterface(port.getUuid().getValue()); + Uint64 dpnId = getDpnForInterface(port.getUuid().getValue()); String ifName = port.getUuid().getValue(); - Interface ifState = getInterfaceStateFromOperDS(ifName); - Short dscpValue = dscpMark.getDscpMark(); - if (dpnId.equals(BigInteger.ZERO)) { - LOG.info("DPN ID for interface {} not found", port.getUuid().getValue()); + if (dpnId.equals(Uint64.ZERO)) { + LOG.info("DPN ID for interface {} not found. Cannot set dscp value {} on port {}", + port.getUuid().getValue(), dscpMark, port.getUuid().getValue()); return; } - int ipVersions = getIpVersions(port); + if (!qosEosHandler.isQosClusterOwner()) { + qosServiceConfiguredPorts.add(port.getUuid()); + LOG.trace("Not Qos Cluster Owner. Ignoring setting DSCP marking"); + return; + } else { + Interface ifState = getInterfaceStateFromOperDS(ifName); + Short dscpValue = dscpMark.getDscpMark().toJava(); + int ipVersions = getIpVersions(port); + //1. OF rules + if (hasIpv4Addr(ipVersions)) { + LOG.trace("setting ipv4 flow for port: {}, dscp: {}", ifName, dscpValue); + addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV4, ifState); + } + if (hasIpv6Addr(ipVersions)) { + LOG.trace("setting ipv6 flow for port: {}, dscp: {}", ifName, dscpValue); + addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV6, ifState); + } - //1. OF rules - if (hasIpv4Addr(ipVersions)) { - LOG.trace("setting ipv4 flow for port: {}, dscp: {}", ifName, dscpValue); - addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV4, ifState); - } - if (hasIpv6Addr(ipVersions)) { - LOG.trace("setting ipv6 flow for port: {}, dscp: {}", ifName, dscpValue); - addFlow(dpnId, dscpValue, ifName, NwConstants.ETHTYPE_IPV6, ifState); - } + if (qosServiceConfiguredPorts.add(port.getUuid())) { + // bind qos service to interface + bindservice(ifName); + } - if (qosServiceConfiguredPorts.add(port.getUuid())) { - // bind qos service to interface - bindservice(ifName); } } public void unsetPortDscpMark(Port port) { - if (!qosEosHandler.isQosClusterOwner()) { - LOG.trace("Not Qos Cluster Owner. Ignoring unsetting DSCP marking"); - return; - } - LOG.trace("Removing dscp marking rule from Port {}", port); - BigInteger dpnId = getDpnForInterface(port.getUuid().getValue()); + Uint64 dpnId = getDpnForInterface(port.getUuid().getValue()); String ifName = port.getUuid().getValue(); - if (dpnId.equals(BigInteger.ZERO)) { - LOG.info("DPN ID for port {} not found", port); + if (dpnId.equals(Uint64.ZERO)) { + LOG.debug("DPN ID for port {} not found. Cannot unset dscp value", port.getUuid().getValue()); return; } - Interface intf = getInterfaceStateFromOperDS(ifName); - //unbind service from interface - unbindservice(ifName); - // 1. OF - int ipVersions = getIpVersions(port); - if (hasIpv4Addr(ipVersions)) { - removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV4, intf); - } - if (hasIpv6Addr(ipVersions)) { - removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV6, intf); + if (!qosEosHandler.isQosClusterOwner()) { + qosServiceConfiguredPorts.remove(port.getUuid()); + LOG.debug("Not Qos Cluster Owner. Ignoring unsetting DSCP marking"); + return; + } else { + LOG.trace("Removing dscp marking rule from Port {}", port.getUuid().getValue()); + Interface intf = getInterfaceStateFromOperDS(ifName); + //unbind service from interface + unbindservice(ifName); + // 1. OF + int ipVersions = getIpVersions(port); + if (hasIpv4Addr(ipVersions)) { + removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV4, intf); + } + if (hasIpv6Addr(ipVersions)) { + removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV6, intf); + } + qosServiceConfiguredPorts.remove(port.getUuid()); } - qosServiceConfiguredPorts.remove(port.getUuid()); } public void unsetPortDscpMark(Port port, Interface intrf) { - if (!qosEosHandler.isQosClusterOwner()) { - return; - } - LOG.trace("Removing dscp marking rule from Port {}", port); - BigInteger dpnId = getDpIdFromInterface(intrf); + Uint64 dpnId = getDpIdFromInterface(intrf); String ifName = port.getUuid().getValue(); - if (dpnId.equals(BigInteger.ZERO)) { - LOG.error("Unable to retrieve DPN Id for interface {}", ifName); + if (dpnId.equals(Uint64.ZERO)) { + LOG.error("Unable to retrieve DPN Id for interface {}. Cannot unset dscp value on port", ifName); return; } - unbindservice(ifName); - int ipVersions = getIpVersions(port); - if (hasIpv4Addr(ipVersions)) { - removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV4, intrf); - } - if (hasIpv6Addr(ipVersions)) { - removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV6, intrf); + if (!qosEosHandler.isQosClusterOwner()) { + qosServiceConfiguredPorts.remove(port.getUuid()); + return; + } else { + LOG.trace("Removing dscp marking rule from Port {}", port.getUuid().getValue()); + unbindservice(ifName); + int ipVersions = getIpVersions(port); + if (hasIpv4Addr(ipVersions)) { + removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV4, intrf); + } + if (hasIpv6Addr(ipVersions)) { + removeFlow(dpnId, ifName, NwConstants.ETHTYPE_IPV6, intrf); + } + qosServiceConfiguredPorts.remove(port.getUuid()); } - qosServiceConfiguredPorts.remove(port.getUuid()); } - private static BigInteger getDpIdFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf + private static Uint64 getDpIdFromInterface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf .interfaces.rev140508.interfaces.state.Interface ifState) { String lowerLayerIf = ifState.getLowerLayerIf().get(0); NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf); - return BigInteger.valueOf(MDSALUtil.getDpnIdFromPortName(nodeConnectorId)); + Long dpIdLong = MDSALUtil.getDpnIdFromPortName(nodeConnectorId); + Uint64 dpnId = dpIdLong < 0 ? Uint64.ZERO : Uint64.valueOf(dpIdLong); + return dpnId; } - public BigInteger getDpnForInterface(String ifName) { - BigInteger nodeId = BigInteger.ZERO; + public Uint64 getDpnForInterface(String ifName) { + Uint64 nodeId = Uint64.ZERO; try { GetDpidFromInterfaceInput dpIdInput = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build(); @@ -587,13 +625,17 @@ public class QosNeutronUtils { LOG.error("Could not retrieve DPN Id for interface {}", ifName); } } catch (NullPointerException | InterruptedException | ExecutionException e) { - LOG.error("Exception when getting dpn for interface {}", ifName, e); + if (LOG.isDebugEnabled()) { + LOG.debug("Exception when getting DPN for interface {} exception ", ifName, e); + } else { + LOG.error("Could not retrieve DPN for interface {}", ifName); + } } return nodeId; } @Nullable - private BridgeEntry getBridgeEntryFromConfigDS(BigInteger dpnId) { + private BridgeEntry getBridgeEntryFromConfigDS(Uint64 dpnId) { BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(dpnId); InstanceIdentifier bridgeEntryInstanceIdentifier = getBridgeEntryIdentifier(bridgeEntryKey); LOG.debug("Trying to retrieve bridge entry from config for Id: {}", bridgeEntryInstanceIdentifier); @@ -602,16 +644,17 @@ public class QosNeutronUtils { @Nullable private BridgeEntry getBridgeEntryFromConfigDS(InstanceIdentifier bridgeEntryInstanceIdentifier) { - return MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, dataBroker).orNull(); + return MDSALUtil.read(LogicalDatastoreType.CONFIGURATION, bridgeEntryInstanceIdentifier, dataBroker) + .orElse(null); } @Nullable private BridgeRefEntry getBridgeRefEntryFromOperDS(InstanceIdentifier dpnBridgeEntryIid) { - return MDSALUtil.read(LogicalDatastoreType.OPERATIONAL, dpnBridgeEntryIid, dataBroker).orNull(); + return MDSALUtil.read(LogicalDatastoreType.OPERATIONAL, dpnBridgeEntryIid, dataBroker).orElse(null); } @Nullable - private OvsdbBridgeRef getBridgeRefEntryFromOperDS(BigInteger dpId) { + private OvsdbBridgeRef getBridgeRefEntryFromOperDS(Uint64 dpId) { BridgeRefEntryKey bridgeRefEntryKey = new BridgeRefEntryKey(dpId); InstanceIdentifier bridgeRefEntryIid = getBridgeRefEntryIdentifier(bridgeRefEntryKey); BridgeRefEntry bridgeRefEntry = getBridgeRefEntryFromOperDS(bridgeRefEntryIid); @@ -627,12 +670,12 @@ public class QosNeutronUtils { return bridgeRefEntry.getBridgeReference(); } - @Nonnull + @NonNull private static InstanceIdentifier getBridgeRefEntryIdentifier(BridgeRefEntryKey bridgeRefEntryKey) { return InstanceIdentifier.builder(BridgeRefInfo.class).child(BridgeRefEntry.class, bridgeRefEntryKey).build(); } - @Nonnull + @NonNull private static InstanceIdentifier getBridgeEntryIdentifier(BridgeEntryKey bridgeEntryKey) { return InstanceIdentifier.builder(BridgeInterfaceInfo.class).child(BridgeEntry.class, bridgeEntryKey).build(); } @@ -640,7 +683,7 @@ public class QosNeutronUtils { public void removeStaleFlowEntry(Interface intrf, int ethType) { List matches = new ArrayList<>(); - BigInteger dpnId = getDpIdFromInterface(intrf); + Uint64 dpnId = getDpIdFromInterface(intrf); Integer ifIndex = intrf.getIfIndex(); matches.add(new MatchMetadata(MetaDataUtil.getLportTagMetaData(ifIndex), MetaDataUtil.METADATA_MASK_LPORT_TAG)); @@ -651,9 +694,9 @@ public class QosNeutronUtils { mdsalUtils.removeFlow(flowEntity); } - public void addFlow(BigInteger dpnId, Short dscpValue, String ifName, int ethType, Interface ifState) { + public void addFlow(Uint64 dpnId, Short dscpValue, String ifName, int ethType, Interface ifState) { if (ifState == null) { - LOG.trace("Could not find the ifState for interface {}", ifName); + LOG.debug("Could not find the ifState for interface {}", ifName); return; } Integer ifIndex = ifState.getIfIndex(); @@ -674,9 +717,9 @@ public class QosNeutronUtils { mdsalUtils.installFlow(flowEntity); } - public void removeFlow(BigInteger dpnId, String ifName, int ethType, Interface ifState) { + public void removeFlow(Uint64 dpnId, String ifName, int ethType, Interface ifState) { if (ifState == null) { - LOG.trace("Could not find the ifState for interface {}", ifName); + LOG.debug("Could not find the ifState for interface {}", ifName); return; } Integer ifIndex = ifState.getIfIndex(); @@ -685,15 +728,19 @@ public class QosNeutronUtils { new FlowId(getQosFlowId(NwConstants.QOS_DSCP_TABLE, dpnId, ifIndex, ethType))); } - @Nullable - public org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang - .ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS( - String interfaceName) { - return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, - createInterfaceStateInstanceIdentifier(interfaceName)).orNull(); + public org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state + .@Nullable Interface getInterfaceStateFromOperDS(String interfaceName) { + try { + return SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, + createInterfaceStateInstanceIdentifier(interfaceName)).orElse(null); + } catch (ExecutionException | InterruptedException e) { + LOG.error("getInterfaceStateFromOperDS: Exception while reading interface DS for the interface {}", + interfaceName, e); + } + return null; } - @Nonnull + @NonNull public static InstanceIdentifier createInterfaceStateInstanceIdentifier( String interfaceName) { @@ -734,7 +781,7 @@ public class QosNeutronUtils { } private static BoundServices getBoundServices(String serviceName, short qosServiceIndex, int priority, - BigInteger cookieQosTable, List instructions) { + Uint64 cookieQosTable, List instructions) { StypeOpenflowBuilder augBuilder = new StypeOpenflowBuilder().setFlowCookie(cookieQosTable) .setFlowPriority(priority).setInstruction(instructions); return new BoundServicesBuilder().withKey(new BoundServicesKey(qosServiceIndex)).setServiceName(serviceName) @@ -742,20 +789,20 @@ public class QosNeutronUtils { .addAugmentation(StypeOpenflow.class, augBuilder.build()).build(); } - @Nonnull - public static String getQosFlowId(short tableId, BigInteger dpId, int lportTag, int ethType) { + @NonNull + public static String getQosFlowId(short tableId, Uint64 dpId, int lportTag, int ethType) { return new StringBuilder().append(tableId).append(NwConstants.FLOWID_SEPARATOR).append(dpId) .append(NwConstants.FLOWID_SEPARATOR).append(lportTag) .append(NwConstants.FLOWID_SEPARATOR).append(ethType).toString(); } public boolean portHasQosPolicy(Port port) { - LOG.trace("checking qos policy for port: {}", port.getUuid()); + LOG.trace("checking qos policy for port: {}", port.getUuid().getValue()); boolean isQosPolicy = port.augmentation(QosPortExtension.class) != null && port.augmentation(QosPortExtension.class).getQosPolicyId() != null; - LOG.trace("portHasQosPolicy for port: {} return value {}", port.getUuid(), isQosPolicy); + LOG.trace("portHasQosPolicy for port: {} return value {}", port.getUuid().getValue(), isQosPolicy); return isQosPolicy; } @@ -769,7 +816,7 @@ public class QosNeutronUtils { } else { Network network = neutronVpnManager.getNeutronNetwork(port.getNetworkId()); - if (network.augmentation(QosNetworkExtension.class) != null) { + if (network != null && network.augmentation(QosNetworkExtension.class) != null) { qosUuid = network.augmentation(QosNetworkExtension.class).getQosPolicyId(); } } @@ -816,14 +863,16 @@ public class QosNeutronUtils { return neutronNetworkMap.get(networkUuid); } - public static BigInteger getDpnIdFromLowerLayerIf(String lowerLayerIf) { + @Nullable + public static Uint64 getDpnIdFromLowerLayerIf(String lowerLayerIf) { try { - return new BigInteger(lowerLayerIf.substring(lowerLayerIf.indexOf(":") + 1, lowerLayerIf.lastIndexOf(":"))); + return Uint64.valueOf(lowerLayerIf.substring(lowerLayerIf.indexOf(":") + 1, lowerLayerIf.lastIndexOf(":"))); } catch (NullPointerException e) { return null; } } + @Nullable public static String getPortNumberFromLowerLayerIf(String lowerLayerIf) { try { return (lowerLayerIf.substring(lowerLayerIf.lastIndexOf(":") + 1)); @@ -845,16 +894,23 @@ public class QosNeutronUtils { } public boolean hasIpv4Addr(int versions) { - if ((versions & (1 << QosConstants.IPV4_ADDR_MASK_BIT)) != 0) { - return true; - } - return false; + return (versions & (1 << QosConstants.IPV4_ADDR_MASK_BIT)) != 0; } public boolean hasIpv6Addr(int versions) { - if ((versions & (1 << QosConstants.IPV6_ADDR_MASK_BIT)) != 0) { - return true; + return (versions & (1 << QosConstants.IPV6_ADDR_MASK_BIT)) != 0; + } + + public boolean isBindServiceDone(Optional uuid) { + if (uuid != null) { + return qosServiceConfiguredPorts.contains(uuid.get()); } return false; } + + public void removeInterfaceInQosConfiguredPorts(Optional uuid) { + if (uuid != null) { + qosServiceConfiguredPorts.remove(uuid.get()); + } + } }