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.serialization.match.OxmIpDscpSerializerTest.java

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IP_DSCP, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IP_PROTO, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_BYTE_IN_BYTES, buffer.readUnsignedByte());
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IPV4_DST, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    if (hasMask) {
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());
    } else {//from  ww  w . j  ava 2 s .co  m
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());
    }
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IPV4_SRC, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    if (hasMask) {
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());
    } else {/*from  ww  w .  j  a  v  a  2  s .co m*/
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());
    }
}

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

License:Open Source License

/**
 * Test correct serialization/*from w  w w.j a  v  a2s.c om*/
 */
@Test
public void testSerializeWithoutMask() {
    MatchEntryBuilder builder = prepareIpv6ExtHdrMatchEntry(false,
            new Ipv6ExthdrFlags(true, false, true, false, true, false, true, false, true));

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

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

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

License:Open Source License

/**
 * Test correct serialization/*from   w  ww.  java  2 s  .  c  o  m*/
 */
@Test
public void testSerializeWithMask() {
    MatchEntryBuilder builder = prepareIpv6ExtHdrMatchEntry(true,
            new Ipv6ExthdrFlags(false, true, false, true, false, true, false, true, false));

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

    checkHeader(buffer, true);
    assertEquals("Wrong value", 153, buffer.readUnsignedShort());
    byte[] tmp = new byte[2];
    buffer.readBytes(tmp);
    Assert.assertArrayEquals("Wrong mask", new byte[] { 0, 15 }, tmp);
    assertTrue("Unexpected data", buffer.readableBytes() == 0);
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_EXTHDR, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    if (hasMask) {
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());
    } else {//from  ww  w . ja v  a  2 s .  c om
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
    }
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_ND_SLL, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());
}

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

License:Open Source License

private static void checkHeader(ByteBuf buffer, boolean hasMask) {
    assertEquals("Wrong oxm-class", OxmMatchConstants.OPENFLOW_BASIC_CLASS, buffer.readUnsignedShort());
    short fieldAndMask = buffer.readUnsignedByte();
    assertEquals("Wrong oxm-field", OxmMatchConstants.IPV6_ND_TLL, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.MAC_ADDRESS_LENGTH, buffer.readUnsignedByte());
}

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

License:Open Source License

/**
 * Test correct serialization/*from  w  w w .  j  av  a 2  s .  c  o m*/
 */
@Test
public void testSerializeWithoutMask() {
    MatchEntryBuilder builder = prepareMatchEntry(false, "aaaa:bbbb:1111:2222::");

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

    checkHeader(buffer, false);
    Assert.assertEquals("Wrong ipv6 address", 43690, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 48059, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 4369, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 8738, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, buffer.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, buffer.readUnsignedShort());
    assertTrue("Unexpected data", buffer.readableBytes() == 0);
}