X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=aclservice%2Fimpl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Faclservice%2Flisteners%2FAclInterfaceStateListener.java;h=6967a0a2302ab380a004fa24a7df704b53403fc1;hb=2f0569ed75ef8a1fb60f992d19c8bbdf92ff45bf;hp=288307fc404186664d3e0fa9dc66803b2d52acfa;hpb=178b1978dbc7b95b2ff05a78a1b610559a75d0c1;p=netvirt.git diff --git a/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclInterfaceStateListener.java b/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclInterfaceStateListener.java index 288307fc40..6967a0a230 100644 --- a/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclInterfaceStateListener.java +++ b/aclservice/impl/src/main/java/org/opendaylight/netvirt/aclservice/listeners/AclInterfaceStateListener.java @@ -7,18 +7,18 @@ */ package org.opendaylight.netvirt.aclservice.listeners; +import java.util.Collections; import java.util.List; import java.util.SortedSet; -import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Singleton; -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.genius.interfacemanager.interfaces.IInterfaceManager; -import org.opendaylight.genius.srm.RecoverableListener; -import org.opendaylight.genius.srm.ServiceRecoveryRegistry; +import org.opendaylight.infrautils.jobcoordinator.JobCoordinator; +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; @@ -26,21 +26,23 @@ import org.opendaylight.netvirt.aclservice.api.utils.AclInterface; import org.opendaylight.netvirt.aclservice.utils.AclClusterUtil; import org.opendaylight.netvirt.aclservice.utils.AclDataUtil; import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan; +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.iana._if.type.rev170119.L2vlan; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.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.DirectionEgress; 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.port.subnets.port.subnet.SubnetInfo; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton -public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase implements ClusteredDataTreeChangeListener, RecoverableListener { +public class AclInterfaceStateListener extends AbstractAsyncDataTreeChangeListener + implements ClusteredDataTreeChangeListener, RecoverableListener { private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceStateListener.class); @@ -52,13 +54,16 @@ public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase getWildCardPath() { - return InstanceIdentifier.create(InterfacesState.class).child(Interface.class); + public void deregisterListener() { + super.close(); } @Override - protected void remove(InstanceIdentifier key, Interface deleted) { + public void remove(InstanceIdentifier key, Interface deleted) { if (!L2vlan.class.equals(deleted.getType())) { return; } @@ -105,13 +108,18 @@ public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase { + aclDataUtil.removeAclInterfaceMap(acl, aclInterface); + return Collections.emptyList(); + }); + } } } } @Override - protected void update(InstanceIdentifier key, Interface before, Interface after) { + public void update(InstanceIdentifier key, Interface before, Interface after) { /* * The update is not of interest as the attributes populated from this listener will not change. * The northbound updates are handled in AclInterfaceListener. @@ -126,33 +134,14 @@ public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase key, Interface added) { + public void add(InstanceIdentifier key, Interface added) { if (!L2vlan.class.equals(added.getType())) { return; } - AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> { - builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()) - .isMarkedForDelete(false); - - if (AclServiceUtils.isOfInterest(prevAclInterface)) { - if (prevAclInterface.getSubnetInfo() == null) { - // For upgrades - List subnetInfo = aclServiceUtils.getSubnetInfo(added.getName()); - builder.subnetInfo(subnetInfo); - } - SortedSet ingressRemoteAclTags = - aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionIngress.class); - SortedSet egressRemoteAclTags = - aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionEgress.class); - builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags); - } - }); - - List aclList = aclInterface.getSecurityGroups(); - if (aclList == null) { + if (aclInterfaceCache.get(added.getName()) == null) { org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces - .Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName()); + .Interface iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName()); if (iface == null) { LOG.error("No interface with name {} available in interfaceConfig, servicing interfaceState ADD" + "for ACL failed", added.getName()); @@ -164,11 +153,28 @@ public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase { + builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()) + .interfaceType(aclInPort.getInterfaceType()).securityGroups(aclInPort.getSecurityGroups()) + .allowedAddressPairs(aclInPort.getAllowedAddressPairs()).subnetInfo(aclInPort.getSubnetInfo()); + }); } + AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> { + builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()) + .isMarkedForDelete(false); + if (AclServiceUtils.isOfInterest(prevAclInterface)) { + SortedSet ingressRemoteAclTags = + aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionIngress.class); + SortedSet egressRemoteAclTags = + aclServiceUtils.getRemoteAclTags(prevAclInterface.getSecurityGroups(), DirectionEgress.class); + builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags); + } + }); if (AclServiceUtils.isOfInterest(aclInterface)) { + List aclList = aclInterface.getSecurityGroups(); if (aclList != null) { - aclDataUtil.addAclInterfaceMap(aclList, aclInterface); + aclDataUtil.addOrUpdateAclInterfaceMap(aclList, aclInterface); } if (aclInterface.getElanId() == null) { LOG.debug("On Add event, skip ADD since ElanId is not updated"); @@ -186,7 +192,9 @@ public class AclInterfaceStateListener extends AsyncDataTreeChangeListenerBase