2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.aclservice.listeners;
10 import javax.annotation.PostConstruct;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
17 import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
18 import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
19 import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
20 import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
21 import org.opendaylight.netvirt.aclservice.utils.AclClusterUtil;
22 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
23 import org.opendaylight.serviceutils.srm.RecoverableListener;
24 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.ElanInterfaces;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 public class AclElanInterfaceListener extends AsyncDataTreeChangeListenerBase<ElanInterface, AclElanInterfaceListener>
34 implements ClusteredDataTreeChangeListener<ElanInterface>, RecoverableListener {
35 private static final Logger LOG = LoggerFactory.getLogger(AclElanInterfaceListener.class);
37 private final AclServiceManager aclServiceManager;
38 private final AclClusterUtil aclClusterUtil;
39 private final DataBroker dataBroker;
40 private final AclInterfaceCache aclInterfaceCache;
43 public AclElanInterfaceListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil,
44 DataBroker dataBroker, AclInterfaceCache aclInterfaceCache,
45 ServiceRecoveryRegistry serviceRecoveryRegistry) {
46 super(ElanInterface.class, AclElanInterfaceListener.class);
47 this.aclServiceManager = aclServiceManager;
48 this.aclClusterUtil = aclClusterUtil;
49 this.dataBroker = dataBroker;
50 this.aclInterfaceCache = aclInterfaceCache;
51 serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
57 LOG.info("{} start", getClass().getSimpleName());
62 public void registerListener() {
63 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
67 protected InstanceIdentifier<ElanInterface> getWildCardPath() {
68 return InstanceIdentifier.create(ElanInterfaces.class).child(ElanInterface.class);
72 protected void remove(InstanceIdentifier<ElanInterface> key, ElanInterface dataObjectModification) {
77 protected void update(InstanceIdentifier<ElanInterface> key, ElanInterface dataObjectModificationBefore,
78 ElanInterface dataObjectModificationAfter) {
83 protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
84 String interfaceId = elanInterface.getName();
85 AclInterface aclInterface = aclInterfaceCache.updateIfPresent(interfaceId, (prevAclInterface, builder) -> {
86 if (prevAclInterface.getElanId() == null) {
87 ElanInstance elanInfo = AclServiceUtils.getElanInstanceByName(elanInterface.getElanInstanceName(),
89 if (elanInfo != null) {
90 builder.elanId(elanInfo.getElanTag().toJava());
98 if (aclInterface == null) {
99 LOG.debug("On Add event, ignore if AclInterface was not found in cache or was not updated");
103 if (aclInterface.getDpId() != null && aclClusterUtil.isEntityOwner()) {
104 // Notify ADD flows, if InterfaceStateListener has processed before ELAN-ID getting populated
105 LOG.debug("On add event, notify ACL service manager to BIND/ADD ACL for interface: {}", aclInterface);
106 aclServiceManager.notify(aclInterface, null, Action.BIND);
107 aclServiceManager.notify(aclInterface, null, Action.ADD);
112 protected AclElanInterfaceListener getDataTreeChangeListener() {