2 * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package test.mock.util;
10 import java.util.Collections;
11 import java.util.concurrent.ExecutionException;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfigBuilder;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 public abstract class FRMTest extends AbstractDataBrokerTest {
32 public void addFlowCapableNode(NodeKey nodeKey) {
33 Nodes nodes = new NodesBuilder().setNode(Collections.<Node>emptyList()).build();
34 InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class)
35 .child(Node.class, nodeKey);
37 FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder();
38 NodeBuilder nodeBuilder = new NodeBuilder();
39 nodeBuilder.setKey(nodeKey);
40 nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build());
42 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
43 writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes);
44 writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build());
45 writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes);
46 writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build());
47 assertCommit(writeTx.submit());
50 public void removeNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
51 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
52 writeTx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey));
53 writeTx.submit().get();
56 public void addTable(final TableKey tableKey, final NodeKey nodeKey) {
57 addFlowCapableNode(nodeKey);
58 final Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
59 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
60 InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)
61 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
62 writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
63 assertCommit(writeTx.submit());
66 public ForwardingRulesManagerConfig getConfig(){
67 ForwardingRulesManagerConfigBuilder cfgBuilder = new ForwardingRulesManagerConfigBuilder();
68 cfgBuilder.setStaleMarkingEnabled(false);
69 cfgBuilder.setReconciliationRetryCount(0);
70 return cfgBuilder.build();