package org.opendaylight.netvirt.aclservice.listeners;
import com.google.common.collect.ImmutableSet;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.controller.md.sal.binding.api.ClusteredDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
+import org.opendaylight.infrautils.utils.concurrent.Executors;
+import org.opendaylight.mdsal.binding.api.ClusteredDataTreeChangeListener;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.utils.AclInterface;
import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
import org.opendaylight.serviceutils.srm.RecoverableListener;
import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
+import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.AccessLists;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace;
import org.slf4j.LoggerFactory;
@Singleton
-public class AclEventListener extends AsyncDataTreeChangeListenerBase<Acl, AclEventListener> implements
+public class AclEventListener extends AbstractAsyncDataTreeChangeListener<Acl> implements
ClusteredDataTreeChangeListener<Acl>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclEventListener.class);
public AclEventListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil, DataBroker dataBroker,
AclDataUtil aclDataUtil, AclServiceUtils aclServicUtils, AclInterfaceCache aclInterfaceCache,
ServiceRecoveryRegistry serviceRecoveryRegistry) {
- super(Acl.class, AclEventListener.class);
+ super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.create(AccessLists.class).child(Acl.class),
+ Executors.newListeningSingleThreadExecutor("AclEventListener", LOG));
this.aclServiceManager = aclServiceManager;
this.aclClusterUtil = aclClusterUtil;
this.dataBroker = dataBroker;
serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
- @Override
- @PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
- registerListener();
}
@Override
public void registerListener() {
- registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
+ super.register();
}
@Override
- protected InstanceIdentifier<Acl> getWildCardPath() {
- return InstanceIdentifier.create(AccessLists.class).child(Acl.class);
+ public void deregisterListener() {
+ super.close();
}
@Override
- protected void remove(InstanceIdentifier<Acl> key, Acl acl) {
+ public void remove(InstanceIdentifier<Acl> key, Acl acl) {
LOG.trace("On remove event, remove ACL: {}", acl);
String aclName = acl.getAclName();
this.aclDataUtil.removeAcl(aclName);
updateRemoteAclCache(AclServiceUtils.getAceListFromAcl(acl), aclName, AclServiceManager.Action.REMOVE);
if (aclClusterUtil.isEntityOwner()) {
- if (aclTag != null) {
- this.aclServiceUtils.releaseAclTag(aclName);
- }
// Handle Rule deletion If SG Remove event is received before SG Rule delete event
List<Ace> aceList = AclServiceUtils.aceList(acl);
if (!aceList.isEmpty()) {
}
@Override
- protected void update(InstanceIdentifier<Acl> key, Acl aclBefore, Acl aclAfter) {
+ public void update(InstanceIdentifier<Acl> key, Acl aclBefore, Acl aclAfter) {
String aclName = aclAfter.getAclName();
Collection<AclInterface> interfacesBefore =
ImmutableSet.copyOf(aclDataUtil.getInterfaceList(new Uuid(aclName)));
AclServiceManager.Action action) {
LOG.trace("update ace rules - action: {} , ace rules: {}", action.name(), aceList);
for (AclInterface port : interfaceList) {
- for (Ace aceRule : aceList) {
- aclServiceManager.notifyAce(port, action, aclName, aceRule);
+ BigInteger dpId = port.getDpId();
+ Long elanId = port.getElanId();
+ if (dpId != null && elanId != null) {
+ for (Ace aceRule : aceList) {
+ aclServiceManager.notifyAce(port, action, aclName, aceRule);
+ }
+ } else {
+ LOG.debug("Skip update ACE rules as DP ID or ELAN ID for interface {} is not present. "
+ + "DP Id: {} ELAN ID: {}", port.getInterfaceId(), dpId, elanId);
}
}
}
@Override
- protected void add(InstanceIdentifier<Acl> key, Acl acl) {
+ public void add(InstanceIdentifier<Acl> key, Acl acl) {
LOG.trace("On add event, add ACL: {}", acl);
this.aclDataUtil.addAcl(acl);
String aclName = acl.getAclName();
- Integer aclTag = this.aclServiceUtils.allocateAclTag(aclName);
+ Integer aclTag = AclServiceUtils.getAclTag(acl);
if (aclTag != null && aclTag != AclConstants.INVALID_ACL_TAG) {
this.aclDataUtil.addAclTag(aclName, aclTag);
}
String aclName = aclAfter.getAclName();
Integer aclTag = this.aclDataUtil.getAclTag(aclName);
if (aclTag == null) {
- aclTag = this.aclServiceUtils.allocateAclTag(aclName);
+ aclTag = AclServiceUtils.getAclTag(aclAfter);
if (aclTag != null && aclTag != AclConstants.INVALID_ACL_TAG) {
this.aclDataUtil.addAclTag(aclName, aclTag);
}
}
}
- @Override
- protected AclEventListener getDataTreeChangeListener() {
- return this;
- }
-
private static @NonNull List<Ace> getChangedAceList(Acl updatedAcl, Acl currentAcl) {
if (updatedAcl == null) {
return Collections.emptyList();
}
return deletedAceList;
}
+
+ @Override
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
+ }
}