Search in sources :

Example 81 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class SyncPlanPushStrategyIncrementalImpl method removeRedundantFlows.

ListenableFuture<RpcResult<Void>> removeRedundantFlows(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final Map<TableKey, ItemSyncBox<Flow>> removalPlan, final SyncCrudCounters counters) {
    if (removalPlan.isEmpty()) {
        LOG.trace("no tables in operational for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }
    final List<ListenableFuture<RpcResult<RemoveFlowOutput>>> allResults = new ArrayList<>();
    final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
    for (final Map.Entry<TableKey, ItemSyncBox<Flow>> flowsPerTable : removalPlan.entrySet()) {
        final KeyedInstanceIdentifier<Table, TableKey> tableIdent = nodeIdent.child(Table.class, flowsPerTable.getKey());
        // loop flows on device and check if the are configured
        for (final Flow flow : flowsPerTable.getValue().getItemsToPush()) {
            final KeyedInstanceIdentifier<Flow, FlowKey> flowIdent = tableIdent.child(Flow.class, flow.getKey());
            allResults.add(JdkFutureAdapters.listenInPoolThread(flowForwarder.remove(flowIdent, flow, nodeIdent)));
            flowCrudCounts.incRemoved();
        }
    }
    final ListenableFuture<RpcResult<Void>> singleVoidResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<RemoveFlowOutput>createRpcResultCondenser("flow remove"), MoreExecutors.directExecutor());
    return Futures.transformAsync(singleVoidResult, ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService), MoreExecutors.directExecutor());
}
Also used : FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) RemoveFlowOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowOutput) ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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) CrudCounts(org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Map(java.util.Map)

Example 82 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class SyncReactorImpl method syncup.

@Override
public ListenableFuture<Boolean> syncup(final InstanceIdentifier<FlowCapableNode> nodeIdent, final SyncupEntry syncupEntry) {
    final NodeId nodeId = PathUtil.digNodeId(nodeIdent);
    FlowCapableNode configTree = syncupEntry.getAfter();
    FlowCapableNode operationalTree = syncupEntry.getBefore();
    final SyncCrudCounters counters = new SyncCrudCounters();
    /**
     * instructions:
     *  - extract diff changes and prepare change steps in safe order
     *    - optimization: decide if updates needed
     *  - execute chosen implementation (e.g. conventional API, bulk API, flat bulk API)
     *  - recommended order follows:
     * reconciliation strategy - phase 1: - add/update missing objects in following order:
     *  - table features - groups (reordered) - meters - flows
     * reconciliation strategy - phase 2: - remove redundant objects in following order:
     *  - flows - meters - groups (reordered)
     */
    final List<ItemSyncBox<Group>> groupsToAddOrUpdate = extractGroupsToAddOrUpdate(nodeId, configTree, operationalTree);
    final ItemSyncBox<Meter> metersToAddOrUpdate = extractMetersToAddOrUpdate(nodeId, configTree, operationalTree);
    final Map<TableKey, ItemSyncBox<Flow>> flowsToAddOrUpdate = extractFlowsToAddOrUpdate(nodeId, configTree, operationalTree);
    final Map<TableKey, ItemSyncBox<Flow>> flowsToRemove = extractFlowsToRemove(nodeId, configTree, operationalTree);
    final ItemSyncBox<Meter> metersToRemove = extractMetersToRemove(nodeId, configTree, operationalTree);
    final List<ItemSyncBox<Group>> groupsToRemove = extractGroupsToRemove(nodeId, configTree, operationalTree);
    final SynchronizationDiffInput input = new SynchronizationDiffInput(nodeIdent, groupsToAddOrUpdate, metersToAddOrUpdate, flowsToAddOrUpdate, flowsToRemove, metersToRemove, groupsToRemove);
    final ListenableFuture<RpcResult<Void>> bootstrapResultFuture = RpcResultBuilder.<Void>success().buildFuture();
    final ListenableFuture<RpcResult<Void>> resultVehicle = syncPlanPushStrategy.executeSyncStrategy(bootstrapResultFuture, input, counters);
    return Futures.transform(resultVehicle, input1 -> {
        if (input1 == null) {
            return false;
        }
        if (LOG.isDebugEnabled()) {
            final CrudCounts flowCrudCounts = counters.getFlowCrudCounts();
            final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
            final CrudCounts groupCrudCounts = counters.getGroupCrudCounts();
            LOG.debug("Syncup outcome[{}] (added/updated/removed): flow={}/{}/{}, group={}/{}/{}, " + "meter={}/{}/{}, errors={}", nodeId.getValue(), flowCrudCounts.getAdded(), flowCrudCounts.getUpdated(), flowCrudCounts.getRemoved(), groupCrudCounts.getAdded(), groupCrudCounts.getUpdated(), groupCrudCounts.getRemoved(), meterCrudCounts.getAdded(), meterCrudCounts.getUpdated(), meterCrudCounts.getRemoved(), Arrays.toString(input1.getErrors().toArray()));
        }
        return input1.isSuccessful();
    }, MoreExecutors.directExecutor());
}
Also used : ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) 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) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) CrudCounts(org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) SyncCrudCounters(org.opendaylight.openflowplugin.applications.frsync.util.SyncCrudCounters) SynchronizationDiffInput(org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SynchronizationDiffInput)

