use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.
the class FlowForwarder method add.
@Override
public Future<RpcResult<AddFlowOutput>> add(final InstanceIdentifier<Flow> identifier, final Flow addDataObj, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
LOG.trace("Forwarding the Flow ADD request [Tbl id, node Id {} {} {}", identifier, nodeIdent, addDataObj);
final Future<RpcResult<AddFlowOutput>> output;
final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class);
if (tableIdValidationPrecondition(tableKey, addDataObj)) {
final AddFlowInputBuilder builder = new AddFlowInputBuilder(addDataObj);
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setFlowRef(new FlowRef(identifier));
builder.setFlowTable(new FlowTableRef(nodeIdent.child(Table.class, tableKey)));
output = salFlowService.addFlow(builder.build());
} else {
output = RpcResultBuilder.<AddFlowOutput>failed().withError(RpcError.ErrorType.APPLICATION, TABLE_ID_MISMATCH).buildFuture();
}
return output;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyFlatBatchImpl method assembleAddOrUpdateFlows.
@VisibleForTesting
static int assembleAddOrUpdateFlows(final List<Batch> batchBag, int batchOrder, final Map<TableKey, ItemSyncBox<Flow>> flowItemSyncTableMap) {
// process flow add+update
int order = batchOrder;
if (flowItemSyncTableMap != null) {
for (Map.Entry<TableKey, ItemSyncBox<Flow>> syncBoxEntry : flowItemSyncTableMap.entrySet()) {
final ItemSyncBox<Flow> flowItemSyncBox = syncBoxEntry.getValue();
if (!flowItemSyncBox.getItemsToPush().isEmpty()) {
final List<FlatBatchAddFlow> flatBatchAddFlowBag = new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
int itemOrder = 0;
for (Flow flow : flowItemSyncBox.getItemsToPush()) {
flatBatchAddFlowBag.add(new FlatBatchAddFlowBuilder(flow).setBatchOrder(itemOrder++).setFlowId(flow.getId()).build());
}
final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchAddFlowCaseBuilder().setFlatBatchAddFlow(flatBatchAddFlowBag).build()).setBatchOrder(order).build();
order += itemOrder;
batchBag.add(batch);
}
if (!flowItemSyncBox.getItemsToUpdate().isEmpty()) {
final List<FlatBatchUpdateFlow> flatBatchUpdateFlowBag = new ArrayList<>(flowItemSyncBox.getItemsToUpdate().size());
int itemOrder = 0;
for (ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowItemSyncBox.getItemsToUpdate()) {
flatBatchUpdateFlowBag.add(new FlatBatchUpdateFlowBuilder().setBatchOrder(itemOrder++).setFlowId(flowUpdate.getUpdated().getId()).setOriginalBatchedFlow(new OriginalBatchedFlowBuilder(flowUpdate.getOriginal()).build()).setUpdatedBatchedFlow(new UpdatedBatchedFlowBuilder(flowUpdate.getUpdated()).build()).build());
}
final Batch batch = new BatchBuilder().setBatchChoice(new FlatBatchUpdateFlowCaseBuilder().setFlatBatchUpdateFlow(flatBatchUpdateFlowBag).build()).setBatchOrder(order).build();
order += itemOrder;
batchBag.add(batch);
}
}
}
return order;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.
the class SyncPlanPushStrategyIncrementalImpl method addMissingFlows.
ListenableFuture<RpcResult<Void>> addMissingFlows(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final Map<TableKey, ItemSyncBox<Flow>> flowsInTablesSyncBox, final SyncCrudCounters counters) {
if (flowsInTablesSyncBox.isEmpty()) {
LOG.trace("no tables in config for node: {} -> SKIPPING", nodeId.getValue());
return RpcResultBuilder.<Void>success().buildFuture();
}
final List<ListenableFuture<RpcResult<AddFlowOutput>>> allResults = new ArrayList<>();
final List<ListenableFuture<RpcResult<UpdateFlowOutput>>> allUpdateResults = new ArrayList<>();
final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
for (Map.Entry<TableKey, ItemSyncBox<Flow>> flowsInTableBoxEntry : flowsInTablesSyncBox.entrySet()) {
final TableKey tableKey = flowsInTableBoxEntry.getKey();
final ItemSyncBox<Flow> flowSyncBox = flowsInTableBoxEntry.getValue();
final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class, tableKey);
for (final Flow flow : flowSyncBox.getItemsToPush()) {
final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, flow.getKey());
LOG.trace("adding flow {} in table {} - absent on device {} match{}", flow.getId(), tableKey, nodeId, flow.getMatch());
allResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.add(flowIdent, flow, nodeIdent)));
flowCrudCounts.incAdded();
}
for (final ItemSyncBox.ItemUpdateTuple<Flow> flowUpdate : flowSyncBox.getItemsToUpdate()) {
final Flow existingFlow = flowUpdate.getOriginal();
final Flow updatedFlow = flowUpdate.getUpdated();
final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, updatedFlow.getKey());
LOG.trace("flow {} in table {} - needs update on device {} match{}", updatedFlow.getId(), tableKey, nodeId, updatedFlow.getMatch());
allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.update(flowIdent, existingFlow, updatedFlow, nodeIdent)));
flowCrudCounts.incUpdated();
}
}
final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddFlowOutput>createRpcResultCondenser("flow adding"), MoreExecutors.directExecutor());
final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateFlowOutput>createRpcResultCondenser("flow updating"), MoreExecutors.directExecutor());
return Futures.transform(Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult), ReconcileUtil.<Void>createRpcResultCondenser("flow add/update"), MoreExecutors.directExecutor());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.
the class TableForwarder method update.
@Override
public Future<RpcResult<UpdateTableOutput>> update(final InstanceIdentifier<TableFeatures> identifier, final TableFeatures original, final TableFeatures update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
LOG.debug("Forwarding Table Update request [Tbl id, node Id {} {}", identifier, nodeIdent);
final UpdateTableInputBuilder builder = new UpdateTableInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
final InstanceIdentifier<Table> iiToTable = nodeIdent.child(Table.class, new TableKey(identifier.firstKeyOf(TableFeatures.class).getTableId()));
builder.setTableRef(new TableRef(iiToTable));
builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(update)).build());
builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures(Collections.singletonList(original)).build());
LOG.debug("Invoking SalTableService {} ", nodeIdent);
return salTableService.updateTable(builder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey in project openflowplugin by opendaylight.
the class FlowListenerTest method updateFlowTest.
@Test
public void updateFlowTest() throws Exception {
addFlowCapableNode(NODE_KEY);
FlowKey flowKey = new FlowKey(new FlowId("test_Flow"));
InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
InstanceIdentifier<Flow> flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
Flow flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
assertCommit(writeTx.submit());
SalFlowServiceMock salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
List<AddFlowInput> addFlowCalls = salFlowService.getAddFlowCalls();
assertEquals(1, addFlowCalls.size());
assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue());
flowKey = new FlowKey(new FlowId("test_Flow"));
flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey);
flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).setOutGroup((long) 5).build();
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow);
assertCommit(writeTx.submit());
salFlowService = (SalFlowServiceMock) forwardingRulesManager.getSalFlowService();
List<UpdateFlowInput> updateFlowCalls = salFlowService.getUpdateFlowCalls();
assertEquals(1, updateFlowCalls.size());
assertEquals("DOM-1", updateFlowCalls.get(0).getTransactionUri().getValue());
assertEquals(flowII, updateFlowCalls.get(0).getFlowRef().getValue());
assertEquals(Boolean.TRUE, updateFlowCalls.get(0).getOriginalFlow().isStrict());
assertEquals(Boolean.TRUE, updateFlowCalls.get(0).getUpdatedFlow().isStrict());
}
Aggregations