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.deserialization.match.OxmInPortDeserializer.java

License:Open Source License

private static void addInPortValue(ByteBuf input, MatchEntryBuilder builder) {
    InPortCaseBuilder caseBuilder = new InPortCaseBuilder();
    InPortBuilder inPortBuilder = new InPortBuilder();
    inPortBuilder.setPortNumber(new PortNumber(input.readUnsignedInt()));
    caseBuilder.setInPort(inPortBuilder.build());
    builder.setMatchEntryValue(caseBuilder.build());
}

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

License:Open Source License

private static void addIpv6FlabelValue(ByteBuf input, MatchEntryBuilder builder) {
    Ipv6FlabelCaseBuilder caseBuilder = new Ipv6FlabelCaseBuilder();
    Ipv6FlabelBuilder labelBuilder = new Ipv6FlabelBuilder();
    labelBuilder.setIpv6Flabel(new Ipv6FlowLabel(input.readUnsignedInt()));
    if (builder.isHasMask()) {
        labelBuilder.setMask(OxmDeserializerHelper.convertMask(input, EncodeConstants.SIZE_OF_INT_IN_BYTES));
    }/*ww w  .j  a v a2 s  .  c o m*/
    caseBuilder.setIpv6Flabel(labelBuilder.build());
    builder.setMatchEntryValue(caseBuilder.build());
}

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

License:Open Source License

private static void addMplsLabelValue(ByteBuf input, MatchEntryBuilder builder) {
    MplsLabelCaseBuilder caseBuilder = new MplsLabelCaseBuilder();
    MplsLabelBuilder labelBuilder = new MplsLabelBuilder();
    labelBuilder.setMplsLabel(input.readUnsignedInt());
    caseBuilder.setMplsLabel(labelBuilder.build());
    builder.setMatchEntryValue(caseBuilder.build());
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactoryTest.java

License:Open Source License

@Test
public void testSerializeWithoutProperties() {
    BundleAddMessageBuilder builder = new BundleAddMessageBuilder();
    builder.setBundleId(new BundleId(1L));
    builder.setFlags(new BundleFlags(true, false));

    Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase();
    builder.setMessage(innerMessage);/*from w w  w .  j a va  2s.  com*/

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(portModSerializer);
    ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
    factory.serialize(builder.build(), out);

    Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
    long padding = out.readUnsignedShort();
    Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());
    Mockito.verify(portModSerializer, Mockito.times(1)).serialize((PortMod) innerMessage, out);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleAddMessageFactoryTest.java

License:Open Source License

@Test
public void testSerializeWithExperimenterProperty() {
    BundleAddMessageBuilder builder = new BundleAddMessageBuilder();
    builder.setBundleId(new BundleId(2L));
    builder.setFlags(new BundleFlags(true, false));

    Message innerMessage = AbstractBundleMessageFactoryTest.createPortModCase();
    builder.setMessage(innerMessage);/*  ww  w. j  av a  2 s  .co m*/

    BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest
            .createBundleExperimenterPropertyData();
    builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data));

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(portModSerializer)
            .thenReturn(propertySerializer);
    ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
    factory.serialize(builder.build(), out);

    Assert.assertEquals("Wrong bundle ID", 2L, out.readUnsignedInt());
    long padding = out.readUnsignedShort();
    Assert.assertEquals("Wrong flags", 1, out.readUnsignedShort());
    Mockito.verify(portModSerializer, Mockito.times(1)).serialize((PortMod) innerMessage, out);
    Mockito.verify(propertySerializer, Mockito.times(1)).serialize(data, out);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactoryTest.java

License:Open Source License

