Bug 4996 - Wrong flows when using SFC coexistence
[netvirt.git] / openstack / net-virt-sfc / impl / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / sfc / RspListener.java
1 /*
2  * Copyright © 2015 Red Hat, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
9
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.RenderedServicePaths;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.rsp.rev140701.rendered.service.paths.RenderedServicePath;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Data tree listener for {@link RenderedServicePath}
23  */
24 public class RspListener extends AbstractDataTreeListener<RenderedServicePath> {
25     private static final Logger LOG = LoggerFactory.getLogger(RspListener.class);
26     private ListenerRegistration<RspListener> listenerRegistration;
27
28     public RspListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
29         super(provider, RenderedServicePath.class);
30         Preconditions.checkNotNull(db, "DataBroker can not be null!");
31
32         registrationListener(db);
33     }
34
35     public InstanceIdentifier<RenderedServicePath> getRspIid() {
36         return InstanceIdentifier.create(RenderedServicePaths.class).child(RenderedServicePath.class);
37     }
38
39     private void registrationListener(final DataBroker db) {
40         final DataTreeIdentifier<RenderedServicePath> treeId =
41                 new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, getRspIid());
42         try {
43             LOG.info("Registering Data Change Listener for NetvirtSfc RenderedServicePath configuration.");
44             listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
45         } catch (final Exception e) {
46             LOG.warn("Netvirt RenderedServicePath DataChange listener registration failed!");
47             throw new IllegalStateException("RspListener startup failed! System needs restart.", e);
48         }
49     }
50
51     @Override
52     public void remove(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
53         Preconditions.checkNotNull(change, "Removed object can not be null!");
54         provider.removeRsp(change);
55     }
56
57     @Override
58     public void update(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath original,
59                        RenderedServicePath change) {
60         Preconditions.checkNotNull(original, "Updated original object can not be null!");
61         Preconditions.checkNotNull(original, "Updated update object can not be null!");
62         remove(identifier, original);
63         provider.addRsp(change);
64     }
65
66     @Override
67     public void add(final InstanceIdentifier<RenderedServicePath> identifier, final RenderedServicePath change) {
68         Preconditions.checkNotNull(change, "Created object can not be null!");
69         provider.addRsp(change);
70     }
71
72     @Override
73     public void close() throws Exception {
74
75     }
76 }