Search in sources :

Example 11 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.

the class MultipartReplyMeterConfigDeserializer method deserialize.

@Override
public MultipartReplyBody deserialize(ByteBuf message) {
    final MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();
    final List<MeterConfigStats> items = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final int itemLength = message.readUnsignedShort();
        final MeterConfigStatsBuilder itemBuilder = new MeterConfigStatsBuilder().setFlags(readMeterFlags(message)).setMeterId(new MeterId(message.readUnsignedInt()));
        final List<MeterBandHeader> subItems = new ArrayList<>();
        int actualLength = METER_CONFIG_LENGTH;
        while (actualLength < itemLength) {
            final int itemStartIndex = message.readerIndex();
            final int itemBandType = message.readUnsignedShort();
            final MeterBandHeaderBuilder subItemBuilder = new MeterBandHeaderBuilder();
            actualLength += message.readUnsignedShort();
            switch(itemBandType) {
                case OFPMBTDROP:
                    subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(true, false, false)).build()).setBandType(new DropBuilder().setDropRate(message.readUnsignedInt()).setDropBurstSize(message.readUnsignedInt()).build());
                    message.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
                    break;
                case OFPMBTDSCP:
                    subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, true, false)).build()).setBandType(new DscpRemarkBuilder().setDscpRemarkRate(message.readUnsignedInt()).setDscpRemarkBurstSize(message.readUnsignedInt()).setPrecLevel(message.readUnsignedByte()).build());
                    message.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                    break;
                case OFPMBTEXPERIMENTER:
                    // TODO: Finish meter band experimenter deserialization
                    final long expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
                    message.readerIndex(itemStartIndex);
                    final OFDeserializer<Experimenter> deserializer = registry.getDeserializer(new ExperimenterIdDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, Experimenter.class));
                    subItemBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, false, true)).build()).setBandType(deserializer.deserialize(message));
                    break;
                default:
            }
            subItems.add(subItemBuilder.build());
        }
        items.add(itemBuilder.setKey(new MeterConfigStatsKey(itemBuilder.getMeterId())).setMeterBandHeaders(new MeterBandHeadersBuilder().setMeterBandHeader(subItems).build()).build());
    }
    return builder.setMeterConfigStats(items).build();
}
Also used : MeterConfigStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStatsBuilder) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) Experimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Experimenter) MultipartReplyMeterConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder) ArrayList(java.util.ArrayList) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) DropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder) ExperimenterIdDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) MeterConfigStatsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStatsKey) MeterConfigStats(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.config.stats.reply.MeterConfigStats)

Example 12 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.

the class MeterMessageDeserializer method deserialize.

@Override
public MeterMessage deserialize(ByteBuf message) {
    final MeterMessageBuilder builder = new MeterMessageBuilder().setVersion((short) EncodeConstants.OF13_VERSION_ID).setXid(message.readUnsignedInt()).setCommand(MeterModCommand.forValue(message.readUnsignedShort())).setFlags(readMeterFlags(message)).setMeterId(new MeterId(message.readUnsignedInt()));
    final List<MeterBandHeader> bands = new ArrayList<>();
    while (message.readableBytes() > 0) {
        final MeterBandHeaderBuilder bandBuilder = new MeterBandHeaderBuilder();
        final int bandStartIndex = message.readerIndex();
        final int bandType = message.readUnsignedShort();
        switch(bandType) {
            case OFPMBTDROP:
                {
                    bandBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(true, false, false)).build()).setBandType(new DropBuilder().setDropRate(message.readUnsignedInt()).setDropBurstSize(message.readUnsignedInt()).build());
                    message.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
                    break;
                }
            case OFPMBTDSCP:
                {
                    bandBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, true, false)).build()).setBandType(new DscpRemarkBuilder().setDscpRemarkRate(message.readUnsignedInt()).setDscpRemarkBurstSize(message.readUnsignedInt()).setPrecLevel(message.readUnsignedByte()).build());
                    message.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                    break;
                }
            case OFPMBTEXPERIMENTER:
                {
                    // TODO: Finish meter band experimenter deserialization
                    long expId = message.getUnsignedInt(message.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
                    message.readerIndex(bandStartIndex);
                    OFDeserializer<Experimenter> deserializer = registry.getDeserializer(new ExperimenterIdDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId, Experimenter.class));
                    bandBuilder.setMeterBandTypes(new MeterBandTypesBuilder().setFlags(new MeterBandType(false, false, true)).build()).setBandType(deserializer.deserialize(message));
                    break;
                }
            default:
        }
        bands.add(bandBuilder.build());
    }
    return builder.setMeterBandHeaders(new MeterBandHeadersBuilder().setMeterBandHeader(bands).build()).build();
}
Also used : OFDeserializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) ArrayList(java.util.ArrayList) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) DropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder) ExperimenterIdDeserializerKey(org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) MeterMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessageBuilder) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)

