diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-06-15 13:10:53 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-06-19 18:56:27 +0000 |
commit | a0884f2792c31a3a93fb1654ceea754b6c612920 (patch) | |
tree | 7eff9ff4f745a6ca116ebbf6884d178a508b9303 /srv6/srv6-impl/src/test | |
parent | 3edc384ac6cbeb68d36dbb4a51aa027c3bd3257d (diff) |
HC2VPP-288 - add readers for SRv6 module
Changes:
- add locator context to map locator name to locator IPv6Prefix
- add readers for SRv6 module
- implements reading of local sids and their end functions.
- implements support for FIB table management (HC2VPP-345)
Change-Id: Ib04402539a0b6666c5a1d0b4e1b5b5e08ccbf67b
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'srv6/srv6-impl/src/test')
9 files changed, 781 insertions, 8 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 index c465dfbaf..54e4cdd26 100644 --- 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 @@ -31,10 +31,13 @@ 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.read.Srv6ReaderFactory; 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.read.registry.CompositeReaderRegistryBuilder; import io.fd.honeycomb.translate.impl.write.registry.FlatWriterRegistryBuilder; +import io.fd.honeycomb.translate.read.ReaderFactory; import io.fd.honeycomb.translate.util.YangDAG; import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.vpp.jvpp.core.future.FutureJVppCore; @@ -44,6 +47,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.RoutingBuilder; public class Srv6ModuleTest { @@ -75,6 +79,9 @@ public class Srv6ModuleTest { private VppClassifierContextManager classifierContextManager; @Inject + private Set<ReaderFactory> readerFactories = new HashSet<>(); + + @Inject private Set<WriterFactory> writerFactories = new HashSet<>(); @Before @@ -85,6 +92,19 @@ public class Srv6ModuleTest { } @Test + public void testReaderFactories() { + assertThat(readerFactories, is(not(empty()))); + + // Test registration process (all dependencies present, topological order of readers does exist, etc.) + final CompositeReaderRegistryBuilder registryBuilder = new CompositeReaderRegistryBuilder(new YangDAG()); + readerFactories.forEach(factory -> factory.init(registryBuilder)); + registryBuilder.addStructuralReader(Srv6IIds.RT, RoutingBuilder.class); + assertNotNull(registryBuilder.build()); + assertEquals(1, readerFactories.size()); + assertTrue(readerFactories.iterator().next() instanceof Srv6ReaderFactory); + } + + @Test public void testWriterFactories() { assertThat(writerFactories, is(not(empty()))); diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/LocatorCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/LocatorCustomizerTest.java new file mode 100644 index 000000000..3f2a74fd7 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/LocatorCustomizerTest.java @@ -0,0 +1,102 @@ +/* + * 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.read.sid; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetails; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.Srv6Sid; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +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.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.LocatorsBuilder; +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; + +public class LocatorCustomizerTest extends LocalSidRequestTest { + + private static final Ipv6Address SID_ADR = new Ipv6Address("a::101"); + + @Mock + private ReadContext readCtx; + + @Mock + private ModificationCache modificationCache; + + private SrLocalsidsDetailsReplyDump replyDump = new SrLocalsidsDetailsReplyDump(); + + @Override + protected void init() { + when(readCtx.getModificationCache()).thenReturn(modificationCache); + when(modificationCache.get(any())).thenReturn(replyDump); + when(locatorContext.getLocator(eq(LOCATOR.getName()), any())).thenReturn(new Ipv6Prefix("a::/64")); + } + + @Test + public void getAllIdsTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + srLocalsidsDetails.behavior = 1; + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + + LocatorCustomizer customizer = new LocatorCustomizer(api, locatorContext); + List<LocatorKey> allIds = customizer.getAllIds(SID_A_101.firstIdentifierOf(Locator.class), readCtx); + + Assert.assertNotNull(allIds); + Assert.assertFalse(allIds.isEmpty()); + Assert.assertTrue(allIds.contains(SID_A_101.firstKeyOf(Locator.class))); + } + + @Test + public void readCurrentAttributesTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + srLocalsidsDetails.behavior = 1; + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + + LocatorCustomizer customizer = new LocatorCustomizer(api, locatorContext); + LocatorBuilder builder = new LocatorBuilder(); + customizer.readCurrentAttributes(SID_A_101.firstIdentifierOf(Locator.class), builder, readCtx); + Assert.assertEquals(SID_A_101.firstKeyOf(Locator.class), builder.getKey()); + Assert.assertNotNull(customizer.getBuilder(SID_A_101.firstIdentifierOf(Locator.class))); + + LocatorsBuilder parentBuilder = new LocatorsBuilder(); + customizer.merge(parentBuilder, Collections.singletonList(builder.build())); + + Assert.assertNotNull(parentBuilder.getLocator()); + Assert.assertFalse(parentBuilder.getLocator().isEmpty()); + Assert.assertTrue(parentBuilder.getLocator().contains(builder.build())); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/SidCustomizerTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/SidCustomizerTest.java new file mode 100644 index 000000000..419c431ed --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/SidCustomizerTest.java @@ -0,0 +1,109 @@ +/* + * 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.read.sid; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import com.google.common.base.Optional; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetails; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.Srv6Sid; +import java.util.Collections; +import java.util.List; +import org.junit.Assert; +import org.junit.Test; +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.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.routing.srv6.locators.locator._static.LocalSidsBuilder; +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._static.cfg.SidKey; + +public class SidCustomizerTest extends LocalSidRequestTest { + + private static final Ipv6Address SID_ADR = new Ipv6Address("a::101"); + + @Mock + private ReadContext readCtx; + + @Mock + private ModificationCache modificationCache; + + @Mock + private MappingContext mappingContext; + + private SrLocalsidsDetailsReplyDump replyDump = new SrLocalsidsDetailsReplyDump(); + + @Override + protected void init() { + when(readCtx.getModificationCache()).thenReturn(modificationCache); + when(modificationCache.get(any())).thenReturn(replyDump); + when(readCtx.getMappingContext()).thenReturn(mappingContext); + when(mappingContext.read(any())).thenReturn(Optional.of(LOCATOR)); + when(locatorContext.getLocator(eq(LOCATOR.getName()), any())).thenReturn(new Ipv6Prefix("a::/64")); + } + + @Test + public void getAllIdsTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + srLocalsidsDetails.behavior = 1; + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + + SidCustomizer customizer = new SidCustomizer(api, READ_REGISTRY, locatorContext); + List<SidKey> allIds = customizer.getAllIds(SID_A_101, readCtx); + + Assert.assertNotNull(allIds); + Assert.assertFalse(allIds.isEmpty()); + Assert.assertTrue(allIds.contains(SID_A_101.firstKeyOf(Sid.class))); + } + + @Test + public void readCurrentAttributesTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + srLocalsidsDetails.behavior = 1; + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + + SidCustomizer customizer = new SidCustomizer(api, READ_REGISTRY, locatorContext); + SidBuilder builder = new SidBuilder(); + customizer.readCurrentAttributes(SID_A_101, builder, readCtx); + Assert.assertEquals(SID_A_101.firstKeyOf(Sid.class), builder.getKey()); + Assert.assertNotNull(builder.getEnd()); + Assert.assertNotNull(customizer.getBuilder(SID_A_101)); + + LocalSidsBuilder parentBuilder = new LocalSidsBuilder(); + customizer.merge(parentBuilder, Collections.singletonList(builder.build())); + Assert.assertNotNull(parentBuilder.getSid()); + Assert.assertFalse(parentBuilder.getSid().isEmpty()); + Assert.assertTrue(parentBuilder.getSid().contains(builder.build())); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocalSidReadRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocalSidReadRequestTest.java new file mode 100644 index 000000000..21668e3b1 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocalSidReadRequestTest.java @@ -0,0 +1,193 @@ +/* + * 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.read.sid.request; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetails; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.Srv6Sid; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; +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.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.inet.types.rev130715.Ipv6AddressNoZone; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing; +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.SidBuilder; +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.Routing1; +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.srv6.locators.Locators; +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.LocatorKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6FuncOpcodeUnreserved; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class LocalSidReadRequestTest extends LocalSidRequestTest { + + private static final String LOCAL_0 = "local0"; + private static final String VLAN_0 = "vlan0"; + private static final Ipv6Address SID_ADR = new Ipv6Address("a::100"); + private static final Ipv6Address SID_ADR_2 = new Ipv6Address("a::101"); + private static final Ipv6AddressNoZone ADDRESS_NO_ZONE = new Ipv6AddressNoZone(SID_ADR_2); + private static final long OPERATION = 256L; // 100 in hex IPv6 format + private static final InstanceIdentifier<Sid> ID_SID = + InstanceIdentifier.create(Routing.class) + .augmentation(Routing1.class) + .child(Srv6.class) + .child(Locators.class) + .child(Locator.class, new LocatorKey("a::")) + .augmentation(Locator1.class) + .child(Static.class) + .child(LocalSids.class) + .child(Sid.class, new SidKey(new Srv6FuncOpcodeUnreserved(OPERATION))); + + @Mock + private ReadContext readCtx; + + @Mock + private CompletionStage<SrLocalsidsDetailsReplyDump> stage; + + @Mock + private CompletableFuture<SrLocalsidsDetailsReplyDump> detailsFuture; + + @Mock + private ModificationCache modificationCache; + + @Mock + private MappingContext mappingContext; + + private SrLocalsidsDetailsReplyDump replyDump = new SrLocalsidsDetailsReplyDump(); + + @Override + protected void init() { + MockitoAnnotations.initMocks(this); + defineMapping(mappingContext, LOCAL_0, 1, "interface-context"); + defineMapping(mappingContext, VLAN_0, 2, "interface-context"); + replyDump.srLocalsidsDetails = new ArrayList<>(); + when(ctx.getMappingContext()).thenReturn(mappingContext); + when(readCtx.getMappingContext()).thenReturn(mappingContext); + when(readCtx.getModificationCache()).thenReturn(modificationCache); + when(modificationCache.get(any())).thenReturn(replyDump); + when(api.srLocalsidsDump(any())).thenReturn(stage); + when(stage.toCompletableFuture()).thenReturn(detailsFuture); + when(locatorContext.getLocator(eq(LOCATOR.getName()), any())).thenReturn(new Ipv6Prefix("a::/64")); + + + try { + when(detailsFuture.get()).thenReturn(replyDump); + } catch (InterruptedException | ExecutionException e) { + // noop + } + } + + @Test + public void readAllKeysTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + + SrLocalsidsDetails srLocalsidsDetails2 = new SrLocalsidsDetails(); + Srv6Sid sid2 = new Srv6Sid(); + sid2.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR_2)); + srLocalsidsDetails2.addr = sid2; + + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + replyDump.srLocalsidsDetails.add(srLocalsidsDetails2); + + final LocalSidReadRequest request = new LocalSidReadRequest(api, locatorContext, READ_REGISTRY); + request.checkValid(); + List<SidKey> sidKeys = request.readAllKeys(ID_SID, readCtx); + + Assert.assertFalse(sidKeys.isEmpty()); + Assert.assertEquals(2, sidKeys.size()); + } + + @Test + public void readSpecificEndXTest() throws ReadFailedException { + SrLocalsidsDetails endX = new SrLocalsidsDetails(); + endX.behavior = 2; + endX.endPsp = 0; + endX.xconnectNhAddr6 = AddressTranslator.INSTANCE.ipv6AddressNoZoneToArray(SID_ADR_2); + endX.xconnectIfaceOrVrfTable = 1; + + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + endX.addr = sid; + + replyDump.srLocalsidsDetails.add(endX); + + final LocalSidReadRequest request = new LocalSidReadRequest(api, locatorContext, READ_REGISTRY); + SidBuilder sidBuilder = new SidBuilder(); + request.readSpecific(ID_SID, readCtx, sidBuilder); + + Assert.assertNotNull(sidBuilder.getEndX()); + Assert.assertEquals(EndX.class, sidBuilder.getEndBehaviorType()); + Assert.assertEquals(OPERATION, sidBuilder.getOpcode().getValue().longValue()); + Assert.assertNotNull(sidBuilder.getEndX().getPaths().getPath()); + Assert.assertFalse(sidBuilder.getEndX().getPaths().getPath().isEmpty()); + Assert.assertEquals(LOCAL_0, sidBuilder.getEndX().getPaths().getPath().get(0).getInterface()); + Assert.assertEquals(ADDRESS_NO_ZONE, sidBuilder.getEndX().getPaths().getPath().get(0).getNextHop()); + } + + + @Test + public void readSpecificEndTTest() throws ReadFailedException { + SrLocalsidsDetails endT = new SrLocalsidsDetails(); + endT.behavior = 3; + endT.xconnectIfaceOrVrfTable = 4; + endT.endPsp = 0; + + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + endT.addr = sid; + + replyDump.srLocalsidsDetails.add(endT); + + final LocalSidReadRequest request = new LocalSidReadRequest(api, locatorContext, READ_REGISTRY); + SidBuilder sidBuilder = new SidBuilder(); + request.readSpecific(ID_SID, readCtx, sidBuilder); + + Assert.assertNotNull(sidBuilder.getEndT()); + Assert.assertEquals(EndT.class, sidBuilder.getEndBehaviorType()); + Assert.assertEquals(OPERATION, sidBuilder.getOpcode().getValue().longValue()); + Assert.assertEquals(4L, sidBuilder.getEndT().getLookupTableIpv6().getValue().longValue()); + } +} diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocatorReadRequestTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocatorReadRequestTest.java new file mode 100644 index 000000000..404aa6b9d --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/read/sid/request/LocatorReadRequestTest.java @@ -0,0 +1,141 @@ +/* + * 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.read.sid.request; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidRequestTest; +import io.fd.honeycomb.translate.ModificationCache; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetails; +import io.fd.vpp.jvpp.core.dto.SrLocalsidsDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.Srv6Sid; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; +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.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.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev180313.Routing; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.Routing1; +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.srv6.locators.Locators; +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.yangtools.yang.binding.InstanceIdentifier; + +public class LocatorReadRequestTest extends LocalSidRequestTest { + + private static final String LOCAL_0 = "local0"; + private static final Ipv6Address SID_ADR = new Ipv6Address("a::100"); + private static final Ipv6Address SID_ADR_2 = new Ipv6Address("b::101"); + private static final InstanceIdentifier<Locator> ID_LOC = + InstanceIdentifier.create(Routing.class) + .augmentation(Routing1.class) + .child(Srv6.class) + .child(Locators.class) + .child(Locator.class, new LocatorKey("a::")); + + @Mock + private ReadContext readCtx; + + @Mock + private CompletionStage<SrLocalsidsDetailsReplyDump> stage; + + @Mock + private CompletableFuture<SrLocalsidsDetailsReplyDump> detailsFuture; + + @Mock + private ModificationCache modificationCache; + + private SrLocalsidsDetailsReplyDump replyDump = new SrLocalsidsDetailsReplyDump(); + + @Override + protected void init() { + MockitoAnnotations.initMocks(this); + defineMapping(mappingContext, LOCAL_0, 1, "interface-context"); + replyDump.srLocalsidsDetails = new ArrayList<>(); + when(readCtx.getModificationCache()).thenReturn(modificationCache); + when(modificationCache.get(any())).thenReturn(replyDump); + when(api.srLocalsidsDump(any())).thenReturn(stage); + when(stage.toCompletableFuture()).thenReturn(detailsFuture); + when(locatorContext.getLocator(eq(LOCATOR.getName()), any())).thenReturn(new Ipv6Prefix("a::/64")); + + try { + when(detailsFuture.get()).thenReturn(replyDump); + } catch (InterruptedException | ExecutionException e) { + // noop + } + } + + @Test + public void readAllKeysTest() throws ReadFailedException { + SrLocalsidsDetails srLocalsidsDetails = new SrLocalsidsDetails(); + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + srLocalsidsDetails.addr = sid; + + SrLocalsidsDetails srLocalsidsDetails2 = new SrLocalsidsDetails(); + Srv6Sid sid2 = new Srv6Sid(); + sid2.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR_2)); + srLocalsidsDetails2.addr = sid2; + + replyDump.srLocalsidsDetails.add(srLocalsidsDetails); + replyDump.srLocalsidsDetails.add(srLocalsidsDetails2); + + final LocatorReadRequest request = new LocatorReadRequest(api, locatorContext); + request.checkValid(); + List<LocatorKey> locatorKeys = request.readAllKeys(ID_LOC, readCtx); + + Assert.assertFalse(locatorKeys.isEmpty()); + Assert.assertEquals(2, locatorKeys.size()); + Assert.assertTrue(locatorKeys.contains(new LocatorKey("a::"))); + Assert.assertTrue(locatorKeys.contains(new LocatorKey("b::"))); + } + + @Test + public void readSpecificEndXTest() throws ReadFailedException { + SrLocalsidsDetails endX = new SrLocalsidsDetails(); + endX.behavior = 2; + endX.endPsp = 0; + endX.xconnectNhAddr6 = AddressTranslator.INSTANCE.ipv6AddressNoZoneToArray(SID_ADR_2); + endX.xconnectIfaceOrVrfTable = 1; + + Srv6Sid sid = new Srv6Sid(); + sid.addr = AddressTranslator.INSTANCE.ipAddressToArray(new IpAddress(SID_ADR)); + endX.addr = sid; + + replyDump.srLocalsidsDetails.add(endX); + + final LocatorReadRequest request = new LocatorReadRequest(api, locatorContext); + LocatorBuilder builder = new LocatorBuilder(); + request.readSpecific(ID_LOC, readCtx, builder); + + Assert.assertEquals(new LocatorKey("a::"), builder.getKey()); + } +} 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 index 0bc3f6b6d..cd3369956 100644 --- 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 @@ -21,6 +21,7 @@ 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.LocalSidFunctionReadBindingRegistry; 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; @@ -43,6 +44,8 @@ import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext; @RunWith(HoneycombTestRunner.class) public abstract class JvppRequestTest implements FutureProducer, NamingContextHelper { + protected static final LocalSidFunctionReadBindingRegistry READ_REGISTRY = + new LocalSidFunctionReadBindingRegistry(); protected static final LocalSidFunctionWriteBindingRegistry WRITE_REGISTRY = new LocalSidFunctionWriteBindingRegistry(); @@ -69,14 +72,22 @@ public abstract class JvppRequestTest implements FutureProducer, NamingContextHe 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); + READ_REGISTRY.registerReadFunctionType(endFunctionBinder); + READ_REGISTRY.registerReadFunctionType(endTFunctionBinder); + READ_REGISTRY.registerReadFunctionType(endDT4FunctionBinder); + READ_REGISTRY.registerReadFunctionType(endDT6FunctionBinder); + READ_REGISTRY.registerReadFunctionType(endXFunctionBinder); + READ_REGISTRY.registerReadFunctionType(endDX2FunctionBinder); + READ_REGISTRY.registerReadFunctionType(endDX4FunctionBinder); + READ_REGISTRY.registerReadFunctionType(endDX6FunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endFunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endTFunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endDT4FunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endDT6FunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endXFunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endDX2FunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endDX4FunctionBinder); + WRITE_REGISTRY.registerWriteFunctionType(endDX6FunctionBinder); init(); } diff --git a/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/LocatorContextManagerImplTest.java b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/LocatorContextManagerImplTest.java new file mode 100644 index 000000000..919e013b1 --- /dev/null +++ b/srv6/srv6-impl/src/test/java/io/fd/hc2vpp/srv6/util/LocatorContextManagerImplTest.java @@ -0,0 +1,94 @@ +/* + * 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 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.MappingContext; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.locator.context.rev180605.srv6.locator.context.attributes.srv6.locator.mappings.Srv6LocatorMapping; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.locator.context.rev180605.srv6.locator.context.attributes.srv6.locator.mappings.Srv6LocatorMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class LocatorContextManagerImplTest extends LocalSidRequestTest { + + private static final Ipv6Prefix LOCATOR_PREFIX = new Ipv6Prefix("a::/64"); + + @Mock + MappingContext mappingContext; + + @Captor + ArgumentCaptor<Srv6LocatorMapping> locMappingCaptor; + + @Captor + ArgumentCaptor<InstanceIdentifier<Srv6LocatorMapping>> iidCaptor; + + @Before + public void setup() { + Srv6LocatorMapping locatorMapping = + new Srv6LocatorMappingBuilder().setName(LOCATOR.getName()).setPrefix(LOCATOR_PREFIX).build(); + when(ctx.getMappingContext()).thenReturn(mappingContext); + when(mappingContext.read(any())).thenReturn(Optional.of(locatorMapping)); + } + + @Test + public void addLocatorTest() { + LocatorContextManagerImpl contextManager = new LocatorContextManagerImpl(64); + contextManager.addLocator(LOCATOR.getName(), LOCATOR_PREFIX, ctx.getMappingContext()); + verify(mappingContext, times(1)).put(any(), locMappingCaptor.capture()); + Srv6LocatorMapping mapping = locMappingCaptor.getValue(); + + Assert.assertEquals(mapping.getPrefix(), LOCATOR_PREFIX); + Assert.assertEquals(mapping.getName(), LOCATOR.getName()); + } + + @Test + public void containsLocatorTest() { + LocatorContextManagerImpl contextManager = new LocatorContextManagerImpl(64); + boolean containsLocator = contextManager.containsLocator(LOCATOR.getName(), ctx.getMappingContext()); + Assert.assertTrue(containsLocator); + } + + + @Test + public void getLocatorTest() { + LocatorContextManagerImpl contextManager = new LocatorContextManagerImpl(64); + Ipv6Prefix locator = contextManager.getLocator(LOCATOR.getName(), ctx.getMappingContext()); + Assert.assertEquals(LOCATOR_PREFIX, locator); + } + + @Test + public void removeLocatorTest() { + MappingContext mappingContext = ctx.getMappingContext(); + LocatorContextManagerImpl contextManager = new LocatorContextManagerImpl(64); + contextManager.removeLocator(LOCATOR.getName(), mappingContext); + verify(mappingContext, times(1)).delete(iidCaptor.capture()); + Assert.assertEquals(LOCATOR.getName(), iidCaptor.getValue().firstKeyOf(Srv6LocatorMapping.class).getName()); + } +} 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 index 66ddf48db..998916ee1 100644 --- 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 @@ -19,6 +19,7 @@ package io.fd.hc2vpp.srv6.util.function; import static org.mockito.Mockito.when; import com.google.common.base.Optional; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; import io.fd.hc2vpp.fib.management.FibManagementIIds; import io.fd.hc2vpp.srv6.util.JvppRequestTest; import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; @@ -26,6 +27,7 @@ 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 io.fd.vpp.jvpp.core.dto.SrLocalsidsDetails; import java.util.Collections; import org.junit.Assert; import org.junit.Test; @@ -114,6 +116,16 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndVpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 1; + details.endPsp = 0; + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEnd()); + } + + @Test public void testEndX() { EndX endX = new EndXBuilder() .setPaths(new PathsBuilder().setPath(Collections.singletonList( @@ -138,6 +150,20 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndXVpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 2; + details.endPsp = 0; + details.xconnectNhAddr6 = AddressTranslator.INSTANCE.ipv6AddressNoZoneToArray(A); + details.xconnectIfaceOrVrfTable = 1; + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndX()); + Assert.assertEquals(LOCAL_0, builder.getEndX().getPaths().getPath().get(0).getInterface()); + Assert.assertEquals(A_NO_ZONE, builder.getEndX().getPaths().getPath().get(0).getNextHop()); + } + + @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() @@ -156,6 +182,17 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndDX2Vpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 5; + details.xconnectIfaceOrVrfTable = 1; + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndDx2()); + Assert.assertEquals(LOCAL_0, builder.getEndDx2().getPaths().getInterface()); + } + + @Test public void testEndDX6() { EndDx6 endDx6 = new EndDx6Builder() .setPaths(new PathsBuilder() @@ -178,6 +215,19 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndDX6Vpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 6; + details.xconnectIfaceOrVrfTable = 1; + details.xconnectNhAddr6 = AddressTranslator.INSTANCE.ipv6AddressNoZoneToArray(A); + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndDx6()); + Assert.assertEquals(LOCAL_0, builder.getEndDx6().getPaths().getPath().get(0).getInterface()); + Assert.assertEquals(A_NO_ZONE, builder.getEndDx6().getPaths().getPath().get(0).getNextHop()); + } + + @Test public void testEndDX4() { EndDx4 endDx4 = new EndDx4Builder() .setPaths( @@ -202,6 +252,19 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndDX4Vpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 7; + details.xconnectIfaceOrVrfTable = 1; + details.xconnectNhAddr4 = AddressTranslator.INSTANCE.ipv4AddressNoZoneToArray(A_V4); + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndDx4()); + Assert.assertEquals(LOCAL_0, builder.getEndDx4().getPaths().getPath().get(0).getInterface()); + Assert.assertEquals(A_V4, builder.getEndDx4().getPaths().getPath().get(0).getNextHop()); + } + + @Test public void testEndT() { EndT endT = new EndTBuilder().setLookupTableIpv6(TABLE_ID_4).build(); Sid localSid = new SidBuilder() @@ -217,6 +280,18 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndDTVpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 3; + details.xconnectIfaceOrVrfTable = TABLE_ID_4.getValue().intValue(); + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndT()); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), + builder.getEndT().getLookupTableIpv6().getValue().intValue()); + } + + @Test public void testEndDT6() { EndDt6 endDt6 = new EndDt6Builder().setLookupTableIpv6(TABLE_ID_4).build(); Sid localSid = new SidBuilder() @@ -231,6 +306,18 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { } @Test + public void testEndDT6Vpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 8; + details.xconnectIfaceOrVrfTable = TABLE_ID_4.getValue().intValue(); + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndDt6()); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), + builder.getEndDt6().getLookupTableIpv6().getValue().intValue()); + } + + @Test public void testEndDT4() { EndDt4 endDt4 = new EndDt4Builder().setLookupTableIpv4(TABLE_ID_4).build(); Sid localSid = new SidBuilder() @@ -243,4 +330,16 @@ public class LocalSidFunctionBindingRegistryTest extends JvppRequestTest { TableLookupLocalSidRequest tableLookupRequest = TableLookupLocalSidRequest.class.cast(request); Assert.assertEquals(TABLE_ID_4.getValue().intValue(), tableLookupRequest.getLookupFibTable()); } + + @Test + public void testEndDT4Vpp() { + SrLocalsidsDetails details = new SrLocalsidsDetails(); + details.behavior = 9; + details.xconnectIfaceOrVrfTable = TABLE_ID_4.getValue().intValue(); + SidBuilder builder = new SidBuilder(); + READ_REGISTRY.bind(details, readCtx, builder); + Assert.assertNotNull(builder.getEndDt4()); + Assert.assertEquals(TABLE_ID_4.getValue().intValue(), + builder.getEndDt4().getLookupTableIpv4().getValue().intValue()); + } } 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 index 80cf47aa0..fa30c07fb 100644 --- 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 @@ -25,6 +25,7 @@ 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.hc2vpp.srv6.util.LocatorContextManager; import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDelReply; import java.util.Arrays; @@ -60,6 +61,9 @@ public abstract class LocalSidRequestTest extends JvppRequestTest { new PrefixBuilder().setLength(new Srv6LocatorLen((short) 64)).setAddress(new Ipv6Address("a::")).build()) .build(); + @Mock + protected static LocatorContextManager locatorContext; + @Captor ArgumentCaptor<SrLocalsidAddDel> requestcaptor; |