import java.util.ArrayList;
import java.util.List;
-import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.jdt.annotation.Nullable;
-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.AclServiceManager.Action;
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.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
-public class AclInterfaceListener extends AsyncDataTreeChangeListenerBase<Interface, AclInterfaceListener>
+public class AclInterfaceListener extends AbstractAsyncDataTreeChangeListener<Interface>
implements ClusteredDataTreeChangeListener<Interface>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceListener.class);
public AclInterfaceListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil,
DataBroker dataBroker, AclDataUtil aclDataUtil, AclInterfaceCache aclInterfaceCache,
AclServiceUtils aclServicUtils, ServiceRecoveryRegistry serviceRecoveryRegistry) {
- super(Interface.class, AclInterfaceListener.class);
+ super(dataBroker, LogicalDatastoreType.CONFIGURATION,
+ InstanceIdentifier.create(Interfaces.class).child(Interface.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<Interface> getWildCardPath() {
- return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
+ public void deregisterListener() {
+ super.close();
}
@Override
boolean isSgChanged = isSecurityGroupsChanged(sgsBefore, aclInPortAfter.getSecurityGroups());
AclInterface aclInterfaceAfter =
addOrUpdateAclInterfaceCache(interfaceId, aclInPortAfter, isSgChanged, interfaceState);
+ updateCacheWithAddedAcls(aclInterfaceBefore, aclInterfaceAfter);
if (aclClusterUtil.isEntityOwner()) {
// Handle bind/unbind service irrespective of interface state (up/down)
}
private void updateCacheWithAclChange(AclInterface aclInterfaceBefore, AclInterface aclInterfaceAfter) {
- List<Uuid> addedAcls = AclServiceUtils.getUpdatedAclList(aclInterfaceAfter.getSecurityGroups(),
- aclInterfaceBefore.getSecurityGroups());
List<Uuid> deletedAcls = AclServiceUtils.getUpdatedAclList(aclInterfaceBefore.getSecurityGroups(),
aclInterfaceAfter.getSecurityGroups());
if (!deletedAcls.isEmpty()) {
aclDataUtil.removeAclInterfaceMap(deletedAcls, aclInterfaceAfter);
}
- if (!addedAcls.isEmpty()) {
- aclDataUtil.addOrUpdateAclInterfaceMap(addedAcls, aclInterfaceAfter);
- }
List<AllowedAddressPairs> addedAap = AclServiceUtils.getUpdatedAllowedAddressPairs(aclInterfaceAfter
.getAllowedAddressPairs(), aclInterfaceBefore.getAllowedAddressPairs());
List<AllowedAddressPairs> deletedAap = AclServiceUtils.getUpdatedAllowedAddressPairs(aclInterfaceBefore
}
}
+ private void updateCacheWithAddedAcls(AclInterface aclInterfaceBefore, AclInterface aclInterfaceAfter) {
+ List<Uuid> addedAcls = AclServiceUtils.getUpdatedAclList(aclInterfaceAfter.getSecurityGroups(),
+ aclInterfaceBefore.getSecurityGroups());
+ if (addedAcls != null && !addedAcls.isEmpty()) {
+ LOG.debug("Update cache by adding interface={}", aclInterfaceAfter.getInterfaceId());
+ aclDataUtil.addOrUpdateAclInterfaceMap(addedAcls, aclInterfaceAfter);
+ }
+ }
+
private boolean isPortSecurityEnabledNow(InterfaceAcl aclInPortBefore, InterfaceAcl aclInPortAfter) {
return aclInPortBefore != null && !aclInPortBefore.isPortSecurityEnabled() && aclInPortAfter != null
&& aclInPortAfter.isPortSecurityEnabled();
sgs = aclInPort.getSecurityGroups();
builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled())
.interfaceType(aclInPort.getInterfaceType()).securityGroups(sgs)
- .allowedAddressPairs(aclInPort.getAllowedAddressPairs()).subnetInfo(aclInPort.getSubnetInfo());
+ .allowedAddressPairs(new ArrayList<AllowedAddressPairs>(aclInPort
+ .getAllowedAddressPairs().values())).subnetInfo(new ArrayList<SubnetInfo>(aclInPort
+ .getSubnetInfo().values()));
}
if ((prevAclInterface == null || prevAclInterface.getLPortTag() == null) && interfaceState != null) {
}
@Override
- protected AclInterfaceListener getDataTreeChangeListener() {
- return this;
+ @PreDestroy
+ public void close() {
+ super.close();
+ Executors.shutdownAndAwaitTermination(getExecutorService());
}
}