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.srm.RecoverableListener;
+import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
import org.opendaylight.netvirt.aclservice.api.AclInterfaceCache;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager;
import org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action;
@Singleton
public class AclInterfaceListener extends AsyncDataTreeChangeListenerBase<Interface, AclInterfaceListener>
- implements ClusteredDataTreeChangeListener<Interface> {
+ implements ClusteredDataTreeChangeListener<Interface>, RecoverableListener {
private static final Logger LOG = LoggerFactory.getLogger(AclInterfaceListener.class);
private final AclServiceManager aclServiceManager;
@Inject
public AclInterfaceListener(AclServiceManager aclServiceManager, AclClusterUtil aclClusterUtil,
DataBroker dataBroker, AclDataUtil aclDataUtil, AclInterfaceCache aclInterfaceCache,
- AclServiceUtils aclServicUtils) {
+ AclServiceUtils aclServicUtils, ServiceRecoveryRegistry serviceRecoveryRegistry) {
super(Interface.class, AclInterfaceListener.class);
this.aclServiceManager = aclServiceManager;
this.aclClusterUtil = aclClusterUtil;
this.aclDataUtil = aclDataUtil;
this.aclInterfaceCache = aclInterfaceCache;
this.aclServiceUtils = aclServicUtils;
+ serviceRecoveryRegistry.addRecoverableListener(AclServiceUtils.getRecoverServiceRegistryKey(), this);
}
@Override
@PostConstruct
public void init() {
LOG.info("{} start", getClass().getSimpleName());
+ registerListener();
+ }
+
+ @Override
+ public void registerListener() {
registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
}
@Override
protected InstanceIdentifier<Interface> getWildCardPath() {
- return InstanceIdentifier
- .create(Interfaces.class)
- .child(Interface.class);
+ return InstanceIdentifier.create(Interfaces.class).child(Interface.class);
}
@Override
- protected void remove(InstanceIdentifier<Interface> key, Interface port) {
+ public void remove(InstanceIdentifier<Interface> key, Interface port) {
LOG.trace("Received AclInterface remove event, port={}", port);
String interfaceId = port.getName();
AclInterface aclInterface = aclInterfaceCache.remove(interfaceId);
if (AclServiceUtils.isOfInterest(aclInterface)) {
if (aclClusterUtil.isEntityOwner()) {
- LOG.debug("On remove event, notify ACL service manager to unbind ACL from interface: {}", port);
+ LOG.debug("On remove event, notify ACL unbind/remove for interface: {}", interfaceId);
aclServiceManager.notify(aclInterface, null, Action.UNBIND);
- AclServiceUtils.deleteSubnetIpPrefixes(dataBroker, interfaceId);
+ if (aclInterface.getDpId() != null) {
+ aclServiceManager.notify(aclInterface, null, Action.REMOVE);
+ }
+ aclServiceUtils.deleteSubnetInfo(interfaceId);
}
}
}
@Override
- protected void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
- if (portBefore.getAugmentation(ParentRefs.class) == null
- && portAfter.getAugmentation(ParentRefs.class) != null) {
+ public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
+ if (portBefore.augmentation(ParentRefs.class) == null
+ && portAfter.augmentation(ParentRefs.class) != null) {
LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
return;
}
LOG.trace("Received AclInterface update event, portBefore={}, portAfter={}", portBefore, portAfter);
- InterfaceAcl aclInPortAfter = portAfter.getAugmentation(InterfaceAcl.class);
- InterfaceAcl aclInPortBefore = portBefore.getAugmentation(InterfaceAcl.class);
+ InterfaceAcl aclInPortAfter = portAfter.augmentation(InterfaceAcl.class);
+ InterfaceAcl aclInPortBefore = portBefore.augmentation(InterfaceAcl.class);
String interfaceId = portAfter.getName();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state
}
if (aclInPortAfter != null && aclInPortAfter.isPortSecurityEnabled()
|| aclInPortBefore != null && aclInPortBefore.isPortSecurityEnabled()) {
- boolean isSgChanged =
- isSecurityGroupsChanged(aclInPortBefore.getSecurityGroups(), aclInPortAfter.getSecurityGroups());
+ List<Uuid> sgsBefore = null;
+ if (aclInPortBefore != null) {
+ sgsBefore = aclInPortBefore.getSecurityGroups();
+ }
+ boolean isSgChanged = isSecurityGroupsChanged(sgsBefore, aclInPortAfter.getSecurityGroups());
AclInterface aclInterfaceAfter =
addOrUpdateAclInterfaceCache(interfaceId, aclInPortAfter, isSgChanged, interfaceState);
// Handle bind/unbind service irrespective of interface state (up/down)
boolean isPortSecurityEnable = aclInterfaceAfter.isPortSecurityEnabled();
boolean isPortSecurityEnableBefore = aclInterfaceBefore.isPortSecurityEnabled();
- // if port security enable is changed, bind/unbind ACL service
- if (isPortSecurityEnableBefore != isPortSecurityEnable) {
- LOG.debug("Notify bind/unbind ACL service for interface={}, isPortSecurityEnable={}", interfaceId,
+ // if port security enable is changed and is disabled, unbind ACL service
+ if (isPortSecurityEnableBefore != isPortSecurityEnable && !isPortSecurityEnable) {
+ LOG.debug("Notify unbind ACL service for interface={}, isPortSecurityEnable={}", interfaceId,
isPortSecurityEnable);
- if (isPortSecurityEnable) {
- aclServiceManager.notify(aclInterfaceAfter, null, Action.BIND);
- } else {
- aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
- }
+ aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
}
if (interfaceState != null && interfaceState.getOperStatus().equals(
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces
.state.Interface.OperStatus.Up)) {
+ // if port security enable is changed and is enabled, bind ACL service
+ if (isPortSecurityEnableBefore != isPortSecurityEnable && isPortSecurityEnable) {
+ LOG.debug("Notify bind ACL service for interface={}, isPortSecurityEnable={}", interfaceId,
+ isPortSecurityEnable);
+ aclServiceManager.notify(aclInterfaceAfter, null, Action.BIND);
+ }
LOG.debug("On update event, notify ACL service manager to update ACL for interface: {}",
interfaceId);
// handle add for AclPortsLookup before processing update
.lPortTag(interfaceState.getIfIndex()).isMarkedForDelete(false);
}
- if (prevAclInterface == null) {
- builder.subnetIpPrefixes(AclServiceUtils.getSubnetIpPrefixes(dataBroker, interfaceId));
- }
+ builder.subnetInfo(aclServiceUtils.getSubnetInfo(interfaceId));
if (prevAclInterface == null || prevAclInterface.getElanId() == null) {
builder.elanId(AclServiceUtils.getElanIdFromInterface(interfaceId, dataBroker));
}
}
@Override
- protected void add(InstanceIdentifier<Interface> key, Interface port) {
+ public void add(InstanceIdentifier<Interface> key, Interface port) {
LOG.trace("Received AclInterface add event, port={}", port);
- InterfaceAcl aclInPort = port.getAugmentation(InterfaceAcl.class);
+ InterfaceAcl aclInPort = port.augmentation(InterfaceAcl.class);
if (aclInPort != null && aclInPort.isPortSecurityEnabled()) {
String interfaceId = port.getName();
AclInterface aclInterface = addOrUpdateAclInterfaceCache(interfaceId, aclInPort);
- if (aclClusterUtil.isEntityOwner()) {
- LOG.debug("On add event, notify ACL service manager to bind ACL for interface: {}", port);
+ // if interface state event comes first followed by interface config event.
+ if (aclInterface.getDpId() != null && aclInterface.getElanId() != null && aclClusterUtil.isEntityOwner()) {
+ LOG.debug("On add event, notify ACL bind/add for interface: {}", interfaceId);
aclServiceManager.notify(aclInterface, null, Action.BIND);
+ aclServiceManager.notify(aclInterface, null, Action.ADD);
}
}
}