diff options
author | Srihari Raghavan <srihari@cisco.com> | 2016-10-27 15:23:36 +0530 |
---|---|---|
committer | Srihari Raghavan <srihari@cisco.com> | 2016-11-03 18:26:00 +0530 |
commit | e83f0e1d6451c96ef9850b4a8b058c4b5c307617 (patch) | |
tree | a13b6175ba62b510ea7a3b4de6ea7447dbe8931d /ioam/impl/src/test/java | |
parent | 096e3e9a8b66970ed0b4a0e7f45dbd349902b20d (diff) |
HONEYCOMB-257 - Honeycomb support for in-band OAM (iOAM) path tracing
- Add iOAM module to handle configuration for the iOAM trace VPP plugin
- Add iOAM module test to verify add/delete configurations
- Reader/Initializers for future, dependent on https://gerrit.fd.io/r/3387
Change-Id: I557604a955771c139165aed7cd9e5716abbac3d1
Signed-off-by: Srihari Raghavan <srihari@cisco.com>
Diffstat (limited to 'ioam/impl/src/test/java')
-rw-r--r-- | ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java | 97 | ||||
-rw-r--r-- | ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java | 186 |
2 files changed, 283 insertions, 0 deletions
diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java new file mode 100644 index 000000000..288122fd0 --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/VppIoamModuleTest.java @@ -0,0 +1,97 @@ +/* + * 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.honeycomb.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; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.honeycomb.translate.util.read.registry.CompositeReaderRegistryBuilder; +import io.fd.honeycomb.translate.util.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriterFactory; +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 org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import io.fd.honeycomb.vppioam.impl.config.VppIoamWriterFactory; +import io.fd.honeycomb.vppioam.impl.util.JVppIoamProvider; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtraceFacade; +import io.fd.vpp.jvpp.JVppRegistry; + + +public class VppIoamModuleTest { + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Bind + @Mock + private JVppRegistry registry; + + @Inject + private Set<WriterFactory> writerFactories = new HashSet<>(); + + @Before + public void setUp() throws Exception { + + initMocks(this); + + Guice.createInjector(new VppIoamModule(MockJVppIoamProvider.class), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testWriterFactories() throws Exception { + assertThat(writerFactories, is(not(empty()))); + + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + } + + private static final class MockJVppIoamProvider implements Provider<FutureJVppIoamtraceFacade> { + + @Override + public FutureJVppIoamtraceFacade get() { + return mock(FutureJVppIoamtraceFacade.class); + } + } +} + diff --git a/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java new file mode 100644 index 000000000..8c182dd01 --- /dev/null +++ b/ioam/impl/src/test/java/io/fd/honeycomb/vppioam/impl/config/IoamTraceWriterCustomizerTest.java @@ -0,0 +1,186 @@ +/* + * 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.honeycomb.vppioam.impl.config; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAdd; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileAddReply; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDel; +import io.fd.vpp.jvpp.ioamtrace.dto.TraceProfileDelReply; +import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace; +import io.fd.vpp.jvpp.VppBaseCallException; +import io.fd.vpp.jvpp.VppCallbackException; + +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.TraceConfig.TraceTsp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig.TraceOp; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfigKey; +import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.trace.config.NodeInterfaces; + + +public class IoamTraceWriterCustomizerTest extends WriterCustomizerTest { + + private static final String TRACE_NAME = "trace_test"; + + @Mock + protected FutureJVppIoamtrace jvppIoam; + + private IoamTraceWriterCustomizer customizer; + + @Override + public void setUp() throws Exception { + customizer = new IoamTraceWriterCustomizer(jvppIoam); + } + + private static TraceConfig generateTraceConfig(final String name) { + final TraceConfigBuilder builder = new TraceConfigBuilder(); + builder.setTraceConfigName(name); + builder.setKey(new TraceConfigKey(name)); + builder.setAclName(name); + builder.setTraceType(new Short("31")); + builder.setTraceNumElt(new Short("4")); + builder.setTraceTsp(TraceTsp.Milliseconds); + builder.setTraceOp(TraceOp.Add); + builder.setTraceAppData(new Long("123")); + builder.setNodeId(new Long("1")); + + return builder.build(); + } + + private static InstanceIdentifier<TraceConfig> getTraceConfigId(final String name) { + return InstanceIdentifier.create(IoamTraceConfig.class) + .child(TraceConfig.class, new TraceConfigKey(name)); + } + + private void whenTraceAddThenSuccess() { + final TraceProfileAddReply reply = new TraceProfileAddReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceAddThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileAdd(any(TraceProfileAdd.class)); + } + + private void whenTraceDelThenSuccess() { + final TraceProfileDelReply reply = new TraceProfileDelReply(); + reply.context = 1; + doReturn(future(reply)).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private void whenTraceDelThenFailure() { + doReturn(failedFuture()).when(jvppIoam).traceProfileDel(any(TraceProfileDel.class)); + } + + private static TraceProfileAdd generateTraceProfileAdd() { + final TraceProfileAdd request = new TraceProfileAdd(); + request.traceType = 0x1f; + request.numElts = 4; + request.nodeId = 1; + request.traceTsp = 1; + request.appData = 123; + + return request; + } + + private static TraceProfileDel generateTraceProfileDel() { + final TraceProfileDel request = new TraceProfileDel(); + + return request; + } + + @Test + public void testCreate() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier<TraceConfig> id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenSuccess(); + + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + } + + @Test + public void testCreateFailed() throws Exception { + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier<TraceConfig> id = getTraceConfigId(TRACE_NAME); + + whenTraceAddThenFailure(); + + try { + customizer.writeCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileAdd(generateTraceProfileAdd()); + + return; + } + fail("WriteFailedException.CreateFailedException was expected"); + } + + @Test + public void testDelete() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier<TraceConfig> id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenSuccess(); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + } + + @Test + public void testDeleteFailed() throws Exception { + + final TraceConfig traceConfig = generateTraceConfig(TRACE_NAME); + final InstanceIdentifier<TraceConfig> id = getTraceConfigId(TRACE_NAME); + + whenTraceDelThenFailure(); + + try { + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } catch (WriteFailedException e) { + //assertTrue(e.getCause() instanceof VppBaseCallException); + verify(jvppIoam).traceProfileDel(generateTraceProfileDel()); + + return; + } + fail("WriteFailedException.DeleteFailedException was expected"); + + customizer.deleteCurrentAttributes(id, traceConfig, writeContext); + } +} |