use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput in project openflowplugin by opendaylight.
the class MeterConvertorTest method testMeterModCommandConvertorNoValidBandData.
@Test
public void testMeterModCommandConvertorNoValidBandData() {
// / DROP Band
MeterBandHeaderBuilder meterBandHeaderBuilder = new MeterBandHeaderBuilder();
MeterBandTypesBuilder meterBandTypesB = new MeterBandTypesBuilder();
MeterBandType bandFlag = new MeterBandType(true, false, false);
// _ofpmbtDrop
meterBandTypesB.setFlags(bandFlag);
meterBandHeaderBuilder.setMeterBandTypes(meterBandTypesB.build());
final MeterBandHeader meterBH = meterBandHeaderBuilder.build();
// DSCP Mark
MeterBandTypesBuilder meterBandTypesB1 = new MeterBandTypesBuilder();
MeterBandType bandFlag1 = new MeterBandType(false, true, false);
meterBandTypesB1.setFlags(bandFlag1);
DscpRemarkBuilder dscp = new DscpRemarkBuilder();
dscp.setDscpRemarkBurstSize(11L);
dscp.setDscpRemarkRate(21L);
dscp.setPrecLevel((short) 1);
DscpRemark dscpRemark = dscp.build();
MeterBandHeaderBuilder meterBandHeaderBuilder1 = new MeterBandHeaderBuilder();
meterBandHeaderBuilder1.setBandType(dscpRemark);
meterBandHeaderBuilder1.setMeterBandTypes(meterBandTypesB1.build());
final MeterBandHeader meterBH1 = meterBandHeaderBuilder1.build();
// Experimental
ExperimenterBuilder exp = new ExperimenterBuilder();
exp.setExperimenterBurstSize(12L);
exp.setExperimenterRate(22L);
exp.setExperimenter(23L);
Experimenter experimenter = exp.build();
MeterBandHeaderBuilder meterBandHeaderBuilder2 = new MeterBandHeaderBuilder();
meterBandHeaderBuilder2.setBandType(experimenter);
MeterBandTypesBuilder meterBandTypesB2 = new MeterBandTypesBuilder();
meterBandHeaderBuilder2.setMeterBandTypes(meterBandTypesB2.build());
MeterBandHeader meterBH2 = meterBandHeaderBuilder2.build();
List<MeterBandHeader> meterBandList = new ArrayList<>();
meterBandList.add(0, meterBH);
meterBandList.add(1, meterBH1);
meterBandList.add(2, meterBH2);
// Constructing List of Bands
MeterBandHeadersBuilder meterBandHeadersBuilder = new MeterBandHeadersBuilder();
meterBandHeadersBuilder.setMeterBandHeader(meterBandList);
MeterBandHeaders meterBandHeaders = meterBandHeadersBuilder.build();
AddMeterInputBuilder addMeterFromSAL = new AddMeterInputBuilder();
// MeterBands
addMeterFromSAL.setMeterBandHeaders(meterBandHeaders);
// NodeKey key = new NodeKey(new NodeId("24"));
// InstanceIdentifier<Node> path =
// InstanceIdentifier.builder().node(Nodes.class).node(Node.class,
// key).build();
addMeterFromSAL.setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(10L));
MeterFlags flagV = new MeterFlags(true, true, true, true);
addMeterFromSAL.setFlags(flagV);
AddMeterInput meterInputCommand = addMeterFromSAL.build();
MeterModInputBuilder outMeterModInput = convert(meterInputCommand, new VersionConvertorData((short) 0X4));
assertEquals(MeterModCommand.OFPMCADD, outMeterModInput.getCommand());
assertTrue(outMeterModInput.getFlags().isOFPMFBURST());
assertEquals(Long.valueOf(10L), outMeterModInput.getMeterId().getValue());
// BandInformation starts here:
List<Bands> bands = outMeterModInput.getBands();
for (Bands currentBand : bands) {
MeterBand meterBand = currentBand.getMeterBand();
if (meterBand instanceof MeterBandDropCase) {
assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDROP, ((MeterBandDropCase) meterBand).getMeterBandDrop().getType());
assertEquals((long) 20, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getBurstSize());
assertEquals((long) 10, (long) ((MeterBandDropCase) meterBand).getMeterBandDrop().getRate());
}
if (meterBand instanceof MeterBandDscpRemarkCase) {
assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTDSCPREMARK, ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getType());
assertEquals((long) 11, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getBurstSize());
assertEquals((long) 21, (long) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getRate());
assertEquals((short) 1, (short) ((MeterBandDscpRemarkCase) meterBand).getMeterBandDscpRemark().getPrecLevel());
}
if (meterBand instanceof MeterBandExperimenterCase) {
assertEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType.OFPMBTEXPERIMENTER, ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getType());
assertEquals((long) 12, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getBurstSize());
assertEquals((long) 22, (long) ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getRate());
ExperimenterIdMeterBand expBand = ((MeterBandExperimenterCase) meterBand).getMeterBandExperimenter().getAugmentation(ExperimenterIdMeterBand.class);
assertEquals((long) 23, (long) expBand.getExperimenter().getValue());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput in project openflowplugin by opendaylight.
the class MeterForwarderTest method testAdd.
@Test
public void testAdd() throws Exception {
Mockito.when(salMeterService.addMeter(addMeterInputCpt.capture())).thenReturn(RpcResultBuilder.success(new AddMeterOutputBuilder().setTransactionId(txId).build()).buildFuture());
final Future<RpcResult<AddMeterOutput>> addResult = meterForwarder.add(meterPath, meter, flowCapableNodePath);
Mockito.verify(salMeterService).addMeter(Matchers.<AddMeterInput>any());
Assert.assertTrue(addResult.isDone());
final RpcResult<AddMeterOutput> meterResult = addResult.get(2, TimeUnit.SECONDS);
Assert.assertTrue(meterResult.isSuccessful());
Assert.assertEquals(1, meterResult.getResult().getTransactionId().getValue().intValue());
final AddMeterInput addMeterInput = addMeterInputCpt.getValue();
Assert.assertEquals(meterPath, addMeterInput.getMeterRef().getValue());
Assert.assertEquals(nodePath, addMeterInput.getNode().getValue());
Assert.assertEquals("test-meter", addMeterInput.getMeterName());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput in project openflowplugin by opendaylight.
the class SalMeterServiceImplTest method addMeter.
private void addMeter() {
final MeterId dummyMeterId = new MeterId(DUMMY_METER_ID);
AddMeterInput addMeterInput = new AddMeterInputBuilder().setMeterId(dummyMeterId).build();
this.<AddMeterOutput>mockSuccessfulFuture();
salMeterService.addMeter(addMeterInput);
verify(mockedRequestContextStack).createRequestContext();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput 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.AddMeterInput in project openflowplugin by opendaylight.
the class SalMetersBatchServiceImplTest method testAddMetersBatch_failure.
@Test
public void testAddMetersBatch_failure() throws Exception {
Mockito.when(salMeterService.addMeter(Mockito.<AddMeterInput>any())).thenReturn(RpcResultBuilder.<AddMeterOutput>failed().withError(RpcError.ErrorType.APPLICATION, "ut-groupAddError").buildFuture());
final AddMetersBatchInput input = new AddMetersBatchInputBuilder().setNode(NODE_REF).setBarrierAfter(true).setBatchAddMeters(Lists.newArrayList(createEmptyBatchAddMeter(42L), createEmptyBatchAddMeter(43L))).build();
final Future<RpcResult<AddMetersBatchOutput>> resultFuture = salMetersBatchService.addMetersBatch(input);
Assert.assertTrue(resultFuture.isDone());
Assert.assertFalse(resultFuture.get().isSuccessful());
Assert.assertEquals(2, resultFuture.get().getResult().getBatchFailedMetersOutput().size());
Assert.assertEquals(42L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(0).getMeterId().getValue().longValue());
Assert.assertEquals(43L, resultFuture.get().getResult().getBatchFailedMetersOutput().get(1).getMeterId().getValue().longValue());
Assert.assertEquals(2, resultFuture.get().getErrors().size());
final InOrder inOrder = Mockito.inOrder(salMeterService, transactionService);
inOrder.verify(salMeterService, Mockito.times(2)).addMeter(addMeterInputCpt.capture());
final List<AddMeterInput> allValues = addMeterInputCpt.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());
}
Aggregations