use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput in project openflowplugin by opendaylight.
the class MeterForwarderTest method testRemove.
@Test
public void testRemove() throws Exception {
Mockito.when(salMeterService.removeMeter(removeMeterInputCpt.capture())).thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().setTransactionId(txId).build()).buildFuture());
Meter removeMeter = new MeterBuilder(meter).build();
final Future<RpcResult<RemoveMeterOutput>> removeResult = meterForwarder.remove(meterPath, removeMeter, flowCapableNodePath);
Mockito.verify(salMeterService).removeMeter(Matchers.<RemoveMeterInput>any());
Assert.assertTrue(removeResult.isDone());
final RpcResult<RemoveMeterOutput> meterResult = removeResult.get(2, TimeUnit.SECONDS);
Assert.assertTrue(meterResult.isSuccessful());
Assert.assertEquals(1, meterResult.getResult().getTransactionId().getValue().intValue());
final RemoveMeterInput removeMeterInput = removeMeterInputCpt.getValue();
Assert.assertEquals(meterPath, removeMeterInput.getMeterRef().getValue());
Assert.assertEquals(nodePath, removeMeterInput.getNode().getValue());
Assert.assertEquals("test-meter", removeMeterInput.getMeterName());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput in project openflowplugin by opendaylight.
the class MeterListenerTest method removeMeterTest.
@Test
public void removeMeterTest() throws Exception {
addFlowCapableNode(NODE_KEY);
MeterKey meterKey = new MeterKey(new MeterId((long) 2000));
InstanceIdentifier<Meter> meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).child(Meter.class, meterKey);
Meter meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_one").build();
WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, meterII, meter);
assertCommit(writeTx.submit());
SalMeterServiceMock salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
List<AddMeterInput> addMeterCalls = salMeterService.getAddMeterCalls();
assertEquals(1, addMeterCalls.size());
assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue());
writeTx = getDataBroker().newWriteOnlyTransaction();
writeTx.delete(LogicalDatastoreType.CONFIGURATION, meterII);
assertCommit(writeTx.submit());
salMeterService = (SalMeterServiceMock) forwardingRulesManager.getSalMeterService();
List<RemoveMeterInput> removeMeterCalls = salMeterService.getRemoveMeterCalls();
assertEquals(1, removeMeterCalls.size());
assertEquals("DOM-1", removeMeterCalls.get(0).getTransactionUri().getValue());
assertEquals(meterII, removeMeterCalls.get(0).getMeterRef().getValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testRemoveMetersBatch_success.
@Test
public void testRemoveMetersBatch_success() throws Exception {
Mockito.when(salMeterService.removeMeter(Mockito.<RemoveMeterInput>any())).thenReturn(RpcResultBuilder.success(new RemoveMeterOutputBuilder().build()).buildFuture());
final RemoveMetersBatchInput input = new RemoveMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchRemoveMeters(Lists.newArrayList(createEmptyBatchRemoveMeter(42L), createEmptyBatchRemoveMeter(43L))).build();
final Future<RpcResult<RemoveMetersBatchOutput>> resultFuture = salMetersBatchService.removeMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertTrue(resultFuture.get().isSuccessful());
final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
inOrder.verify(salMeterService, Mockito.times(2)).removeMeter(removeMeterInputCpt.capture());
final List<RemoveMeterInput> allValues = removeMeterInputCpt.getAllValues();
Assert.assertEquals(2, allValues.size());
Assert.assertEquals(42L, allValues.get(0).getMeterId().getValue().longValue());
Assert.assertEquals(43L, allValues.get(1).getMeterId().getValue().longValue());
inOrder.verify(transactionService).sendBarrier(Matchers.<SendBarrierInput>any());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImpl method removeMetersBatch.
@Override
public Future<RpcResult<RemoveMetersBatchOutput>> removeMetersBatch(final RemoveMetersBatchInput input) {
LOG.trace("Removing meters @ {} : {}", PathUtil.extractNodeId(input.getNode()), input.getBatchRemoveMeters().size());
final ArrayList<ListenableFuture<RpcResult<RemoveMeterOutput>>> resultsLot = new ArrayList<>();
for (BatchRemoveMeters addMeter : input.getBatchRemoveMeters()) {
final RemoveMeterInput removeMeterInput = new RemoveMeterInputBuilder(addMeter).setMeterRef(createMeterRef(input.getNode(), addMeter)).setNode(input.getNode()).build();
resultsLot.add(JdkFutureAdapters.listenInPoolThread(salMeterService.removeMeter(removeMeterInput)));
}
final ListenableFuture<RpcResult<List<BatchFailedMetersOutput>>> commonResult = Futures.transform(Futures.allAsList(resultsLot), MeterUtil.<RemoveMeterOutput>createCumulativeFunction(input.getBatchRemoveMeters()), MoreExecutors.directExecutor());
ListenableFuture<RpcResult<RemoveMetersBatchOutput>> removeMetersBulkFuture = Futures.transform(commonResult, MeterUtil.METER_REMOVE_TRANSFORM, MoreExecutors.directExecutor());
if (input.isBarrierAfter()) {
removeMetersBulkFuture = BarrierUtil.chainBarrier(removeMetersBulkFuture, input.getNode(), transactionService, MeterUtil.METER_REMOVE_COMPOSING_TRANSFORM);
}
return removeMetersBulkFuture;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput in project openflowplugin by opendaylight.
the class MeterConvertor method convert.
@Override
public MeterModInputBuilder convert(Meter source, VersionConvertorData data) {
MeterModInputBuilder meterModInputBuilder = new MeterModInputBuilder();
List<Bands> bands = new ArrayList<>();
if (source instanceof AddMeterInput) {
meterModInputBuilder.setCommand(MeterModCommand.OFPMCADD);
} else if (source instanceof RemoveMeterInput) {
meterModInputBuilder.setCommand(MeterModCommand.OFPMCDELETE);
} else if (source instanceof UpdatedMeter) {
meterModInputBuilder.setCommand(MeterModCommand.OFPMCMODIFY);
}
meterModInputBuilder.setMeterId(new MeterId(source.getMeterId().getValue()));
if (null != source.getFlags()) {
meterModInputBuilder.setFlags(new MeterFlags(source.getFlags().isMeterBurst(), source.getFlags().isMeterKbps(), source.getFlags().isMeterPktps(), source.getFlags().isMeterStats()));
} else {
/*
* As per 0F1.3.1,The rate field indicates the rate value above
* which the corresponding band may apply to packets (see 5.7.1).
* The rate value is in kilobit per seconds, unless the flags eld
* includes OFPMF_PKTPS, in which case the rate is in packets per
* seconds.
*/
meterModInputBuilder.setFlags(new MeterFlags(false, false, true, false));
}
if (source.getMeterBandHeaders() != null) {
getBandsFromSAL(source.getMeterBandHeaders(), bands);
meterModInputBuilder.setBands(bands);
} else {
LOG.error("For this meter Id" + source.getMeterId().getValue() + ",no associated band data found!");
}
meterModInputBuilder.setVersion(data.getVersion());
return meterModInputBuilder;
}
Aggregations