diff options
Diffstat (limited to 'srv6/srv6-impl/src/test/java/io/fd')
11 files changed, 1062 insertions, 0 deletions
diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java new file mode 100644 index 000000000..c465dfbaf --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/Srv6ModuleTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.name.Named; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.write.Srv6WriterFactory; +import io.fd.hc2vpp.vpp.classifier.context.VppClassifierContextManager; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.util.YangDAG; +import io.fd.honeycomb.translate.write.WriterFactory; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +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; + +public class Srv6ModuleTest { + + @Bind + @Named("interface-context") + private NamingContext interfaceContext; + + @Bind + @Mock + private FutureJVppCore futureJVppCore; + + @Bind + @Mock + private ModificationCache modificationCache; + + @Named("honeycomb-context") + @Bind + @Mock + private DataBroker honeycombContext; + + @Named("honeycomb-initializer") + @Bind + @Mock + private DataBroker honeycombInitializer; + + @Named("classify-table-context") + @Bind + @Mock + private VppClassifierContextManager classifierContextManager; + + @Inject + private Set<WriterFactory> writerFactories = new HashSet<>(); + + @Before + public void setUp() { + initMocks(this); + interfaceContext = new NamingContext("interfaceContext", "interfaceContext"); + Guice.createInjector(new Srv6Module(), BoundFieldModule.of(this)).injectMembers(this); + } + + @Test + public void testWriterFactories() { + assertThat(writerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of writers does exist, etc.) + final FlatWriterRegistryBuilder registryBuilder = new FlatWriterRegistryBuilder(new YangDAG()); + writerFactories.forEach(factory -> factory.init(registryBuilder)); + assertNotNull(registryBuilder.build()); + assertEquals(1, writerFactories.size()); + assertTrue(writerFactories.iterator().next() instanceof Srv6WriterFactory); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java new file mode 100644 index 000000000..0bc3f6b6d --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/JvppRequestTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.util; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Inject; +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.common.test.util.NamingContextHelper; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry; +import io.fd.hc2vpp.srv6.util.function.lookup.EndDT4FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.lookup.EndDT6FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.lookup.EndTFunctionBinder; +import io.fd.hc2vpp.srv6.util.function.nofunction.EndFunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX2FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX4FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX6FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndXFunctionBinder; +import io.fd.honeycomb.test.tools.HoneycombTestRunner; +import io.fd.honeycomb.test.tools.annotations.SchemaContextProvider; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.junit.Before; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; + +@RunWith(HoneycombTestRunner.class) +public abstract class JvppRequestTest implements FutureProducer, NamingContextHelper { + protected static final LocalSidFunctionWriteBindingRegistry WRITE_REGISTRY = + new LocalSidFunctionWriteBindingRegistry(); + + @Inject + @Mock + protected static FutureJVppCore api; + + @Mock + protected static WriteContext ctx; + + @Mock + protected static MappingContext mappingContext; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + NamingContext interfaceContext = new NamingContext("iface", "interface-context"); + + EndFunctionBinder endFunctionBinder = new EndFunctionBinder(api); + EndTFunctionBinder endTFunctionBinder = new EndTFunctionBinder(api); + EndDT4FunctionBinder endDT4FunctionBinder = new EndDT4FunctionBinder(api); + EndDT6FunctionBinder endDT6FunctionBinder = new EndDT6FunctionBinder(api); + EndXFunctionBinder endXFunctionBinder = new EndXFunctionBinder(api, interfaceContext); + EndDX2FunctionBinder endDX2FunctionBinder = new EndDX2FunctionBinder(api, interfaceContext); + EndDX4FunctionBinder endDX4FunctionBinder = new EndDX4FunctionBinder(api, interfaceContext); + EndDX6FunctionBinder endDX6FunctionBinder = new EndDX6FunctionBinder(api, interfaceContext); + WRITE_REGISTRY.registerFunctionType(endFunctionBinder); + WRITE_REGISTRY.registerFunctionType(endTFunctionBinder); + WRITE_REGISTRY.registerFunctionType(endDT4FunctionBinder); + WRITE_REGISTRY.registerFunctionType(endDT6FunctionBinder); + WRITE_REGISTRY.registerFunctionType(endXFunctionBinder); + WRITE_REGISTRY.registerFunctionType(endDX2FunctionBinder); + WRITE_REGISTRY.registerFunctionType(endDX4FunctionBinder); + WRITE_REGISTRY.registerFunctionType(endDX6FunctionBinder); + init(); + } + + @SchemaContextProvider + public ModuleInfoBackedContext createSchemaContext() { + ModuleInfoBackedContext mibContext = ModuleInfoBackedContext.create(); + mibContext.addModuleInfos(ImmutableSet.of( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl + .getInstance())); + return mibContext; + } + + protected abstract void init(); +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java new file mode 100644 index 000000000..66ddf48db --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistryTest.java @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.util.function; + +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.srv6.util.JvppRequestTest; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; +import io.fd.hc2vpp.srv6.write.sid.request.NoProtocolLocalSidRequest; +import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +import io.fd.honeycomb.translate.read.ReadContext; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.PathsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.PathBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.End; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDt6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx2Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndDx6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndT; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndTBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndX; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.EndXBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.PathAttrsCmn; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.TableId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; + +public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { + + private static final Ipv6Address A = new Ipv6Address("A::101"); + private static final Ipv6AddressNoZone A_NO_ZONE = new Ipv6AddressNoZone("a::101"); + private static final Ipv4Address V4HOP = new Ipv4Address("0.0.1.0"); + private static final Ipv4AddressNoZone A_V4 = new Ipv4AddressNoZone("10.0.0.1"); + private static final String LOCAL_0 = "local0"; + private static final TableId TABLE_ID_4 = new TableId(4L); + private static final TableKey TABLE_4_IPV6_KEY = new TableKey(Ipv6.class, new VniReference(TABLE_ID_4.getValue())); + private static final TableKey TABLE_4_IPV4_KEY = new TableKey(Ipv4.class, new VniReference(TABLE_ID_4.getValue())); + + @Mock + private ReadContext readCtx; + + @Override + protected void init() { + MockitoAnnotations.initMocks(this); + defineMapping(mappingContext, "local0", 1, "interface-context"); + defineMapping(mappingContext, "vlan0", 2, "interface-context"); + when(ctx.getMappingContext()).thenReturn(mappingContext); + when(readCtx.getMappingContext()).thenReturn(mappingContext); + when(ctx.readAfter(FibManagementIIds.FM_FIB_TABLES.child(Table.class, TABLE_4_IPV6_KEY))) + .thenReturn(Optional.of( + new TableBuilder().setTableId(TABLE_4_IPV6_KEY.getTableId()).setKey(TABLE_4_IPV6_KEY) + .setAddressFamily(TABLE_4_IPV6_KEY.getAddressFamily()).build())); + when(ctx.readAfter(FibManagementIIds.FM_FIB_TABLES.child(Table.class, TABLE_4_IPV4_KEY))) + .thenReturn(Optional.of( + new TableBuilder().setTableId(TABLE_4_IPV4_KEY.getTableId()).setKey(TABLE_4_IPV4_KEY) + .setAddressFamily(TABLE_4_IPV4_KEY.getAddressFamily()).build())); + } + + @Test + public void testEnd() { + End end = new EndBuilder().build(); + Sid localSid = new SidBuilder() + .setEnd(end) + .setEndBehaviorType( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof NoProtocolLocalSidRequest); + Assert.assertEquals(1, request.getFunction()); + } + + @Test + public void testEndX() { + EndX endX = new EndXBuilder() + .setPaths(new PathsBuilder().setPath(Collections.singletonList( + new PathBuilder().setRole(PathAttrsCmn.Role.PRIMARY) + .setWeight(1L) + .setPathIndex((short) 1) + .setInterface(LOCAL_0) + .setNextHop(A) + .build())).build()) + .build(); + Sid localSid = new SidBuilder() + .setEndX(endX) + .setEndBehaviorType( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof XConnectLocalSidRequest); + Assert.assertEquals(2, request.getFunction()); + XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request); + Assert.assertEquals(A, xConnectRequest.getNextHopAddress().getIpv6Address()); + Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex()); + } + + @Test + public void testEndDX2() { + EndDx2 endDx2 = new EndDx2Builder().setPaths( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6.sid.config.end.dx2.PathsBuilder() + .setInterface(LOCAL_0) + .build()).build(); + Sid localSid = new SidBuilder() + .setEndDx2(endDx2) + .setEndBehaviorType(EndDX2.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof XConnectLocalSidRequest); + Assert.assertEquals(5, request.getFunction()); + XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request); + Assert.assertNull(xConnectRequest.getNextHopAddress()); + Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex()); + } + + @Test + public void testEndDX6() { + EndDx6 endDx6 = new EndDx6Builder() + .setPaths(new PathsBuilder() + .setPath(Collections.singletonList(new PathBuilder() + .setNextHop(A) + .setInterface(LOCAL_0) + .build())) + .build()) + .build(); + Sid localSid = new SidBuilder() + .setEndDx6(endDx6) + .setEndBehaviorType(EndDX6.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof XConnectLocalSidRequest); + Assert.assertEquals(6, request.getFunction()); + XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request); + Assert.assertEquals(A, xConnectRequest.getNextHopAddress().getIpv6Address()); + Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex()); + } + + @Test + public void testEndDX4() { + EndDx4 endDx4 = new EndDx4Builder() + .setPaths( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.PathsBuilder() + .setPath(Collections.singletonList( + new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.PathBuilder() + .setNextHop(V4HOP) + .setInterface(LOCAL_0) + .build())) + .build()) + .build(); + Sid localSid = new SidBuilder() + .setEndDx4(endDx4) + .setEndBehaviorType(EndDX4.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof XConnectLocalSidRequest); + Assert.assertEquals(7, request.getFunction()); + XConnectLocalSidRequest xConnectRequest = XConnectLocalSidRequest.class.cast(request); + Assert.assertEquals(V4HOP, xConnectRequest.getNextHopAddress().getIpv4Address()); + Assert.assertEquals(1, xConnectRequest.getOutgoingInterfaceIndex()); + } + + @Test + public void testEndT() { + EndT endT = new EndTBuilder().setLookupTableIpv6(TABLE_ID_4).build(); + Sid localSid = new SidBuilder() + .setEndT(endT) + .setEndBehaviorType( + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof TableLookupLocalSidRequest); + Assert.assertEquals(3, request.getFunction()); + TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable()); + } + + @Test + public void testEndDT6() { + EndDt6 endDt6 = new EndDt6Builder().setLookupTableIpv6(TABLE_ID_4).build(); + Sid localSid = new SidBuilder() + .setEndDt6(endDt6) + .setEndBehaviorType(EndDT6.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof TableLookupLocalSidRequest); + Assert.assertEquals(8, request.getFunction()); + TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable()); + } + + @Test + public void testEndDT4() { + EndDt4 endDt4 = new EndDt4Builder().setLookupTableIpv4(TABLE_ID_4).build(); + Sid localSid = new SidBuilder() + .setEndDt4(endDt4) + .setEndBehaviorType(EndDT4.class) + .build(); + LocalSidFunctionRequest request = WRITE_REGISTRY.bind(localSid, ctx); + Assert.assertTrue(request instanceof TableLookupLocalSidRequest); + Assert.assertEquals(9, request.getFunction()); + TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable()); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java new file mode 100644 index 000000000..b4f5bf9b7 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/Srv6CustomizerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write; + +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.write.WriteFailedException; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.routing.Srv6Builder; + +public class Srv6CustomizerTest extends LocalSidRequestTest { + + @Test(expected = WriteFailedException.class) + public void writeCurrentAttributesNullTest() throws WriteFailedException { + Srv6Customizer customizer = new Srv6Customizer(); + Srv6 srv6 = new Srv6Builder().setEnable(true).build(); + customizer.writeCurrentAttributes(Srv6IIds.RT_SRV6, srv6, ctx); + } + + @Test(expected = WriteFailedException.class) + public void deleteCurrentAttributesNullTest() throws WriteFailedException { + Srv6Customizer customizer = new Srv6Customizer(); + Srv6 srv6 = new Srv6Builder().setEnable(true).build(); + customizer.deleteCurrentAttributes(Srv6IIds.RT_SRV6, srv6, ctx); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java new file mode 100644 index 000000000..0daef976a --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/EncapsulationSourceCustomizerTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.encap.source; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.util.FutureProducer; +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.hc2vpp.srv6.util.JvppRequestTest; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrSetEncapSource; +import io.fd.vpp.jvpp.core.dto.SrSetEncapSourceReply; +import java.util.Arrays; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.Encapsulation; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.encap.EncapsulationBuilder; + +public class EncapsulationSourceCustomizerTest extends JvppRequestTest implements FutureProducer { + + private static final byte[] BSID_BYTES = {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; + private static Ipv6Address A1 = new Ipv6Address("a::1"); + private static EncapsulationSourceCustomizer sourceCustomizer; + private static Encapsulation encapsulation = new EncapsulationBuilder() + .setIpTtlPropagation(false) + .setSourceAddress(A1) + .build(); + + @Captor + private ArgumentCaptor<SrSetEncapSource> requestCaptor; + + @Override + protected void init() { + MockitoAnnotations.initMocks(this); + sourceCustomizer = new EncapsulationSourceCustomizer(api); + when(api.srSetEncapSource(requestCaptor.capture())).thenReturn(future(new SrSetEncapSourceReply())); + } + + @Test + public void writeCurrentAttributesTest() throws WriteFailedException { + sourceCustomizer.writeCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx); + verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture()); + Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource)); + } + + @Test + public void deleteCurrentAttributesTest() throws WriteFailedException { + sourceCustomizer.deleteCurrentAttributes(Srv6IIds.RT_SRV6_ENCAP, encapsulation, ctx); + verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture()); + Assert.assertNull(requestCaptor.getValue().encapsSource); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java new file mode 100644 index 000000000..442b87cdd --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/encap/source/request/EncapsulationSourceRequestTest.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.encap.source.request; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.hc2vpp.srv6.util.JvppRequestTest; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrSetEncapSource; +import io.fd.vpp.jvpp.core.dto.SrSetEncapSourceReply; +import java.util.Arrays; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mockito; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; + +public class EncapsulationSourceRequestTest extends JvppRequestTest { + + private static final Ipv6Address BSID = new Ipv6Address("C1::"); + private static final byte[] BSID_BYTES = {0, -63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + + @Captor + private ArgumentCaptor<SrSetEncapSource> requestCaptor; + + @Override + protected void init() { + Mockito.when(api.srSetEncapSource(any())).thenReturn(future(new SrSetEncapSourceReply())); + } + + @Test + public void testWriteInvalid() throws WriteFailedException { + try { + new EncapsulationSourceWriteRequest(api).write(Srv6IIds.RT_SRV6_ENCAP); + } catch (NullPointerException e) { + verifyNoMoreInteractions(api); + return; + } + Assert.fail("NullPointerException was expected"); + } + + @Test + public void testWriteValid() throws WriteFailedException { + final EncapsulationSourceWriteRequest request = new EncapsulationSourceWriteRequest(api).setBsid(BSID); + + request.write(Srv6IIds.RT_SRV6_ENCAP); + verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture()); + Assert.assertEquals(BSID, request.getBsid()); + Assert.assertTrue(Arrays.equals(BSID_BYTES, requestCaptor.getValue().encapsSource)); + } + + @Test + public void testDeleteValid() throws WriteFailedException { + final EncapsulationSourceDeleteRequest request = new EncapsulationSourceDeleteRequest(api); + + request.delete(Srv6IIds.RT_SRV6_ENCAP); + verify(api, Mockito.times(1)).srSetEncapSource(requestCaptor.capture()); + Assert.assertNull(requestCaptor.getValue().encapsSource); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java new file mode 100644 index 000000000..ae72161e5 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizerTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid; + +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.write.WriteFailedException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.PrefixBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6LocatorLen; + +public class SidCustomizerTest extends LocalSidRequestTest { + + private static final Ipv6Address IP_ADDRESS = new Ipv6Address("a::101"); + + @Before + public void setup() { + when(ctx.readAfter(any())).thenReturn(Optional.of(LOCATOR)); + when(ctx.readBefore(any())).thenReturn(Optional.of(LOCATOR)); + } + + @Test(expected = NullPointerException.class) + public void writeCurrentAttributesNullTest() throws WriteFailedException { + SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY); + Sid localSid = getSidNull(); + customizer.writeCurrentAttributes(SID_A_101, localSid, ctx); + verify(api, times(0)).srLocalsidAddDel(any()); + } + + @Test(expected = NullPointerException.class) + public void deleteCurrentAttributesNullTest() throws WriteFailedException { + SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY); + Sid localSid = getSidNull(); + customizer.deleteCurrentAttributes(SID_A_101, localSid, ctx); + verify(api, times(0)).srLocalsidAddDel(any()); + } + + @Test + public void resolveSidAddressTest() { + Sid localSid = getSidNull(); + SidCustomizer customizer = new SidCustomizer(api, WRITE_REGISTRY); + Prefix locPrefix = new PrefixBuilder().setAddress(new Ipv6Address("a::")).setLength(new Srv6LocatorLen( + (short) 64)).build(); + Ipv6Address ipv6Address = customizer.resolveSidAddress(locPrefix, localSid); + assertTrue((IP_ADDRESS.equals(ipv6Address))); + } + + private Sid getSidNull() { + return new SidBuilder() + .setOpcode(OPCODE_A_101) + .setEndBehaviorType(End.class) + .setEnd(null) + .build(); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java new file mode 100644 index 000000000..80cf47aa0 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidRequestTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.hc2vpp.srv6.util.JvppRequestTest; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDelReply; +import java.util.Arrays; +import org.junit.Assert; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +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.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.Locator1; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator.Static; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator._static.LocalSids; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.PrefixBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6FuncOpcodeUnreserved; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6LocatorLen; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public abstract class LocalSidRequestTest extends JvppRequestTest { + + protected static final Srv6FuncOpcodeUnreserved OPCODE_A_101 = + new Srv6FuncOpcodeUnreserved(257L); // 101 in hex format for IPv6 + protected static final InstanceIdentifier<Sid> SID_A_101 = + Srv6IIds.RT_SRV6_LOCATORS.child(Locator.class, new LocatorKey("a::")).augmentation(Locator1.class) + .child(Static.class).child(LocalSids.class).child(Sid.class, new SidKey(OPCODE_A_101)); + static final byte[] SID_BYTES = {0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + static final Ipv6Address SID = new Ipv6Address("A::0"); + protected static Locator LOCATOR = new LocatorBuilder().setName("a::").setPrefix( + new PrefixBuilder().setLength(new Srv6LocatorLen((short) 64)).setAddress(new Ipv6Address("a::")).build()) + .build(); + + @Captor + ArgumentCaptor<SrLocalsidAddDel> requestcaptor; + + static void assertIsCreate(final SrLocalsidAddDel request) { + assertEquals(0, request.isDel); + } + + static void assertIsDelete(final SrLocalsidAddDel request) { + assertEquals(1, request.isDel); + } + + static void assertBaseFields(final SrLocalsidAddDel request, final byte[] localSidAddress, + final int installFibTable, final int segmentRoutingBehavior, + final int isDecapsulationEnabled) { + assertEquals(installFibTable, request.fibTable); + assertEquals(isDecapsulationEnabled, request.endPsp); + assertEquals(segmentRoutingBehavior, request.behavior); + assertTrue(Arrays.equals(localSidAddress, request.localsid.addr)); + } + + public static void assertRequestEqual(SrLocalsidAddDel srLocalsidAddDel, int behaviour, boolean isWrite, + String localSid) { + //PSP is true whe USP is false and vice versa + Assert.assertFalse(!ByteDataTranslator.INSTANCE.byteToBoolean(srLocalsidAddDel.endPsp)); + Assert.assertEquals(behaviour, (int) srLocalsidAddDel.behavior); + Assert.assertEquals(isWrite, !ByteDataTranslator.INSTANCE.byteToBoolean(srLocalsidAddDel.isDel)); + IpAddress ipAddress = AddressTranslator.INSTANCE.arrayToIpAddress(true, srLocalsidAddDel.localsid.addr); + Assert.assertEquals(localSid.toLowerCase(), ipAddress.getIpv6Address().getValue().toLowerCase()); + } + + @Override + protected void init() { + when(api.srLocalsidAddDel(any())).thenReturn(future(new SrLocalsidAddDelReply())); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java new file mode 100644 index 000000000..a53fc09ba --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequestTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; + +public class NoProtocolLocalSidRequestTest extends LocalSidRequestTest { + + private static final int END_VALUE = 1; + + private static void assertRequestBody(final SrLocalsidAddDel jvppRequest) { + assertNull(jvppRequest.nhAddr6); + assertNull(jvppRequest.nhAddr4); + assertEquals(0, jvppRequest.vlanIndex); + assertEquals(0, jvppRequest.swIfIndex); + } + + private static NoProtocolLocalSidRequest createValidRequest(final FutureJVppCore api) { + final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api); + request.setLocalSidAddress(new Ipv6Address("A::0")); + request.setFunction(END_VALUE); + request.setInstallFibTable(0); + return request; + } + + @Test(expected = NullPointerException.class) + public void testNoAddress() throws WriteFailedException { + final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test(expected = IllegalStateException.class) + public void testNoBehavior() throws WriteFailedException { + final NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(api); + request.setLocalSidAddress(SID); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test + public void testWriteValid() throws WriteFailedException { + createValidRequest(api).write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + assertIsCreate(jvppRequest); + assertRequestBody(jvppRequest); + } + + @Test + public void testDeleteValid() throws WriteFailedException { + createValidRequest(api).delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + assertIsDelete(jvppRequest); + assertBaseFields(jvppRequest, SID_BYTES, 0, END_VALUE, 1); + assertRequestBody(jvppRequest); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java new file mode 100644 index 000000000..0cedec73b --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequestTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import static io.fd.vpp.jvpp.Assertions.assertEquals; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import org.junit.Test; + +public class TableLookupLocalSidRequestTest extends LocalSidRequestTest { + + private static final int END_T_VALUE = 3; + + @Test(expected = NullPointerException.class) + public void testNoAddress() throws WriteFailedException { + final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test(expected = IllegalStateException.class) + public void testNoBehavior() throws WriteFailedException { + final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api); + request.setLocalSidAddress(SID); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test + public void testWriteValid() throws WriteFailedException { + createValidRequest().write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + + assertIsCreate(jvppRequest); + assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1); + assertEquals(7, jvppRequest.swIfIndex); + } + + @Test + public void testDeleteValid() throws WriteFailedException { + createValidRequest().delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + + assertIsDelete(jvppRequest); + assertBaseFields(jvppRequest, SID_BYTES, 0, END_T_VALUE, 1); + assertEquals(7, jvppRequest.swIfIndex); + } + + private TableLookupLocalSidRequest createValidRequest() { + final TableLookupLocalSidRequest request = new TableLookupLocalSidRequest(api); + request.setLookupFibTable(7); + request.setInstallFibTable(0); + request.setLocalSidAddress(SID); + request.setFunction(END_T_VALUE); + return request; + } + +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java new file mode 100644 index 000000000..970295001 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequestTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import static io.fd.vpp.jvpp.Assertions.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import io.fd.hc2vpp.srv6.Srv6IIds; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Arrays; +import org.junit.Test; +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.inet.types.rev130715.Ipv6Address; + +public class XConnectLocalSidRequestTest extends LocalSidRequestTest { + + private static final IpAddress NEXT_HOP_ADDRESS = new IpAddress(new Ipv6Address("B::0")); + private static final byte[] NEXT_HOP_ADDRESS_BYTES = new byte[]{0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + private static final int END_DX6_VALUE = 6; + + private static XConnectLocalSidRequest createValidRequest(final FutureJVppCore api) { + final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api); + request.setLocalSidAddress(SID); + request.setNextHopAddress(NEXT_HOP_ADDRESS); + request.setOutgoingInterfaceIndex(7); + request.setVlanIndex(4); + request.setInstallFibTable(0); + request.setFunction(END_DX6_VALUE); + return request; + } + + @Test(expected = NullPointerException.class) + public void testNoAddress() throws WriteFailedException { + final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test(expected = IllegalStateException.class) + public void testNoBehavior() throws WriteFailedException { + final XConnectLocalSidRequest request = new XConnectLocalSidRequest(api); + request.setLocalSidAddress(SID); + request.write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + } + + @Test + public void testWriteValid() throws WriteFailedException { + createValidRequest(api).write(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + + assertIsCreate(jvppRequest); + assertBaseFields(jvppRequest, SID_BYTES, 0, END_DX6_VALUE, 1); + assertEquals(7, jvppRequest.swIfIndex); + assertEquals(4, jvppRequest.vlanIndex); + assertTrue(Arrays.equals(NEXT_HOP_ADDRESS_BYTES, jvppRequest.nhAddr6)); + } + + @Test + public void testDeleteValid() throws WriteFailedException { + createValidRequest(api).delete(Srv6IIds.RT_SRV6_LOCS_LOC_ST_LS_SID); + verify(api, times(1)).srLocalsidAddDel(requestcaptor.capture()); + + final SrLocalsidAddDel jvppRequest = requestcaptor.getValue(); + + assertIsDelete(jvppRequest); + assertBaseFields(jvppRequest, SID_BYTES, 0, END_DX6_VALUE, 1); + assertEquals(7, jvppRequest.swIfIndex); + assertEquals(4, jvppRequest.vlanIndex); + assertTrue(Arrays.equals(NEXT_HOP_ADDRESS_BYTES, jvppRequest.nhAddr6)); + } +} |