Search in sources :

Example 21 with MeterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId in project openflowplugin by opendaylight.

the class FlowCapableNodeLookups method wrapMetersToMap.

@Nonnull
public static Map<MeterId, Meter> wrapMetersToMap(@Nullable final List<Meter> meters) {
    final Map<MeterId, Meter> meterMap;
    if (meters == null) {
        meterMap = Collections.emptyMap();
    } else {
        LOG.trace("meters found: {}", meters.size());
        meterMap = new HashMap<>();
        for (Meter meter : meters) {
            meterMap.put(meter.getMeterId(), meter);
        }
    }
    return meterMap;
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) Nonnull(javax.annotation.Nonnull)

Example 22 with MeterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId in project openflowplugin by opendaylight.

the class ReconcileUtil method resolveMeterDiffs.

/**
 * Resolves meter differences.
 *
 * @param nodeId              target node
 * @param meterOperationalMap meters present on device
 * @param metersConfigured    meters configured for device
 * @param gatherUpdates       check content of pending item if present on device (and create update task eventually)
 * @return synchronization box
 */
public static ItemSyncBox<Meter> resolveMeterDiffs(final NodeId nodeId, final Map<MeterId, Meter> meterOperationalMap, final List<Meter> metersConfigured, final boolean gatherUpdates) {
    LOG.trace("resolving meters for {}", nodeId.getValue());
    final ItemSyncBox<Meter> syncBox = new ItemSyncBox<>();
    for (Meter meter : metersConfigured) {
        final Meter existingMeter = meterOperationalMap.get(meter.getMeterId());
        if (existingMeter == null) {
            syncBox.getItemsToPush().add(meter);
        } else {
            // compare content and eventually update
            if (gatherUpdates && !meter.equals(existingMeter)) {
                syncBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(existingMeter, meter));
            }
        }
    }
    return syncBox;
}
Also used : Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)

Example 23 with MeterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId in project openflowplugin by opendaylight.

the class MeterModInputMessageFactory method deserialize.

@Override
// FB doesn't recognize Objects.requireNonNull
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public MeterModInput deserialize(ByteBuf rawMessage) {
    Objects.requireNonNull(registry);
    MeterModInputBuilder builder = new MeterModInputBuilder();
    builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setCommand(MeterModCommand.forValue(rawMessage.readUnsignedShort()));
    builder.setFlags(createMeterFlags(rawMessage.readUnsignedShort()));
    builder.setMeterId(new MeterId(rawMessage.readUnsignedInt()));
    List<Bands> bandsList = new ArrayList<>();
    while (rawMessage.readableBytes() > 0) {
        BandsBuilder bandsBuilder = new BandsBuilder();
        int bandStartIndex = rawMessage.readerIndex();
        int bandType = rawMessage.readUnsignedShort();
        switch(bandType) {
            case 1:
                final MeterBandDropCaseBuilder bandDropCaseBuilder = new MeterBandDropCaseBuilder();
                MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();
                bandDropBuilder.setType(MeterBandType.forValue(bandType));
                rawMessage.readUnsignedShort();
                bandDropBuilder.setRate(rawMessage.readUnsignedInt());
                bandDropBuilder.setBurstSize(rawMessage.readUnsignedInt());
                rawMessage.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);
                bandDropCaseBuilder.setMeterBandDrop(bandDropBuilder.build());
                bandsBuilder.setMeterBand(bandDropCaseBuilder.build());
                break;
            case 2:
                final MeterBandDscpRemarkCaseBuilder bandDscpRemarkCaseBuilder = new MeterBandDscpRemarkCaseBuilder();
                MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();
                bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));
                rawMessage.readUnsignedShort();
                bandDscpRemarkBuilder.setRate(rawMessage.readUnsignedInt());
                bandDscpRemarkBuilder.setBurstSize(rawMessage.readUnsignedInt());
                bandDscpRemarkBuilder.setPrecLevel(rawMessage.readUnsignedByte());
                rawMessage.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);
                bandDscpRemarkCaseBuilder.setMeterBandDscpRemark(bandDscpRemarkBuilder.build());
                bandsBuilder.setMeterBand(bandDscpRemarkCaseBuilder.build());
                break;
            case 0xFFFF:
                long expId = rawMessage.getUnsignedInt(rawMessage.readerIndex() + 2 * EncodeConstants.SIZE_OF_INT_IN_BYTES);
                rawMessage.readerIndex(bandStartIndex);
                OFDeserializer<MeterBandExperimenterCase> deserializer = registry.getDeserializer(ExperimenterDeserializerKeyFactory.createMeterBandDeserializerKey(EncodeConstants.OF13_VERSION_ID, expId));
                bandsBuilder.setMeterBand(deserializer.deserialize(rawMessage));
                break;
            default:
                break;
        }
        bandsList.add(bandsBuilder.build());
    }
    builder.setBands(bandsList);
    return builder.build();
}
Also used : MeterModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder) MeterBandDscpRemarkCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkCaseBuilder) ArrayList(java.util.ArrayList) MeterBandDropBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.drop._case.MeterBandDropBuilder) MeterBandExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId) MeterBandDscpRemarkBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.meter.band.dscp.remark._case.MeterBandDscpRemarkBuilder) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands) MeterBandDropCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDropCaseBuilder) BandsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.BandsBuilder) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 24 with MeterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId in project openflowplugin by opendaylight.

the class MeterDirectStatisticsServiceTest method testBuildRequestBody.

