use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder in project openflowplugin by opendaylight.
the class OpenflowPluginBulkTransactionProvider method createTestNode.
private NodeBuilder createTestNode(String nodeId) {
if (nodeId == null) {
nodeId = OpenflowpluginTestActivator.NODE_ID;
}
NodeBuilder builder = new NodeBuilder();
builder.setId(new NodeId(nodeId));
builder.setKey(new NodeKey(builder.getId()));
return builder;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder in project openflowplugin by opendaylight.
the class OpenflowPluginBulkTransactionProvider method writeFlow.
private void writeFlow(final CommandInterpreter ci, FlowBuilder flow, FlowBuilder flow1, FlowBuilder flow2, FlowBuilder flow3, NodeBuilder nodeBuilder) {
ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow.getTableId())).child(Flow.class, flow.getKey());
modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.OPERATIONAL, path1, flow.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path1, flow.build(), true);
InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow1.getTableId())).child(Flow.class, flow1.getKey());
modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.OPERATIONAL, path2, flow1.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path2, flow1.build(), true);
InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow2.getTableId())).child(Flow.class, flow2.getKey());
modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.OPERATIONAL, path3, flow2.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path3, flow2.build(), true);
InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(flow3.getTableId())).child(Flow.class, flow3.getKey());
modification.merge(LogicalDatastoreType.OPERATIONAL, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.OPERATIONAL, path4, flow3.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build(), true);
modification.merge(LogicalDatastoreType.CONFIGURATION, path4, flow3.build(), 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) {
LOG.error(throwable.getMessage(), throwable);
ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder in project openflowplugin by opendaylight.
the class OpenflowPluginBulkTransactionProvider method _removeFlows.
public void _removeFlows(final CommandInterpreter ci) {
ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
NodeBuilder tn = createTestNode(ci.nextArgument());
String flowtype = ci.nextArgument();
Integer flowcnt = Integer.parseInt(flowtype);
FlowBuilder tf = null;
FlowBuilder tf1 = null;
FlowBuilder tf2 = null;
FlowBuilder tf3 = null;
switch(flowcnt) {
case 1:
// add case 1
tf = createTestFlow(tn, "f1", "10");
tf1 = createTestFlow(tn, "f2", "11");
tf2 = createTestFlow(tn, "f3", "12");
tf3 = createTestFlow(tn, "f4", "13");
break;
case 2:
// modify case 1
tf = createTestFlow(tn, "f82", "10");
tf1 = createTestFlow(tn, "f83", "11");
tf2 = createTestFlow(tn, "f84", "12");
tf3 = createTestFlow(tn, "f85", "13");
break;
case 3:
// add case 2
tf = createTestFlow(tn, "f3", "3");
tf1 = createTestFlow(tn, "f4", "4");
tf2 = createTestFlow(tn, "f5", "5");
tf3 = createTestFlow(tn, "f6", "6");
break;
case 4:
// modify case 2
tf = createTestFlow(tn, "f700", "3");
tf1 = createTestFlow(tn, "f4", "4");
tf2 = createTestFlow(tn, "f900", "5");
tf3 = createTestFlow(tn, "f86", "6");
break;
case 5:
// add case 3
tf = createTestFlow(tn, "f7", "7");
tf1 = createTestFlow(tn, "f8", "8");
tf2 = createTestFlow(tn, "f9", "9");
tf3 = createTestFlow(tn, "f10", "10");
break;
case 6:
// modify case 3
tf = createTestFlow(tn, "f91", "7");
tf1 = createTestFlow(tn, "f92", "8");
tf2 = createTestFlow(tn, "f93", "9");
tf3 = createTestFlow(tn, "f94", "10");
break;
case 7:
// -ve scenario
tf = createTestFlow(tn, "f23", "3");
tf1 = createTestFlow(tn, "f34", "4");
tf2 = createTestFlow(tn, "f35", "5");
tf3 = createTestFlow(tn, "f36", "6");
break;
case 8:
// +ve scenario
// modify case 6 -ve
tf = createTestFlow(tn, "f23", "3");
tf1 = createTestFlow(tn, "f99", "4");
tf2 = createTestFlow(tn, "f100", "5");
tf3 = createTestFlow(tn, "f101", "6");
break;
case 9:
// modify case 6
tf = createTestFlow(tn, "f700", "7");
tf1 = createTestFlow(tn, "f230", "23");
tf2 = createTestFlow(tn, "f900", "9");
tf3 = createTestFlow(tn, "f1000", "10");
break;
default:
throw new IllegalArgumentException("Invalid flowtype: " + flowtype);
}
InstanceIdentifier<Flow> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf.getTableId())).child(Flow.class, tf.getKey());
modification.delete(LogicalDatastoreType.OPERATIONAL, path1);
modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
InstanceIdentifier<Flow> path2 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf1.getTableId())).child(Flow.class, tf1.getKey());
modification.delete(LogicalDatastoreType.OPERATIONAL, path2);
modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
modification.delete(LogicalDatastoreType.CONFIGURATION, path2);
InstanceIdentifier<Flow> path3 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf2.getTableId())).child(Flow.class, tf2.getKey());
modification.delete(LogicalDatastoreType.OPERATIONAL, path3);
modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
modification.delete(LogicalDatastoreType.CONFIGURATION, path3);
InstanceIdentifier<Flow> path4 = InstanceIdentifier.create(Nodes.class).child(Node.class, tn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tf3.getTableId())).child(Flow.class, tf3.getKey());
modification.delete(LogicalDatastoreType.OPERATIONAL, path4);
modification.delete(LogicalDatastoreType.CONFIGURATION, nodeBuilderToInstanceId(tn));
modification.delete(LogicalDatastoreType.CONFIGURATION, path4);
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) {
LOG.error(throwable.getMessage(), throwable);
ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder in project genius by opendaylight.
the class OvsdbTestUtil method updateNode.
public static CheckedFuture<Void, TransactionCommitFailedException> updateNode(ConnectionInfo connectionInfo, String tepIp, String tzName, String brName, DataBroker dataBroker) throws Exception {
final InstanceIdentifier<Node> iid = SouthboundUtils.createInstanceIdentifier(connectionInfo);
Node oldOvsdbNode = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, iid).checkedGet().get();
// build Node using its builder class
NodeBuilder nodeBuilder = new NodeBuilder();
nodeBuilder.setNodeId(oldOvsdbNode.getNodeId());
// build OvsdbNodeAugmentation for Node
OvsdbNodeAugmentationBuilder ovsdbNodeAugBuilder = new OvsdbNodeAugmentationBuilder();
ovsdbNodeAugBuilder.setConnectionInfo(connectionInfo);
// create map of key-val pairs
Map<String, String> externalIds = new HashMap<>();
Map<String, String> otherConfigs = new HashMap<>();
if (tepIp != null && !tepIp.isEmpty()) {
otherConfigs.put(ItmTestConstants.OTHER_CFG_TEP_IP_KEY, tepIp);
}
if (tzName != null) {
externalIds.put(ItmTestConstants.EXTERNAL_ID_TZNAME_KEY, tzName);
}
if (brName != null && !brName.isEmpty()) {
externalIds.put(ItmTestConstants.EXTERNAL_ID_BR_NAME_KEY, brName);
}
// get map-keys into set.
Set<String> externalIdKeys = externalIds.keySet();
Set<String> otherConfigKeys = otherConfigs.keySet();
List<OpenvswitchExternalIds> externalIdsList = new ArrayList<>();
String externalIdValue = null;
for (String externalIdKey : externalIdKeys) {
externalIdValue = externalIds.get(externalIdKey);
if (externalIdKey != null && externalIdValue != null) {
externalIdsList.add(new OpenvswitchExternalIdsBuilder().setExternalIdKey(externalIdKey).setExternalIdValue(externalIdValue).build());
}
}
List<OpenvswitchOtherConfigs> otherConfigsList = new ArrayList<>();
String otherConfigsValue = null;
for (String otherConfigKey : otherConfigKeys) {
otherConfigsValue = otherConfigs.get(otherConfigKey);
if (otherConfigKey != null && otherConfigsValue != null) {
otherConfigsList.add(new OpenvswitchOtherConfigsBuilder().setOtherConfigKey(otherConfigKey).setOtherConfigValue(otherConfigsValue).build());
}
}
// set ExternalIds list into Node
ovsdbNodeAugBuilder.setOpenvswitchExternalIds(externalIdsList);
// set OtherConfigs list into Node
ovsdbNodeAugBuilder.setOpenvswitchOtherConfigs(otherConfigsList);
// add OvsdbNodeAugmentation into Node
nodeBuilder.addAugmentation(OvsdbNodeAugmentation.class, ovsdbNodeAugBuilder.build());
Node ovsdbNode = nodeBuilder.build();
// ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
transaction.put(LogicalDatastoreType.OPERATIONAL, iid, ovsdbNode, true);
return transaction.submit();
}
Aggregations