diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-01-12 10:05:46 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-01-12 09:27:00 +0000 |
commit | cf1483b4917db72ca798f0a09512839aaaf13828 (patch) | |
tree | 27b4e1b7396798c0f119f3ae6d2c5b852fede18b /v3po/v3po2vpp/src/main | |
parent | fd7cd756fe7e13e0bddde7be8ef7afecd2ba9fb7 (diff) |
HONEYCOMB-267 - Reference check for Bridge domain in L2
Eliminate attempts to remove bridge domain referenced in L2
Change-Id: Ia8ddafe68f87ef9fac0b091fb40d2142ce456cd4
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main')
-rw-r--r-- | v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java index b4b86264b..2962ec578 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/vpp/BridgeDomainCustomizer.java @@ -18,29 +18,37 @@ package io.fd.hc2vpp.v3po.vpp; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.stream.Collectors.toList; import com.google.common.base.Preconditions; -import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.common.translate.util.ReferenceCheck; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDel; import io.fd.vpp.jvpp.core.dto.BridgeDomainAddDelReply; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Collections; +import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.concurrent.GuardedBy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.L2BaseAttributes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.l2.base.attributes.interconnection.BridgeBased; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomain; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev161214.vpp.bridge.domains.BridgeDomainKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class BridgeDomainCustomizer - extends FutureJVppCustomizer - implements ListWriterCustomizer<BridgeDomain, BridgeDomainKey>, ByteDataTranslator, JvppReplyConsumer { +public class BridgeDomainCustomizer extends FutureJVppCustomizer + implements ListWriterCustomizer<BridgeDomain, BridgeDomainKey>, ByteDataTranslator, JvppReplyConsumer, + ReferenceCheck { private static final Logger LOG = LoggerFactory.getLogger(BridgeDomainCustomizer.class); @@ -110,6 +118,24 @@ public class BridgeDomainCustomizer throws WriteFailedException { LOG.debug("deleteCurrentAttributes: id={}, dataBefore={}, ctx={}", id, dataBefore, ctx); final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); + + final com.google.common.base.Optional<Interfaces> after = + ctx.readAfter(InstanceIdentifier.create(Interfaces.class)); + + if (after.isPresent()) { + checkReferenceExist(id, Optional.ofNullable(after.get().getInterface()) + .orElse(Collections.emptyList()) + .stream() + .map(iface -> Optional.ofNullable(iface.getAugmentation(VppInterfaceAugmentation.class)) + .map(VppInterfaceAugmentation::getL2) + .map(L2BaseAttributes::getInterconnection) + .orElse(null)) + .filter(interconnection -> interconnection instanceof BridgeBased) + .map(BridgeBased.class::cast) + .filter(bridgeBased -> bdName.equals(bridgeBased.getBridgeDomain())) + .collect(toList())); + } + int bdId = bdContext.getIndex(bdName, ctx.getMappingContext()); final BridgeDomainAddDel request = new BridgeDomainAddDel(); |