Search in sources :

Example 1 with MeterMessage

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

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

the class SingleLayerMeterServiceTest method buildRequest.

@Test
public void buildRequest() throws Exception {
    final AddMeterInput input = new AddMeterInputBuilder().setMeterId(new MeterId(METER_ID)).build();
    final OfHeader ofHeader = service.buildRequest(DUMMY_XID, input);
    assertEquals(MeterMessage.class, ofHeader.getImplementedInterface());
    final MeterMessage result = MeterMessage.class.cast(ofHeader);
    assertEquals(MeterModCommand.OFPMCADD, result.getCommand());
    assertEquals(METER_ID, result.getMeterId().getValue().longValue());
}
Also used : AddMeterInput(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) MeterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage) AddMeterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder) MeterId(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId) Test(org.junit.Test)

Example 3 with MeterMessage

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

the class MeterMessageSerializer method serialize.

@Override
public void serialize(final MeterMessage message, final ByteBuf outBuffer) {
    final int index = outBuffer.writerIndex();
    super.serialize(message, outBuffer);
    outBuffer.writeShort(message.getCommand().getIntValue());
    outBuffer.writeShort(createMeterFlagsBitMask(MoreObjects.firstNonNull(message.getFlags(), new MeterFlags(false, false, true, false))));
    outBuffer.writeInt(message.getMeterId().getValue().intValue());
    serializeBands(message.getMeterBandHeaders(), outBuffer);
    outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
}
Also used : MeterFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags)

Example 4 with MeterMessage

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

the class MeterMessageDeserializerTest method deserialize.

@Test
public void deserialize() throws Exception {
    // Message type
    buffer.writeByte(TYPE);
    buffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    buffer.writeInt(XID);
    buffer.writeShort(COMMAND.getIntValue());
    buffer.writeShort(ByteBufUtils.fillBitMask(0, IS_KBPS, IS_PKTPS, IS_BURST, IS_STATS));
    buffer.writeInt(ID);
    // Drop band
    buffer.writeShort(1);
    buffer.writeInt(DROP_RATE);
    buffer.writeInt(DROP_BURST);
    buffer.writeZero(PADDING_IN_METER_BAND_DROP_HEADER);
    // Dscp remark band
    buffer.writeShort(2);
    buffer.writeInt(DSCP_RATE);
    buffer.writeInt(DSCP_BURST);
    buffer.writeByte(DSCP_PREC);
    buffer.writeZero(PADDING_IN_METER_BAND_DSCP_HEADER);
    final MeterMessage message = (MeterMessage) getFactory().deserialize(buffer, EncodeConstants.OF13_VERSION_ID);
    assertEquals(message.getXid().intValue(), XID);
    assertEquals(message.getCommand().getIntValue(), COMMAND.getIntValue());
    assertEquals(message.getFlags().isMeterBurst(), IS_BURST);
    assertEquals(message.getFlags().isMeterKbps(), IS_KBPS);
    assertEquals(message.getFlags().isMeterPktps(), IS_PKTPS);
    assertEquals(message.getFlags().isMeterStats(), IS_STATS);
    assertEquals(message.getMeterId().getValue().intValue(), ID);
    final List<MeterBandHeader> meterBandHeader = message.getMeterBandHeaders().getMeterBandHeader();
    assertEquals(meterBandHeader.size(), 2);
    // Drop band
    final MeterBandHeader dropHeader = meterBandHeader.get(0);
    assertEquals(Drop.class, dropHeader.getBandType().getImplementedInterface());
    assertTrue(dropHeader.getMeterBandTypes().getFlags().isOfpmbtDrop());
    final Drop drop = Drop.class.cast(dropHeader.getBandType());
    assertEquals(DROP_RATE, drop.getDropRate().intValue());
    assertEquals(DROP_BURST, drop.getDropBurstSize().intValue());
    // Dscp band
    final MeterBandHeader dscpHeader = meterBandHeader.get(1);
    assertEquals(DscpRemark.class, dscpHeader.getBandType().getImplementedInterface());
    assertTrue(dscpHeader.getMeterBandTypes().getFlags().isOfpmbtDscpRemark());
    final DscpRemark dscpRemark = DscpRemark.class.cast(dscpHeader.getBandType());
    assertEquals(DSCP_RATE, dscpRemark.getDscpRemarkRate().intValue());
    assertEquals(DSCP_BURST, dscpRemark.getDscpRemarkBurstSize().intValue());
    assertEquals(buffer.readableBytes(), 0);
}
Also used : DscpRemark(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark) MeterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage) MeterBandHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader) Drop(org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop) Test(org.junit.Test) AbstractDeserializerTest(org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)

Aggregations

Test (org.junit.Test)2 MeterId (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId)2 MeterMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessage)2 MeterBandHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeader)2 ArrayList (java.util.ArrayList)1 OFDeserializer (org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer)1 ExperimenterIdDeserializerKey (org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdDeserializerKey)1 AbstractDeserializerTest (org.opendaylight.openflowplugin.impl.protocol.deserialization.AbstractDeserializerTest)1 AddMeterInput (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput)1 AddMeterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder)1 MeterBandType (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandType)1 MeterFlags (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags)1 MeterMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterMessageBuilder)1 Drop (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop)1 DropBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DropBuilder)1 DscpRemark (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark)1 DscpRemarkBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemarkBuilder)1 MeterBandHeadersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.MeterBandHeadersBuilder)1 MeterBandHeaderBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.MeterBandHeaderBuilder)1 MeterBandTypesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.meter.band.headers.meter.band.header.MeterBandTypesBuilder)1