@Test
public void testSerializeWithoutProperties() {
    BundleControlBuilder builder = new BundleControlBuilder();
    builder.setBundleId(new BundleId(1L));
    builder.setType(BundleControlType.ONFBCTOPENREQUEST);
    builder.setFlags(new BundleFlags(true, true));

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(builder.build(), out);

    Assert.assertEquals("Wrong bundle ID", 1L, out.readUnsignedInt());
    Assert.assertEquals("Wrong type", BundleControlType.ONFBCTOPENREQUEST.getIntValue(),
            out.readUnsignedShort());/*from   ww  w .j  av  a  2s  .c o m*/
    Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
    Assert.assertTrue("Unexpected data", out.readableBytes() == 0);
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.BundleControlFactoryTest.java

License:Open Source License

@Test
public void testSerializeWithExperimenterProperty() {
    BundleControlBuilder builder = new BundleControlBuilder();
    builder.setBundleId(new BundleId(3L));
    builder.setType(BundleControlType.ONFBCTCOMMITREQUEST);
    builder.setFlags(new BundleFlags(false, true));

    BundleExperimenterPropertyData data = AbstractBundleMessageFactoryTest
            .createBundleExperimenterPropertyData();
    builder.setBundleProperty(AbstractBundleMessageFactoryTest.createListWithBundleExperimenterProperty(data));

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    Mockito.when(registry.getSerializer(Matchers.any(MessageTypeKey.class))).thenReturn(serializer);
    ((SerializerRegistryInjector) factory).injectSerializerRegistry(registry);
    factory.serialize(builder.build(), out);

    Assert.assertEquals("Wrong bundle ID", 3L, out.readUnsignedInt());
    Assert.assertEquals("Wrong type", BundleControlType.ONFBCTCOMMITREQUEST.getIntValue(),
            out.readUnsignedShort());//from w w  w .j  ava2  s  .  c  o m
    Assert.assertEquals("Wrong flags", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong property type", BundlePropertyType.ONFETBPTEXPERIMENTER.getIntValue(),
            out.readUnsignedShort());
    int length = out.readUnsignedShort();
    Assert.assertEquals("Wrong experimenter ID", 1, out.readUnsignedInt());
    Assert.assertEquals("Wrong experimenter type", 2, out.readUnsignedInt());
    Mockito.verify(serializer, Mockito.times(1)).serialize(data, out);
}

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

License:Open Source License

/**
 * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO
 * @throws Exception //from w  w  w .j  a  v a2s .c  om
 */
@Test
public void test() throws Exception {
    ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setExperimenter(0x0001020304L);
    builder.setExpType(0x0001020304L);
    builder.setData(new byte[] { 0x01, 0x02, 0x03 });
    ExperimenterInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message));
    Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
    Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());
    Assert.assertArrayEquals("Wrong data", message.getData(), readData(out));
}

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

License:Open Source License

/**
 * @throws Exception // w  ww . j a v  a  2s . c om
 * Testing of {@link FlowModInputMessageFactory} for correct translation from POJO
 */
@Test
public void testFlowModInputMessageFactory() throws Exception {
    FlowModInputBuilder builder = new FlowModInputBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    byte[] cookie = new byte[] { (byte) 0xFF, 0x01, 0x04, 0x01, 0x06, 0x00, 0x07, 0x01 };
    builder.setCookie(new BigInteger(1, cookie));
    byte[] cookieMask = new byte[] { (byte) 0xFF, 0x05, 0x00, 0x00, 0x09, 0x30, 0x00, 0x30 };
    builder.setCookieMask(new BigInteger(1, cookieMask));
    builder.setTableId(new TableId(65L));
    builder.setCommand(FlowModCommand.forValue(2));
    builder.setIdleTimeout(12);
    builder.setHardTimeout(0);
    builder.setPriority(126);
    builder.setBufferId(2L);
    builder.setOutPort(new PortNumber(4422L));
    builder.setOutGroup(98L);
    builder.setFlags(new FlowModFlags(true, false, true, false, true));
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setType(OxmMatchType.class);
    List<MatchEntries> entries = new ArrayList<>();
    MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    PortNumberMatchEntryBuilder portNumberBuilder = new PortNumberMatchEntryBuilder();
    portNumberBuilder.setPortNumber(new PortNumber(42L));
    entriesBuilder.addAugmentation(PortNumberMatchEntry.class, portNumberBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(Nxm0Class.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
    ecnBuilder.setEcn((short) 4);
    entriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntries(entries);
    builder.setMatch(matchBuilder.build());
    List<Instruction> instructions = new ArrayList<>();
    InstructionBuilder insBuilder = new InstructionBuilder();
    insBuilder.setType(GotoTable.class);
    TableIdInstructionBuilder idBuilder = new TableIdInstructionBuilder();
    idBuilder.setTableId((short) 43);
    insBuilder.addAugmentation(TableIdInstruction.class, idBuilder.build());
    instructions.add(insBuilder.build());
    insBuilder.setType(WriteMetadata.class);
    MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder();
    metaBuilder.setMetadata(cookie);
    metaBuilder.setMetadataMask(cookieMask);
    insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(insBuilder.build());
    insBuilder = new InstructionBuilder();
    insBuilder.setType(ApplyActions.class);
    insBuilder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(insBuilder.build());
    builder.setInstruction(instructions);
    FlowModInput message = builder.build();

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

    BufferHelper.checkHeaderV13(out, factory.getMessageType(), factory.computeLength(message));
    cookie = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookie);
    Assert.assertEquals("Wrong cookie", message.getCookie(), new BigInteger(1, cookie));
    cookieMask = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieMask);
    Assert.assertEquals("Wrong cookieMask", message.getCookieMask(), new BigInteger(1, cookieMask));
    Assert.assertEquals("Wrong tableId", message.getTableId().getValue().intValue(), out.readUnsignedByte());
    Assert.assertEquals("Wrong command", message.getCommand().getIntValue(), out.readUnsignedByte());
    Assert.assertEquals("Wrong idleTimeOut", message.getIdleTimeout().intValue(), out.readShort());
    Assert.assertEquals("Wrong hardTimeOut", message.getHardTimeout().intValue(), out.readShort());
    Assert.assertEquals("Wrong priority", message.getPriority().intValue(), out.readUnsignedShort());
    Assert.assertEquals("Wrong bufferId", message.getBufferId().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong outPort", message.getOutPort().getValue().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong outGroup", message.getOutGroup().intValue(), out.readUnsignedInt());
    Assert.assertEquals("Wrong flags", message.getFlags(),
            createFlowModFlagsFromBitmap(out.readUnsignedShort()));
    out.skipBytes(PADDING_IN_FLOW_MOD_MESSAGE);
    Assert.assertEquals("Wrong match type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, out.readUnsignedShort());
    short fieldAndMask = out.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0, out.readUnsignedShort());
    fieldAndMask = out.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, out.readUnsignedByte());
    out.skipBytes(7);
    Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong instruction value", 43, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    out.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
    byte[] cookieRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieRead);
    byte[] cookieMaskRead = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(cookieMaskRead);
    Assert.assertArrayEquals("Wrong metadata", cookie, cookieRead);
    Assert.assertArrayEquals("Wrong metadata mask", cookieMask, cookieMaskRead);
    Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}

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

