Example usage for io.netty.buffer ByteBuf setShort

List of usage examples for io.netty.buffer ByteBuf setShort

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf setShort.

Prototype

public abstract ByteBuf setShort(int index, int value);

Source Link

Document

Sets the specified 16-bit short integer at the specified absolute index in this buffer.

Usage

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void writeInstructionRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property,
        final byte code) {
    int startIndex = output.writerIndex();
    output.writeShort(code);/*  www  .  jav a  2  s .co m*/
    int lengthIndex = output.writerIndex();
    output.writeShort(EncodeConstants.EMPTY_LENGTH);
    List<Instruction> instructions = property.getAugmentation(InstructionRelatedTableFeatureProperty.class)
            .getInstruction();
    if (instructions != null) {
        TypeKeyMaker<Instruction> keyMaker = TypeKeyMakerFactory
                .createInstructionKeyMaker(EncodeConstants.OF13_VERSION_ID);
        ListSerializer.serializeHeaderList(instructions, keyMaker, registry, output);
    }
    int length = output.writerIndex() - startIndex;
    output.setShort(lengthIndex, length);
    output.writeZero(paddingNeeded(length));
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void serializeMeterConfigBody(MultipartReplyBody body, ByteBuf outBuffer) {
    MultipartReplyMeterConfigCase meterConfigCase = (MultipartReplyMeterConfigCase) body;
    MultipartReplyMeterConfig meter = meterConfigCase.getMultipartReplyMeterConfig();
    for (MeterConfig meterConfig : meter.getMeterConfig()) {
        ByteBuf meterConfigBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        meterConfigBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        writeMeterFlags(meterConfig.getFlags(), meterConfigBuff);
        meterConfigBuff.writeInt(meterConfig.getMeterId().getValue().intValue());
        for (Bands currentBand : meterConfig.getBands()) {
            MeterBand meterBand = currentBand.getMeterBand();
            if (meterBand instanceof MeterBandDropCase) {
                MeterBandDropCase dropBandCase = (MeterBandDropCase) meterBand;
                MeterBandDrop dropBand = dropBandCase.getMeterBandDrop();
                writeBandCommonFields(dropBand, meterConfigBuff);
            } else if (meterBand instanceof MeterBandDscpRemarkCase) {
                MeterBandDscpRemarkCase dscpRemarkBandCase = (MeterBandDscpRemarkCase) meterBand;
                MeterBandDscpRemark dscpRemarkBand = dscpRemarkBandCase.getMeterBandDscpRemark();
                writeBandCommonFields(dscpRemarkBand, meterConfigBuff);
            } else if (meterBand instanceof MeterBandExperimenterCase) {
                MeterBandExperimenterCase experimenterBandCase = (MeterBandExperimenterCase) meterBand;
                MeterBandExperimenter experimenterBand = experimenterBandCase.getMeterBandExperimenter();
                writeBandCommonFields(experimenterBand, meterConfigBuff);
            }//  www  . j  a va  2s  .  c  om
        }
        meterConfigBuff.setShort(METER_CONFIG_LENGTH_INDEX, meterConfigBuff.readableBytes());
        outBuffer.writeBytes(meterConfigBuff);
    }
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void serializeGroupDescBody(MultipartReplyBody body, ByteBuf outBuffer, MultipartReplyMessage message) {
    MultipartReplyGroupDescCase groupDescCase = (MultipartReplyGroupDescCase) body;
    MultipartReplyGroupDesc group = groupDescCase.getMultipartReplyGroupDesc();
    for (GroupDesc groupDesc : group.getGroupDesc()) {
        ByteBuf groupDescBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        groupDescBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        groupDescBuff.writeByte(groupDesc.getType().getIntValue());
        groupDescBuff.writeZero(GROUP_DESC_PADDING);
        groupDescBuff.writeInt(groupDesc.getGroupId().getValue().intValue());
        for (BucketsList bucket : groupDesc.getBucketsList()) {
            ByteBuf bucketBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
            bucketBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
            bucketBuff.writeShort(bucket.getWeight());
            bucketBuff.writeInt(bucket.getWatchPort().getValue().intValue());
            bucketBuff.writeInt(bucket.getWatchGroup().intValue());
            bucketBuff.writeZero(BUCKET_PADDING);
            ListSerializer.serializeList(bucket.getAction(),
                    TypeKeyMakerFactory.createActionKeyMaker(message.getVersion()), registry, bucketBuff);
            bucketBuff.setShort(BUCKET_LENGTH_INDEX, bucketBuff.readableBytes());
            groupDescBuff.writeBytes(bucketBuff);
        }// w  ww . j  a  v  a 2  s . c o  m
        groupDescBuff.setShort(GROUP_DESC_LENGTH_INDEX, groupDescBuff.readableBytes());
        outBuffer.writeBytes(groupDescBuff);
    }
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void serializeGroupBody(MultipartReplyBody body, ByteBuf outBuffer) {
    MultipartReplyGroupCase groupCase = (MultipartReplyGroupCase) body;
    MultipartReplyGroup group = groupCase.getMultipartReplyGroup();
    for (GroupStats groupStats : group.getGroupStats()) {
        ByteBuf groupStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        groupStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        groupStatsBuff.writeZero(GROUP_STATS_PADDING_1);
        groupStatsBuff.writeInt(groupStats.getGroupId().getValue().intValue());
        groupStatsBuff.writeInt(groupStats.getRefCount().intValue());
        groupStatsBuff.writeZero(GROUP_STATS_PADDING_2);
        groupStatsBuff.writeLong(groupStats.getPacketCount().longValue());
        groupStatsBuff.writeLong(groupStats.getByteCount().longValue());
        groupStatsBuff.writeInt(groupStats.getDurationSec().intValue());
        groupStatsBuff.writeInt(groupStats.getDurationNsec().intValue());
        for (BucketStats bucketStats : groupStats.getBucketStats()) {
            groupStatsBuff.writeLong(bucketStats.getPacketCount().longValue());
            groupStatsBuff.writeLong(bucketStats.getByteCount().longValue());
        }//from w  w  w .  jav a 2s  .  c  o  m
        groupStatsBuff.setShort(GROUP_STATS_LENGTH_INDEX, groupStatsBuff.readableBytes());
        outBuffer.writeBytes(groupStatsBuff);
    }
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void serializeFlowBody(MultipartReplyBody body, ByteBuf outBuffer, MultipartReplyMessage message) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    for (FlowStats flowStats : flow.getFlowStats()) {
        ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        flowStatsBuff.writeByte(new Long(flowStats.getTableId()).byteValue());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
        flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
        flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
        flowStatsBuff.writeShort(flowStats.getPriority());
        flowStatsBuff.writeShort(flowStats.getIdleTimeout());
        flowStatsBuff.writeShort(flowStats.getHardTimeout());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
        flowStatsBuff.writeLong(flowStats.getCookie().longValue());
        flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
        flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
        OFSerializer<Match> matchSerializer = registry.<Match, OFSerializer<Match>>getSerializer(
                new MessageTypeKey<>(message.getVersion(), Match.class));
        matchSerializer.serialize(flowStats.getMatch(), flowStatsBuff);
        ListSerializer.serializeList(flowStats.getInstruction(),
                TypeKeyMakerFactory.createInstructionKeyMaker(message.getVersion()), registry, flowStatsBuff);

        flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
        outBuffer.writeBytes(flowStatsBuff);
    }/*w  ww . ja va  2s  . c o  m*/
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.NetIdePacketOutInputMessageFactory.java

License:Open Source License

@Override
public void serialize(PacketOutInput message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeInt(message.getBufferId().intValue());
    outBuffer.writeInt(message.getInPort().getValue().intValue());
    int actionsLengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(message.getAction().size());
    outBuffer.writeZero(PADDING_IN_PACKET_OUT_MESSAGE);
    int actionsStartIndex = outBuffer.writerIndex();
    ListSerializer.serializeList(message.getAction(),
            TypeKeyMakerFactory.createActionKeyMaker(message.getVersion()), registry, outBuffer);
    outBuffer.setShort(actionsLengthIndex, outBuffer.writerIndex() - actionsStartIndex);
    byte[] data = message.getData();
    if (data != null) {
        outBuffer.writeBytes(data);//w w  w  . ja v  a  2s . c  o m
    }
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10QueueGetConfigReplyMessageFactory.java

License:Open Source License

@Override
public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeShort(message.getPort().getValue().intValue());
    outBuffer.writeZero(PADDING);//from   ww w .j av  a2 s  .  co  m
    for (Queues queue : message.getQueues()) {
        ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        queueBuff.writeInt(queue.getQueueId().getValue().intValue());
        queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        queueBuff.writeZero(QUEUE_PADDING);
        for (QueueProperty queueProperty : queue.getQueueProperty()) {
            ByteBuf queuePropertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
            queuePropertyBuff.writeShort(queueProperty.getProperty().getIntValue());
            queuePropertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
            queuePropertyBuff.writeZero(4);
            if (queueProperty.getProperty() == QueueProperties.OFPQTMINRATE) {
                RateQueueProperty body = queueProperty.getAugmentation(RateQueueProperty.class);
                queuePropertyBuff.writeShort(body.getRate().intValue());
                queuePropertyBuff.writeZero(QUEUE_PROPERTY_PADDING);
            }
            queuePropertyBuff.setShort(QUEUE_PROPERTY_LENGTH_INDEX, queuePropertyBuff.readableBytes());
            queueBuff.writeBytes(queuePropertyBuff);
        }
        queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes());
        outBuffer.writeBytes(queueBuff);
    }

    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactory.java

License:Open Source License

private void serializeQueueBody(MultipartReplyBody body, ByteBuf outBuffer) {
    MultipartReplyQueueCase queueCase = (MultipartReplyQueueCase) body;
    MultipartReplyQueue queue = queueCase.getMultipartReplyQueue();
    for (QueueStats queueStats : queue.getQueueStats()) {
        ByteBuf queueStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        queueStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        queueStatsBuff.writeZero(QUEUE_PADDING);
        queueStatsBuff.writeInt(queueStats.getQueueId().intValue());
        queueStatsBuff.writeLong(queueStats.getTxBytes().longValue());
        queueStatsBuff.writeLong(queueStats.getTxPackets().longValue());
        queueStatsBuff.writeLong(queueStats.getTxErrors().longValue());
        queueStatsBuff.setShort(QUEUE_STATS_LENGTH_INDEX, queueStatsBuff.readableBytes());
        outBuffer.writeBytes(queueStatsBuff);
    }//from  w  ww .j  a  v  a2s.c  o m
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.OF10StatsReplyMessageFactory.java

License:Open Source License

private void serializeFlowBody(MultipartReplyBody body, ByteBuf outBuffer, MultipartReplyMessage message) {
    MultipartReplyFlowCase flowCase = (MultipartReplyFlowCase) body;
    MultipartReplyFlow flow = flowCase.getMultipartReplyFlow();
    for (FlowStats flowStats : flow.getFlowStats()) {
        ByteBuf flowStatsBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        flowStatsBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        flowStatsBuff.writeByte(new Long(flowStats.getTableId()).byteValue());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_1);
        OFSerializer<MatchV10> matchSerializer = registry
                .getSerializer(new MessageTypeKey<>(message.getVersion(), MatchV10.class));
        matchSerializer.serialize(flowStats.getMatchV10(), flowStatsBuff);
        flowStatsBuff.writeInt(flowStats.getDurationSec().intValue());
        flowStatsBuff.writeInt(flowStats.getDurationNsec().intValue());
        flowStatsBuff.writeShort(flowStats.getPriority());
        flowStatsBuff.writeShort(flowStats.getIdleTimeout());
        flowStatsBuff.writeShort(flowStats.getHardTimeout());
        flowStatsBuff.writeZero(FLOW_STATS_PADDING_2);
        flowStatsBuff.writeLong(flowStats.getCookie().longValue());
        flowStatsBuff.writeLong(flowStats.getPacketCount().longValue());
        flowStatsBuff.writeLong(flowStats.getByteCount().longValue());
        ListSerializer.serializeList(flowStats.getAction(), ACTION_KEY_MAKER, registry, flowStatsBuff);
        flowStatsBuff.setShort(FLOW_STATS_LENGTH_INDEX, flowStatsBuff.readableBytes());
        outBuffer.writeBytes(flowStatsBuff);
    }/*from w  ww.j  av a2s .c o m*/
}

From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.QueueGetConfigReplyMessageFactory.java

License:Open Source License

@Override
public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeInt(message.getPort().getValue().intValue());
    outBuffer.writeZero(PADDING);/*  w ww  .  java 2 s.  com*/
    for (Queues queue : message.getQueues()) {
        ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
        queueBuff.writeInt(queue.getQueueId().getValue().intValue());
        queueBuff.writeInt(queue.getPort().getValue().intValue());
        queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
        queueBuff.writeZero(QUEUE_PADDING);

        for (QueueProperty property : queue.getQueueProperty()) {
            ByteBuf propertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
            propertyBuff.writeShort(property.getProperty().getIntValue());
            propertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
            propertyBuff.writeZero(PROPERTY_HEADER_PADDING);
            switch (property.getProperty()) {
            case OFPQTMINRATE:
                serializeRateBody(property.getAugmentation(RateQueueProperty.class), propertyBuff);
                break;
            case OFPQTMAXRATE:
                serializeRateBody(property.getAugmentation(RateQueueProperty.class), propertyBuff);
                break;
            case OFPQTEXPERIMENTER:
                serializeExperimenterBody(property.getAugmentation(ExperimenterIdQueueProperty.class),
                        propertyBuff);
                break;
            default:
                break;
            }
            propertyBuff.setShort(PROPERTY_LENGTH_INDEX, propertyBuff.readableBytes());
            queueBuff.writeBytes(propertyBuff);
        }

        queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes());
        outBuffer.writeBytes(queueBuff);
    }
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}