Search in sources :

Example 1 with MeterStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.

the class MultipartReplyMeterStatsDeserializer method deserialize.

@Override
public MultipartReplyBody deserialize(ByteBuf message) {
    final MultipartReplyMeterStatsBuilder builder = new MultipartReplyMeterStatsBuilder();
    final List<MeterStats> items = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final MeterStatsBuilder itemBuilder = new MeterStatsBuilder().setMeterId(new MeterId(message.readUnsignedInt()));
        final int itemLength = message.readUnsignedShort();
        message.skipBytes(PADDING_IN_METER_STATS_HEADER);
        itemBuilder.setKey(new MeterStatsKey(itemBuilder.getMeterId())).setFlowCount(new Counter32(message.readUnsignedInt()));
        final byte[] packetCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        message.readBytes(packetCount);
        final byte[] byteCount = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
        message.readBytes(byteCount);
        itemBuilder.setPacketInCount(new Counter64(new BigInteger(1, packetCount))).setByteInCount(new Counter64(new BigInteger(1, byteCount))).setDuration(new DurationBuilder().setSecond(new Counter32(message.readUnsignedInt())).setNanosecond(new Counter32(message.readUnsignedInt())).build());
        final List<BandStat> subItems = new ArrayList<>();
        int actualLength = METER_BODY_LENGTH;
        long bandKey = 0;
        while (actualLength < itemLength) {
            final byte[] packetCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
            message.readBytes(packetCountB);
            final byte[] byteCountB = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
            message.readBytes(byteCountB);
            subItems.add(new BandStatBuilder().setBandId(new BandId(bandKey)).setKey(new BandStatKey(new BandId(bandKey))).setPacketBandCount(new Counter64(new BigInteger(1, packetCountB))).setByteBandCount(new Counter64(new BigInteger(1, byteCountB))).build());
            bandKey++;
            actualLength += METER_BAND_STATS_LENGTH;
        }
        items.add(itemBuilder.setMeterBandStats(new MeterBandStatsBuilder().setBandStat(subItems).build()).build());
    }
    return builder.setMeterStats(items).build();
}
Also used : ArrayList(java.util.ArrayList) MeterStatsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey) BandStat(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) Counter32(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32) Counter64(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64) MultipartReplyMeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterStatsBuilder) 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) MeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder) MultipartReplyMeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterStatsBuilder) BigInteger(java.math.BigInteger) BandId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId) BandStatKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStatKey) 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)

Example 2 with MeterStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.

the class MeterDirectStatisticsServiceTest method testBuildReply.

@Override
public void testBuildReply() throws Exception {
    final MultipartReply reply = mock(MultipartReply.class);
    final MultipartReplyMeterCase MeterCase = mock(MultipartReplyMeterCase.class);
    final MultipartReplyMeter meter = mock(MultipartReplyMeter.class);
    final MeterStats meterStat = new MeterStatsBuilder().setMeterId(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId(METER_NO)).setByteInCount(BigInteger.ONE).setPacketInCount(BigInteger.ONE).setDurationSec(1L).setDurationNsec(1L).setFlowCount(0L).setMeterBandStats(Collections.emptyList()).build();
    final List<MeterStats> meterStats = Collections.singletonList(meterStat);
    final List<MultipartReply> input = Collections.singletonList(reply);
    when(meter.getMeterStats()).thenReturn(meterStats);
    when(MeterCase.getMultipartReplyMeter()).thenReturn(meter);
    when(reply.getMultipartReplyBody()).thenReturn(MeterCase);
    final GetMeterStatisticsOutput output = service.buildReply(input, true);
    assertTrue(output.getMeterStats().size() > 0);
    final org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats stats = output.getMeterStats().get(0);
    assertEquals(stats.getMeterId().getValue(), METER_NO);
}
Also used : MultipartReplyMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter) MultipartReplyMeterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase) MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.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) GetMeterStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsOutput) MeterStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder)

Example 3 with MeterStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.

the class OpenflowpluginStatsTestCommandProvider method _meterStats.