@Override
public void testBuildRequestBody() throws Exception {
    final GetMeterStatisticsInput input = mock(GetMeterStatisticsInput.class);
    when(input.getNode()).thenReturn(createNodeRef(NODE_ID));
    when(input.getMeterId()).thenReturn(new MeterId(METER_NO));
    final MultipartRequestMeterStats body = (MultipartRequestMeterStats) ((MultipartRequest) service.buildRequest(new Xid(42L), input)).getMultipartRequestBody();
    assertEquals(METER_NO, body.getMeterId().getValue());
}
Also used : Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) MultipartRequestMeterStats(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterStats) GetMeterStatisticsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetMeterStatisticsInput) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)

Example 25 with MeterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId in project openflowplugin by opendaylight.

the class MultipartReplyMessageFactoryTest method testMultipartReplyMeterBodyMulti.

/**
 * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO.
 */
@Test
public void testMultipartReplyMeterBodyMulti() {
    ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 " + // meterId_0
    "00 00 00 09 " + // len_0
    "00 58 " + // pad_0
    "00 00 00 00 00 00 " + // flowCount_0
    "00 00 00 07 " + // packetInCount_0
    "FF 01 01 01 01 01 01 01 " + // byteInCount_0
    "FF 01 01 01 01 01 01 01 " + // durationSec_0
    "00 00 00 05 " + // durationNsec_0
    "00 00 00 05 " + // packetBandCount_01
    "FF 01 01 01 01 01 01 01 " + // byteBandCount_01
    "FF 01 01 01 01 01 01 01 " + // packetBandCount_02
    "FF 02 02 02 02 02 02 02 " + // byteBandCount_02
    "FF 02 02 02 02 02 02 02 " + // packetBandCount_03
    "FF 03 03 03 03 03 03 03 " + // byteBandCount_03
    "FF 03 03 03 03 03 03 03 " + // meterId_1
    "00 00 00 08 " + // len_1
    "00 58 " + // pad_1
    "00 00 00 00 00 00 " + // flowCount_1
    "00 00 00 07 " + // packetInCount_1
    "FF 01 01 01 01 01 01 01 " + // byteInCount_1
    "FF 01 01 01 01 01 01 01 " + // durationSec_1
    "00 00 00 05 " + // durationNsec_1
    "00 00 00 05 " + // packetBandCount_11
    "FF 01 01 01 01 01 01 01 " + // byteBandCount_11
    "FF 01 01 01 01 01 01 01 " + // packetBandCount_12
    "FF 02 02 02 02 02 02 02 " + // byteBandCount_12
    "FF 02 02 02 02 02 02 02 " + // packetBandCount_13
    "FF 03 03 03 03 03 03 03 " + // byteBandCount_13
    "FF 03 03 03 03 03 03 03");
    MultipartReplyMessage builtByFactory = BufferHelper.deserialize(multipartFactory, bb);
    BufferHelper.checkHeaderV13(builtByFactory);
    Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue());
    Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());
    MultipartReplyMeterCase messageCase = (MultipartReplyMeterCase) builtByFactory.getMultipartReplyBody();
    MultipartReplyMeter message = messageCase.getMultipartReplyMeter();
    Assert.assertEquals("Wrong meterId", 9, message.getMeterStats().get(0).getMeterId().getValue().intValue());
    Assert.assertEquals("Wrong flowCount", 7, message.getMeterStats().get(0).getFlowCount().intValue());
    Assert.assertEquals("Wrong packetInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getPacketInCount());
    Assert.assertEquals("Wrong byteInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getByteInCount());
    Assert.assertEquals("Wrong durationSec", 5, message.getMeterStats().get(0).getDurationSec().intValue());
    Assert.assertEquals("Wrong durationNsec", 5, message.getMeterStats().get(0).getDurationNsec().intValue());
    Assert.assertEquals("Wrong packetBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount());
    Assert.assertEquals("Wrong packetBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount());
    Assert.assertEquals("Wrong packetBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount());
    Assert.assertEquals("Wrong meterId", 8, message.getMeterStats().get(1).getMeterId().getValue().intValue());
    Assert.assertEquals("Wrong flowCount", 7, message.getMeterStats().get(1).getFlowCount().intValue());
    Assert.assertEquals("Wrong packetInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getPacketInCount());
    Assert.assertEquals("Wrong byteInCount", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getByteInCount());
    Assert.assertEquals("Wrong durationSec", 5, message.getMeterStats().get(1).getDurationSec().intValue());
    Assert.assertEquals("Wrong durationNsec", 5, message.getMeterStats().get(1).getDurationNsec().intValue());
    Assert.assertEquals("Wrong packetBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_01", new BigInteger(1, new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 }), message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount());
    Assert.assertEquals("Wrong packetBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_02", new BigInteger(1, new byte[] { (byte) 0xFF, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 }), message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount());
    Assert.assertEquals("Wrong packetBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount());
    Assert.assertEquals("Wrong byteBandCount_03", new BigInteger(1, new byte[] { (byte) 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 }), message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount());
}
Also used : MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) 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) BigInteger(java.math.BigInteger) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)32 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)24 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId)23 ByteBuf (io.netty.buffer.ByteBuf)11 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)10 MeterFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags)9 MeterBandType (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType)8 DscpRemarkBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder)8 MeterBandHeadersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder)8 MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)8 MeterBandHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder)8 MeterBandTypesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder)8 MeterModInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder)8 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder)7 MeterKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey)7 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)6 Meter (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter)6 MeterCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCaseBuilder)6 MeterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.MeterBuilder)6