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());
}
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());
}
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());
}
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();
}
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");
}
Aggregations