ioam: export plugin - support for ioam-export plugin in hc2vpp 01/4401/8
authorSagar Srivastav <[email protected]>
Mon, 19 Dec 2016 09:42:11 +0000 (01:42 -0800)
committerSagar Srivastav <[email protected]>
Tue, 7 Feb 2017 06:45:26 +0000 (22:45 -0800)
Change-Id: I2314a2de3b9c2a1d9c2e5950659e44cb9bdda985
Signed-off-by: Sagar Srivastav <[email protected]>
ioam/api/src/main/yang/ioam-sb-export.yang [new file with mode: 0644]
ioam/impl/pom.xml
ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/VppIoamModule.java
ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java [new file with mode: 0644]
ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/VppIoamWriterFactory.java
ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java [new file with mode: 0644]
ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java [new file with mode: 0644]
ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/VppIoamModuleTest.java
ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizerTest.java [new file with mode: 0644]
ioam/ioam_postman_collection.json

diff --git a/ioam/api/src/main/yang/ioam-sb-export.yang b/ioam/api/src/main/yang/ioam-sb-export.yang
new file mode 100644 (file)
index 0000000..f04028a
--- /dev/null
@@ -0,0 +1,46 @@
+module ioam-sb-export {
+
+  yang-version 1;
+
+  namespace "urn:cisco:params:xml:ns:yang:ioam-sb-export";
+
+  prefix ioam-sb-export;
+
+  organization "Cisco Systems, Inc.";
+  contact
+    "Shwetha Bhandari <[email protected]>
+     Sagar Srivastav <[email protected]>";
+
+  description
+    "This module contains a collection of YANG definitions for
+     managing in-band OAM based export
+     parameters.";
+
+  revision 2017-02-06 {
+    description
+      "set source and collector addresses as mandatory";
+    reference
+      "";
+  }
+
+  import ietf-inet-types {
+    prefix inet;
+  }
+
+  container ioam-export {
+
+    leaf disable {
+       type boolean;
+    }
+
+    leaf collector-address {
+        mandatory true;
+        type inet:ipv4-address;
+    }
+
+    leaf source-address {
+        mandatory true;
+        type inet:ipv4-address;
+    }
+  }
+}
index 0b058a7..e88a040 100644 (file)
       <artifactId>jvpp-ioampot</artifactId>
       <version>${ioam.version}</version>
     </dependency>
+    <dependency>
+      <groupId>io.fd.vpp</groupId>
+      <artifactId>jvpp-ioamexport</artifactId>
+      <version>${ioam.version}</version>
+    </dependency>
     <dependency>
       <groupId>io.fd.hc2vpp.common</groupId>
       <artifactId>vpp-translate-utils</artifactId>
index 204d003..228653c 100755 (executable)
@@ -20,12 +20,15 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
-import io.fd.hc2vpp.vppioam.impl.oper.VppIoamReaderFactory;
-import io.fd.honeycomb.translate.read.ReaderFactory;
-import io.fd.honeycomb.translate.write.WriterFactory;
 import io.fd.hc2vpp.vppioam.impl.config.VppIoamWriterFactory;
+import io.fd.hc2vpp.vppioam.impl.oper.VppIoamReaderFactory;
+import io.fd.hc2vpp.vppioam.impl.util.JVppIoamExportProvider;
 import io.fd.hc2vpp.vppioam.impl.util.JVppIoamPotProvider;
 import io.fd.hc2vpp.vppioam.impl.util.JVppIoamTraceProvider;
+import io.fd.honeycomb.translate.read.ReaderFactory;
+import io.fd.honeycomb.translate.write.WriterFactory;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade;
 import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
 import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampotFacade;
 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace;
