Search in sources :

Example 41 with Meter

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

the class MultipartReplyMessageFactoryTest method testFlowBody.

private static void testFlowBody(MultipartReplyBody body, ByteBuf output) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    FlowStats flowStats = flow.getFlowStats().get(0);
    Assert.assertEquals("Wrong length", 176, output.readShort());
    Assert.assertEquals("Wrong Table ID", flowStats.getTableId().intValue(), output.readUnsignedByte());
    output.skipBytes(1);
    Assert.assertEquals("Wrong duration sec", flowStats.getDurationSec().intValue(), output.readInt());
    Assert.assertEquals("Wrong duration nsec", flowStats.getDurationNsec().intValue(), output.readInt());
    Assert.assertEquals("Wrong priority", flowStats.getPriority().intValue(), output.readShort());
    Assert.assertEquals("Wrong idle timeout", flowStats.getIdleTimeout().intValue(), output.readShort());
    Assert.assertEquals("Wrong hard timeout", flowStats.getHardTimeout().intValue(), output.readShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong cookie", flowStats.getCookie().longValue(), output.readLong());
    Assert.assertEquals("Wrong Packet count", flowStats.getPacketCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong Byte count", flowStats.getByteCount().longValue(), output.readLong());
    Assert.assertEquals("Wrong match type", 1, output.readUnsignedShort());
    output.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    short fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, output.readUnsignedShort());
    fieldAndMask = output.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    output.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, output.readUnsignedByte());
    output.skipBytes(7);
    Assert.assertEquals("Wrong instruction type", 1, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction table-id", 5, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    byte[] actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07", ByteBufUtils.bytesToHexString(actual));
    actual = new byte[8];
    output.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00", ByteBufUtils.bytesToHexString(actual));
    Assert.assertEquals("Wrong instruction type", 5, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong instruction type", 6, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction meter-id", 42, output.readUnsignedInt());
    Assert.assertEquals("Wrong instruction type", 3, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 32, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, output.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, output.readUnsignedShort());
    output.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, output.readUnsignedByte());
    output.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 4, output.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 14, output.readUnsignedShort());
    output.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, output.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, output.readUnsignedShort());
    output.skipBytes(4);
    Assert.assertTrue("Not all data were read", output.readableBytes() == 0);
}
Also used : FlowStats(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats) MultipartReplyFlow(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlow) MultipartReplyFlowCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCase)

Example 42 with Meter

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

the class MultipartReplyMessageFactoryTest method testMeterFeaturesSerialize.

@Test
public void testMeterFeaturesSerialize() throws Exception {
    MultipartReplyMessageBuilder builder = new MultipartReplyMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setFlags(new MultipartRequestFlags(true));
    builder.setType(MultipartType.forValue(11));
    final MultipartReplyMeterFeaturesCaseBuilder meterFeaturesCase = new MultipartReplyMeterFeaturesCaseBuilder();
    MultipartReplyMeterFeaturesBuilder meterFeatures = new MultipartReplyMeterFeaturesBuilder();
    meterFeatures.setMaxMeter(1L);
    meterFeatures.setBandTypes(new MeterBandTypeBitmap(true, false));
    meterFeatures.setCapabilities(new MeterFlags(true, false, true, false));
    meterFeatures.setMaxBands((short) 1);
    meterFeatures.setMaxColor((short) 1);
    meterFeaturesCase.setMultipartReplyMeterFeatures(meterFeatures.build());
    builder.setMultipartReplyBody(meterFeaturesCase.build());
    MultipartReplyMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 30);
    Assert.assertEquals("Wrong type", MultipartType.OFPMPMETERFEATURES.getIntValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong flags", message.getFlags(), createMultipartRequestFlags(serializedBuffer.readShort()));
    serializedBuffer.skipBytes(PADDING);
    MultipartReplyMeterFeaturesCase body = (MultipartReplyMeterFeaturesCase) message.getMultipartReplyBody();
    MultipartReplyMeterFeatures messageOutput = body.getMultipartReplyMeterFeatures();
    Assert.assertEquals("Wrong max meter", messageOutput.getMaxMeter().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong band type", messageOutput.getBandTypes(), createMeterBandTypeBitmap(serializedBuffer.readInt()));
    Assert.assertEquals("Wrong capabilities", messageOutput.getCapabilities(), createMeterFlags(serializedBuffer.readShort()));
    Assert.assertEquals("Wrong max bands", messageOutput.getMaxBands().shortValue(), serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong max color", messageOutput.getMaxColor().shortValue(), serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(2);
}
Also used : MultipartReplyMeterFeaturesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder) MultipartReplyMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartReplyMeterFeaturesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder) MultipartReplyMeterFeatures(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeatures) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) MeterBandTypeBitmap(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap) ByteBuf(io.netty.buffer.ByteBuf) MultipartReplyMeterFeaturesCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCase) Test(org.junit.Test)

