/* * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.sal.binding.test.connect.dom; import static junit.framework.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import java.math.BigInteger; import java.util.Collections; import java.util.Map; import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.data.DataReader; import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance; import org.opendaylight.controller.sal.binding.api.mount.MountProviderService; import org.opendaylight.controller.sal.binding.test.util.BindingBrokerTestFactory; import org.opendaylight.controller.sal.binding.test.util.BindingTestContext; import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance; import org.opendaylight.controller.sal.core.api.mount.MountProvisionService; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.CompositeNode; import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; import com.google.common.util.concurrent.MoreExecutors; public class CrossBrokerMountPointTest { private static final QName NODE_ID_QNAME = QName.create(Node.QNAME, "id"); private static final QName FLOW_ID_QNAME = QName.create(Flow.QNAME, "id"); private static final QName FLOW_NODE_QNAME = QName.create(Flow.QNAME, "node"); private static final QName TABLE_ID_QNAME = QName.create(Table.QNAME, "id"); private static final String NODE_ID = "node:1"; private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID)); private static final Map NODE_KEY_BI = Collections. singletonMap(NODE_ID_QNAME, NODE_ID); private static final InstanceIdentifier NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) // .child(Node.class, NODE_KEY).toInstance(); private static GroupKey GROUP_KEY = new GroupKey(new GroupId(0L)); private static final InstanceIdentifier GROUP_STATISTICS_ID_BA = NODE_INSTANCE_ID_BA .builder().augmentation(FlowCapableNode.class) // .child(Group.class, GROUP_KEY) // .augmentation(NodeGroupStatistics.class) // .child(GroupStatistics.class) // .toInstance(); private static final QName AUGMENTED_GROUP_STATISTICS = QName.create(NodeGroupStatistics.QNAME, GroupStatistics.QNAME.getLocalName()); private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier NODE_INSTANCE_ID_BI = // org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.builder() // .node(Nodes.QNAME) // .nodeWithKey(Node.QNAME, NODE_KEY_BI) // .toInstance(); private static final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier GROUP_STATISTICS_ID_BI = org.opendaylight.yangtools.yang.data.api.InstanceIdentifier // .builder(NODE_INSTANCE_ID_BI) .nodeWithKey(QName.create(FlowCapableNode.QNAME, "group"), QName.create(FlowCapableNode.QNAME, "group-id"), 0L).node(AUGMENTED_GROUP_STATISTICS).toInstance(); private static final NodeRef NODE_REF = new NodeRef(NODE_INSTANCE_ID_BA); private BindingTestContext testContext; private MountProviderService bindingMountPointService; private MountProvisionService domMountPointService; @Before public void setup() { BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory(); testFactory.setExecutor(MoreExecutors.sameThreadExecutor()); testFactory.setStartWithParsedSchema(true); testContext = testFactory.getTestContext(); testContext.start(); bindingMountPointService = testContext.getBindingMountProviderService(); domMountPointService = testContext.getDomMountProviderService(); // biRpcInvoker = testContext.getDomRpcInvoker(); assertNotNull(bindingMountPointService); assertNotNull(domMountPointService); // flowService = MessageCapturingFlowService.create(baRpcRegistry); } @Test public void testMountPoint() { testContext.getBindingDataBroker().readOperationalData(NODE_INSTANCE_ID_BA); MountProvisionInstance domMountPoint = domMountPointService.createMountPoint(NODE_INSTANCE_ID_BI); assertNotNull(domMountPoint); MountProviderInstance bindingMountPoint = bindingMountPointService.getMountPoint(NODE_INSTANCE_ID_BA); assertNotNull(bindingMountPoint); final BigInteger packetCount = BigInteger.valueOf(500L); DataReader simpleReader = new DataReader() { @Override public CompositeNode readConfigurationData(org.opendaylight.yangtools.yang.data.api.InstanceIdentifier arg0) { return null; } @Override public CompositeNode readOperationalData(org.opendaylight.yangtools.yang.data.api.InstanceIdentifier arg0) { if (arg0.equals(GROUP_STATISTICS_ID_BI)) { ImmutableCompositeNode data = ImmutableCompositeNode .builder() .setQName(AUGMENTED_GROUP_STATISTICS) .addLeaf(QName.create(AUGMENTED_GROUP_STATISTICS, "packet-count"), packetCount) // .toInstance(); return data; } return null; } }; domMountPoint.registerOperationalReader(NODE_INSTANCE_ID_BI, simpleReader); GroupStatistics data = (GroupStatistics) bindingMountPoint.readOperationalData(GROUP_STATISTICS_ID_BA); assertNotNull(data); assertEquals(packetCount,data.getPacketCount().getValue()); } }