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.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java

License:Open Source License

private void serializePortStatsBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyPortStatsCase portStatsCase = (MultipartReplyPortStatsCase) body;
    MultipartReplyPortStats portStats = portStatsCase.getMultipartReplyPortStats();
    for (PortStats portStat : portStats.getPortStats()) {
        outBuffer.writeInt(portStat.getPortNo().intValue());
        outBuffer.writeZero(PORT_STATS_PADDING);
        outBuffer.writeLong(portStat.getRxPackets().longValue());
        outBuffer.writeLong(portStat.getTxPackets().longValue());
        outBuffer.writeLong(portStat.getRxBytes().longValue());
        outBuffer.writeLong(portStat.getTxBytes().longValue());
        outBuffer.writeLong(portStat.getRxDropped().longValue());
        outBuffer.writeLong(portStat.getTxDropped().longValue());
        outBuffer.writeLong(portStat.getRxErrors().longValue());
        outBuffer.writeLong(portStat.getTxErrors().longValue());
        outBuffer.writeLong(portStat.getRxFrameErr().longValue());
        outBuffer.writeLong(portStat.getRxOverErr().longValue());
        outBuffer.writeLong(portStat.getRxCrcErr().longValue());
        outBuffer.writeLong(portStat.getCollisions().longValue());
        outBuffer.writeInt(portStat.getDurationSec().intValue());
        outBuffer.writeInt(portStat.getDurationNsec().intValue());
    }/* w ww  . j a  v  a 2s. c o  m*/
}

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

License:Open Source License

private void serializeTableBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyTableCase tableCase = (MultipartReplyTableCase) body;
    MultipartReplyTable table = tableCase.getMultipartReplyTable();
    for (TableStats tableStats : table.getTableStats()) {
        outBuffer.writeByte(tableStats.getTableId());
        outBuffer.writeZero(TABLE_PADDING);
        outBuffer.writeInt(tableStats.getActiveCount().intValue());
        outBuffer.writeLong(tableStats.getLookupCount().longValue());
        outBuffer.writeLong(tableStats.getMatchedCount().longValue());
    }// w ww.ja va2 s .  com
}

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

License:Open Source License

private void serializeAggregateBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyAggregateCase aggregateCase = (MultipartReplyAggregateCase) body;
    MultipartReplyAggregate aggregate = aggregateCase.getMultipartReplyAggregate();
    outBuffer.writeLong(aggregate.getPacketCount().longValue());
    outBuffer.writeLong(aggregate.getByteCount().longValue());
    outBuffer.writeInt(aggregate.getFlowCount().intValue());
    outBuffer.writeZero(AGGREGATE_PADDING);
}

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

License:Open Source License

private void serializeFlowBody(final MultipartReplyBody body, final ByteBuf outBuffer,
        final 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);
    }/*from  w  w  w.java 2  s. co m*/
}

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

License:Open Source License

private void serializePortDescBody(final MultipartReplyBody body, final ByteBuf outBuffer) {
    MultipartReplyPortDescCase portCase = (MultipartReplyPortDescCase) body;
    MultipartReplyPortDesc portDesc = portCase.getMultipartReplyPortDesc();
    for (Ports port : portDesc.getPorts()) {
        outBuffer.writeInt(port.getPortNo().intValue()); // Assuming PortNo
                                                         // = PortId
        outBuffer.writeZero(PORT_DESC_PADDING_1);
        outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(port.getHwAddr()));
        outBuffer.writeZero(PORT_DESC_PADDING_2);
        writeName(port.getName(), outBuffer);
        writePortConfig(port.getConfig(), outBuffer);
        writePortState(port.getState(), outBuffer);
        writePortFeatures(port.getCurrentFeatures(), outBuffer);
        writePortFeatures(port.getAdvertisedFeatures(), outBuffer);
        writePortFeatures(port.getSupportedFeatures(), outBuffer);
        writePortFeatures(port.getPeerFeatures(), outBuffer);
        outBuffer.writeInt(port.getCurrSpeed().intValue());
        outBuffer.writeInt(port.getMaxSpeed().intValue());
    }/*from   ww  w . j a  v  a 2s.com*/
}

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

License:Open Source License

@Override
public void serialize(final GetFeaturesOutput message, final ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeLong(message.getDatapathId().longValue());
    outBuffer.writeInt(message.getBuffers().intValue());
    outBuffer.writeByte(message.getTables().intValue());
    outBuffer.writeZero(PADDING);
    outBuffer.writeInt(createCapabilities(message.getCapabilitiesV10()));
    outBuffer.writeInt(createActionsV10(message.getActionsV10()));
    for (PhyPort port : message.getPhyPort()) {
        outBuffer.writeShort(port.getPortNo().intValue());
        outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(port.getHwAddr()));
        writeName(port.getName(), outBuffer);
        writePortConfig(port.getConfigV10(), outBuffer);
        writePortState(port.getStateV10(), outBuffer);
        writePortFeature(port.getCurrentFeaturesV10(), outBuffer);
        writePortFeature(port.getAdvertisedFeaturesV10(), outBuffer);
        writePortFeature(port.getSupportedFeaturesV10(), outBuffer);
        writePortFeature(port.getPeerFeaturesV10(), outBuffer);
    }//from w w  w.j ava  2  s.  co  m
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

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

License:Open Source License

@Override
public void serialize(final PortStatusMessage message, final ByteBuf outBuffer) {
    ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeByte(message.getReason().getIntValue());
    outBuffer.writeZero(PADDING);
    outBuffer.writeShort(message.getPortNo().intValue());
    outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddr()));
    writeName(message.getName(), outBuffer);
    writePortConfig(message.getConfigV10(), outBuffer);
    writePortState(message.getStateV10(), outBuffer);
    writePortFeature(message.getCurrentFeaturesV10(), outBuffer);
    writePortFeature(message.getAdvertisedFeaturesV10(), outBuffer);
    writePortFeature(message.getSupportedFeaturesV10(), outBuffer);
    writePortFeature(message.getPeerFeaturesV10(), outBuffer);
    ByteBufUtils.updateOFHeaderLength(outBuffer);
}

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

License:Open Source License

@Override
public void serialize(final PortStatusMessage message, final 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);
    outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddr()));
    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.openflowjava.protocol.impl.serialization.instruction.AbstractActionInstructionSerializer.java

License:Open Source License

protected void writeActions(final List<Action> actions, final ByteBuf outBuffer, int startIndex) {
    int lengthIndex = outBuffer.writerIndex();
    outBuffer.writeShort(EncodeConstants.EMPTY_LENGTH);
    outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    ListSerializer.serializeList(actions, ACTION_KEY_MAKER, getRegistry(), outBuffer);
    int instructionLength = outBuffer.writerIndex() - startIndex;
    outBuffer.setShort(lengthIndex, instructionLength);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.instruction.ApplyActionsInstructionSerializer.java

License:Open Source License

@Override
public void serialize(final Instruction instruction, final ByteBuf outBuffer) {
    int startIndex = outBuffer.writerIndex();
    outBuffer.writeShort(getType());//ww  w  .java 2  s . c om
    ApplyActionsCase actionsCase = (ApplyActionsCase) instruction.getInstructionChoice();
    if (actionsCase != null) {
        List<Action> actions = actionsCase.getApplyActions().getAction();
        writeActions(actions, outBuffer, startIndex);
    } else {
        outBuffer.writeShort(InstructionConstants.STANDARD_INSTRUCTION_LENGTH);
        outBuffer.writeZero(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    }
}