diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-12 13:15:50 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-05-15 05:24:48 +0000 |
commit | 9f3503ac117d485d75e604364647d7f59401f24a (patch) | |
tree | ab1d757f46b46180db19f1d012fef2e7a03729d7 /v3po/v3po2vpp/src/main | |
parent | 31bad643f16b6986434571b46158e6c662a240be (diff) |
HC2VPP-144 - Sub-interface span
Provides option to define port mirroring from
interface to subinterface
Change-Id: I8c04e8eb6b980c830e77e1ef2b75ddff3d59364c
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Signed-off-by: jsrnicek <jsrnicek@cisco.com>
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main')
9 files changed, 208 insertions, 61 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java index e75f97d93..3d78094a3 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesStateReaderFactory.java @@ -31,7 +31,7 @@ import io.fd.hc2vpp.v3po.interfacesstate.VhostUserCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.VxlanCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.VxlanGpeCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.pbb.PbbRewriteStateCustomizer; -import io.fd.hc2vpp.v3po.interfacesstate.span.MirroredInterfacesCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.span.InterfaceMirroredInterfacesCustomizer; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.impl.read.GenericInitReader; import io.fd.honeycomb.translate.impl.read.GenericReader; @@ -130,7 +130,7 @@ public final class InterfacesStateReaderFactory implements ReaderFactory { registry.subtreeAdd( ImmutableSet.of(InstanceIdentifier.create(MirroredInterfaces.class).child(MirroredInterface.class)), new GenericInitReader<>(spanId.child(MirroredInterfaces.class), - new MirroredInterfacesCustomizer(jvpp, ifcNamingCtx))); + new InterfaceMirroredInterfacesCustomizer(jvpp, ifcNamingCtx))); } private void initPbbRewriteAugmentation(final ModifiableReaderRegistryBuilder registry, diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java index 7fba6360a..6b9d514f2 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/InterfacesWriterFactory.java @@ -141,8 +141,8 @@ public final class InterfacesWriterFactory implements WriterFactory { .child(Span.class) .child(MirroredInterfaces.class) .child(MirroredInterface.class); - registry.addAfter(new GenericWriter<>(mirroredIfcId, new MirroredInterfaceCustomizer(jvpp, ifcNamingContext)), - ifcId); + registry.addAfter(new GenericWriter<>(mirroredIfcId, new MirroredInterfaceCustomizer(jvpp, ifcNamingContext, + id -> id.firstKeyOf(Interface.class).getName())), ifcId); } private void addPbbAugmentationWriters(final InstanceIdentifier<Interface> ifcId, diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java index be202f6fa..8c412b5e2 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceAugmentationWriterFactory.java @@ -24,12 +24,18 @@ import io.fd.hc2vpp.v3po.interfaces.RewriteCustomizer; import io.fd.hc2vpp.v3po.interfaces.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.interfaces.SubInterfaceL2Customizer; import io.fd.hc2vpp.v3po.interfaces.SubInterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.interfaces.span.MirroredInterfaceCustomizer; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; import io.fd.honeycomb.translate.impl.write.GenericListWriter; import io.fd.honeycomb.translate.impl.write.GenericWriter; import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.VppSubinterfaceSpanAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.interfaces._interface.sub.interfaces.sub._interface.Span; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.SubinterfaceAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.SubInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; @@ -95,5 +101,14 @@ public final class SubinterfaceAugmentationWriterFactory implements WriterFactor L2_ID); final InstanceIdentifier<Routing> routingId = SUB_IFC_ID.child(Routing.class); registry.add(new GenericWriter<>(routingId, new SubInterfaceRoutingCustomizer(jvpp, ifcContext))); + + final InstanceIdentifier<MirroredInterface> mirroredId = + SUB_IFC_ID.augmentation(VppSubinterfaceSpanAugmentation.class) + .child(Span.class) + .child(MirroredInterfaces.class) + .child(MirroredInterface.class); + registry.addAfter(new GenericListWriter<>(mirroredId, + new MirroredInterfaceCustomizer(jvpp, ifcContext, SubInterfaceUtils::subInterfaceFullNameConfig)), + SUB_IFC_ID); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java index 9a6619838..ee1fd6034 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/factory/SubinterfaceStateAugmentationReaderFactory.java @@ -24,6 +24,7 @@ import io.fd.hc2vpp.v3po.interfacesstate.RewriteCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceL2Customizer; import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceRoutingCustomizer; +import io.fd.hc2vpp.v3po.interfacesstate.span.SubInterfaceMirroredInterfacesCustomizer; import io.fd.honeycomb.translate.impl.read.GenericInitListReader; import io.fd.honeycomb.translate.impl.read.GenericInitReader; import io.fd.honeycomb.translate.impl.read.GenericReader; @@ -31,6 +32,11 @@ import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import org.opendaylight.yang.gen.v1.urn.ieee.params.xml.ns.yang.dot1q.types.rev150626.dot1q.tag.or.any.Dot1qTag; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.VppSubinterfaceSpanStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.VppSubinterfaceSpanStateAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.interfaces.state._interface.sub.interfaces.sub._interface.SpanState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.interfaces.state._interface.sub.interfaces.sub._interface.SpanStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.SubinterfaceStateAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.SubinterfaceStateAugmentationBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces.state._interface.SubInterfaces; @@ -91,5 +97,15 @@ public final class SubinterfaceStateAugmentationReaderFactory implements ReaderF new GenericReader<>(l2Id.child(Rewrite.class), new RewriteCustomizer(jvpp, ifcCtx))); final InstanceIdentifier<Routing> routingId = subIfcId.child(Routing.class); registry.add(new GenericReader<>(routingId, new SubInterfaceRoutingCustomizer(jvpp, ifcCtx))); + + final InstanceIdentifier<VppSubinterfaceSpanStateAugmentation> spanStateAugId = subIfcId.augmentation(VppSubinterfaceSpanStateAugmentation.class); + registry.addStructuralReader(spanStateAugId, VppSubinterfaceSpanStateAugmentationBuilder.class); + + final InstanceIdentifier<SpanState> spanStateId = spanStateAugId + .child(SpanState.class); + registry.addStructuralReader(spanStateId, SpanStateBuilder.class); + + final InstanceIdentifier<MirroredInterfaces> mirroredInterfacesId = spanStateId.child(MirroredInterfaces.class); + registry.add(new GenericInitReader<>(mirroredInterfacesId, new SubInterfaceMirroredInterfacesCustomizer(jvpp, ifcCtx))); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java index 993120b68..4d6ea9864 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/span/MirroredInterfaceCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco and/or its affiliates. + * Copyright (c) 2017 Cisco and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package io.fd.hc2vpp.v3po.interfaces.span; +import static io.fd.honeycomb.translate.util.RWUtils.cutId; + import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; @@ -24,48 +26,41 @@ import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.vpp.jvpp.core.dto.SwInterfaceSpanEnableDisable; import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.function.Function; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.SpanState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterfaceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class MirroredInterfaceCustomizer - extends FutureJVppCustomizer +public final class MirroredInterfaceCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<MirroredInterface, MirroredInterfaceKey>, JvppReplyConsumer { private static final Logger LOG = LoggerFactory.getLogger(MirroredInterfaceCustomizer.class); private final NamingContext ifcContext; + private final Function<InstanceIdentifier<MirroredInterfaces>, String> destinationInterfaceNameExtractor; - public MirroredInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, final NamingContext ifcContext) { + public MirroredInterfaceCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext, + @Nonnull final Function<InstanceIdentifier<MirroredInterfaces>, String> destinationInterfaceNameExtractor) { super(futureJVppCore); this.ifcContext = ifcContext; + this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; } - private SwInterfaceSpanEnableDisable getSpanAddDelRequest(final int dstId, final Integer srcId, final boolean isAdd, - @Nullable final SpanState state) { - final SwInterfaceSpanEnableDisable spanAddDel = new SwInterfaceSpanEnableDisable(); - spanAddDel.state = (byte) (isAdd - ? state != null - ? state.getIntValue() - : 0 - : 0);// either one of 1(rx),2(tx),3(both) or 0 for disable/delete - spanAddDel.swIfIndexFrom = srcId; - spanAddDel.swIfIndexTo = dstId; - return spanAddDel; - } @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MirroredInterface> instanceIdentifier, + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<MirroredInterface> id, @Nonnull final MirroredInterface mirroredInterface, @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String destinationInterfaceName = instanceIdentifier.firstKeyOf(Interface.class).getName(); + final String destinationInterfaceName = + destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); final String sourceInterfaceName = mirroredInterface.getIfaceRef(); final SpanState spanState = mirroredInterface.getState(); @@ -78,7 +73,7 @@ public final class MirroredInterfaceCustomizer interfaceId(writeContext, ifcContext, sourceInterfaceName), true, spanState)) - .toCompletableFuture(), instanceIdentifier); + .toCompletableFuture(), id); LOG.debug("Span for source interface {} | destination interface {} | state {} successfully enabled", sourceInterfaceName, destinationInterfaceName, spanState); } @@ -94,10 +89,11 @@ public final class MirroredInterfaceCustomizer } @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MirroredInterface> instanceIdentifier, + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MirroredInterface> id, @Nonnull final MirroredInterface mirroredInterface, @Nonnull final WriteContext writeContext) throws WriteFailedException { - final String destinationInterfaceName = instanceIdentifier.firstKeyOf(Interface.class).getName(); + final String destinationInterfaceName = + destinationInterfaceNameExtractor.apply(cutId(id, MirroredInterfaces.class)); final String sourceInterfaceName = mirroredInterface.getIfaceRef(); LOG.debug("Disabling span for source interface {} | destination interface {} ", sourceInterfaceName, destinationInterfaceName); @@ -108,11 +104,24 @@ public final class MirroredInterfaceCustomizer interfaceId(writeContext, ifcContext, sourceInterfaceName), false, null)) - .toCompletableFuture(), instanceIdentifier); + .toCompletableFuture(), id); LOG.debug("Span for source interface {} | destination interface {} successfully disabled", sourceInterfaceName, destinationInterfaceName); } + private SwInterfaceSpanEnableDisable getSpanAddDelRequest(final int dstId, final Integer srcId, final boolean isAdd, + @Nullable final SpanState state) { + final SwInterfaceSpanEnableDisable spanAddDel = new SwInterfaceSpanEnableDisable(); + spanAddDel.state = (byte) (isAdd + ? state != null + ? state.getIntValue() + : 0 + : 0);// either one of 1(rx),2(tx),3(both) or 0 for disable/delete + spanAddDel.swIfIndexFrom = srcId; + spanAddDel.swIfIndexTo = dstId; + return spanAddDel; + } + private static int interfaceId(final WriteContext writeContext, final NamingContext ifcContext, final String name) { return ifcContext.getIndex(name, writeContext.getMappingContext()); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java index 229ed6948..fbfbf67a4 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/MirroredInterfacesCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/AbstractMirroredInterfacesCustomizer.java @@ -19,45 +19,42 @@ package io.fd.hc2vpp.v3po.interfacesstate.span; 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.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; -import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; import io.fd.vpp.jvpp.core.dto.SwInterfaceSpanDetailsReplyDump; import io.fd.vpp.jvpp.core.dto.SwInterfaceSpanDump; import io.fd.vpp.jvpp.core.future.FutureJVppCore; import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; import javax.annotation.Nonnull; -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.opendaylight.params.xml.ns.yang.v3po.rev170315.SpanState; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Span; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces.state._interface.SpanBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfacesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterfaceBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.mirrored.interfaces.MirroredInterfaceKey; -import org.opendaylight.yangtools.concepts.Builder; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class MirroredInterfacesCustomizer +abstract class AbstractMirroredInterfacesCustomizer extends FutureJVppCustomizer implements InitializingReaderCustomizer<MirroredInterfaces, MirroredInterfacesBuilder>, JvppReplyConsumer { - private static final Logger LOG = LoggerFactory.getLogger(MirroredInterfacesCustomizer.class); + private static final Logger LOG = LoggerFactory.getLogger(AbstractMirroredInterfacesCustomizer.class); private final NamingContext ifcContext; + private final Function<InstanceIdentifier<MirroredInterfaces>, String> destinationInterfaceNameExtractor; - public MirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, final NamingContext ifcContext) { + protected AbstractMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext, + @Nonnull final Function<InstanceIdentifier<MirroredInterfaces>, String> destinationInterfaceNameExtractor) { super(futureJVppCore); this.ifcContext = ifcContext; + this.destinationInterfaceNameExtractor = destinationInterfaceNameExtractor; } @Nonnull @@ -71,8 +68,7 @@ public final class MirroredInterfacesCustomizer @Nonnull final MirroredInterfacesBuilder builder, @Nonnull final ReadContext ctx) throws ReadFailedException { LOG.trace("Reading mirrored interfaces under: {}", id); - final int dstId = - ifcContext.getIndex(id.firstKeyOf(Interface.class).getName(), ctx.getMappingContext()); + final int dstId = destinationInterfaceIndex(id, ctx.getMappingContext()); final SwInterfaceSpanDetailsReplyDump replyForRead; if (ctx.getModificationCache().containsKey(getCacheKey())) { @@ -110,22 +106,9 @@ public final class MirroredInterfacesCustomizer return getClass().getName(); } - @Override - public void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, - @Nonnull final MirroredInterfaces readValue) { - ((SpanBuilder) parentBuilder).setMirroredInterfaces(readValue); - } - - @Nonnull - @Override - public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<MirroredInterfaces> id, - @Nonnull final MirroredInterfaces readValue, - @Nonnull final ReadContext ctx) { - final InstanceIdentifier<MirroredInterfaces> cfgId = - InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) - .augmentation(VppInterfaceAugmentation.class) - .child(Span.class) - .child(MirroredInterfaces.class); - return Initialized.create(cfgId, readValue); + private int destinationInterfaceIndex(@Nonnull final InstanceIdentifier<MirroredInterfaces> id, + @Nonnull final MappingContext mappingContext) { + final String destinationInterfaceName = destinationInterfaceNameExtractor.apply(id); + return ifcContext.getIndex(destinationInterfaceName, mappingContext); } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java new file mode 100644 index 000000000..9f05c61df --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/InterfaceMirroredInterfacesCustomizer.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.interfacesstate.span; + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.InterfaceCustomizer; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +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.opendaylight.params.xml.ns.yang.v3po.rev170315.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces.state._interface.SpanBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Provides interface-specific logic to read/init port mirroring configuration + */ +public class InterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { + + public InterfaceMirroredInterfacesCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final NamingContext ifcContext) { + super(futureJVppCore, ifcContext, id -> id.firstKeyOf(Interface.class).getName()); + } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<MirroredInterfaces> id, + @Nonnull final MirroredInterfaces readValue, + @Nonnull final ReadContext ctx) { + final InstanceIdentifier<MirroredInterfaces> cfgId = + InterfaceCustomizer.getCfgId(RWUtils.cutId(id, Interface.class)) + .augmentation(VppInterfaceAugmentation.class) + .child(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.interfaces._interface.Span.class) + .child(MirroredInterfaces.class); + return Initialized.create(cfgId, readValue); + } + + @Override + public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull MirroredInterfaces mirroredInterfaces) { + ((SpanBuilder) builder).setMirroredInterfaces(mirroredInterfaces); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java new file mode 100644 index 000000000..8d3557f96 --- /dev/null +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/span/SubInterfaceMirroredInterfacesCustomizer.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.v3po.interfacesstate.span; + + +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.v3po.interfacesstate.SubInterfaceCustomizer; +import io.fd.hc2vpp.v3po.util.SubInterfaceUtils; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.spi.read.Initialized; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.VppSubinterfaceSpanAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.interfaces._interface.sub.interfaces.sub._interface.Span; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.subinterface.span.rev170510.interfaces.state._interface.sub.interfaces.sub._interface.SpanStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170315.span.attributes.MirroredInterfaces; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces.state._interface.sub.interfaces.SubInterface; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Provides sub-interface-specific logic to read/init port mirroring configuration + */ +public class SubInterfaceMirroredInterfacesCustomizer extends AbstractMirroredInterfacesCustomizer { + + public SubInterfaceMirroredInterfacesCustomizer(@Nonnull FutureJVppCore futureJVppCore, NamingContext ifcContext) { + super(futureJVppCore, ifcContext, SubInterfaceUtils::subInterfaceFullNameOperational); + } + + @Nonnull + @Override + public Initialized<? extends DataObject> init(@Nonnull InstanceIdentifier<MirroredInterfaces> id, + @Nonnull MirroredInterfaces readValue, + @Nonnull ReadContext readContext) { + final InstanceIdentifier<MirroredInterfaces> cfgId = + SubInterfaceCustomizer.getCfgId(RWUtils.cutId(id, SubInterface.class)) + .augmentation(VppSubinterfaceSpanAugmentation.class) + .child(Span.class) + .child(MirroredInterfaces.class); + + return Initialized.create(cfgId, readValue); + } + + @Override + public void merge(@Nonnull Builder<? extends DataObject> builder, @Nonnull MirroredInterfaces mirroredInterfaces) { + ((SpanStateBuilder) builder).setMirroredInterfaces(mirroredInterfaces); + } +} diff --git a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java index 7b83aafec..6fdf2e12d 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/util/SubInterfaceUtils.java @@ -26,7 +26,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces. import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.interfaces._interface.sub.interfaces.SubInterface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.Tags; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.base.attributes.tags.Tag; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170509.sub._interface.routing.attributes.Routing; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public final class SubInterfaceUtils { @@ -39,7 +38,7 @@ public final class SubInterfaceUtils { return String.format("%s.%d", superIfName, subIfaceId); } - public static String subInterfaceFullNameConfig(final @Nonnull InstanceIdentifier<Routing> instanceIdentifier) { + public static String subInterfaceFullNameConfig(final @Nonnull InstanceIdentifier<?> instanceIdentifier) { final String parentInterfaceName = checkNotNull(instanceIdentifier.firstKeyOf(Interface.class), "Configuration identifier expected") .getName(); @@ -47,7 +46,7 @@ public final class SubInterfaceUtils { return SubInterfaceUtils.getSubInterfaceName(parentInterfaceName, subIfId.intValue()); } - public static String subInterfaceFullNameOperational(final @Nonnull InstanceIdentifier<Routing> instanceIdentifier) { + public static String subInterfaceFullNameOperational(final @Nonnull InstanceIdentifier<?> instanceIdentifier) { final String parentInterfaceName = checkNotNull(instanceIdentifier.firstKeyOf( org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.class), "Operational identifier expected").getName(); |