ca2d80771d9fa91cd47223f17d86e1307ddf6e00
[openflowplugin.git] / applications / forwardingrules-manager / src / test / java / test / mock / util / FRMTest.java
1 package test.mock.util;
2
3 import java.util.Collections;
4 import java.util.concurrent.ExecutionException;
5 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
6 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
7 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfig;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.forwardingrules.manager.config.rev160511.ForwardingRulesManagerConfigBuilder;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public abstract class FRMTest extends AbstractDataBrokerTest {
24
25     public void addFlowCapableNode(NodeKey nodeKey) {
26         Nodes nodes = new NodesBuilder().setNode(Collections.<Node>emptyList()).build();
27         InstanceIdentifier<Node> flowNodeIdentifier = InstanceIdentifier.create(Nodes.class)
28                 .child(Node.class, nodeKey);
29
30         FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder();
31         NodeBuilder nodeBuilder = new NodeBuilder();
32         nodeBuilder.setKey(nodeKey);
33         nodeBuilder.addAugmentation(FlowCapableNode.class, fcnBuilder.build());
34
35         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
36         writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes);
37         writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build());
38         writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes);
39         writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build());
40         assertCommit(writeTx.submit());
41     }
42
43     public void removeNode(NodeKey nodeKey) throws ExecutionException, InterruptedException {
44         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
45         writeTx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey));
46         writeTx.submit().get();
47     }
48
49     public void addTable(final TableKey tableKey, final NodeKey nodeKey) {
50         addFlowCapableNode(nodeKey);
51         final Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
52         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
53         InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)
54                 .augmentation(FlowCapableNode.class).child(Table.class, tableKey);
55         writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
56         assertCommit(writeTx.submit());
57     }
58
59     public ForwardingRulesManagerConfig getConfig(){
60         ForwardingRulesManagerConfigBuilder cfgBuilder = new ForwardingRulesManagerConfigBuilder();
61         cfgBuilder.setStaleMarkingEnabled(false);
62         cfgBuilder.setReconciliationRetryCount(0);
63         return cfgBuilder.build();
64
65     }
66 }