@@ -41,16 +44,19 @@ public final class VppIoamModule extends AbstractModule {
     private static final Logger LOG = LoggerFactory.getLogger(VppIoamModule.class);
     private final Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamTraceProviderClass;
     private final Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass;
+    private final Class<? extends Provider<FutureJVppIoamexportFacade>> jvppIoamExportProviderClass;
 
     public VppIoamModule() {
-        this(JVppIoamTraceProvider.class, JVppIoamPotProvider.class);
+        this(JVppIoamTraceProvider.class, JVppIoamPotProvider.class, JVppIoamExportProvider.class);
     }
 
     @VisibleForTesting
     VppIoamModule(Class<? extends Provider<FutureJVppIoamtraceFacade>> jvppIoamTraceProvider,
-                  Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass) {
+                  Class<? extends Provider<FutureJVppIoampotFacade>> jvppIoamPotProviderClass,
+                  Class<? extends Provider<FutureJVppIoamexportFacade>> jvppIoamExportProviderClass) {
         this.jvppIoamTraceProviderClass = jvppIoamTraceProvider;
         this.jvppIoamPotProviderClass = jvppIoamPotProviderClass;
+        this.jvppIoamExportProviderClass = jvppIoamExportProviderClass;
     }
 
     @Override
@@ -60,6 +66,7 @@ public final class VppIoamModule extends AbstractModule {
         // Bind to Plugin's JVPP.
         bind(FutureJVppIoamtrace.class).toProvider(jvppIoamTraceProviderClass).in(Singleton.class);
         bind(FutureJVppIoampot.class).toProvider(jvppIoamPotProviderClass).in(Singleton.class);
+        bind(FutureJVppIoamexport.class).toProvider(jvppIoamExportProviderClass).in(Singleton.class);
 
         // Below are classes picked up by HC framework
         Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppIoamWriterFactory.class);
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizer.java
new file mode 100644 (file)
index 0000000..2172750
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2016 Cisco and 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.vppioam.impl.config;
+
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.vppioam.impl.util.FutureJVppIoamexportCustomizer;
+import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.WriteContext;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisable;
+import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.export.rev170206.IoamExport;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class IoamExportWriterCustomizer extends FutureJVppIoamexportCustomizer
+        implements WriterCustomizer<IoamExport>, JvppReplyConsumer, Ipv4Translator {
+
+    private static final Logger LOG = LoggerFactory.getLogger(IoamExportWriterCustomizer.class);
+
+    public IoamExportWriterCustomizer(FutureJVppIoamexport jVppIoamexport){
+        super(jVppIoamexport);
+    }
+
+    @Override
+    public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier,
+                                       @Nonnull final IoamExport ioamExport, @Nonnull final WriteContext writeContext)
+            throws WriteFailedException {
+        addExportProfile(ioamExport,instanceIdentifier);
+        LOG.info("Export profile {} created, id: {}", ioamExport, instanceIdentifier);
+    }
+
+    @Override
+    public void updateCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier,
+                                        @Nonnull final IoamExport dataBefore, @Nonnull final IoamExport dataAfter,
+                                        @Nonnull final WriteContext writeContext) throws WriteFailedException {
+        addExportProfile(dataAfter,instanceIdentifier);
+        LOG.info("Export profile {} updated , id: {}", dataAfter, instanceIdentifier);
+    }
+
+    @Override
+    public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<IoamExport> instanceIdentifier,
+                                        @Nonnull final IoamExport ioamExport, @Nonnull final WriteContext writeContext)
+            throws WriteFailedException {
+        deleteExportProfile(ioamExport,instanceIdentifier);
+        LOG.info("Export profile {} deleted, id: {}", ioamExport, instanceIdentifier);
+    }
+
+    private IoamExportIp6EnableDisableReply addExportProfile(IoamExport ioamExport, InstanceIdentifier<IoamExport> id)
+            throws WriteFailedException {
+        IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable();
+        if (ioamExport.isDisable()==null)
+            request.isDisable = 1;
+        else
+            request.isDisable = (byte)(ioamExport.isDisable()?1:0);
+        request.srcAddress = ipv4AddressNoZoneToArray(ioamExport.getSourceAddress().getValue());
+        request.collectorAddress = ipv4AddressNoZoneToArray(ioamExport.getCollectorAddress().getValue());
+        return getReplyForCreate(getFutureJVppIoamexport()
+                .ioamExportIp6EnableDisable(request)
+                .toCompletableFuture(),id,ioamExport);
+
+    }
+
+    private IoamExportIp6EnableDisableReply deleteExportProfile(IoamExport ioamExport,
+                                                                InstanceIdentifier<IoamExport> id)
+            throws WriteFailedException {
+        IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable();
+        request.isDisable = 1;     //disable when deleted
+        request.srcAddress = ipv4AddressNoZoneToArray(ioamExport.getSourceAddress().getValue());
+        request.collectorAddress = ipv4AddressNoZoneToArray(ioamExport.getCollectorAddress().getValue());
+
+        return getReplyForDelete(getFutureJVppIoamexport()
+                .ioamExportIp6EnableDisable(request)
+                .toCompletableFuture(),id);
+    }
+
+}
index 15d312f..ba105eb 100755 (executable)
@@ -19,11 +19,14 @@ package io.fd.hc2vpp.vppioam.impl.config;
 import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 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.ioamexport.future.FutureJVppIoamexport;
 import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace;
 import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.export.rev170206.IoamExport;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces;