License:Open Source License

@Test
public void testSerialize() throws Exception {
    FlowRemovedMessageBuilder builder = new FlowRemovedMessageBuilder();
    BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
    builder.setCookie(BigInteger.valueOf(1234L));
    builder.setPriority(1234);//from  w  w  w  . j a  v  a2  s.  c o  m
    builder.setReason(FlowRemovedReason.forValue(2));
    builder.setTableId(new TableId(65L));
    builder.setDurationSec(1234L);
    builder.setDurationNsec(1234L);
    builder.setIdleTimeout(1234);
    builder.setHardTimeout(1234);
    builder.setPacketCount(BigInteger.valueOf(1234L));
    builder.setByteCount(BigInteger.valueOf(1234L));
    MatchBuilder matchBuilder = new MatchBuilder();
    matchBuilder.setType(OxmMatchType.class);
    List<MatchEntry> entries = new ArrayList<>();
    MatchEntryBuilder entriesBuilder = new MatchEntryBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(InPhyPort.class);
    entriesBuilder.setHasMask(false);
    InPhyPortCaseBuilder inPhyPortCaseBuilder = new InPhyPortCaseBuilder();
    InPhyPortBuilder inPhyPortBuilder = new InPhyPortBuilder();
    inPhyPortBuilder.setPortNumber(new PortNumber(42L));
    inPhyPortCaseBuilder.setInPhyPort(inPhyPortBuilder.build());
    entriesBuilder.setMatchEntryValue(inPhyPortCaseBuilder.build());
    entries.add(entriesBuilder.build());
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(IpEcn.class);
    entriesBuilder.setHasMask(false);
    IpEcnCaseBuilder ipEcnCaseBuilder = new IpEcnCaseBuilder();
    IpEcnBuilder ipEcnBuilder = new IpEcnBuilder();
    ipEcnBuilder.setEcn((short) 4);
    ipEcnCaseBuilder.setIpEcn(ipEcnBuilder.build());
    entriesBuilder.setMatchEntryValue(ipEcnCaseBuilder.build());
    entries.add(entriesBuilder.build());
    matchBuilder.setMatchEntry(entries);
    builder.setMatch(matchBuilder.build());
    FlowRemovedMessage message = builder.build();
    ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
    factory.serialize(message, serializedBuffer);

    BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 72);
    Assert.assertEquals("Wrong cookie", message.getCookie().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong priority", message.getPriority().intValue(), serializedBuffer.readShort());
    Assert.assertEquals("Wrong reason", message.getReason().getIntValue(), serializedBuffer.readByte());
    Assert.assertEquals("Wrong Table ID", message.getTableId().getValue().intValue(),
            serializedBuffer.readUnsignedByte());
    Assert.assertEquals("Wrong duration sec", message.getDurationSec().intValue(), serializedBuffer.readInt());
    Assert.assertEquals("Wrong duration nsec", message.getDurationNsec().intValue(),
            serializedBuffer.readInt());
    Assert.assertEquals("Wrong Idle timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Hard timeout", message.getIdleTimeout().intValue(),
            serializedBuffer.readShort());
    Assert.assertEquals("Wrong Packet count", message.getPacketCount().longValue(),
            serializedBuffer.readLong());
    Assert.assertEquals("Wrong Byte count", message.getByteCount().longValue(), serializedBuffer.readLong());
    Assert.assertEquals("Wrong match type", 1, serializedBuffer.readUnsignedShort());
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    short fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 1, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 42, serializedBuffer.readUnsignedInt());
    Assert.assertEquals("Wrong oxm class", 0x8000, serializedBuffer.readUnsignedShort());
    fieldAndMask = serializedBuffer.readUnsignedByte();
    Assert.assertEquals("Wrong oxm hasMask", 0, fieldAndMask & 1);
    Assert.assertEquals("Wrong oxm field", 9, fieldAndMask >> 1);
    serializedBuffer.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong oxm value", 4, serializedBuffer.readUnsignedByte());
    serializedBuffer.skipBytes(7);
}