Search in sources :

Example 36 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project openflowplugin by opendaylight.

the class ReconcileUtil method resolveAndDivideGroupDiffs.

/**
 * Returns a list of safe synchronization steps.
 *
 * @param nodeId             target node
 * @param installedGroupsArg groups resent on device
 * @param pendingGroups      groups configured for device
 * @param gatherUpdates      check content of pending item if present on device (and create update task eventually)
 * @return list of safe synchronization steps
 */
public static List<ItemSyncBox<Group>> resolveAndDivideGroupDiffs(final NodeId nodeId, final Map<Long, Group> installedGroupsArg, final Collection<Group> pendingGroups, final boolean gatherUpdates) {
    final Map<Long, Group> installedGroups = new HashMap<>(installedGroupsArg);
    final List<ItemSyncBox<Group>> plan = new ArrayList<>();
    while (!Iterables.isEmpty(pendingGroups)) {
        final ItemSyncBox<Group> stepPlan = new ItemSyncBox<>();
        final Iterator<Group> iterator = pendingGroups.iterator();
        final Map<Long, Group> installIncrement = new HashMap<>();
        while (iterator.hasNext()) {
            final Group group = iterator.next();
            final Group existingGroup = installedGroups.get(group.getGroupId().getValue());
            if (existingGroup != null) {
                if (!gatherUpdates) {
                    iterator.remove();
                } else {
                    // check buckets and eventually update
                    if (group.equals(existingGroup)) {
                        iterator.remove();
                    } else {
                        if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                            iterator.remove();
                            LOG.trace("Group {} on device {} differs - planned for update", group.getGroupId(), nodeId);
                            stepPlan.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingGroup, group));
                        }
                    }
                }
            } else if (checkGroupPrecondition(installedGroups.keySet(), group)) {
                iterator.remove();
                installIncrement.put(group.getGroupId().getValue(), group);
                stepPlan.getItemsToPush().add(group);
            }
        }
        if (!stepPlan.isEmpty()) {
            // atomic update of installed flows in order to keep plan portions clean of local group dependencies
            installedGroups.putAll(installIncrement);
            plan.add(stepPlan);
        } else if (!pendingGroups.isEmpty()) {
            LOG.warn("Failed to resolve and divide groups into preconditions-match based ordered plan: {}, " + "resolving stuck at level {}", nodeId.getValue(), plan.size());
            throw new IllegalStateException("Failed to resolve and divide groups when matching preconditions");
        }
    }
    return plan;
}
Also used : Group(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 37 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update 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 38 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project openflowplugin by opendaylight.

the class ReconcileUtil method resolveMeterDiffs.

/**
 * Resolves meter differences.
 *
 * @param nodeId              target node
 * @param meterOperationalMap meters present on device
 * @param metersConfigured    meters configured for device
 * @param gatherUpdates       check content of pending item if present on device (and create update task eventually)
 * @return synchronization box
 */
public static ItemSyncBox<Meter> resolveMeterDiffs(final NodeId nodeId, final Map<MeterId, Meter> meterOperationalMap, final List<Meter> metersConfigured, final boolean gatherUpdates) {
    LOG.trace("resolving meters for {}", nodeId.getValue());
    final ItemSyncBox<Meter> syncBox = new ItemSyncBox<>();
    for (Meter meter : metersConfigured) {
        final Meter existingMeter = meterOperationalMap.get(meter.getMeterId());
        if (existingMeter == null) {
            syncBox.getItemsToPush().add(meter);
        } else {
            // compare content and eventually update
            if (gatherUpdates && !meter.equals(existingMeter)) {
                syncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingMeter, meter));
            }
        }
    }
    return syncBox;
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)

Example 39 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project openflowplugin by opendaylight.

the class FlatBatchFlowAdapters method adaptFlatBatchUpdateFlow.

/**
 * Adapt flat batch update flow.
 * @param planStep batch step containing changes of the same type
 * @param node     pointer for RPC routing
 * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
 * .opendaylight.flows.service.rev160314.SalFlowsBatchService#updateFlowsBatch(UpdateFlowsBatchInput)}
 */
public static UpdateFlowsBatchInput adaptFlatBatchUpdateFlow(final BatchPlanStep planStep, final NodeRef node) {
    final List<BatchUpdateFlows> batchFlows = new ArrayList<>();
    for (FlatBatchUpdateFlow batchUpdateFlow : planStep.<FlatBatchUpdateFlow>getTaskBag()) {
        final BatchUpdateFlows updateFlows = new BatchUpdateFlowsBuilder(batchUpdateFlow).build();
        batchFlows.add(updateFlows);
    }
    return new UpdateFlowsBatchInputBuilder().setBarrierAfter(planStep.isBarrierAfter()).setNode(node).setBatchUpdateFlows(batchFlows).build();
}
Also used : UpdateFlowsBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.UpdateFlowsBatchInputBuilder) BatchUpdateFlowsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.update.flows.batch.input.BatchUpdateFlowsBuilder) ArrayList(java.util.ArrayList) FlatBatchUpdateFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlow) BatchUpdateFlows(org.opendaylight.yang.gen.v1.urn.opendaylight.flows.service.rev160314.update.flows.batch.input.BatchUpdateFlows)

Example 40 with Update

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update in project openflowplugin by opendaylight.

the class FlatBatchMeterAdapters method adaptFlatBatchUpdateMeter.

/**
 * Adapt flat batch update meter.
 * @param planStep batch step containing changes of the same type
 * @param node     pointer for RPC routing
 * @return input suitable for {@link org.opendaylight.yang.gen.v1.urn
 * .opendaylight.meters.service.rev160316.SalMetersBatchService#updateMetersBatch(UpdateMetersBatchInput)}
 */
public static UpdateMetersBatchInput adaptFlatBatchUpdateMeter(final BatchPlanStep planStep, final NodeRef node) {
    final List<BatchUpdateMeters> batchMeters = new ArrayList<>();
    for (FlatBatchUpdateMeter batchUpdateMeter : planStep.<FlatBatchUpdateMeter>getTaskBag()) {
        final BatchUpdateMeters updateMeters = new BatchUpdateMetersBuilder(batchUpdateMeter).build();
        batchMeters.add(updateMeters);
    }
    return new UpdateMetersBatchInputBuilder().setBarrierAfter(planStep.isBarrierAfter()).setNode(node).setBatchUpdateMeters(batchMeters).build();
}
Also used : BatchUpdateMeters(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.update.meters.batch.input.BatchUpdateMeters) FlatBatchUpdateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter) BatchUpdateMetersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.update.meters.batch.input.BatchUpdateMetersBuilder) ArrayList(java.util.ArrayList) UpdateMetersBatchInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meters.service.rev160316.UpdateMetersBatchInputBuilder)

Aggregations

ArrayList (java.util.ArrayList)120 Test (org.junit.Test)85 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)71 Update (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Update)64 ExecutionException (java.util.concurrent.ExecutionException)56 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)47 List (java.util.List)46 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)38 Logger (org.slf4j.Logger)38 LoggerFactory (org.slf4j.LoggerFactory)38 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)37 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)35 Collections (java.util.Collections)35 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)35 Uint32 (org.opendaylight.yangtools.yang.common.Uint32)34 Map (java.util.Map)33 Inject (javax.inject.Inject)32 Singleton (javax.inject.Singleton)32 BigInteger (java.math.BigInteger)31 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)29