public void _meterStats(CommandInterpreter ci) {
    int meterCount = 0;
    int meterStatsCount = 0;
    NodeMeterStatistics data = null;
    List<Node> nodes = getNodes();
    for (Node node2 : nodes) {
        NodeKey nodeKey = node2.getKey();
        InstanceIdentifier<FlowCapableNode> nodeRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class);
        ReadOnlyTransaction readOnlyTransaction = dataProviderService.newReadOnlyTransaction();
        FlowCapableNode node = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, nodeRef);
        if (node != null) {
            if (node.getMeter() != null) {
                List<Meter> meters = node.getMeter();
                for (Meter meter2 : meters) {
                    meterCount++;
                    MeterKey meterKey = meter2.getKey();
                    InstanceIdentifier<Meter> meterRef = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey).augmentation(FlowCapableNode.class).child(Meter.class, meterKey);
                    Meter meter = TestProviderTransactionUtil.getDataObject(readOnlyTransaction, meterRef);
                    if (meter != null) {
                        data = meter.getAugmentation(NodeMeterStatistics.class);
                        if (null != data) {
                            meterStatsCount++;
                        }
                    }
                }
            }
        }
    }
    if (meterCount == meterStatsCount) {
        LOG.debug("---------------------------meterStats - Success-------------------------------------");
    } else {
        LOG.debug("----------------------------meterStats - Failed-------------------------------------");
        LOG.debug("System fetchs stats data in 50 seconds interval, so pls wait and try again.");
    }
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) NodeMeterStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)

Example 4 with MeterStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats in project openflowplugin by opendaylight.

the class MeterStatsResponseConvertorTest method testToSALMeterStatsList.

@Test
public /**
 * Test of basic mapping functionality of {@link MeterStatsResponseConvertor#convert(java.util.List)}
 */
void testToSALMeterStatsList() {
    final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
    Optional<List<MeterStats>> meterStatsListOptional = convertorManager.convert(createMeterStatsLit(), new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
    List<MeterStats> meterStatsList = meterStatsListOptional.orElse(Collections.emptyList());
    assertEquals(PRESET_COUNT, meterStatsList.size());
    int cnt = 0;
    for (MeterStats meterStats : meterStatsList) {
        assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId((long) cnt)).getMeterId(), meterStats.getKey().getMeterId());
        assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
        assertEquals(new Long(1000 * cnt), meterStats.getDuration().getNanosecond().getValue());
        assertEquals(new Long(10 * cnt), meterStats.getDuration().getSecond().getValue());
        assertEquals(new Long(cnt), meterStats.getFlowCount().getValue());
        assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
        assertEquals(PRESET_COUNT, meterStats.getMeterBandStats().getBandStat().size());
        int bandStatCount = 0;
        for (BandStat bandStat : meterStats.getMeterBandStats().getBandStat()) {
            assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getByteBandCount().getValue());
            assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getPacketBandCount().getValue());
            bandStatCount++;
        }
        assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId((long) cnt)).getMeterId(), meterStats.getMeterId());
        assertEquals(BigInteger.valueOf(cnt), meterStats.getPacketInCount().getValue());
        cnt++;
    }
}
Also used : MeterStatsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey) BandStat(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat) VersionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData) MeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with MeterStats

use of org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats 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)

Aggregations

ArrayList (java.util.ArrayList)7 MeterStats (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats)6 MultipartReplyMeterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterCase)5 MultipartReplyMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.MultipartReplyMeter)5 MeterStats (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats)5 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)4 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)4 ByteBuf (io.netty.buffer.ByteBuf)3 List (java.util.List)3 Test (org.junit.Test)3 Counter32 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32)3 Counter64 (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64)3 DurationBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.DurationBuilder)3 MeterBandStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.MeterBandStatsBuilder)3 BandStat (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat)3 MeterStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder)3 MeterStatsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey)3 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)3 MeterStatsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder)3 BigInteger (java.math.BigInteger)2