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());
}
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());
}
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;
}
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;
}
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);
}
}
Aggregations