Example usage for io.netty.buffer ByteBuf readUnsignedShort

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

Introduction

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

Prototype

public abstract int readUnsignedShort();

Source Link

Document

Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

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

License:Open Source License

private static List<Queues> createQueuesList(ByteBuf input) {
    List<Queues> queuesList = new ArrayList<>();
    while (input.readableBytes() > 0) {
        QueuesBuilder queueBuilder = new QueuesBuilder();
        queueBuilder.setQueueId(new QueueId(input.readUnsignedInt()));
        queueBuilder.setPort(new PortNumber(input.readUnsignedInt()));
        int length = input.readUnsignedShort();
        input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER);
        queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH));
        queuesList.add(queueBuilder.build());
    }/*  w w  w .  ja v  a2s.com*/
    return queuesList;
}

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

License:Open Source License

private static List<QueueProperty> createPropertiesList(ByteBuf input, int length) {
    int propertiesLength = length;
    List<QueueProperty> propertiesList = new ArrayList<>();
    while (propertiesLength > 0) {
        QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder();
        QueueProperties property = QueueProperties.forValue(input.readUnsignedShort());
        propertiesBuilder.setProperty(property);
        int currentPropertyLength = input.readUnsignedShort();
        propertiesLength -= currentPropertyLength;
        input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER);
        if (property.equals(QueueProperties.OFPQTMINRATE) || property.equals(QueueProperties.OFPQTMAXRATE)) {
            RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
            rateBuilder.setRate(input.readUnsignedShort());
            propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build());
            input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY);
        } else if (property.equals(QueueProperties.OFPQTEXPERIMENTER)) {
            ExperimenterQueuePropertyBuilder expBuilder = new ExperimenterQueuePropertyBuilder();
            expBuilder.setExperimenter(input.readUnsignedInt());
            input.skipBytes(PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY);
            expBuilder.setData(input.readBytes(currentPropertyLength - EncodeConstants.SIZE_OF_INT_IN_BYTES
                    - PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY).array());
            propertiesBuilder.addAugmentation(RateQueueProperty.class, expBuilder.build());
        }/*from www. j a v a  2s. com*/
        propertiesList.add(propertiesBuilder.build());
    }
    return propertiesList;
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.factories.SetConfigInputMessageFactory.java

License:Open Source License

@Override
public SetConfigInput deserialize(ByteBuf rawMessage) {
    SetConfigInputBuilder builder = new SetConfigInputBuilder();
    builder.setVersion(getVersion());/* ww w .  j a v  a2 s . com*/
    builder.setXid(rawMessage.readUnsignedInt());
    builder.setFlags(SwitchConfigFlag.forValue(rawMessage.readUnsignedShort()));
    builder.setMissSendLen(rawMessage.readUnsignedShort());
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.AbstractInstructionDeserializer.java

License:Open Source License

protected InstructionBuilder processHeader(ByteBuf input) {
    InstructionBuilder builder = new InstructionBuilder();
    int type = input.readUnsignedShort();
    switch (type) {
    case 1:/*  ww  w. ja v a2s.  c  o m*/
        builder.setType(GotoTable.class);
        break;
    case 2:
        builder.setType(WriteMetadata.class);
        break;
    case 3:
        builder.setType(WriteActions.class);
        break;
    case 4:
        builder.setType(ApplyActions.class);
        break;
    case 5:
        builder.setType(ClearActions.class);
        break;
    case 6:
        builder.setType(Meter.class);
        break;
    default:
        throw new IllegalStateException("Unknown instruction type received, type: " + type);
    }
    return builder;
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.ApplyActionsInstructionDeserializer.java

License:Open Source License

@Override
public Instruction deserialize(ByteBuf input) {
    InstructionBuilder builder = new InstructionBuilder();
    input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    int instructionLength = input.readUnsignedShort();
    input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    ApplyActionsCaseBuilder caseBuilder = new ApplyActionsCaseBuilder();
    ApplyActionsBuilder actionsBuilder = new ApplyActionsBuilder();
    actionsBuilder.setAction(deserializeActions(input, instructionLength));
    caseBuilder.setApplyActions(actionsBuilder.build());
    builder.setInstructionChoice(caseBuilder.build());
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.instruction.WriteActionsInstructionDeserializer.java

License:Open Source License

@Override
public Instruction deserialize(ByteBuf input) {
    InstructionBuilder builder = new InstructionBuilder();
    input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    int instructionLength = input.readUnsignedShort();
    input.skipBytes(InstructionConstants.PADDING_IN_ACTIONS_INSTRUCTION);
    WriteActionsCaseBuilder caseBuilder = new WriteActionsCaseBuilder();
    WriteActionsBuilder actionsBuilder = new WriteActionsBuilder();
    actionsBuilder.setAction(deserializeActions(input, instructionLength));
    caseBuilder.setWriteActions(actionsBuilder.build());
    builder.setInstructionChoice(caseBuilder.build());
    return builder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.AbstractOxmIpv6AddressDeserializer.java

License:Open Source License

private static void addIpv6AddressAugmentation(MatchEntriesBuilder builder, ByteBuf input) {
    Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder();
    List<String> groups = new ArrayList<>();
    for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) {
        groups.add(String.format("%04X", input.readUnsignedShort()));
    }/*ww w .  ja v a 2s .c o  m*/
    Joiner joiner = Joiner.on(":");
    ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups)));
    builder.addAugmentation(Ipv6AddressMatchEntry.class, ipv6AddressBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.AbstractOxmPortDeserializer.java

License:Open Source License

private static void addPortAugmentation(MatchEntriesBuilder builder, ByteBuf input) {
    PortMatchEntryBuilder portBuilder = new PortMatchEntryBuilder();
    portBuilder.setPort(new PortNumber(input.readUnsignedShort()));
    builder.addAugmentation(PortMatchEntry.class, portBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.ext.OnfOxmTcpFlagsDeserializer.java

License:Open Source License

private static void addTcpFlagsAugmentation(ByteBuf input, ExperimenterIdCaseBuilder expCaseBuilder,
        boolean hasMask) {
    TcpFlagsContainerBuilder flagsContainerBuilder = new TcpFlagsContainerBuilder();
    TcpFlagsBuilder flagsBuilder = new TcpFlagsBuilder();
    flagsBuilder.setFlags(input.readUnsignedShort());
    if (hasMask) {
        byte[] mask = new byte[EncodeConstants.SIZE_OF_SHORT_IN_BYTES];
        input.readBytes(mask);/*from  ww w  . j  a v  a  2 s .  c  o  m*/
        flagsBuilder.setMask(mask);
    }
    flagsContainerBuilder.setTcpFlags(flagsBuilder.build());
    expCaseBuilder.addAugmentation(TcpFlagsContainer.class, flagsContainerBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.deserialization.match.NxmTcpFlagDeserializer.java

License:Open Source License

private static void addTcpFlagAugmentation(ByteBuf input, MatchEntriesBuilder builder) {
    TcpFlagMatchEntryBuilder tcpFlagMatchEntryBuilder = new TcpFlagMatchEntryBuilder();
    tcpFlagMatchEntryBuilder.setTcpFlag(input.readUnsignedShort());
}