Example 13 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter 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 14 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.

the class OpenflowpluginMeterTestCommandProvider method _removeMeter.

public void _removeMeter(final CommandInterpreter ci) {
    String nref = ci.nextArgument();
    if (nref == null) {
        ci.println("test node added");
        createTestNode();
    } else {
        ci.println("User node added" + nref);
        createUserNode(nref);
    }
    createTestMeter();
    ReadWriteTransaction modification = dataBroker.newReadWriteTransaction();
    InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()).augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(testMeter.getMeterId()));
    modification.delete(LogicalDatastoreType.CONFIGURATION, path1);
    CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit();
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void notUsed) {
            ci.println("Status of Group Data Loaded Transaction: success.");
        }

        @Override
        public void onFailure(Throwable throwable) {
            ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable));
        }
    }, MoreExecutors.directExecutor());
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) 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) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Example 15 with Meter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter in project openflowplugin by opendaylight.

the class OpenflowpluginMeterTestCommandProvider method createTestMeters.

private MeterBuilder createTestMeters(String s1, String s2) {
    // Sample data , committing to DataStore
    long id = Integer.parseInt(s1);
    MeterKey key = new MeterKey(new MeterId(id));
    MeterBuilder meter = new MeterBuilder();
    meter.setContainerName("abcd");
    meter.setKey(key);
    meter.setMeterId(new MeterId(9L));
    MeterBandHeaderBuilder bandHeader = new MeterBandHeaderBuilder();
    if (s2.equalsIgnoreCase("modify")) {
        meter.setMeterName(updatedMeterName);
        bandHeader.setBandRate((long) 234);
    } else {
        meter.setMeterName(originalMeterName);
        bandHeader.setBandRate((long) 123);
    }
    meter.setFlags(new MeterFlags(true, false, false, false));
    bandHeader.setBandBurstSize((long) 444);
    DscpRemarkBuilder dscpRemark = new DscpRemarkBuilder();
    dscpRemark.setDscpRemarkBurstSize((long) 5);
    dscpRemark.setPrecLevel((short) 1);
    dscpRemark.setDscpRemarkRate((long) 12);
    bandHeader.setBandType(dscpRemark.build());
    MeterBandTypesBuilder bandTypes = new MeterBandTypesBuilder();
    MeterBandType bandType = new MeterBandType(false, true, false);
    bandTypes.setFlags(bandType);
    bandHeader.setMeterBandTypes(bandTypes.build());
    bandHeader.setBandId(new BandId(0L));
    List<MeterBandHeader> bandHdr = new ArrayList<>();
    bandHdr.add(bandHeader.build());
    MeterBandHeadersBuilder bandHeaders = new MeterBandHeadersBuilder();
    bandHeaders.setMeterBandHeader(bandHdr);
    meter.setMeterBandHeaders(bandHeaders.build());
    if (Integer.parseInt(s1) == 1) {
        testMeter1 = meter.build();
    } else if (Integer.parseInt(s1) == 2) {
        testMeter2 = meter.build();
    } else if (Integer.parseInt(s1) == 3) {
        testMeter1 = meter.build();
    } else if (Integer.parseInt(s1) == 4) {
        testMeter2 = meter.build();
    } else if (Integer.parseInt(s1) == 5) {
        testMeter1 = meter.build();
    } else if (Integer.parseInt(s1) == 6) {
        testMeter2 = meter.build();
    } else if (Integer.parseInt(s1) == 7) {
        testMeter1 = meter.build();
    } else if (Integer.parseInt(s1) == 8) {
        testMeter2 = meter.build();
    }
    return meter;
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder) DscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder) MeterBandType(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType) MeterBandTypesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder) ArrayList(java.util.ArrayList) MeterBandHeaderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) MeterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey) MeterBandHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) BandId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.BandId)

Aggregations

Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)24 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)19 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)15 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)14 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)14 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)13 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder)11 MeterRef (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef)10 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)9 ByteBuf (io.netty.buffer.ByteBuf)6 ItemSyncBox (org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox)6 StaleMeter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeter)6 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)6 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)6 StaleMeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterKey)5 MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)5 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)4 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)4 StaleMeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.StaleMeterBuilder)4