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.OxmTcpDstSerializerTest.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.TCP_DST, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
}

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

License:Open Source License

/**
 * Test correct serialization/* w  w w.  ja v  a2 s  .c om*/
 */
@Test
public void testSerialize() {
    MatchEntryBuilder builder = prepareMatchEntry(512);

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

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

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTcpSrcSerializerTest.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.TCP_SRC, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmTunnelIdSerializerTest.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.TUNNEL_ID, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    if (hasMask) {
        assertEquals("Wrong length", 2 * EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());
    } else {//from  w w w.j a v a 2 s .  com
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_LONG_IN_BYTES, buffer.readUnsignedByte());
    }
}

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

License:Open Source License

/**
 * Test correct serialization//from  ww w . j  a v a 2s .co m
 */
@Test
public void testSerialize() {
    MatchEntryBuilder builder = prepareMatchEntry(2048);

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

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

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpDstSerializerTest.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.UDP_DST, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
}

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

License:Open Source License

/**
 * Test correct serialization//from   w ww .  j a v  a  2s .c o  m
 */
@Test
public void testSerialize() {
    MatchEntryBuilder builder = prepareMatchEntry(1024);

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

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

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmUdpSrcSerializerTest.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.UDP_SRC, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanPcpSerializerTest.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.VLAN_PCP, 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.OxmVlanVidSerializerTest.java

License:Open Source License

/**
 * Test correct serialization/*  ww  w  . j  a  v  a2  s . co m*/
 */
@Test
public void testSerializeWithCfiBitSet() {
    MatchEntryBuilder builder = prepareVlanVidMatchEntry(false, true);

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

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