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.genius.srm.RecoverableListener;
17 import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
18 import org.opendaylight.netvirt.qosservice.recovery.QosServiceRecoveryHandler;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.ext.rev160613.QosPortExtension;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 public class QosNeutronPortChangeListener extends AsyncClusteredDataTreeChangeListenerBase<Port,
29 QosNeutronPortChangeListener> implements RecoverableListener {
30 private static final Logger LOG = LoggerFactory.getLogger(QosNeutronPortChangeListener.class);
31 private final DataBroker dataBroker;
32 private final QosNeutronUtils qosNeutronUtils;
35 public QosNeutronPortChangeListener(final DataBroker dataBroker,
36 final QosNeutronUtils qosNeutronUtils, final QosServiceRecoveryHandler qosServiceRecoveryHandler,
37 final ServiceRecoveryRegistry serviceRecoveryRegistry) {
38 super(Port.class, QosNeutronPortChangeListener.class);
39 this.dataBroker = dataBroker;
40 this.qosNeutronUtils = qosNeutronUtils;
41 serviceRecoveryRegistry.addRecoverableListener(qosServiceRecoveryHandler.buildServiceRegistryKey(),
43 LOG.debug("{} created", getClass().getSimpleName());
49 LOG.debug("{} init and registerListener done", getClass().getSimpleName());
53 protected InstanceIdentifier<Port> getWildCardPath() {
54 return InstanceIdentifier.create(Neutron.class).child(Ports.class).child(Port.class);
58 public void registerListener() {
59 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
63 protected QosNeutronPortChangeListener getDataTreeChangeListener() {
64 return QosNeutronPortChangeListener.this;
68 protected void add(InstanceIdentifier<Port> instanceIdentifier, Port port) {
69 qosNeutronUtils.addToPortCache(port);
73 protected void remove(InstanceIdentifier<Port> instanceIdentifier, Port port) {
74 qosNeutronUtils.removeFromPortCache(port);
78 protected void update(InstanceIdentifier<Port> instanceIdentifier, Port original, Port update) {
79 qosNeutronUtils.addToPortCache(update);
80 // check for QoS updates
81 QosPortExtension updateQos = update.augmentation(QosPortExtension.class);
82 QosPortExtension originalQos = original.augmentation(QosPortExtension.class);
84 if (originalQos == null && updateQos != null) {
85 // qosservice policy add
86 qosNeutronUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
87 qosNeutronUtils.handleNeutronPortQosAdd(update, updateQos.getQosPolicyId());
88 } else if (originalQos != null && updateQos != null
89 && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
91 // qosservice policy update
92 qosNeutronUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);
93 qosNeutronUtils.addToQosPortsCache(updateQos.getQosPolicyId(), update);
94 qosNeutronUtils.handleNeutronPortQosUpdate(update, updateQos.getQosPolicyId(),
95 originalQos.getQosPolicyId());
96 } else if (originalQos != null && updateQos == null) {
97 // qosservice policy delete
98 qosNeutronUtils.handleNeutronPortQosRemove(original, originalQos.getQosPolicyId());
99 qosNeutronUtils.removeFromQosPortsCache(originalQos.getQosPolicyId(), original);