Example usage for io.netty.buffer ByteBuf readUnsignedInt

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

Introduction

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

Prototype

public abstract long readUnsignedInt();

Source Link

Document

Gets an unsigned 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    RoleRequestOutputBuilder builder = new RoleRequestOutputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(0));
    builder.setGenerationId(BigInteger.valueOf(1L));
    RoleRequestOutput message = builder.build();

    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);
    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 24);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
            ControllerRole.forValue((int) serializedBuffer.readUnsignedInt()).getIntValue());
    serializedBuffer.skipBytes(PADDING);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    serializedBuffer.readBytes(genId);//from w ww  . j ava 2  s.c o  m
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}

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

License:Open Source License

/**
 * Testing of {@link RoleRequestInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from  w w  w .  ja v  a2s. co m*/
 */
@Test
public void testRoleRequestInputMessage() throws Exception {
    RoleRequestInputBuilder builder = new RoleRequestInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setRole(ControllerRole.forValue(2));
    byte[] generationId = new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
    builder.setGenerationId(new BigInteger(1, generationId));
    RoleRequestInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    RoleRequestInputMessageFactory factory = RoleRequestInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, MESSAGE_LENGTH);
    Assert.assertEquals("Wrong role", message.getRole().getIntValue(),
            ControllerRole.forValue((int) out.readUnsignedInt()).getIntValue());
    out.skipBytes(PADDING_IN_ROLE_REQUEST_MESSAGE);
    byte[] genId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(genId);
    Assert.assertEquals("Wrong generation ID", message.getGenerationId(), new BigInteger(1, genId));
}

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

License:Open Source License

/**
 * @throws Exception //from  ww  w  . j  av a 2 s .  co m
 * Testing of {@link SetAsyncInputMessageFactory} for correct translation from POJO
 */
@Test
public void testSetAsyncInputMessage() throws Exception {
    SetAsyncInputBuilder builder = new SetAsyncInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setPacketInMask(createPacketInMask());
    builder.setPortStatusMask(createPortStatusMask());
    builder.setFlowRemovedMask(createFlowRemowedMask());
    SetAsyncInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    SetAsyncInputMessageFactory factory = SetAsyncInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
    LOGGER.debug("<< " + ByteBufUtils.byteBufToHexString(out));
    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    Assert.assertEquals("Wrong packetInMask", 5, out.readUnsignedInt());
    Assert.assertEquals("Wrong packetInMask", 7, out.readUnsignedInt());
    Assert.assertEquals("Wrong portStatusMask", 6, out.readUnsignedInt());
    Assert.assertEquals("Wrong portStatusMask", 0, out.readUnsignedInt());
    Assert.assertEquals("Wrong flowRemovedMask", 10, out.readUnsignedInt());
    Assert.assertEquals("Wrong flowRemovedMask", 5, out.readUnsignedInt());

}

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

License:Open Source License

/**
 * Testing of {@link TableModInputMessageFactory} for correct translation from POJO
 * @throws Exception /*from   ww w. ja  v a 2s  . c  o  m*/
 */
@Test
public void testTableModInput() throws Exception {
    TableModInputBuilder builder = new TableModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setTableId(new TableId(9L));
    builder.setConfig(new TableConfig(true));
    TableModInput message = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    TableModInputMessageFactory factory = TableModInputMessageFactory.getInstance();
    factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);

    BufferHelper.checkHeaderV13(out, MESSAGE_TYPE, 16);
    Assert.assertEquals("Wrong TableID", message.getTableId().getValue().intValue(), out.readUnsignedByte());
    out.skipBytes(PADDING_IN_TABLE_MOD_MESSAGE);
    Assert.assertEquals("Wrong TableConfig", 8, out.readUnsignedInt());
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsLabelSerializerTest.java

License:Open Source License

/**
 * Test correct serialization/*from  ww  w.ja  va 2s  .  c  o m*/
 */
