Example usage for io.netty.buffer ByteBuf writeZero

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

Introduction

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

Prototype

public abstract ByteBuf writeZero(int length);

Source Link

Document

Fills this buffer with NUL (0x00) starting at the current writerIndex and increases the writerIndex by the specified length .

Usage

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);
    }//  w w w .j  a v  a 2s .  c o  m
}

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

License:Open Source License

@Override
public void serialize(PacketInMessage message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeInt(message.getBufferId().intValue());
    outBuffer.writeShort(message.getTotalLen().intValue());
    outBuffer.writeByte(message.getReason().getIntValue());
    outBuffer.writeByte(message.getTableId().getValue().byteValue());
    outBuffer.writeLong(message.getCookie().longValue());
    OFSerializer<Match> matchSerializer = registry
            .<Match, OFSerializer<Match>>getSerializer(new MessageTypeKey<>(message.getVersion(), Match.class));
    matchSerializer.serialize(message.getMatch(), outBuffer);
    outBuffer.writeZero(PADDING);

    byte[] data = message.getData();

    if (data != null) {
        outBuffer.writeBytes(data);//  w  w  w  .  java  2  s  . c o m
    }
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

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

License:Open Source License

@Override
public void serialize(PortStatusMessage message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeByte(message.getReason().getIntValue());
    outBuffer.writeZero(PADDING);
    outBuffer.writeInt(message.getPortNo().intValue());
    outBuffer.writeZero(PORT_PADDING_1);
    writeMacAddress(message.getHwAddr().getValue(), outBuffer);
    outBuffer.writeZero(PORT_PADDING_2);
    writeName(message.getName(), outBuffer);
    writePortConfig(message.getConfig(), outBuffer);
    writePortState(message.getState(), outBuffer);
    writePortFeatures(message.getCurrentFeatures(), outBuffer);
    writePortFeatures(message.getAdvertisedFeatures(), outBuffer);
    writePortFeatures(message.getSupportedFeatures(), outBuffer);
    writePortFeatures(message.getPeerFeatures(), outBuffer);
    outBuffer.writeInt(message.getCurrSpeed().intValue());
    outBuffer.writeInt(message.getMaxSpeed().intValue());
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

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);
    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);//from   w w w .  ja v  a  2 s.  c o  m
                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);
}

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

License:Open Source License

private void serializeRateBody(RateQueueProperty body, ByteBuf outBuffer) {
    outBuffer.writeShort(body.getRate());
    outBuffer.writeZero(PROPERTY_RATE_PADDING);
}

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

License:Open Source License

private void serializeExperimenterBody(ExperimenterIdQueueProperty body, ByteBuf outBuffer) {
    // TODO: Experimenter Data is vendor specific that should implement its
    // own serializer
    outBuffer.writeInt(body.getExperimenter().getValue().intValue());
    outBuffer.writeZero(PROPERTY_EXPERIMENTER_PADDING);
}

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

License:Open Source License

@Override
public void serialize(RoleRequestOutput message, ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeInt(message.getRole().getIntValue());
    outBuffer.writeZero(PADDING);
    outBuffer.writeLong(message.getGenerationId().longValue());
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

From source file:org.opendaylight.openflowjava.nx.codec.action.ConntrackCodec.java

License:Open Source License

@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
    ActionConntrack action = ((ActionConntrack) input.getActionChoice());
    serializeHeader(LENGTH, NXAST_CONNTRACK_SUBTYPE, outBuffer);

    outBuffer.writeShort(action.getNxActionConntrack().getFlags().shortValue());
    outBuffer.writeInt(action.getNxActionConntrack().getZoneSrc().intValue());
    outBuffer.writeShort(action.getNxActionConntrack().getConntrackZone().shortValue());
    outBuffer.writeByte(action.getNxActionConntrack().getRecircTable().byteValue());
    outBuffer.writeZero(5);
}

From source file:org.opendaylight.openflowjava.nx.codec.action.ConntrackCodecTest.java

License:Open Source License

private void createBufer(ByteBuf message) {
    message.writeShort(EncodeConstants.EXPERIMENTER_VALUE);
    message.writeShort(LENGTH);//from   ww  w  . j  a va2s.  c  o m
    message.writeInt(NiciraConstants.NX_VENDOR_ID.intValue());
    message.writeShort(NXAST_CONNTRACK_SUBTYPE);
    //FLAG = 1
    message.writeShort(1);
    //ZONE_SRC = 2
    message.writeInt(2);
    //CONNTRACK_ZONE = 3
    message.writeShort(3);
    //RECIRC_TABLE = 4
    message.writeByte(4);
    //ADDS 5 empty bytes
    message.writeZero(5);
}

From source file:org.opendaylight.openflowjava.nx.codec.action.LearnCodec.java

License:Open Source License

@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
    ActionLearn action = (ActionLearn) input.getActionChoice();
    int length = LearnCodecUtil.calcLength(action);
    int lengthMod = length % MUL_LENGTH;
    if (lengthMod != 0) {
        lengthMod = MUL_LENGTH - lengthMod;
    }/*  w  ww . j a  v a2 s .  com*/
    serializeHeader(length + lengthMod, NXAST_LEARN_SUBTYPE, outBuffer);

    LearnCodecUtil.serializeLearnHeader(outBuffer, action);
    LearnCodecUtil.serializeFlowMods(outBuffer, action);

    //pad with zeros for the length to be multiplication by 8
    if (lengthMod != 0) {
        outBuffer.writeZero(lengthMod);
    }

}