@@ -38,12 +41,16 @@ public class VppIoamWriterFactory implements WriterFactory {
     private final FutureJVppIoamtrace jVppIoamtrace;
     @Nonnull
     private final FutureJVppIoampot jVppIoampot;
+    @Nonnull
+    private final FutureJVppIoamexport jVppIoamexport;
 
     @Inject
     public VppIoamWriterFactory(@Nonnull final FutureJVppIoamtrace jVppIoamtrace,
-                                @Nonnull final FutureJVppIoampot jVppIoampot) {
+                                @Nonnull final FutureJVppIoampot jVppIoampot,
+                                @Nonnull final FutureJVppIoamexport jVppIoamexport) {
         this.jVppIoamtrace = jVppIoamtrace;
         this.jVppIoampot = jVppIoampot;
+        this.jVppIoamexport = jVppIoamexport;
     }
 
     @Override
@@ -60,6 +67,10 @@ public class VppIoamWriterFactory implements WriterFactory {
         registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(PotProfileSet.class)
                         .child(PotProfileList.class)),
                 new GenericListWriter<>(potId, new IoamPotWriterCustomizer(jVppIoampot)));
+        //Export Config
+        final InstanceIdentifier<IoamExport> exportId =
+                InstanceIdentifier.create(IoamExport.class);
+        registry.add(new GenericWriter<>(exportId,new IoamExportWriterCustomizer(jVppIoamexport)));
 
     }
 }
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/FutureJVppIoamexportCustomizer.java
new file mode 100644 (file)
index 0000000..adc2ffc
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Cisco and 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.vppioam.impl.util;
+
+import com.google.common.base.Preconditions;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport;
+import javax.annotation.Nonnull;
+
+public abstract class FutureJVppIoamexportCustomizer {
+
+    private final FutureJVppIoamexport futureJVppIoamexport;
+
+    public FutureJVppIoamexportCustomizer (@Nonnull final FutureJVppIoamexport futureJVppIoamexport) {
+        this.futureJVppIoamexport = Preconditions.checkNotNull(futureJVppIoamexport,
+                "futureJVppIoamexport should not be null");
+    }
+
+    /**
+     * Get Ioam POT Api reference
+     *
+     * @return Ioam POT Api reference
+     */
+    public FutureJVppIoamexport getFutureJVppIoamexport() {
+        return futureJVppIoamexport;
+    }
+
+}
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/util/JVppIoamExportProvider.java
new file mode 100644 (file)
index 0000000..fa4d200
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2016 Cisco and 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.vppioam.impl.util;
+
+import com.google.inject.Inject;
+import io.fd.honeycomb.infra.distro.ProviderTrait;
+import io.fd.vpp.jvpp.JVppRegistry;
+import io.fd.vpp.jvpp.ioamexport.JVppIoamexportImpl;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade;
+import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JVppIoamExportProvider extends ProviderTrait<FutureJVppIoamexportFacade> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(JVppIoamExportProvider.class);
+
+    @Inject
+    private JVppRegistry registry;
+
+    @Override
+    protected FutureJVppIoamexportFacade create() {
+        try {
+            final JVppIoamexportImpl jVppIoamexport = new JVppIoamexportImpl();
+            // Free jvpp-ioam-export plugin's resources on shutdown
+            Runtime.getRuntime().addShutdownHook(new Thread() {
+                @Override
+                public void run() {
+                    LOG.info("Unloading jvpp-ioam-export plugin");
+                    jVppIoamexport.close();
+                    LOG.info("Successfully unloaded jvpp-ioam-export plugin");
+                }
+            });
+
+            LOG.info("Successfully loaded jvpp-ioam-export plugin");
+            return new FutureJVppIoamexportFacade(registry, jVppIoamexport);
+        } catch (IOException e) {
+            throw new IllegalStateException("Unable to open VPP management connection", e);
+        }
+    }
+}
index c11ee2d..45b6732 100644 (file)
 
 package io.fd.hc2vpp.vppioam.impl;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.empty;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.MockitoAnnotations.initMocks;
