public void addAllFlowsToSwitch(List afc, NodeBuilder nodeBuilder) {
/*
ActionBuilder > list > ApplyActionsBuilder > ApplyActionsCaseBuilder > InstructionBuilder > list > InstructionsBuilder > flowBuilder
*/
for(Flow flow : afc) {
if (flow != null) {
System.out.println("Adding Flow=" + flow.toString());
FlowBuilder ffb = new FlowBuilder();
ffb.fieldsFrom(flow);
//ffb.setTableId(flow.getTableId());
ffb.setTableId((short)0x8);
ffb.setCookie(BigInteger.valueOf(0x8));
if(flow.getId() != null) {
//ffb.setId(new FlowId(flow.getId().getValue()));
ffb.setId(new FlowId("1234"));
}
//FlowKey fkey = new FlowKey(new FlowId(flow.getId().getValue()));
FlowKey fkey = new FlowKey(new FlowId("1234"));
ffb.setKey(fkey);
DataModification, DataObject>
modification = dataBrokerService.beginTransaction();
//System.out.println("addAllFlowsToSwitch: tid=" + ffb.getTableId() + "fc= " + ffb.getCookie() + "fkey=" + ffb.getKey().toString());
InstanceIdentifier flowRef = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(ffb.getTableId())).child(Flow.class, ffb.getKey()).build();
modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
modification.putConfigurationData(flowRef, ffb.build());
Future> commitFuture = modification.commit();
try {
RpcResult result = commitFuture.get();
TransactionStatus status = result.getResult();
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
} catch (ExecutionException e) {
LOG.error(e.getMessage(), e);
}
}
}
}
/*
ActionBuilder > list > ApplyActionsBuilder > ApplyActionsCaseBuilder > InstructionBuilder > list > InstructionsBuilder > flowBuilder
*/
for(Flow flow : afc) {
if (flow != null) {
System.out.println("Adding Flow=" + flow.toString());
FlowBuilder ffb = new FlowBuilder();
ffb.fieldsFrom(flow);
//ffb.setTableId(flow.getTableId());
ffb.setTableId((short)0x8);
ffb.setCookie(BigInteger.valueOf(0x8));
if(flow.getId() != null) {
//ffb.setId(new FlowId(flow.getId().getValue()));
ffb.setId(new FlowId("1234"));
}
//FlowKey fkey = new FlowKey(new FlowId(flow.getId().getValue()));
FlowKey fkey = new FlowKey(new FlowId("1234"));
ffb.setKey(fkey);
DataModification
//System.out.println("addAllFlowsToSwitch: tid=" + ffb.getTableId() + "fc= " + ffb.getCookie() + "fkey=" + ffb.getKey().toString());
InstanceIdentifier
.child(Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class)
.child(Table.class, new TableKey(ffb.getTableId())).child(Flow.class, ffb.getKey()).build();
modification.putConfigurationData(nodeBuilderToInstanceId(nodeBuilder), nodeBuilder.build());
modification.putConfigurationData(flowRef, ffb.build());
Future
try {
RpcResult
TransactionStatus status = result.getResult();
} catch (InterruptedException e) {
LOG.error(e.getMessage(), e);
} catch (ExecutionException e) {
LOG.error(e.getMessage(), e);
}
}
}
}
We are using two-phase commit procedure to write Flows onto Switches.