diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-03-17 09:57:39 +0100 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-03-22 09:47:01 +0000 |
commit | 19606a9d653db34ea2813bc5734d9473703bf6be (patch) | |
tree | 9aeb87947fa408408b3da765068f6322afbbf5bc /v3po/impl | |
parent | b7ddb9bb91dd0fd886a9e4dde7c9d73d06879bf6 (diff) |
Migrate VppState operational data reads under new readers
Change-Id: Id30f4ad22a1ea5b7cb982005e675d3f337dc78d1
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl')
5 files changed, 520 insertions, 0 deletions
diff --git a/v3po/impl/pom.xml b/v3po/impl/pom.xml index ff27d1202..778d81484 100644 --- a/v3po/impl/pom.xml +++ b/v3po/impl/pom.xml @@ -58,5 +58,18 @@ <artifactId>mockito-all</artifactId> <scope>test</scope> </dependency> + <!--Needed due to final vppAPI, TODO remove once vppAPi refactored--> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>1.5.6</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>1.5.6</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/BridgeDomainCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/BridgeDomainCustomizer.java new file mode 100644 index 000000000..447f8509c --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/BridgeDomainCustomizer.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.vppstate; + +import com.google.common.collect.Lists; +import io.fd.honeycomb.v3po.impl.trans.impl.spi.ListVppReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.VppApiReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.VppReaderUtils; +import java.util.List; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.InterfaceKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2FibBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.vppjapi.vppBridgeDomainDetails; +import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails; +import org.openvpp.vppjapi.vppL2Fib; + +public final class BridgeDomainCustomizer extends VppApiReaderCustomizer + implements ListVppReaderCustomizer<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> { + + public BridgeDomainCustomizer(final org.openvpp.vppjapi.vppApi vppApi) { + super(vppApi); + } + + @Override + public void readCurrentAttributes(final InstanceIdentifier<BridgeDomain> id, + final BridgeDomainBuilder builder) { + final BridgeDomainKey key = id.firstKeyOf(id.getTargetType()); + final int bdId; + try { + bdId = Integer.parseInt(key.getName()); + } catch (NumberFormatException e) { + // LOG.warn("Invalid key", e); + return; + } + final vppBridgeDomainDetails bridgeDomainDetails = getVppApi().getBridgeDomainDetails(bdId); + + // FIXME, the problem here is that while going to VPP, the id for vbd is integer ID + // However in the models vbd's key is the name + // And you can get vbd name from vbd's ID using vppAPI, but not the other way around, making the API hard to use + // TO solve it, we need to store the vbd ID <-> vbd Name mapping in the (not-yet-available) read context and use it here + builder.setName(key.getName()); + // builder.setName(bridgeDomainDetails.name); + builder.setArpTermination(bridgeDomainDetails.arpTerm); + builder.setFlood(bridgeDomainDetails.flood); + builder.setForward(bridgeDomainDetails.forward); + builder.setLearn(bridgeDomainDetails.learn); + builder.setUnknownUnicastFlood(bridgeDomainDetails.uuFlood); + + builder.setInterface(getIfcs(bridgeDomainDetails)); + + final vppL2Fib[] vppL2Fibs = getVppApi().l2FibTableDump(bdId); + final List<L2Fib> l2Fibs = Lists.newArrayListWithCapacity(vppL2Fibs.length); + for (vppL2Fib vppL2Fib : vppL2Fibs) { + l2Fibs.add(new L2FibBuilder() + .setAction((vppL2Fib.filter + ? L2Fib.Action.Filter + : L2Fib.Action.Forward)) + .setBridgedVirtualInterface(vppL2Fib.bridgedVirtualInterface) + .setOutgoingInterface(vppL2Fib.outgoingInterface) + .setPhysAddress(new PhysAddress(getMacAddress(vppL2Fib.physAddress))) + .setStaticConfig(vppL2Fib.staticConfig) + .build()); + } + builder.setL2Fib(l2Fibs); + } + + private static String getMacAddress(byte[] mac) { + StringBuilder sb = new StringBuilder(18); + for (byte b : mac) { + if (sb.length() > 0) { + sb.append(':'); + } + sb.append(String.format("%02x", b)); + } + return sb.toString(); + } + + private List<Interface> getIfcs(final vppBridgeDomainDetails bridgeDomainDetails) { + final List<Interface> ifcs = Lists.newArrayListWithExpectedSize(bridgeDomainDetails.interfaces.length); + for (vppBridgeDomainInterfaceDetails anInterface : bridgeDomainDetails.interfaces) { + ifcs.add(new InterfaceBuilder() + .setBridgedVirtualInterface(bridgeDomainDetails.bviInterfaceName.equals(anInterface.interfaceName)) + .setName(anInterface.interfaceName) + .setKey(new InterfaceKey(anInterface.interfaceName)) + .build()); + } + return ifcs; + } + + @Override + public BridgeDomainBuilder getBuilder(final BridgeDomainKey id) { + return new BridgeDomainBuilder(); + } + + @Override + public List<InstanceIdentifier<BridgeDomain>> getAllIds(final InstanceIdentifier<BridgeDomain> id) { + final int[] ints = getVppApi().bridgeDomainDump(-1); + final List<InstanceIdentifier<BridgeDomain>> allIds = Lists.newArrayListWithExpectedSize(ints.length); + for (int i : ints) { + final InstanceIdentifier.IdentifiableItem<BridgeDomain, BridgeDomainKey> currentBdItem = + VppReaderUtils.getCurrentIdItem(id, new BridgeDomainKey(Integer.toString(i))); + final InstanceIdentifier<BridgeDomain> e = VppReaderUtils.getCurrentId(id, currentBdItem); + allIds.add(e); + } + + return allIds; + } + + @Override + public void merge(final Builder<?> builder, final List<BridgeDomain> currentBuilder) { + ((BridgeDomainsBuilder) builder).setBridgeDomain(currentBuilder); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VersionCustomizer.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VersionCustomizer.java new file mode 100644 index 000000000..3ba21bbfb --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VersionCustomizer.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.vppstate; + +import io.fd.honeycomb.v3po.impl.trans.impl.spi.ChildVppReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.VppApiReaderCustomizer; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.openvpp.vppjapi.vppVersion; + +public final class VersionCustomizer + extends VppApiReaderCustomizer + implements ChildVppReaderCustomizer<Version, VersionBuilder> { + + public VersionCustomizer(final org.openvpp.vppjapi.vppApi vppApi) { + super(vppApi); + } + + @Override + public void merge(final Builder<? extends DataObject> parentBuilder, final Version readValue) { + ((VppStateBuilder) parentBuilder).setVersion(readValue); + } + + @Override + public VersionBuilder getBuilder() { + return new VersionBuilder(); + } + + @Override + public void readCurrentAttributes(final VersionBuilder builder) { + final vppVersion vppVersion = getVppApi().getVppVersion(); + builder.setBranch(vppVersion.gitBranch); + builder.setName(vppVersion.programName); + builder.setBuildDate(vppVersion.buildDate); + builder.setBuildDirectory(vppVersion.buildDirectory); + } +} diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java new file mode 100644 index 000000000..7a4a08eaf --- /dev/null +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/vppstate/VppStateUtils.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.vppstate; + +import io.fd.honeycomb.v3po.impl.trans.ChildVppReader; +import io.fd.honeycomb.v3po.impl.trans.impl.CompositeChildVppReader; +import io.fd.honeycomb.v3po.impl.trans.impl.CompositeListVppReader; +import io.fd.honeycomb.v3po.impl.trans.impl.CompositeRootVppReader; +import io.fd.honeycomb.v3po.impl.trans.impl.spi.RootVppReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.ReflexiveChildReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.ReflexiveRootReaderCustomizer; +import io.fd.honeycomb.v3po.impl.trans.util.VppReaderUtils; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomainsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.openvpp.vppjapi.vppApi; + +public final class VppStateUtils { + + public VppStateUtils() {} + + /** + * Create root VppState reader with all its children wired + */ + public static CompositeRootVppReader<VppState, VppStateBuilder> getVppStateReader(@Nonnull final vppApi vppApi) { + final RootVppReaderCustomizer<VppState, VppStateBuilder> rootVppReaderCustomizer = + new ReflexiveRootReaderCustomizer<>(VppStateBuilder.class); + + final ChildVppReader<Version> versionReader = new CompositeChildVppReader<>( + Version.class, + new VersionCustomizer(vppApi)); + + final CompositeListVppReader<BridgeDomain, BridgeDomainKey, BridgeDomainBuilder> + identifierBuilderCompositeListVppReader = new CompositeListVppReader<>( + BridgeDomain.class, + new BridgeDomainCustomizer(vppApi)); + + final List<ChildVppReader<? extends ChildOf<BridgeDomains>>> bdChildReaders = new ArrayList<>(); + bdChildReaders.add(identifierBuilderCompositeListVppReader); + + final ChildVppReader<BridgeDomains> bridgeDomainsReader = new CompositeChildVppReader<>( + BridgeDomains.class, + bdChildReaders, + new ReflexiveChildReaderCustomizer<>(BridgeDomainsBuilder.class)); + + final List<ChildVppReader<? extends ChildOf<VppState>>> childVppReaders = new ArrayList<>(); + childVppReaders.add(versionReader); + childVppReaders.add(bridgeDomainsReader); + + return new CompositeRootVppReader<>( + VppState.class, + childVppReaders, + VppReaderUtils.<VppState>emptyAugReaderList(), + rootVppReaderCustomizer); + } +} diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/BdTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/BdTest.java new file mode 100644 index 000000000..ab3f6e054 --- /dev/null +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/vppstate/BdTest.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.v3po.impl.vppstate; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import io.fd.honeycomb.v3po.impl.trans.VppReader; +import io.fd.honeycomb.v3po.impl.trans.impl.CompositeRootVppReader; +import io.fd.honeycomb.v3po.impl.trans.util.DelegatingReaderRegistry; +import java.util.Collections; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.Version; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.VersionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomain; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.BridgeDomainKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2Fib; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.state.bridge.domains.bridge.domain.L2FibKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.openvpp.vppjapi.vppApi; +import org.openvpp.vppjapi.vppBridgeDomainDetails; +import org.openvpp.vppjapi.vppBridgeDomainInterfaceDetails; +import org.openvpp.vppjapi.vppL2Fib; +import org.openvpp.vppjapi.vppVersion; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@SuppressStaticInitializationFor("org.openvpp.vppjapi.vppConn") +@PrepareForTest(vppApi.class) +public class BdTest { + + public static final vppVersion VERSION = new vppVersion("test", "1", "2", "33"); + + private vppApi api; + private CompositeRootVppReader<VppState, VppStateBuilder> vppStateReader; + private DelegatingReaderRegistry readerRegistry; + private vppBridgeDomainDetails bdDetails; + + @Before + public void setUp() throws Exception { + api = PowerMockito.mock(vppApi.class); + + bdDetails = new vppBridgeDomainDetails(); + + setIfcs(bdDetails); + setBaseAttrs(bdDetails); + + final vppL2Fib[] l2Fibs = getL2Fibs(); + PowerMockito.doReturn(l2Fibs).when(api).l2FibTableDump(Matchers.anyInt()); + PowerMockito.doReturn(bdDetails).when(api).getBridgeDomainDetails(Matchers.anyInt()); + PowerMockito.doReturn(new int[] {1, 2}).when(api).bridgeDomainDump(Matchers.anyInt()); + PowerMockito.doReturn(VERSION).when(api).getVppVersion(); + vppStateReader = VppStateUtils.getVppStateReader(api); + readerRegistry = new DelegatingReaderRegistry(Collections.<VppReader<? extends DataObject>>singletonList(vppStateReader)); + } + + private vppL2Fib[] getL2Fibs() { + return new vppL2Fib[] { + new vppL2Fib(new byte[]{1,2,3,4,5,6}, true, "ifc1", true, true), + new vppL2Fib(new byte[]{2,2,3,4,5,6}, true, "ifc2", true, true), + }; + } + + private void setIfcs(final vppBridgeDomainDetails bdDetails) { + final vppBridgeDomainInterfaceDetails ifcDetails = new vppBridgeDomainInterfaceDetails(); + ifcDetails.interfaceName = "ifc"; + ifcDetails.splitHorizonGroup = 2; + bdDetails.interfaces = new vppBridgeDomainInterfaceDetails[] {ifcDetails}; + } + + private void setBaseAttrs(final vppBridgeDomainDetails bdDetails) { + bdDetails.name = "bdn"; + bdDetails.arpTerm = true; + bdDetails.bdId = 1; + bdDetails.bviInterfaceName = "ifc"; + bdDetails.flood = true; + bdDetails.forward = true; + bdDetails.learn = true; + bdDetails.uuFlood = true; + } + + @Test + public void testReadAll() throws Exception { + final List<? extends DataObject> dataObjects = readerRegistry.readAll(); + assertEquals(dataObjects.size(), 1); + final DataObject dataObject = dataObjects.get(0); + assertTrue(dataObject instanceof VppState); + assertVersion((VppState) dataObject); + assertEquals(2, ((VppState) dataObject).getBridgeDomains().getBridgeDomain().size()); + } + + private void assertVersion(final VppState dataObject) { + assertEquals( + new VersionBuilder() + .setName("test") + .setBuildDirectory("1") + .setBranch("2") + .setBuildDate("33") + .build(), + dataObject.getVersion()); + } + + @Test + public void testReadSpecific() throws Exception { + final List<? extends DataObject> read = readerRegistry.read(InstanceIdentifier.create(VppState.class)); + assertEquals(read.size(), 1); + assertVersion((VppState) read.get(0)); + } + + @Test + public void testReadBridgeDomains() throws Exception { + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + + List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class)); +// System.err.println(read); + assertEquals(read.size(), 1); + assertEquals(readRoot.getBridgeDomains(), read.get(0)); + } + + /** + * L2fib does not have a dedicated reader, relying on auto filtering + */ + @Test + public void testReadL2Fib() throws Exception { + // Deep child without a dedicated reader with specific l2fib key + List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class, new BridgeDomainKey("1")) + .child(L2Fib.class, new L2FibKey(new PhysAddress("01:02:03:04:05:06")))); +// System.err.println(read); + assertEquals(read.size(), 1); + + // non existing l2fib + read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class, new BridgeDomainKey("1")) + .child(L2Fib.class, new L2FibKey(new PhysAddress("FF:FF:FF:04:05:06")))); +// System.err.println(read); + assertEquals(read.size(), 0); + } + + /** + * L2fib does not have a dedicated reader, relying on auto filtering + */ + @Test + public void testReadL2FibAll() throws Exception { + // Deep child without a dedicated reader + final InstanceIdentifier<L2Fib> id = InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class, new BridgeDomainKey("1")).child(L2Fib.class); + final List<? extends DataObject> read = readerRegistry.read(id); +// System.err.println(read); + assertEquals(read.toString(), read.size(), 2); + + // test if direct read returns the same value + final List<? extends DataObject> read2 = vppStateReader.read(id); +// System.err.println(read); + assertEquals(read, read2); + } + + @Test + public void testReadBridgeDomainAll() throws Exception { + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + + final List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class)); +// System.err.println(read); + assertEquals(read.size(), 2); + assertEquals(readRoot.getBridgeDomains().getBridgeDomain(), read); + } + + @Test + public void testReadBridgeDomain() throws Exception { + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + + final List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class, new BridgeDomainKey("1"))); + +// System.err.println(read); + assertEquals(read.size(), 1); + assertEquals(Iterables.find(readRoot.getBridgeDomains().getBridgeDomain(), new Predicate<BridgeDomain>() { + @Override + public boolean apply(final BridgeDomain input) { +// System.err.println(input.getKey()); + return input.getKey().getName().equals("1"); + } + }), read.get(0)); + } + + @Test + public void testReadBridgeDomainNotExisting() throws Exception { + final List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(BridgeDomains.class).child( + BridgeDomain.class, new BridgeDomainKey("NOT EXISTING"))); + assertEquals(read.size(), 0); + } + + @Test + public void testReadVersion() throws Exception { + VppState readRoot = (VppState) readerRegistry.read(InstanceIdentifier.create(VppState.class)).get(0); + + List<? extends DataObject> read = + readerRegistry.read(InstanceIdentifier.create(VppState.class).child(Version.class)); +// System.err.println(read); + assertEquals(read.size(), 1); + assertEquals(readRoot.getVersion(), read.get(0)); + } +}
\ No newline at end of file |