+
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -27,24 +35,16 @@ import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder;
 import io.fd.honeycomb.translate.read.ReaderFactory;
 import io.fd.honeycomb.translate.write.WriterFactory;
 import io.fd.vpp.jvpp.JVppRegistry;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexportFacade;
 import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampotFacade;
 import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade;
+import java.util.HashSet;
+import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.Matchers.empty;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.MockitoAnnotations.initMocks;
-
 
 public class VppIoamModuleTest {
 
@@ -73,7 +73,10 @@ public class VppIoamModuleTest {
 
         initMocks(this);
 
-        Guice.createInjector(new VppIoamModule(MockJVppIoamTraceProvider.class,MockJVppIoamPotProvider.class), BoundFieldModule.of(this)).injectMembers(this);
+        Guice.createInjector(new VppIoamModule(MockJVppIoamTraceProvider.class,
+                MockJVppIoamPotProvider.class,
+                        MockJVppIoamExportProvider.class),
+                BoundFieldModule.of(this)).injectMembers(this);
     }
 
     @Test
@@ -109,5 +112,13 @@ public class VppIoamModuleTest {
             return mock(FutureJVppIoampotFacade.class);
         }
     }
+
+    private static final class MockJVppIoamExportProvider implements Provider<FutureJVppIoamexportFacade> {
+
+        @Override
+        public FutureJVppIoamexportFacade get() {
+            return mock(FutureJVppIoamexportFacade.class);
+        }
+    }
 }
 