Example 83 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class FlowCapableNodeLookups method wrapTablesToMap.

@Nonnull
public static Map<Short, Table> wrapTablesToMap(@Nullable final List<Table> tables) {
    final Map<Short, Table> tableMap;
    if (tables == null) {
        tableMap = Collections.emptyMap();
    } else {
        LOG.trace("tables found: {}", tables.size());
        tableMap = new HashMap<>();
        for (Table table : tables) {
            tableMap.put(table.getId(), table);
        }
    }
    return tableMap;
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) Nonnull(javax.annotation.Nonnull)

Example 84 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class ReconcileUtil method resolveFlowDiffsInAllTables.

/**
 * Resolves flow differences in all tables.
 *
 * @param nodeId              target node
 * @param tableOperationalMap flow-tables resent on device
 * @param tablesConfigured    flow-tables configured for device
 * @param gatherUpdates       check content of pending item if present on device (and create update task eventually)
 * @return map : key={@link TableKey}, value={@link ItemSyncBox} of safe synchronization steps
 */
public static Map<TableKey, ItemSyncBox<Flow>> resolveFlowDiffsInAllTables(final NodeId nodeId, final Map<Short, Table> tableOperationalMap, final List<Table> tablesConfigured, final boolean gatherUpdates) {
    LOG.trace("resolving flows in tables for {}", nodeId.getValue());
    final Map<TableKey, ItemSyncBox<Flow>> tableFlowSyncBoxes = new HashMap<>();
    for (final Table tableConfigured : tablesConfigured) {
        final List<Flow> flowsConfigured = tableConfigured.getFlow();
        if (flowsConfigured == null || flowsConfigured.isEmpty()) {
            continue;
        }
        // lookup table (on device)
        final Table tableOperational = tableOperationalMap.get(tableConfigured.getId());
        // wrap existing (on device) flows in current table into map
        final Map<FlowDescriptor, Flow> flowOperationalMap = FlowCapableNodeLookups.wrapFlowsToMap(tableOperational != null ? tableOperational.getFlow() : null);
        final ItemSyncBox<Flow> flowsSyncBox = resolveFlowDiffsInTable(flowsConfigured, flowOperationalMap, gatherUpdates);
        if (!flowsSyncBox.isEmpty()) {
            tableFlowSyncBoxes.put(tableConfigured.getKey(), flowsSyncBox);
        }
    }
    return tableFlowSyncBoxes;
}
Also used : Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) HashMap(java.util.HashMap) 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 85 with Table

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table in project openflowplugin by opendaylight.

the class FRMTest method addTable.

public void addTable(final TableKey tableKey, final NodeKey nodeKey) {
    addFlowCapableNode(nodeKey);
    final Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.<Flow>emptyList()).build();
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    InstanceIdentifier<Table> tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Table.class, tableKey);
    writeTx.put(LogicalDatastoreType.CONFIGURATION, tableII, table);
    assertCommit(writeTx.submit());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) Table(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Aggregations

ArrayList (java.util.ArrayList)71 BigInteger (java.math.BigInteger)63 Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)51 Test (org.junit.Test)38 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)27 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)27 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)26 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)25 List (java.util.List)25 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)25 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)23 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)22 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)22 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)20 ByteBuf (io.netty.buffer.ByteBuf)18 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)18 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)17 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)17 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)17