diff options
Diffstat (limited to 'routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/RoutingProtocolCustomizerTest.java')
-rw-r--r-- | routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/RoutingProtocolCustomizerTest.java | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/RoutingProtocolCustomizerTest.java b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/RoutingProtocolCustomizerTest.java new file mode 100644 index 000000000..1d0057cf2 --- /dev/null +++ b/routing/routing-impl/src/test/java/io/fd/hc2vpp/routing/read/RoutingProtocolCustomizerTest.java @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.routing.read; + +import static io.fd.hc2vpp.routing.helpers.RoutingRequestTestHelper.ROUTE_PROTOCOL_NAME; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.core.IsCollectionContaining.hasItems; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.routing.Ipv4RouteData; +import io.fd.hc2vpp.routing.Ipv6RouteData; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetails; +import io.fd.vpp.jvpp.core.dto.Ip6FibDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.IpFibDetails; +import io.fd.vpp.jvpp.core.dto.IpFibDetailsReplyDump; +import io.fd.vpp.jvpp.core.types.FibPath; +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.mockito.Mock; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.Static; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.state.routing.instance.RoutingProtocols; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.state.routing.instance.RoutingProtocolsBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.state.routing.instance.routing.protocols.RoutingProtocol; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.state.routing.instance.routing.protocols.RoutingProtocolBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.routing.rev140524.routing.state.routing.instance.routing.protocols.RoutingProtocolKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class RoutingProtocolCustomizerTest + extends ListReaderCustomizerTest<RoutingProtocol, RoutingProtocolKey, RoutingProtocolBuilder> + implements ByteDataTranslator { + + private static final String VPP_PROTOCOL_PREFIX = "vpp-protocol"; + + @Mock + private EntityDumpExecutor<IpFibDetailsReplyDump, Void> ipv4Executor; + + @Mock + private EntityDumpExecutor<Ip6FibDetailsReplyDump, Void> ipv6Executor; + private DumpCacheManager<IpFibDetailsReplyDump, Void> ipv4RoutesDumpManager; + private DumpCacheManager<Ip6FibDetailsReplyDump, Void> ipv6RoutesDumpManager; + + private NamingContext routingProtocolContext; + + public RoutingProtocolCustomizerTest() { + super(RoutingProtocol.class, RoutingProtocolsBuilder.class); + } + + @Override + protected void setUp() throws Exception { + when(ipv4Executor.executeDump(any(), any())).thenReturn(replyDumpIpv4()); + when(ipv6Executor.executeDump(any(), any())).thenReturn(replyDumpIpv6()); + when(ctx.getModificationCache()).thenReturn(cache); + + ipv4RoutesDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpFibDetailsReplyDump, Void>() + .withExecutor(ipv4Executor) + .acceptOnly(IpFibDetailsReplyDump.class) + .build(); + + ipv6RoutesDumpManager = new DumpCacheManager.DumpCacheManagerBuilder<Ip6FibDetailsReplyDump, Void>() + .withExecutor(ipv6Executor) + .acceptOnly(Ip6FibDetailsReplyDump.class) + .build(); + + routingProtocolContext = new NamingContext("routing-protocol", "routing-protocol-context"); + defineMapping(mappingContext, ROUTE_PROTOCOL_NAME, 1, "routing-protocol-context"); + defineMapping(mappingContext, "tst-protocol-2", 2, "routing-protocol-context"); + defineMapping(mappingContext, "tst-protocol-3", 3, "routing-protocol-context"); + } + + @Test + public void getAllIds() throws Exception { + final List<RoutingProtocolKey> keys = + getCustomizer().getAllIds(InstanceIdentifier.create(RoutingProtocol.class), ctx); + + assertThat(keys, hasSize(3)); + assertThat(keys, hasItems(new RoutingProtocolKey(ROUTE_PROTOCOL_NAME), new RoutingProtocolKey("tst-protocol-2"), + new RoutingProtocolKey("tst-protocol-3"))); + } + + @Test + public void readCurrentAttributes() throws Exception { + final InstanceIdentifier<RoutingProtocol> identifier = InstanceIdentifier.create(RoutingProtocols.class) + .child(RoutingProtocol.class, new RoutingProtocolKey(ROUTE_PROTOCOL_NAME)); + + final RoutingProtocolBuilder builder = new RoutingProtocolBuilder(); + getCustomizer().readCurrentAttributes(identifier, builder, ctx); + + assertEquals(ROUTE_PROTOCOL_NAME, builder.getName()); + assertEquals(ROUTE_PROTOCOL_NAME, builder.getKey().getName()); + assertEquals(Static.class, builder.getType()); + } + + @Override + protected ReaderCustomizer<RoutingProtocol, RoutingProtocolBuilder> initCustomizer() { + return new RoutingProtocolCustomizer(routingProtocolContext, ipv4RoutesDumpManager, ipv6RoutesDumpManager); + } + + private Ip6FibDetailsReplyDump replyDumpIpv6() { + Ip6FibDetailsReplyDump replyDump = new Ip6FibDetailsReplyDump(); + + // first is special + Ip6FibDetails detail1 = new Ip6FibDetails(); + detail1.tableId = 1; + detail1.address = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY; + detail1.addressLength = 24; + + FibPath path1 = new FibPath(); + path1.isLocal = 1; + detail1.path = new FibPath[]{path1}; + + + //second is simple + Ip6FibDetails detail2 = new Ip6FibDetails(); + detail2.tableId = 2; + detail2.address = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY; + detail2.addressLength = 22; + detail2.path = new FibPath[]{}; + + FibPath path2 = new FibPath(); + path2.weight = 3; + path2.nextHop = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY; + path2.afi = 0; + path2.swIfIndex = 1; + detail2.path = new FibPath[]{path2}; + + // third is list + Ip6FibDetails detail3 = new Ip6FibDetails(); + detail3.tableId = 1; + detail3.address = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY; + detail3.addressLength = 16; + + FibPath path3 = new FibPath(); + path3.swIfIndex = 1; + path3.weight = 1; + path3.nextHop = Ipv6RouteData.FIRST_ADDRESS_AS_ARRAY; + path3.afi = 0; + + FibPath path4 = new FibPath(); + path4.swIfIndex = 1; + path4.weight = 2; + path4.nextHop = Ipv6RouteData.SECOND_ADDRESS_AS_ARRAY; + path4.afi = 0; + + detail3.path = new FibPath[]{path3, path4}; + + replyDump.ip6FibDetails = Arrays.asList(detail1, detail2, detail3); + return replyDump; + } + + private IpFibDetailsReplyDump replyDumpIpv4() { + IpFibDetailsReplyDump replyDump = new IpFibDetailsReplyDump(); + + // first is special + IpFibDetails detail1 = new IpFibDetails(); + detail1.tableId = 1; + detail1.address = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY; + detail1.addressLength = 24; + + FibPath path1 = new FibPath(); + path1.isLocal = 1; + detail1.path = new FibPath[]{path1}; + + + //second is simple + IpFibDetails detail2 = new IpFibDetails(); + detail2.tableId = 3; + detail2.address = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY; + detail2.addressLength = 22; + detail2.path = new FibPath[]{}; + + FibPath path2 = new FibPath(); + path2.weight = 3; + path2.nextHop = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY; + path2.afi = 0; + path2.swIfIndex = 1; + detail2.path = new FibPath[]{path2}; + + // third is list + IpFibDetails detail3 = new IpFibDetails(); + detail3.tableId = 1; + detail3.address = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY; + detail3.addressLength = 16; + + FibPath path3 = new FibPath(); + path3.swIfIndex = 1; + path3.weight = 1; + path3.nextHop = Ipv4RouteData.FIRST_ADDRESS_AS_ARRAY; + path3.afi = 0; + + FibPath path4 = new FibPath(); + path4.swIfIndex = 1; + path4.weight = 2; + path4.nextHop = Ipv4RouteData.SECOND_ADDRESS_AS_ARRAY; + path4.afi = 0; + + detail3.path = new FibPath[]{path3, path4}; + + replyDump.ipFibDetails = Arrays.asList(detail1, detail2, detail3); + return replyDump; + } +}
\ No newline at end of file |