@Test
public void testSerialize() {
    MatchEntryBuilder builder = prepareMplsLabelMatchEntry(168535);

    ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
    serializer.serialize(builder.build(), buffer);

    checkHeader(buffer, false);
    assertEquals("Wrong value", 168535, buffer.readUnsignedInt());
    assertTrue("Unexpected data", buffer.readableBytes() == 0);
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java

License:Open Source License

/**
 * Creates action ids - actions without values (OpenFlow v1.3)
 * @param input input ByteBuf//from   w  w  w .jav  a  2 s  .com
 * @param actionsLength length of actions
 * @return ActionsList
 */
public static List<Action> createActionIds(ByteBuf input, int actionsLength) {
    List<Action> actionsList = new ArrayList<>();
    int length = 0;
    ActionBuilder builder;
    while (length < actionsLength) {
        builder = new ActionBuilder();
        int type = input.readUnsignedShort();
        int currentActionLength = input.readUnsignedShort();
        switch (type) {
        case 0:
            builder.setType(Output.class);
            break;
        case 11:
            builder.setType(CopyTtlOut.class);
            break;
        case 12:
            builder.setType(CopyTtlIn.class);
            break;
        case 15:
            builder.setType(SetMplsTtl.class);
            break;
        case 16:
            builder.setType(DecMplsTtl.class);
            break;
        case 17:
            builder.setType(PushVlan.class);
            break;
        case 18:
            builder.setType(PopVlan.class);
            break;
        case 19:
            builder.setType(PushMpls.class);
            break;
        case 20:
            builder.setType(PopMpls.class);
            break;
        case 21:
            builder.setType(SetQueue.class);
            break;
        case 22:
            builder.setType(Group.class);
            break;
        case 23:
            builder.setType(SetNwTtl.class);
            break;
        case 24:
            builder.setType(DecNwTtl.class);
            break;
        case 25:
            builder.setType(SetField.class);
            break;
        case 26:
            builder.setType(PushPbb.class);
            break;
        case 27:
            builder.setType(PopPbb.class);
            break;
        case 0xFFFF:
            builder.setType(Experimenter.class);
            ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
            experimenter.setExperimenter(input.readUnsignedInt());
            builder.addAugmentation(ExperimenterAction.class, experimenter.build());
            break;
        default:
            break;
        }
        actionsList.add(builder.build());
        length += currentActionLength;
    }
    return actionsList;
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java

License:Open Source License

private static Action createOutputAction(ByteBuf in, ActionBuilder actionBuilder) {
    actionBuilder.setType(Output.class);
    PortActionBuilder port = new PortActionBuilder();
    port.setPort(new PortNumber(in.readUnsignedInt()));
    actionBuilder.addAugmentation(PortAction.class, port.build());
    MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();
    maxLen.setMaxLength(in.readUnsignedShort());
    actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());
    in.skipBytes(PADDING_IN_OUTPUT_ACTIONS_HEADER);
    return actionBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java

License:Open Source License

private static Action createSetQueueAction(ByteBuf in, ActionBuilder actionBuilder) {
    actionBuilder.setType(SetQueue.class);
    QueueIdActionBuilder queueId = new QueueIdActionBuilder();
    queueId.setQueueId(in.readUnsignedInt());
    actionBuilder.addAugmentation(QueueIdAction.class, queueId.build());
    return actionBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java

License:Open Source License

private static Action createGroupAction(ByteBuf in, ActionBuilder actionBuilder) {
    actionBuilder.setType(Group.class);
    GroupIdActionBuilder group = new GroupIdActionBuilder();
    group.setGroupId(in.readUnsignedInt());
    actionBuilder.addAugmentation(GroupIdAction.class, group.build());
    return actionBuilder.build();
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.ActionsDeserializer.java

License:Open Source License

private static Action createExperimenterAction(ByteBuf in, ActionBuilder actionBuilder, int actionLength) {
    actionBuilder.setType(Experimenter.class);
    ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
    experimenter.setExperimenter(in.readUnsignedInt());
    int dataLength = actionLength - EXPERIMENTER_ACTION_HEADER_LENGTH;
    if (dataLength > 0) {
        byte[] data = new byte[dataLength];
        in.readBytes(data);/*from   w  w w.j av  a2 s.  c  o  m*/
        experimenter.setData(data);
    }
    actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());
    return actionBuilder.build();
}