Example 43 with Meter

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

the class MeterConvertor method convert.

@Override
public MeterModInputBuilder convert(Meter source, VersionConvertorData data) {
    MeterModInputBuilder meterModInputBuilder = new MeterModInputBuilder();
    List<Bands> bands = new ArrayList<>();
    if (source instanceof AddMeterInput) {
        meterModInputBuilder.setCommand(MeterModCommand.OFPMCADD);
    } else if (source instanceof RemoveMeterInput) {
        meterModInputBuilder.setCommand(MeterModCommand.OFPMCDELETE);
    } else if (source instanceof UpdatedMeter) {
        meterModInputBuilder.setCommand(MeterModCommand.OFPMCMODIFY);
    }
    meterModInputBuilder.setMeterId(new MeterId(source.getMeterId().getValue()));
    if (null != source.getFlags()) {
        meterModInputBuilder.setFlags(new MeterFlags(source.getFlags().isMeterBurst(), source.getFlags().isMeterKbps(), source.getFlags().isMeterPktps(), source.getFlags().isMeterStats()));
    } else {
        /*
             * As per 0F1.3.1,The rate field indicates the rate value above
             * which the corresponding band may apply to packets (see 5.7.1).
             * The rate value is in kilobit per seconds, unless the flags eld
             * includes OFPMF_PKTPS, in which case the rate is in packets per
             * seconds.
             */
        meterModInputBuilder.setFlags(new MeterFlags(false, false, true, false));
    }
    if (source.getMeterBandHeaders() != null) {
        getBandsFromSAL(source.getMeterBandHeaders(), bands);
        meterModInputBuilder.setBands(bands);
    } else {
        LOG.error("For this meter Id" + source.getMeterId().getValue() + ",no associated band data found!");
    }
    meterModInputBuilder.setVersion(data.getVersion());
    return meterModInputBuilder;
}
Also used : MeterModInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInputBuilder) Bands(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.mod.Bands) AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags) ArrayList(java.util.ArrayList) UpdatedMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeter) RemoveMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId)

Example 44 with Meter

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

the class MeterCase method process.

@Override
public Optional<Instruction> process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    Meter meter = source.getMeter();
    MeterCaseBuilder meterCaseBuilder = new MeterCaseBuilder();
    MeterBuilder meterBuilder = new MeterBuilder();
    Long meterId = meter.getMeterId().getValue();
    meterBuilder.setMeterId(meterId);
    meterCaseBuilder.setMeter(meterBuilder.build());
    InstructionBuilder instructionBuilder = new InstructionBuilder();
    instructionBuilder.setInstructionChoice(meterCaseBuilder.build());
    return Optional.of(instructionBuilder.build());
}
Also used : MeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.meter._case.MeterBuilder) InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder) Meter(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.meter._case.Meter) MeterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCaseBuilder)

Example 45 with Meter

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

the class MeterForwarder method update.

@Override
public Future<RpcResult<UpdateMeterOutput>> update(final InstanceIdentifier<Meter> identifier, final Meter original, final Meter update, final InstanceIdentifier<FlowCapableNode> nodeIdent) {
    LOG.trace("Received the Meter UPDATE request [Tbl id, node Id {} {} {}", identifier, nodeIdent, update);
    final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder();
    builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class)));
    builder.setMeterRef(new MeterRef(identifier));
    builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build());
    builder.setOriginalMeter(new OriginalMeterBuilder(original).build());
    return salMeterService.updateMeter(builder.build());
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) UpdateMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder) MeterRef(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef) UpdatedMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder) OriginalMeterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder)

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