Search in sources :

Example 51 with ReadWriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.

the class OpenflowpluginMeterTestCommandProvider method _removeMeters.

public void _removeMeters(final CommandInterpreter ci) {
    String nref = ci.nextArgument();
    if (nref == null) {
        ci.println("test node added");
        createTestNode();
    } else {
        ci.println("User node added" + nref);
        createUserNode(nref);
    }
    Integer count = Integer.parseInt(ci.nextArgument());
    ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    switch(count) {
        case 1:
            createTestMeters("1", "remove");
            InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter1.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
            createTestMeters("2", "remove");
            InstanceIdentifier<Meter> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter2.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
            break;
        case 2:
            createTestMeters("3", "remove");
            InstanceIdentifier<Meter> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter1.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
            createTestMeters("4", "remove");
            InstanceIdentifier<Meter> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter2.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
            break;
        case 3:
            createTestMeters("5", "remove");
            InstanceIdentifier<Meter> path5 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter1.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path5);
            createTestMeters("6", "remove");
            InstanceIdentifier<Meter> path6 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter2.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path6);
            break;
        case 4:
            createTestMeters("7", "remove");
            InstanceIdentifier<Meter> path7 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter1.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path7);
            createTestMeters("8", "remove");
            InstanceIdentifier<Meter> path8 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter2.getMeterId()));
            modification.delete(LogicalDatastoreType.CONFIGURATION, path8);
            break;
        default:
            break;
    }
    CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void notUsed) {
            ci.println("Status of Group Data Loaded Transaction: success.");
        }

        @Override
        public void onFailure(Throwable throwable) {
            ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
        }
    }, MoreExecutors.directExecutor());
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 52 with ReadWriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.

the class OFPluginFlowTest method writeFlow.

static void writeFlow(FlowBuilder flow, InstanceIdentifier<FlowCapableNode> flowNodeIdent) {
    ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    final InstanceIdentifier<Flow> path1 = flowNodeIdent.child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
    modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
    CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            LOG.debug("Write of flow on device succeeded.");
        }

        @Override
        public void onFailure(Throwable throwable) {
            LOG.error("Write of flow on device failed.", throwable);
        }
    }, MoreExecutors.directExecutor());
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 53 with ReadWriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.

the class OpenflowpluginTableFeaturesTestCommandProvider method writeTableFeatures.

private void writeTableFeatures(final CommandInterpreter ci, TableFeatures tableFeatures) {
    ReadWriteTransaction modification = Preconditions.checkNotNull(dataBroker).newReadWriteTransaction();
    KeyedInstanceIdentifier<TableFeatures, TableFeaturesKey> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(TableFeatures.class, new TableFeaturesKey(tableFeatures.getTableId()));
    modification.merge(LogicalDatastoreType.OPERATIONAL, nodeToInstanceId(testNode), testNode, true);
    modification.merge(LogicalDatastoreType.OPERATIONAL, path1, tableFeatures, true);
    modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true);
    modification.merge(LogicalDatastoreType.CONFIGURATION, path1, tableFeatures, true);
    CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void notUsed) {
            ci.println("Status of Group Data Loaded Transaction: success.");
        }

        @Override
        public void onFailure(Throwable throwable) {
            ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
        }
    }, MoreExecutors.directExecutor());
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) TableFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures) TableFeaturesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)

Example 54 with ReadWriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.

the class FlowCommitWrapperImpl method writeFlowToConfig.

@Override
public CheckedFuture<Void, TransactionCommitFailedException> writeFlowToConfig(InstanceIdentifier<Flow> flowPath, Flow flowBody) {
    ReadWriteTransaction addFlowTransaction = dataBrokerService.newReadWriteTransaction();
    addFlowTransaction.put(LogicalDatastoreType.CONFIGURATION, flowPath, flowBody, true);
    return addFlowTransaction.submit();
}
Also used : ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 55 with ReadWriteTransaction

use of org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction in project openflowplugin by opendaylight.

the class DropTestCommiter method processPacket.

@Override
protected void processPacket(final InstanceIdentifier<Node> node, final Match match, final Instructions instructions) {
    // Finally build our flow
    final FlowBuilder fb = BUILDER.get();
    fb.setMatch(match);
    fb.setInstructions(instructions);
    fb.setId(new FlowId(String.valueOf(fb.hashCode()) + "." + ID_COUNTER.getAndIncrement()));
    // Construct the flow instance id
    final InstanceIdentifier<Flow> flowInstanceId = node.builder().augmentation(FlowCapableNode.class).child(Table.class, ZERO_TABLE).child(Flow.class, new FlowKey(fb.getId())).build();
    final Flow flow = fb.build();
    final ReadWriteTransaction transaction = dataService.newReadWriteTransaction();
    if (LOG.isDebugEnabled()) {
        LOG.debug("onPacketReceived - About to write flow {}", flow);
    }
    transaction.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
    transaction.submit();
    LOG.debug("onPacketReceived - About to write flow commited");
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Aggregations

ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)67 Optional (com.google.common.base.Optional)21 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)17 Test (org.junit.Test)16 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)13 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)13 CountDownLatch (java.util.concurrent.CountDownLatch)11 Mockito.doReturn (org.mockito.Mockito.doReturn)11 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)11 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)11 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)10 NodeId (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId)9 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)8 TestUtils.newInvNodeKey (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newInvNodeKey)8 NodeKey (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey)8 TestUtils.newLink (org.opendaylight.openflowplugin.applications.topology.manager.TestUtils.newLink)7 Link (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link)7 ArrayList (java.util.ArrayList)6 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)6 NodeBuilder (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder)6