Search in sources :

Example 31 with Meter

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

the class SyncPlanPushStrategyIncrementalImpl method addMissingMeters.

ListenableFuture<RpcResult<Void>> addMissingMeters(final NodeId nodeId, final InstanceIdentifier<FlowCapableNode> nodeIdent, final ItemSyncBox<Meter> syncBox, final SyncCrudCounters counters) {
    if (syncBox.isEmpty()) {
        LOG.trace("no meters configured for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }
    final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();
    final List<ListenableFuture<RpcResult<AddMeterOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateMeterOutput>>> allUpdateResults = new ArrayList<>();
    for (Meter meter : syncBox.getItemsToPush()) {
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class, meter.getKey());
        LOG.debug("adding meter {} - absent on device {}", meter.getMeterId(), nodeId);
        allResults.add(JdkFutureAdapters.listenInPoolThread(meterForwarder.add(meterIdent, meter, nodeIdent)));
        meterCrudCounts.incAdded();
    }
    for (ItemSyncBox.ItemUpdateTuple<Meter> meterTuple : syncBox.getItemsToUpdate()) {
        final Meter existingMeter = meterTuple.getOriginal();
        final Meter updated = meterTuple.getUpdated();
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class, updated.getKey());
        LOG.trace("meter {} - needs update on device {}", updated.getMeterId(), nodeId);
        allUpdateResults.add(JdkFutureAdapters.listenInPoolThread(meterForwarder.update(meterIdent, existingMeter, updated, nodeIdent)));
        meterCrudCounts.incUpdated();
    }
    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(Futures.allAsList(allResults), ReconcileUtil.<AddMeterOutput>createRpcResultCondenser("meter add"), MoreExecutors.directExecutor());
    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(Futures.allAsList(allUpdateResults), ReconcileUtil.<UpdateMeterOutput>createRpcResultCondenser("meter update"), MoreExecutors.directExecutor());
    return Futures.transform(Futures.allAsList(singleVoidUpdateResult, singleVoidAddResult), ReconcileUtil.<Void>createRpcResultCondenser("meter add/update"), MoreExecutors.directExecutor());
}
Also used : ItemSyncBox(org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox) UpdateMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) CrudCounts(org.opendaylight.openflowplugin.applications.frsync.util.CrudCounts) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) AddMeterOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput) ListenableFuture(com.google.common.util.concurrent.ListenableFuture)

Example 32 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter 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 33 with Meter

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

the class FlowCapableNodeLookups method wrapMetersToMap.

@Nonnull
public static Map<MeterId, Meter> wrapMetersToMap(@Nullable final List<Meter> meters) {
    final Map<MeterId, Meter> meterMap;
    if (meters == null) {
        meterMap = Collections.emptyMap();
    } else {
        LOG.trace("meters found: {}", meters.size());
        meterMap = new HashMap<>();
        for (Meter meter : meters) {
            meterMap.put(meter.getMeterId(), meter);
        }
    }
    return meterMap;
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) Nonnull(javax.annotation.Nonnull)

Example 34 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter 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 35 with Meter

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

the class MultipartReplyMessageFactory method serializeMeterConfigBody.

private void serializeMeterConfigBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyMeterConfigCase meterConfigCase = (MultipartReplyMeterConfigCase) body;
    MultipartReplyMeterConfig meter = meterConfigCase.getMultipartReplyMeterConfig();
    for (MeterConfig meterConfig : meter.getMeterConfig()) {
        ByteBuf meterConfigBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        meterConfigBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        writeMeterFlags(meterConfig.getFlags(), meterConfigBuff);
        meterConfigBuff.writeInt(meterConfig.getMeterId().getValue().intValue());
        for (Bands currentBand : meterConfig.getBands()) {
            MeterBand meterBand = currentBand.getMeterBand();
            if (meterBand instanceof MeterBandDropCase) {
                MeterBandDropCase dropBandCase = (MeterBandDropCase) meterBand;
                MeterBandDrop dropBand = dropBandCase.getMeterBandDrop();
                writeBandCommonFields(dropBand, meterConfigBuff);
            } else if (meterBand instanceof MeterBandDscpRemarkCase) {
                MeterBandDscpRemarkCase dscpRemarkBandCase = (MeterBandDscpRemarkCase) meterBand;
                MeterBandDscpRemark dscpRemarkBand = dscpRemarkBandCase.getMeterBandDscpRemark();
                writeBandCommonFields(dscpRemarkBand, meterConfigBuff);
            } else if (meterBand instanceof MeterBandExperimenterCase) {
                MeterBandExperimenterCase experimenterBandCase = (MeterBandExperimenterCase) meterBand;
                MeterBandExperimenter experimenterBand = experimenterBandCase.getMeterBandExperimenter();
                writeBandCommonFields(experimenterBand, meterConfigBuff);
            }
        }
        meterConfigBuff.setShort(METER_CONFIG_LENGTH_INDEX, meterConfigBuff.readableBytes());
        outBuffer.writeBytes(meterConfigBuff);
    }
}
Also used : MeterBand(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.MeterBand) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands) MeterBandExperimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.experimenter._case.MeterBandExperimenter) MeterBandDrop(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDrop) MultipartReplyMeterConfigCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigCase) MultipartReplyMeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig) MeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfig) ByteBuf(io.netty.buffer.ByteBuf) MeterBandDscpRemarkCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCase) MeterBandDscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemark) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) MultipartReplyMeterConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfig) MeterBandDropCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCase)

Aggregations

Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)24 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)15 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)14 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)14 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)13 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder)11 MeterRef (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef)10 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)9 ByteBuf (io.netty.buffer.ByteBuf)6 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)6 StaleMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter)6 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)6 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)6 StaleMeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey)5 MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)4 StaleMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterBuilder)4