diff --git a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamExportWriterCustomizerTest.java
new file mode 100644 (file)
index 0000000..b2dfaf3
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2016 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.vppioam.impl.config;
+
+import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+import io.fd.hc2vpp.common.test.write.WriterCustomizerTest;
+import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
+import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisable;
+import io.fd.vpp.jvpp.ioamexport.dto.IoamExportIp6EnableDisableReply;
+import io.fd.vpp.jvpp.ioamexport.future.FutureJVppIoamexport;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.export.rev170206.IoamExport;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.export.rev170206.IoamExportBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class IoamExportWriterCustomizerTest extends WriterCustomizerTest
+        implements Ipv4Translator{
+
+    @Mock
+    FutureJVppIoamexport jVppIoamexport;
+
+    private IoamExportWriterCustomizer customizer;
+
+    private static final Logger LOG = LoggerFactory.getLogger(IoamExportWriterCustomizerTest.class);
+
+    @Override
+    public void setUpTest() throws Exception {
+        customizer = new IoamExportWriterCustomizer(jVppIoamexport);
+    }
+
+    private static IoamExport generateExportProfile(){
+        IoamExportBuilder builder = new IoamExportBuilder();
+        builder.setDisable(false);
+        builder.setSourceAddress(new Ipv4Address("127.0.0.1"));
+        builder.setCollectorAddress(new Ipv4Address("127.0.0.2"));
+        return builder.build();
+    }
+
+    private void whenExportAddThenSuccess() {
+        final IoamExportIp6EnableDisableReply reply = new IoamExportIp6EnableDisableReply();
+        reply.context = 1;
+        doReturn(future(reply)).when(jVppIoamexport).ioamExportIp6EnableDisable(any(IoamExportIp6EnableDisable.class));
+    }
+
+    private void whenExportAddThenFailure() {
+        doReturn(failedFuture()).when(jVppIoamexport).ioamExportIp6EnableDisable(any(IoamExportIp6EnableDisable.class));
+    }
+
+    private void whenExportDelThenSuccess() {
+        final IoamExportIp6EnableDisableReply reply = new IoamExportIp6EnableDisableReply();
+        reply.context = 1;
+        doReturn(future(reply)).when(jVppIoamexport).ioamExportIp6EnableDisable(any(IoamExportIp6EnableDisable.class));
+    }
+
+    private void whenExportDelThenFailure() {
+        doReturn(failedFuture()).when(jVppIoamexport).ioamExportIp6EnableDisable(any(IoamExportIp6EnableDisable.class));
+    }
+
+    private IoamExportIp6EnableDisable generateIoamExportIp6EnableDisable(boolean disable) {
+        IoamExportIp6EnableDisable request = new IoamExportIp6EnableDisable();
+        request.isDisable = (byte)(disable?1:0);
+        request.srcAddress = ipv4AddressNoZoneToArray("127.0.0.1");
+        request.collectorAddress = ipv4AddressNoZoneToArray("127.0.0.2");
+
+        return request;
+    }
+
+    @Test
+    public void testCreate() throws Exception {
+        final IoamExport ioamExport = generateExportProfile();
+        final InstanceIdentifier<IoamExport> id = InstanceIdentifier.create(IoamExport.class);
+
+        whenExportAddThenSuccess();
+
+        customizer.writeCurrentAttributes(id, ioamExport, writeContext);
+
+        verify(jVppIoamexport).ioamExportIp6EnableDisable(generateIoamExportIp6EnableDisable(false));
+    }
+
+    @Test
+    public void testCreateFailed() throws Exception {
+        final IoamExport ioamExport = generateExportProfile();
+        final InstanceIdentifier<IoamExport> id = InstanceIdentifier.create(IoamExport.class);
+
+        whenExportAddThenFailure();
+
+        try {
+            customizer.writeCurrentAttributes(id, ioamExport, writeContext);
+        } catch (WriteFailedException e) {
+            verify(jVppIoamexport).ioamExportIp6EnableDisable(generateIoamExportIp6EnableDisable(false));
+
+            return;
+        }
+        fail("WriteFailedException.CreateFailedException was expected");
+    }
+
+    @Test
+    public void testDelete() throws Exception {
+        final IoamExport ioamExport = generateExportProfile();
+        final InstanceIdentifier<IoamExport> id = InstanceIdentifier.create(IoamExport.class);
+
+        whenExportDelThenSuccess();
+
+        customizer.deleteCurrentAttributes(id, ioamExport, writeContext);
+
+        verify(jVppIoamexport).ioamExportIp6EnableDisable(generateIoamExportIp6EnableDisable(true));
+    }
+
+    @Test
+    public void testDeleteFailed() throws Exception {
+        final IoamExport ioamExport = generateExportProfile();
+        final InstanceIdentifier<IoamExport> id = InstanceIdentifier.create(IoamExport.class);
+
+        whenExportDelThenFailure();
+
+        try {
+            customizer.deleteCurrentAttributes(id, ioamExport, writeContext);
+        } catch (WriteFailedException e) {
+            verify(jVppIoamexport).ioamExportIp6EnableDisable(generateIoamExportIp6EnableDisable(true));
+
+            return;
+        }
+        fail("WriteFailedException.CreateFailedException was expected");
+    }
+
+    @Test
+    public void testCreateWithMissingDisabledField() throws Exception {
+        IoamExportBuilder builder = new IoamExportBuilder();
+        builder.setSourceAddress(new Ipv4Address("127.0.0.1"));
+        builder.setCollectorAddress(new Ipv4Address("127.0.0.2"));
+        final IoamExport ioamExport = builder.build();
+        final InstanceIdentifier<IoamExport> id = InstanceIdentifier.create(IoamExport.class);
+
+        whenExportAddThenSuccess();
+
+        customizer.writeCurrentAttributes(id, ioamExport, writeContext);
+
+        verify(jVppIoamexport).ioamExportIp6EnableDisable(generateIoamExportIp6EnableDisable(true));
+    }
+
+}
index abc0292..17ef052 100644 (file)
                                "description": "Read ioam pot config from VPP"
                        },
                        "response": []
+               },
+               {
+                       "name": "iaom export - config",
+                       "request": {
+                               "url": "http://localhost:8183/restconf/config/ioam-sb-export:ioam-export",
+                               "method": "PUT",
+                               "header": [
+                                       {
+                                               "key": "Authorization",
+                                               "value": "Basic YWRtaW46YWRtaW4=",
+                                               "description": ""
+                                       },
+                                       {
+                                               "key": "Content-Type",
+                                               "value": "application/json",
+                                               "description": ""
+                                       }
+                               ],
+                               "body": {
+                                       "mode": "raw",
+                                       "raw": "{   \n\t\"ioam-export\":{\n\t\t\"source-address\":\"127.0.0.1\",\n\t\t\"collector-address\":\"127.0.0.2\",\n\t\t\"disable\":false\n\t}\n}\n"
+                               },
+                               "description": "Configure ioam export config on VPP"
+                       },
+                       "response": []
                }
        ]
 }
\ No newline at end of file