use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testFlowBody.
private static void testFlowBody(MultipartReplyBody body, ByteBuf output) {
MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
FlowStats flowStats = flow.getFlowStats().get(0);
Assert.assertEquals("Wrong length", 176, output.readShort());
Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte());
output.skipBytes(1);
Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt());
Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt());
Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort());
Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort());
Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort());
output.skipBytes(6);
Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong());
Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong());
Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong());
Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort());
output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
short fieldAndMask = output.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt());
Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
fieldAndMask = output.readUnsignedByte();
Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte());
output.skipBytes(7);
Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte());
output.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
output.skipBytes(4);
byte[] actual = new byte[8];
output.readBytes(actual);
Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual));
actual = new byte[8];
output.readBytes(actual);
Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual));
Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
output.skipBytes(4);
Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt());
Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort());
output.skipBytes(4);
Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort());
Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort());
Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt());
Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort());
output.skipBytes(6);
Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte());
output.skipBytes(3);
Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort());
Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
output.skipBytes(4);
Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort());
output.skipBytes(2);
Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort());
Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
output.skipBytes(4);
Assert.assertTrue("Not all data were read", output.readableBytes() == 0);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testMeterFeaturesSerialize.
@Test
public void testMeterFeaturesSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(11));
final MultipartReplyMeterFeaturesCaseBuilder meterFeaturesCase = new MultipartReplyMeterFeaturesCaseBuilder();
MultipartReplyMeterFeaturesBuilder meterFeatures = new MultipartReplyMeterFeaturesBuilder();
meterFeatures.setMaxMeter(1L);
meterFeatures.setBandTypes(new MeterBandTypeBitmap(true, false));
meterFeatures.setCapabilities(new MeterFlags(true, false, true, false));
meterFeatures.setMaxBands((short) 1);
meterFeatures.setMaxColor((short) 1);
meterFeaturesCase.setMultipartReplyMeterFeatures(meterFeatures.build());
builder.setMultipartReplyBody(meterFeaturesCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 30);
Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERFEATURES.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
MultipartReplyMeterFeaturesCase body = (MultipartReplyMeterFeaturesCase) message.getMultipartReplyBody();
MultipartReplyMeterFeatures messageOutput = body.getMultipartReplyMeterFeatures();
Assert.assertEquals("Wrong max meter", messageOutput.getMaxMeter().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong band type", messageOutput.getBandTypes(), createMeterBandTypeBitmap(serializedBuffer.readInt()));
Assert.assertEquals("Wrong capabilities", messageOutput.getCapabilities(), createMeterFlags(serializedBuffer.readShort()));
Assert.assertEquals("Wrong max bands", messageOutput.getMaxBands().shortValue(), serializedBuffer.readUnsignedByte());
Assert.assertEquals("Wrong max color", messageOutput.getMaxColor().shortValue(), serializedBuffer.readUnsignedByte());
serializedBuffer.skipBytes(2);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class MeterCase method process.
@Override
public Optional<Instruction> process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
Meter meter = source.getMeter();
MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
MeterBuilder meterBuilder = new MeterBuilder();
Long meterId = meter.getMeterId().getValue();
meterBuilder.setMeterId(meterId);
meterCaseBuilder.setMeter(meterBuilder.build());
InstructionBuilder instructionBuilder = new InstructionBuilder();
instructionBuilder.setInstructionChoice(meterCaseBuilder.build());
return Optional.of(instructionBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.
the class MeterForwarder method update.
@Override
public Future<RpcResult<UpdateMeterOutput>> update(final InstanceIdentifier<Meter> identifier, final Meter original, final Meter update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
LOG.trace("Received the Meter UPDATE request [Tbl id, node Id {} {} {}", identifier, nodeIdent, update);
final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder();
builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
builder.setMeterRef(new MeterRef(identifier));
builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build());
builder.setOriginalMeter(new OriginalMeterBuilder(original).build());
return salMeterService.updateMeter(builder.build());
}
Aggregations