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
27     public RspListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
28         super(provider, RenderedServicePath.class);
29         Preconditions.checkNotNull(db, "DataBroker can not be null!");
30
31         registrationListener(db);
32     }
33
34     public InstanceIdentifier<RenderedServicePath> getRspIid() {
35         return InstanceIdentifier.create(RenderedServicePaths.class).child(RenderedServicePath.class);
36     }
37
38     private void registrationListener(final DataBroker db) {
39         final DataTreeIdentifier<RenderedServicePath> treeId =
40                 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getRspIid());
41         try {
42             LOG.info("Registering Data Change Listener for NetvirtSfc RenderedServicePath configuration.");
43             ListenerRegistration<RspListener> listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
44         } catch (final Exception e) {
45             LOG.warn("Netvirt RenderedServicePath DataChange listener registration failed!");
46             throw new IllegalStateException("NetvirtSfcAccessListListener startup failed! System needs restart.", e);
47         }
48     }
49
50     @Override
51     public void remove(InstanceIdentifier<RenderedServicePath> identifier, RenderedServicePath change) {
52         Preconditions.checkNotNull(change, "Object can not be null!");
53         LOG.debug("remove RenderedServicePath iid = {}, change = {}", identifier, change);
54         provider.removeRsp(change);
55     }
56
57     @Override
58     public void update(InstanceIdentifier<RenderedServicePath> identifier, RenderedServicePath original,
59                        RenderedServicePath change) {
60         Preconditions.checkNotNull(change, "Object can not be null!");
61         LOG.debug("Update RenderedServicePath iid = {}, change = {}", identifier, change);
62         //provider.addClassifierRules(update);
63     }
64
65     @Override
66     public void add(InstanceIdentifier<RenderedServicePath> identifier, RenderedServicePath change) {
67         Preconditions.checkNotNull(change, "Object can not be null!");
68         LOG.debug("Add RenderedServicePath iid = {}, change = {}", identifier, change);
69     }
70
71     @Override
72     public void close() throws Exception {
73
74     }
75 }