Search in sources :

Example 1 with MeterBandStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactory method serializeMeterBody.

private void serializeMeterBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyMeterCase meterCase = (MultipartReplyMeterCase) body;
    MultipartReplyMeter meter = meterCase.getMultipartReplyMeter();
    for (MeterStats meterStats : meter.getMeterStats()) {
        ByteBuf meterStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        meterStatsBuff.writeInt(meterStats.getMeterId().getValue().intValue());
        meterStatsBuff.writeInt(EncodeConstants.EMPTY_LENGTH);
        meterStatsBuff.writeZero(METER_PADDING);
        meterStatsBuff.writeInt(meterStats.getFlowCount().intValue());
        meterStatsBuff.writeLong(meterStats.getPacketInCount().longValue());
        meterStatsBuff.writeLong(meterStats.getByteInCount().longValue());
        meterStatsBuff.writeInt(meterStats.getDurationSec().intValue());
        meterStatsBuff.writeInt(meterStats.getDurationNsec().intValue());
        for (MeterBandStats meterBandStats : meterStats.getMeterBandStats()) {
            meterStatsBuff.writeLong(meterBandStats.getPacketBandCount().longValue());
            meterStatsBuff.writeLong(meterBandStats.getByteBandCount().longValue());
        }
        meterStatsBuff.setInt(METER_LENGTH_INDEX, meterStatsBuff.readableBytes());
        outBuffer.writeBytes(meterStatsBuff);
    }
}
Also used : MeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats) MultipartReplyMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter) MeterBandStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats) MultipartReplyMeterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with MeterBandStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method createMeterBandStats.

private static List<MeterBandStats> createMeterBandStats() {
    MeterBandStatsBuilder builder = new MeterBandStatsBuilder();
    builder.setPacketBandCount(BigInteger.valueOf(1L));
    builder.setByteBandCount(BigInteger.valueOf(1L));
    List<MeterBandStats> list = new ArrayList<>();
    list.add(builder.build());
    return list;
}
Also used : MeterBandStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats) MeterBandStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder) ArrayList(java.util.ArrayList)

Example 3 with MeterBandStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats 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();
}
Also used : MeterBandStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats) ArrayList(java.util.ArrayList) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId) MeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats) MeterBandStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder) MeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder) BigInteger(java.math.BigInteger) MultipartReplyMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder) MultipartReplyMeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder)

Example 4 with MeterBandStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats 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());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats) MultipartReplyMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter) MeterBandStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats) MultipartReplyMeterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MultipartReplyMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder) ByteBuf(io.netty.buffer.ByteBuf) MultipartReplyMeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder) Test(org.junit.Test)

Example 5 with MeterBandStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats in project openflowplugin by opendaylight.

the class MeterStatsResponseConvertor method convert.

@Override
public List<MeterStats> convert(List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats> source, VersionConvertorData data) {
    List<MeterStats> convertedSALMeters = new ArrayList<>();
    for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats meterStats : source) {
        // Convert MeterStats message from library to MD SAL defined MeterStats
        MeterStatsBuilder salMeterStats = new MeterStatsBuilder();
        salMeterStats.setByteInCount(new Counter64(meterStats.getByteInCount()));
        DurationBuilder time = new DurationBuilder();
        time.setSecond(new Counter32(meterStats.getDurationSec()));
        time.setNanosecond(new Counter32(meterStats.getDurationNsec()));
        salMeterStats.setDuration(time.build());
        salMeterStats.setFlowCount(new Counter32(meterStats.getFlowCount()));
        salMeterStats.setMeterId(new MeterId(meterStats.getMeterId().getValue()));
        salMeterStats.setPacketInCount(new Counter64(meterStats.getPacketInCount()));
        salMeterStats.setKey(new MeterStatsKey(salMeterStats.getMeterId()));
        List<MeterBandStats> allMeterBandStats = meterStats.getMeterBandStats();
        MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
        List<BandStat> listAllBandStats = new ArrayList<>();
        int bandKey = 0;
        for (MeterBandStats meterBandStats : allMeterBandStats) {
            BandStatBuilder bandStatBuilder = new BandStatBuilder();
            bandStatBuilder.setByteBandCount(new Counter64(meterBandStats.getByteBandCount()));
            bandStatBuilder.setPacketBandCount(new Counter64(meterBandStats.getPacketBandCount()));
            BandId bandId = new BandId((long) bandKey);
            bandStatBuilder.setKey(new BandStatKey(bandId));
            bandStatBuilder.setBandId(bandId);
            bandKey++;
            listAllBandStats.add(bandStatBuilder.build());
        }
        meterBandStatsBuilder.setBandStat(listAllBandStats);
        salMeterStats.setMeterBandStats(meterBandStatsBuilder.build());
        convertedSALMeters.add(salMeterStats.build());
    }
    return convertedSALMeters;
}
Also used : ArrayList(java.util.ArrayList) MeterStatsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) MeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder) BandStatKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStatKey) MeterBandStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats) BandStat(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) MeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats) MeterBandStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder) BandId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId) BandStatBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStatBuilder) DurationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder)

Aggregations

MeterBandStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats)6 ArrayList (java.util.ArrayList)4 MeterStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats)3 MeterBandStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder)3 ByteBuf (io.netty.buffer.ByteBuf)2 MeterStats (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats)2 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId)2 MultipartReplyMeterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase)2 MultipartReplyMeterCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCaseBuilder)2 MultipartReplyMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter)2 MultipartReplyMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeterBuilder)2 MeterStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder)2 BigInteger (java.math.BigInteger)1 Test (org.junit.Test)1 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)1 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)1 BandId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId)1 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)1 DurationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder)1 MeterBandStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder)1