use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MeterStatisticsToNotificationTransformer method transformToNotification.
/**
* Transform statistics to notification.
*
* @param mpReplyList raw multipart response from device
* @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId emulated transaction Id
* @param convertorExecutor convertor executor
* @return notification containing flow stats
*/
public static MeterStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList, final DeviceInfo deviceInfo, final OpenflowVersion ofVersion, final TransactionId emulatedTxId, final ConvertorExecutor convertorExecutor) {
VersionConvertorData data = new VersionConvertorData(deviceInfo.getVersion());
MeterStatisticsUpdatedBuilder notification = new MeterStatisticsUpdatedBuilder();
notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
notification.setMeterStats(new ArrayList<>());
for (MultipartReply mpReply : mpReplyList) {
MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody();
MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter();
final Optional<List<MeterStats>> meterStatsList = convertorExecutor.convert(replyBody.getMeterStats(), data);
meterStatsList.ifPresent(meterStats -> notification.getMeterStats().addAll(meterStats));
}
return notification.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MeterDirectStatisticsService method buildReply.
@Override
protected GetMeterStatisticsOutput buildReply(List<MultipartReply> input, boolean success) {
final List<MeterStats> meterStats = new ArrayList<>();
if (success) {
for (final MultipartReply mpReply : input) {
final MultipartReplyMeterCase caseBody = (MultipartReplyMeterCase) mpReply.getMultipartReplyBody();
final MultipartReplyMeter replyBody = caseBody.getMultipartReplyMeter();
final Optional<List<MeterStats>> meterStatsList = getConvertorExecutor().convert(replyBody.getMeterStats(), data);
meterStatsList.ifPresent(meterStats::addAll);
}
}
return new GetMeterStatisticsOutputBuilder().setMeterStats(meterStats).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method createMeterStats.
private static List<MeterStats> createMeterStats() {
MeterStatsBuilder builder = new MeterStatsBuilder();
builder.setMeterId(new MeterId(1L));
builder.setFlowCount(1L);
builder.setPacketInCount(BigInteger.valueOf(1L));
builder.setByteInCount(BigInteger.valueOf(1L));
builder.setDurationSec(1L);
builder.setDurationNsec(1L);
builder.setMeterBandStats(createMeterBandStats());
List<MeterStats> list = new ArrayList<>();
list.add(builder.build());
return list;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactory method setMeter.
private static MultipartReplyMeterCase setMeter(final ByteBuf input) {
MultipartReplyMeterCaseBuilder caseBuilder = new MultipartReplyMeterCaseBuilder();
MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder();
List<MeterStats> meterStatsList = new ArrayList<>();
while (input.readableBytes() > 0) {
MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
meterStatsBuilder.setMeterId(new MeterId(input.readUnsignedInt()));
final int meterStatsBodyLength = input.readUnsignedShort();
input.skipBytes(PADDING_IN_METER_STATS_HEADER);
meterStatsBuilder.setFlowCount(input.readUnsignedInt());
byte[] packetInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetInCount);
meterStatsBuilder.setPacketInCount(new BigInteger(1, packetInCount));
byte[] byteInCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteInCount);
meterStatsBuilder.setByteInCount(new BigInteger(1, byteInCount));
meterStatsBuilder.setDurationSec(input.readUnsignedInt());
meterStatsBuilder.setDurationNsec(input.readUnsignedInt());
int actualLength = METER_BODY_LENGTH;
List<MeterBandStats> meterBandStatsList = new ArrayList<>();
while (actualLength < meterStatsBodyLength) {
MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
byte[] packetBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(packetBandCount);
meterBandStatsBuilder.setPacketBandCount(new BigInteger(1, packetBandCount));
byte[] byteBandCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
input.readBytes(byteBandCount);
meterBandStatsBuilder.setByteBandCount(new BigInteger(1, byteBandCount));
meterBandStatsList.add(meterBandStatsBuilder.build());
actualLength += METER_BAND_STATS_LENGTH;
}
meterStatsBuilder.setMeterBandStats(meterBandStatsList);
meterStatsList.add(meterStatsBuilder.build());
}
builder.setMeterStats(meterStatsList);
caseBuilder.setMultipartReplyMeter(builder.build());
return caseBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.
the class MultipartReplyMessageFactoryTest method testMeterSerialize.
@Test
public void testMeterSerialize() throws Exception {
MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
builder.setFlags(new MultipartRequestFlags(true));
builder.setType(MultipartType.forValue(9));
MultipartReplyMeterCaseBuilder meterCase = new MultipartReplyMeterCaseBuilder();
MultipartReplyMeterBuilder meter = new MultipartReplyMeterBuilder();
meter.setMeterStats(createMeterStats());
meterCase.setMultipartReplyMeter(meter.build());
builder.setMultipartReplyBody(meterCase.build());
MultipartReplyMessage message = builder.build();
ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
factory.serialize(message, serializedBuffer);
BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 74);
Assert.assertEquals("Wrong type", MultipartType.OFPMPMETER.getIntValue(), serializedBuffer.readShort());
Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
serializedBuffer.skipBytes(PADDING);
MultipartReplyMeterCase body = (MultipartReplyMeterCase) message.getMultipartReplyBody();
MultipartReplyMeter messageOutput = body.getMultipartReplyMeter();
MeterStats meterStats = messageOutput.getMeterStats().get(0);
Assert.assertEquals("Wrong meterId", meterStats.getMeterId().getValue().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong len", 58, serializedBuffer.readInt());
serializedBuffer.skipBytes(6);
Assert.assertEquals("Wrong flow count", meterStats.getFlowCount().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong packet in count", meterStats.getPacketInCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong byte in count", meterStats.getByteInCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong duration sec", meterStats.getDurationSec().intValue(), serializedBuffer.readInt());
Assert.assertEquals("Wrong duration nsec", meterStats.getDurationNsec().intValue(), serializedBuffer.readInt());
MeterBandStats meterBandStats = meterStats.getMeterBandStats().get(0);
Assert.assertEquals("Wrong packet in count", meterBandStats.getPacketBandCount().longValue(), serializedBuffer.readLong());
Assert.assertEquals("Wrong byte in count", meterBandStats.getByteBandCount().longValue(), serializedBuffer.readLong());
}
Aggregations