/* * Copyright (c) 2014, 2016 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 test.mock.util; import java.util.Collections; import java.util.concurrent.ExecutionException; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder; 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.TableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfigBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public abstract class FRMTest extends AbstractDataBrokerTest { public void addFlowCapableNode(NodeKey nodeKey) { Nodes nodes = new NodesBuilder().setNode(Collections.<Node>emptyList()).build(); InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class) .child(Node.class, nodeKey); FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder(); NodeBuilder nodeBuilder = new NodeBuilder(); nodeBuilder.setKey(nodeKey); nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build()); WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes); writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build()); writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes); writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build()); assertCommit(writeTx.submit()); } public void removeNode(NodeKey nodeKey) throws ExecutionException, InterruptedException { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)); writeTx.submit().get(); } public void addTable(final TableKey tableKey, final NodeKey nodeKey) { addFlowCapableNode(nodeKey); final Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build(); WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table); assertCommit(writeTx.submit()); } public ForwardingRulesManagerConfig getConfig(){ ForwardingRulesManagerConfigBuilder cfgBuilder = new ForwardingRulesManagerConfigBuilder(); cfgBuilder.setStaleMarkingEnabled(false); cfgBuilder.setReconciliationRetryCount(0); return cfgBuilder.build(); } }