2 * Copyright (c) 2017 Intel Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.qosservice;
10 import javax.annotation.PostConstruct;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.ext.rev160613.QosNetworkExtension;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 public class QosNeutronNetworkChangeListener extends AsyncClusteredDataTreeChangeListenerBase<Network,
26 QosNeutronNetworkChangeListener> {
27 private static final Logger LOG = LoggerFactory.getLogger(QosNeutronNetworkChangeListener.class);
28 private final DataBroker dataBroker;
29 private final QosAlertManager qosAlertManager;
30 private final QosNeutronUtils qosNeutronUtils;
33 public QosNeutronNetworkChangeListener(final DataBroker dataBroker, final QosAlertManager qosAlertManager,
34 final QosNeutronUtils qosNeutronUtils) {
35 super(Network.class, QosNeutronNetworkChangeListener.class);
36 this.dataBroker = dataBroker;
37 this.qosAlertManager = qosAlertManager;
38 this.qosNeutronUtils = qosNeutronUtils;
39 LOG.debug("{} created", getClass().getSimpleName());
44 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
45 LOG.debug("{} init and registerListener done", getClass().getSimpleName());
49 protected InstanceIdentifier<Network> getWildCardPath() {
50 return InstanceIdentifier.create(Neutron.class).child(Networks.class).child(Network.class);
54 protected QosNeutronNetworkChangeListener getDataTreeChangeListener() {
55 return QosNeutronNetworkChangeListener.this;
59 protected void remove(InstanceIdentifier<Network> instanceIdentifier, Network network) {
60 if (qosNeutronUtils.hasBandwidthLimitRule(network)) {
61 qosAlertManager.removeFromQosAlertCache(network);
66 protected void update(InstanceIdentifier<Network> instanceIdentifier, Network original, Network update) {
67 QosNetworkExtension updateQos = update.getAugmentation(QosNetworkExtension.class);
68 QosNetworkExtension originalQos = original.getAugmentation(QosNetworkExtension.class);
69 if (originalQos == null && updateQos != null) {
70 // qosservice policy add
71 qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
72 qosNeutronUtils.handleNeutronNetworkQosUpdate(update, updateQos.getQosPolicyId());
73 if (qosNeutronUtils.hasBandwidthLimitRule(update)) {
74 qosAlertManager.addToQosAlertCache(update);
76 } else if (originalQos != null && updateQos != null
77 && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
79 // qosservice policy update
81 qosNeutronUtils.removeFromQosNetworksCache(originalQos.getQosPolicyId(), original);
82 qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
83 qosNeutronUtils.handleNeutronNetworkQosUpdate(update, updateQos.getQosPolicyId());
85 if (qosNeutronUtils.hasBandwidthLimitRule(original)
86 && !qosNeutronUtils.hasBandwidthLimitRule(update)) {
87 qosAlertManager.removeFromQosAlertCache(original);
88 } else if (!qosNeutronUtils.hasBandwidthLimitRule(original)
89 && qosNeutronUtils.hasBandwidthLimitRule(update)) {
90 qosAlertManager.addToQosAlertCache(update);
93 } else if (originalQos != null && updateQos == null) {
94 // qosservice policy delete
95 if (qosNeutronUtils.hasBandwidthLimitRule(original)) {
96 qosAlertManager.removeFromQosAlertCache(original);
98 qosNeutronUtils.handleNeutronNetworkQosRemove(original, originalQos.getQosPolicyId());
99 qosNeutronUtils.removeFromQosNetworksCache(originalQos.getQosPolicyId(), original);
104 protected void add(InstanceIdentifier<Network> instanceIdentifier, Network network) {
105 QosNetworkExtension networkQos = network.getAugmentation(QosNetworkExtension.class);
106 if (networkQos != null) {
107 qosNeutronUtils.addToQosNetworksCache(networkQos.getQosPolicyId(), network);
108 qosNeutronUtils.handleNeutronNetworkQosUpdate(network, networkQos.getQosPolicyId());
109 if (qosNeutronUtils.hasBandwidthLimitRule(network)) {
110 qosAlertManager.addToQosAlertCache(network);