2 * Copyright © 2015 Dell, Inc. 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
9 package org.opendaylight.ovsdb.openstack.netvirt.sfc;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.AccessLists;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev150317.access.lists.Acl;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Data tree listener for AccessList.
26 public class NetvirtSfcAclListener extends AbstractDataTreeListener<Acl> {
27 private static final Logger LOG = LoggerFactory.getLogger(NetvirtSfcAclListener.class);
28 private ListenerRegistration<NetvirtSfcAclListener> listenerRegistration;
31 * {@link NetvirtSfcAclListener} constructor.
32 * @param provider OpenFlow 1.3 Provider
33 * @param db MdSal {@link DataBroker}
35 public NetvirtSfcAclListener(final INetvirtSfcOF13Provider provider, final DataBroker db) {
36 super(provider, Acl.class);
37 Preconditions.checkNotNull(db, "DataBroker can not be null!");
39 registrationListener(db);
42 private void registrationListener(final DataBroker db) {
43 final DataTreeIdentifier<Acl> treeId =
44 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getIetfAclIid());
46 LOG.info("Registering Data Change Listener for NetvirtSfc AccessList configuration.");
47 listenerRegistration = db.registerDataTreeChangeListener(treeId, this);
48 } catch (final Exception e) {
49 LOG.warn("Netvirt AccesList DataChange listener registration fail!");
50 throw new IllegalStateException("NetvirtSfcAccessListListener startup fail! System needs restart.", e);
56 if (listenerRegistration != null) {
58 listenerRegistration.close();
59 } catch (final Exception e) {
60 LOG.warn("Error while stopping IETF ACL ChangeListener: {}", e.getMessage());
61 LOG.debug("Error while stopping IETF ACL ChangeListener..", e);
63 listenerRegistration = null;
68 public void remove(final InstanceIdentifier<Acl> identifier,
69 final Acl removeDataObj) {
70 Preconditions.checkNotNull(removeDataObj, "Removed object can not be null!");
71 provider.removeClassifierRules(removeDataObj);
75 public void update(final InstanceIdentifier<Acl> identifier,
76 final Acl original, final Acl update) {
80 public void add(final InstanceIdentifier<Acl> identifier,
81 final Acl addDataObj) {
82 Preconditions.checkNotNull(addDataObj, "Added object can not be null!");
83 LOG.debug("Adding accesslist iid = {}, dataObj = {}", identifier, addDataObj);
84 provider.addClassifierRules(addDataObj);
87 public InstanceIdentifier<Acl> getIetfAclIid() {
88 return InstanceIdentifier.create(AccessLists.class).child(Acl.class);