import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.config.ConfigUtil;
import org.opendaylight.groupbasedpolicy.renderer.vpp.event.VppEndpointConfEvent;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.HostRelatedInfoContainer;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PortInterfaces;
import org.opendaylight.groupbasedpolicy.util.DataTreeChangeHandler;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.VppEndpoint;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
import com.google.common.eventbus.EventBus;
+import javax.annotation.Nonnull;
+
public class VppEndpointListener extends DataTreeChangeHandler<VppEndpoint> {
private static final Logger LOG = LoggerFactory.getLogger(VppEndpointListener.class);
+ private Table<String, String, VppEndpointConfEvent> pendingEndpointsTable = HashBasedTable.create();
private EventBus eventBus;
public VppEndpointListener(DataBroker dataProvider, EventBus eventBus) {
@Override
protected void onDelete(DataObjectModification<VppEndpoint> rootNode,
- InstanceIdentifier<VppEndpoint> rootIdentifier) {
- VppEndpointConfEvent event =
- new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter());
- eventBus.post(event);
+ InstanceIdentifier<VppEndpoint> rootIdentifier) {
+ if (ConfigUtil.getInstance().isL3FlatEnabled()) {
+ VppEndpoint vppEndpointBefore = rootNode.getDataBefore();
+ LOG.trace("onDelete -> Vppendpoint deleted: {}", vppEndpointBefore);
+ Preconditions.checkArgument(vppEndpointBefore.getVppNodeId() != null);
+ Preconditions.checkArgument(vppEndpointBefore.getVppInterfaceName() != null);
+ String intfName = rootNode.getDataBefore().getVppInterfaceName();
+ LOG.info("onDelete -> Checking pending endpoint to delete {}", pendingEndpointsTable.get(vppEndpointBefore.getVppNodeId().getValue(), intfName));
+ if(!portIsBusy(rootNode.getDataBefore())) {
+ LOG.info("onDelete -> Endpoint is not busy, deleting {}", vppEndpointBefore);
+ deleteVppEndpoint(new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter()));
+ }
+ else {
+ LOG.info("onDelete -> Caching pending deleted endpoint {}", rootNode.getDataBefore());
+ pendingEndpointsTable.put(vppEndpointBefore.getVppNodeId().getValue(), intfName, new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter()));
+ }
+ } else {
+ deleteVppEndpoint(new VppEndpointConfEvent(rootIdentifier, rootNode.getDataBefore(), rootNode.getDataAfter()));
+ }
+ }
+
+ private boolean portIsBusy(VppEndpoint vppEndpoint) {
+ HostRelatedInfoContainer hrc = HostRelatedInfoContainer.getInstance();
+ boolean intfcIsInUse =
+ hrc.intfcIsBusy(vppEndpoint.getVppNodeId().getValue(), vppEndpoint.getVppInterfaceName());
+ LOG.trace("onDelete -> isPortInUse: {} for vppEp: {}", intfcIsInUse, vppEndpoint);
+ return intfcIsInUse;
+ }
+
+ private void deleteVppEndpoint(VppEndpointConfEvent vppEpConfEvent) {
+ eventBus.post(vppEpConfEvent);
+ }
+
+ public void flushPendingVppEndpoint(@Nonnull String hostName,@Nonnull String intfName) {
+ Preconditions.checkNotNull(hostName);
+ Preconditions.checkNotNull(intfName);
+ LOG.trace("flushPendingVppEndpoint: hostname: {}, intfName: {}", hostName, intfName);
+ VppEndpointConfEvent vppEndpointConfEvent = pendingEndpointsTable.get(hostName, intfName);
+
+ boolean canRemove = (vppEndpointConfEvent != null && !portIsBusy(vppEndpointConfEvent.getBefore().get()));
+ LOG.trace("flushPendingVppEndpoint: can remove {} - > VppEp: {}", canRemove, vppEndpointConfEvent);
+ if (canRemove) {
+ LOG.trace("flushPendingVppEndpoint: hostName: {} for interface: {}", hostName, intfName);
+ deleteVppEndpoint(vppEndpointConfEvent);
+ pendingEndpointsTable.remove(hostName, intfName);
+ }
}
@Override