diff options
author | 2016-05-13 10:04:11 +0200 | |
---|---|---|
committer | 2016-05-17 17:13:08 +0200 | |
commit | 02b2183a113214039611373f84352da4a5f57e2c (patch) | |
tree | 8091ad507e54de75366698c0860be9a0d7980d9b /v3po/v3po2vpp/src/main/java/io/fd | |
parent | 7ebd4ac29fb72b80af0b481f8ea604085ded1bc8 (diff) |
Check expected interface type in sub-Interface nodes
+ Pass full WriteContext to the write customizers, making
them more flexible
Change-Id: I75c55aed02f9300eee20eabb4a3e84e294ed1e0f
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io/fd')
10 files changed, 83 insertions, 68 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/EthernetCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/EthernetCustomizer.java index cdcea45f3..e8d6e39c7 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/EthernetCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/EthernetCustomizer.java @@ -17,10 +17,11 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.AbstractInterfaceTypeCustomizer; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.EthernetCsmacd; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Ethernet; import org.opendaylight.yangtools.yang.binding.DataObject; @@ -29,7 +30,7 @@ import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class EthernetCustomizer extends FutureJVppCustomizer implements ChildWriterCustomizer<Ethernet> { +public class EthernetCustomizer extends AbstractInterfaceTypeCustomizer<Ethernet> { private static final Logger LOG = LoggerFactory.getLogger(EthernetCustomizer.class); @@ -37,6 +38,11 @@ public class EthernetCustomizer extends FutureJVppCustomizer implements ChildWri super(vppApi); } + @Override + protected Class<? extends InterfaceType> getExpectedInterfaceType() { + return EthernetCsmacd.class; + } + @Nonnull @Override public Optional<Ethernet> extract(@Nonnull final InstanceIdentifier<Ethernet> currentId, @@ -45,27 +51,24 @@ public class EthernetCustomizer extends FutureJVppCustomizer implements ChildWri } @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ethernet> id, - @Nonnull final Ethernet dataAfter, @Nonnull final Context writeContext) { + protected final void writeInterface(@Nonnull final InstanceIdentifier<Ethernet> id, + @Nonnull final Ethernet dataAfter, @Nonnull final WriteContext writeContext) { // TODO LOG.warn("Unsupported, ignoring configuration {}", dataAfter); - } @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ethernet> id, @Nonnull final Ethernet dataBefore, @Nonnull final Ethernet dataAfter, - @Nonnull final Context writeContext) { + @Nonnull final WriteContext writeContext) { // TODO LOG.warn("Unsupported, ignoring configuration {}", dataAfter); - } @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ethernet> id, - @Nonnull final Ethernet dataBefore, @Nonnull final Context writeContext) { + @Nonnull final Ethernet dataBefore, @Nonnull final WriteContext writeContext) { // TODO LOG.warn("Unsupported, ignoring configuration delete {}", id); - } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java index b6d8748b9..e6ed62acf 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java @@ -16,12 +16,12 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.List; import java.util.concurrent.CompletionStage; @@ -53,7 +53,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException { try { @@ -68,7 +68,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataBefore, @Nonnull final Interface dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { try { @@ -82,7 +82,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListWri @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Interface> id, @Nonnull final Interface dataBefore, - @Nonnull final Context writeContext) { + @Nonnull final WriteContext writeContext) { // TODO Handle deletes } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java index ee731e7a4..fc43cdb7e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/L2Customizer.java @@ -19,12 +19,12 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import static com.google.common.base.Preconditions.checkArgument; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -65,7 +65,7 @@ public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCus @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); @@ -80,7 +80,7 @@ public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCus @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, - @Nonnull final L2 dataAfter, @Nonnull final Context writeContext) + @Nonnull final L2 dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); @@ -96,7 +96,7 @@ public class L2Customizer extends FutureJVppCustomizer implements ChildWriterCus @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<L2> id, @Nonnull final L2 dataBefore, - @Nonnull final Context writeContext) { + @Nonnull final WriteContext writeContext) { // TODO implement delete (if possible) } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java index b15050cd0..4d17ba098 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/RoutingCustomizer.java @@ -17,12 +17,12 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -56,7 +56,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements ChildWrit @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, - @Nonnull final Routing dataAfter, @Nonnull final Context writeContext) + @Nonnull final Routing dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException.CreateFailedException { try { @@ -70,7 +70,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements ChildWrit @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, @Nonnull final Routing dataBefore, @Nonnull final Routing dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { try { @@ -84,7 +84,7 @@ public class RoutingCustomizer extends FutureJVppCustomizer implements ChildWrit @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Routing> id, - @Nonnull final Routing dataBefore, @Nonnull final Context writeContext) { + @Nonnull final Routing dataBefore, @Nonnull final WriteContext writeContext) { // TODO implement delete } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizer.java index f05238dda..72679fe12 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/TapCustomizer.java @@ -17,15 +17,15 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.AbstractInterfaceTypeCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; @@ -42,7 +42,7 @@ import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TapCustomizer extends FutureJVppCustomizer implements ChildWriterCustomizer<Tap> { +public class TapCustomizer extends AbstractInterfaceTypeCustomizer<Tap> { private static final Logger LOG = LoggerFactory.getLogger(TapCustomizer.class); private final NamingContext interfaceContext; @@ -60,8 +60,13 @@ public class TapCustomizer extends FutureJVppCustomizer implements ChildWriterCu } @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Tap> id, @Nonnull final Tap dataAfter, - @Nonnull final Context writeContext) + protected Class<? extends InterfaceType> getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Tap.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier<Tap> id, @Nonnull final Tap dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException.CreateFailedException { try { createTap(id.firstKeyOf(Interface.class).getName(), dataAfter); @@ -73,7 +78,7 @@ public class TapCustomizer extends FutureJVppCustomizer implements ChildWriterCu @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Tap> id, @Nonnull final Tap dataBefore, - @Nonnull final Tap dataAfter, @Nonnull final Context writeContext) + @Nonnull final Tap dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); @@ -94,7 +99,7 @@ public class TapCustomizer extends FutureJVppCustomizer implements ChildWriterCu @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Tap> id, @Nonnull final Tap dataBefore, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException.DeleteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizer.java index 40669761d..ebefff34a 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VhostUserCustomizer.java @@ -18,15 +18,15 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces; import com.google.common.base.Optional; import com.google.common.base.Preconditions; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.AbstractInterfaceTypeCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; 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.rev150105.VhostUserRole; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppInterfaceAugmentation; @@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory; /** * Writer Customizer responsible for passing vhost user interface CRD operations to VPP */ -public class VhostUserCustomizer extends FutureJVppCustomizer implements ChildWriterCustomizer<VhostUser> { +public class VhostUserCustomizer extends AbstractInterfaceTypeCustomizer<VhostUser> { private static final Logger LOG = LoggerFactory.getLogger(VhostUserCustomizer.class); private final NamingContext interfaceContext; @@ -64,12 +64,17 @@ public class VhostUserCustomizer extends FutureJVppCustomizer implements ChildWr } @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<VhostUser> id, - @Nonnull final VhostUser dataAfter, @Nonnull final Context writeContext) + protected Class<? extends InterfaceType> getExpectedInterfaceType() { + return org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VhostUser.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier<VhostUser> id, + @Nonnull final VhostUser dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException.CreateFailedException { try { createVhostUserIf(id.firstKeyOf(Interface.class).getName(), dataAfter); - } catch (VppApiInvocationException e) { + } catch (VppApiInvocationException | IllegalInterfaceTypeException e) { throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } } @@ -105,12 +110,13 @@ public class VhostUserCustomizer extends FutureJVppCustomizer implements ChildWr @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<VhostUser> id, @Nonnull final VhostUser dataBefore, @Nonnull final VhostUser dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { if (dataBefore.equals(dataAfter)) { LOG.debug("dataBefore equals dataAfter, update will not be performed"); return; } + try { modifyVhostUserIf(id.firstKeyOf(Interface.class).getName(), dataAfter); } catch (VppApiInvocationException e) { @@ -146,7 +152,7 @@ public class VhostUserCustomizer extends FutureJVppCustomizer implements ChildWr @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<VhostUser> id, - @Nonnull final VhostUser dataBefore, @Nonnull final Context writeContext) + @Nonnull final VhostUser dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException.DeleteFailedException { try { deleteVhostUserIf(id.firstKeyOf(Interface.class).getName(), dataBefore); diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java index 6244a20d3..9d11b59b1 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/VxlanCustomizer.java @@ -20,19 +20,20 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.base.Optional; import com.google.common.net.InetAddresses; -import io.fd.honeycomb.v3po.translate.Context; -import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; -import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.v3po.translate.v3po.util.AbstractInterfaceTypeCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.net.InetAddress; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType; 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.rev150105.VppInterfaceAugmentation; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VxlanTunnel; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.interfaces._interface.Vxlan; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -42,7 +43,8 @@ import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriterCustomizer<Vxlan> { +// TODO extract common code from all Interface type specific writer customizers into a superclass +public class VxlanCustomizer extends AbstractInterfaceTypeCustomizer<Vxlan> { private static final Logger LOG = LoggerFactory.getLogger(VxlanCustomizer.class); private final NamingContext interfaceContext; @@ -60,12 +62,17 @@ public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriter } @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataAfter, - @Nonnull final Context writeContext) + protected Class<? extends InterfaceType> getExpectedInterfaceType() { + return VxlanTunnel.class; + } + + @Override + protected final void writeInterface(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataAfter, + @Nonnull final WriteContext writeContext) throws WriteFailedException.CreateFailedException { try { createVxlanTunnel(id.firstKeyOf(Interface.class).getName(), dataAfter); - } catch (VppApiInvocationException e) { + } catch (VppApiInvocationException | IllegalInterfaceTypeException e) { LOG.warn("Write of Vxlan failed", e); throw new WriteFailedException.CreateFailedException(id, dataAfter, e); } @@ -73,9 +80,8 @@ public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriter @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataBefore, - @Nonnull final Vxlan dataAfter, @Nonnull final Context writeContext) + @Nonnull final Vxlan dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException.UpdateFailedException { - if (dataBefore.equals(dataAfter)) { LOG.debug("dataBefore equals dataAfter, update will not be performed"); return; @@ -86,7 +92,7 @@ public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriter @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Vxlan> id, @Nonnull final Vxlan dataBefore, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException.DeleteFailedException { try { deleteVxlanTunnel(id.firstKeyOf(Interface.class).getName(), dataBefore); @@ -97,9 +103,6 @@ public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriter } private void createVxlanTunnel(final String swIfName, final Vxlan vxlan) throws VppApiInvocationException { - // TODO check that the type of interface is vxlan-tunnel (it is expressed in YANG, but not validated on DataTree level) - // DO the same for other interface aguments/types - final byte isIpv6 = (byte) (isIpv6(vxlan) ? 1 : 0); final InetAddress srcAddress = InetAddresses.forString(getAddressString(vxlan.getSrc())); final InetAddress dstAddress = InetAddresses.forString(getAddressString(vxlan.getDst())); @@ -137,9 +140,7 @@ public class VxlanCustomizer extends FutureJVppCustomizer implements ChildWriter } private String getAddressString(final IpAddress addr) { - return addr.getIpv4Address() == null - ? addr.getIpv6Address().getValue() - : addr.getIpv4Address().getValue(); + return addr.getIpv4Address() == null ? addr.getIpv6Address().getValue() : addr.getIpv4Address().getValue(); } private void deleteVxlanTunnel(final String swIfName, final Vxlan vxlan) throws VppApiInvocationException { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java index de2015c64..a54f6c5e3 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv4Customizer.java @@ -20,12 +20,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; @@ -64,7 +64,7 @@ public class Ipv4Customizer extends FutureJVppCustomizer implements ChildWriterC @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> id, - @Nonnull final Ipv4 dataAfter, @Nonnull final Context writeContext) + @Nonnull final Ipv4 dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { try { final String ifcName = id.firstKeyOf(Interface.class).getName(); @@ -78,7 +78,7 @@ public class Ipv4Customizer extends FutureJVppCustomizer implements ChildWriterC @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> id, @Nonnull final Ipv4 dataBefore, @Nonnull final Ipv4 dataAfter, - @Nonnull final Context writeContext) + @Nonnull final WriteContext writeContext) throws WriteFailedException { final String ifcName = id.firstKeyOf(Interface.class).getName(); @@ -93,7 +93,7 @@ public class Ipv4Customizer extends FutureJVppCustomizer implements ChildWriterC @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv4> id, - @Nonnull final Ipv4 dataBefore, @Nonnull final Context writeContext) { + @Nonnull final Ipv4 dataBefore, @Nonnull final WriteContext writeContext) { // TODO implement delete } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv6Customizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv6Customizer.java index e3ad3928e..0fe86435e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv6Customizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/ip/Ipv6Customizer.java @@ -17,9 +17,9 @@ package io.fd.honeycomb.v3po.translate.v3po.interfaces.ip; import com.google.common.base.Optional; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.Interface1; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev140616.interfaces._interface.Ipv6; @@ -46,7 +46,7 @@ public class Ipv6Customizer extends FutureJVppCustomizer implements ChildWriterC @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> id, - @Nonnull final Ipv6 dataAfter, @Nonnull final Context writeContext) { + @Nonnull final Ipv6 dataAfter, @Nonnull final WriteContext writeContext) { // TODO LOG.warn("Unsupported, ignoring configuration {}", dataAfter); } @@ -54,13 +54,13 @@ public class Ipv6Customizer extends FutureJVppCustomizer implements ChildWriterC @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> id, @Nonnull final Ipv6 dataBefore, @Nonnull final Ipv6 dataAfter, - @Nonnull final Context writeContext) { + @Nonnull final WriteContext writeContext) { LOG.warn("Unsupported, ignoring configuration {}", dataAfter); } @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Ipv6> id, - @Nonnull final Ipv6 dataBefore, @Nonnull final Context writeContext) { + @Nonnull final Ipv6 dataBefore, @Nonnull final WriteContext writeContext) { LOG.warn("Unsupported, ignoring configuration delete {}", id); // TODO } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java index a3e2f7340..672a05f4e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java @@ -20,12 +20,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Preconditions; -import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.FutureJVppCustomizer; import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.VppApiInvocationException; import io.fd.honeycomb.v3po.translate.v3po.utils.V3poUtils; +import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; import java.util.List; import javax.annotation.Nonnull; @@ -88,7 +88,7 @@ public class BridgeDomainCustomizer @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomain dataBefore, - @Nonnull final Context ctx) throws WriteFailedException.CreateFailedException { + @Nonnull final WriteContext ctx) throws WriteFailedException.CreateFailedException { LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx); final String bdName = dataBefore.getName(); @@ -116,7 +116,7 @@ public class BridgeDomainCustomizer @Override public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomain dataBefore, - @Nonnull final Context ctx) throws WriteFailedException.DeleteFailedException { + @Nonnull final WriteContext ctx) throws WriteFailedException.DeleteFailedException { LOG.debug("deleteCurrentAttributes: id={}, dataBefore={}, ctx={}", id, dataBefore, ctx); final String bdName = id.firstKeyOf(BridgeDomain.class).getName(); @@ -138,7 +138,7 @@ public class BridgeDomainCustomizer @Override public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomain dataBefore, @Nonnull final BridgeDomain dataAfter, - @Nonnull final Context ctx) throws WriteFailedException.UpdateFailedException { + @Nonnull final WriteContext ctx) throws WriteFailedException.UpdateFailedException { LOG.debug("updateCurrentAttributes: id={}, dataBefore={}, dataAfter={}, ctx={}", id, dataBefore, dataAfter, ctx); |