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.OxmVlanVidSerializerTest.java

License:Open Source License

/**
 * Test correct serialization/* www.  j  av a 2 s  .c o m*/
 */
@Test
public void testSerializeWithoutCfiBitSet() {
    MatchEntryBuilder builder = prepareVlanVidMatchEntry(true, false);

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

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

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmVlanVidSerializerTest.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_VID, fieldAndMask >>> 1);
    assertEquals("Wrong hasMask", hasMask, (fieldAndMask & 1) != 0);
    if (hasMask) {
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_INT_IN_BYTES, buffer.readUnsignedByte());
    } else {//from   www  . j a  va 2 s.  c  om
        assertEquals("Wrong length", EncodeConstants.SIZE_OF_SHORT_IN_BYTES, buffer.readUnsignedByte());
    }
}

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

License:Open Source License

/**
 * Creates list of actions (OpenFlow v1.3)
 * @param input input ByteBuf//from   w w w. j a va  2 s . c om
 * @param actionsLength length of buckets
 * @return ActionsList
 */
public static List<Action> createActions(ByteBuf input, int actionsLength) {
    List<Action> actions = new ArrayList<>();
    int length = 0;
    while (length < actionsLength) {
        int type = input.readUnsignedShort();
        int currentActionLength = input.readUnsignedShort();
        ActionBuilder actionBuilder = new ActionBuilder();
        switch (type) {
        case 0:
            actions.add(createOutputAction(input, actionBuilder));
            break;
        case 11:
            actions.add(createCopyTtlOutAction(input, actionBuilder));
            break;
        case 12:
            actions.add(createCopyTtlInAction(input, actionBuilder));
            break;
        case 15:
            actions.add(createSetMplsTtlAction(input, actionBuilder));
            break;
        case 16:
            actions.add(createDecMplsTtlOutAction(input, actionBuilder));
            break;
        case 17:
            actions.add(createPushVlanAction(input, actionBuilder));
            break;
        case 18:
            actions.add(createPopVlanAction(input, actionBuilder));
            break;
        case 19:
            actions.add(createPushMplsAction(input, actionBuilder));
            break;
        case 20:
            actions.add(createPopMplsAction(input, actionBuilder));
            break;
        case 21:
            actions.add(createSetQueueAction(input, actionBuilder));
            break;
        case 22:
            actions.add(createGroupAction(input, actionBuilder));
            break;
        case 23:
            actions.add(createSetNwTtlAction(input, actionBuilder));
            break;
        case 24:
            actions.add(createDecNwTtlAction(input, actionBuilder));
            break;
        case 25:
            actions.add(createSetFieldAction(input, actionBuilder, currentActionLength));
            break;
        case 26:
            actions.add(createPushPbbAction(input, actionBuilder));
            break;
        case 27:
            actions.add(createPopPbbAction(input, actionBuilder));
            break;
        case 0xFFFF:
            actions.add(createExperimenterAction(input, actionBuilder, currentActionLength));
            break;
        default:
            break;
        }
        length += currentActionLength;
    }
    return actions;
}

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/*ww  w  . ja  va2  s . c  om*/
 * @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 createPushAction(Class<? extends ActionBase> action, ByteBuf in,
        ActionBuilder actionBuilder) {//www .jav  a2s. c om
    actionBuilder.setType(action);
    EthertypeActionBuilder etherType = new EthertypeActionBuilder();
    etherType.setEthertype(new EtherType(in.readUnsignedShort()));
    actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
    in.skipBytes(PADDING_IN_PUSH_VLAN_ACTIONS_HEADER);
    return actionBuilder.build();
}

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

License:Open Source License

/**
 * Testing correct serialization of actions
 */// w  ww.ja va 2s  . c  om
@Test
public void test() {
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setType(Output.class);
    PortActionBuilder port = new PortActionBuilder();
    port.setPort(new PortNumber(42L));
    actionBuilder.addAugmentation(PortAction.class, port.build());
    MaxLengthActionBuilder maxLen = new MaxLengthActionBuilder();
    maxLen.setMaxLength(52);
    actionBuilder.addAugmentation(MaxLengthAction.class, maxLen.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(CopyTtlOut.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(CopyTtlIn.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetMplsTtl.class);
    MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder();
    mplsTtl.setMplsTtl((short) 4);
    actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtl.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(DecMplsTtl.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushVlan.class);
    EthertypeActionBuilder etherType = new EthertypeActionBuilder();
    etherType.setEthertype(new EtherType(16));
    actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopVlan.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushMpls.class);
    etherType = new EthertypeActionBuilder();
    etherType.setEthertype(new EtherType(17));
    actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopMpls.class);
    etherType = new EthertypeActionBuilder();
    etherType.setEthertype(new EtherType(18));
    actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetQueue.class);
    QueueIdActionBuilder queueId = new QueueIdActionBuilder();
    queueId.setQueueId(1234L);
    actionBuilder.addAugmentation(QueueIdAction.class, queueId.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(Group.class);
    GroupIdActionBuilder group = new GroupIdActionBuilder();
    group.setGroupId(555L);
    actionBuilder.addAugmentation(GroupIdAction.class, group.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetNwTtl.class);
    NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();
    nwTtl.setNwTtl((short) 8);
    actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(DecNwTtl.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetField.class);
    OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();
    List<MatchEntries> entries = new ArrayList<>();
    MatchEntriesBuilder matchBuilder = new MatchEntriesBuilder();
    matchBuilder.setOxmClass(OpenflowBasicClass.class);
    matchBuilder.setOxmMatchField(InPort.class);
    matchBuilder.setHasMask(false);
    PortNumberMatchEntryBuilder portBuilder = new PortNumberMatchEntryBuilder();
    portBuilder.setPortNumber(new PortNumber(1L));
    matchBuilder.addAugmentation(PortNumberMatchEntry.class, portBuilder.build());
    entries.add(matchBuilder.build());
    matchEntries.setMatchEntries(entries);
    actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushPbb.class);
    etherType = new EthertypeActionBuilder();
    etherType.setEthertype(new EtherType(19));
    actionBuilder.addAugmentation(EthertypeAction.class, etherType.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopPbb.class);
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(Experimenter.class);
    ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();
    experimenter.setExperimenter(4L);
    experimenter.setData(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 });
    actionBuilder.addAugmentation(ExperimenterAction.class, experimenter.build());
    actions.add(actionBuilder.build());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    ActionsSerializer.encodeActions(actions, out);

    Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong action port", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong action max-length", 52, out.readUnsignedShort());
    out.skipBytes(6);
    Assert.assertEquals("Wrong action type", 11, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 12, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 15, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action mpls-ttl", 4, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong action type", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 16, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 18, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 19, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 17, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 20, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 18, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 21, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action queue-id", 1234, out.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 22, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action group", 555, out.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action nw-ttl", 8, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong action type", 24, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 25, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong match entry class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong match entry field & mask", 0, out.readUnsignedByte());
    Assert.assertEquals("Wrong match entry length", 4, out.readUnsignedByte());
    Assert.assertEquals("Wrong match entry value", 1, out.readUnsignedInt());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 26, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 19, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 65535, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong experimenter", 4, out.readUnsignedInt());
    byte[] data = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    out.readBytes(data);
    Assert.assertArrayEquals("Wrong data", new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, data);
    Assert.assertTrue("Unread data", out.readableBytes() == 0);
}

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

License:Open Source License

/**
 * Creates list of instructions/*from w  ww. j  av  a  2  s  .  c  o m*/
 * @param input
 * @param length
 * @return list of ofp_instruction
 */
public static List<Instruction> createInstructions(ByteBuf input, int length) {
    List<Instruction> instructions = new ArrayList<>();
    if (input.readableBytes() != 0) {
        int lengthOfInstructions = length;
        while (lengthOfInstructions > 0) {
            InstructionBuilder builder = new InstructionBuilder();
            int type = input.readUnsignedShort();
            int instructionLength = input.readUnsignedShort();
            lengthOfInstructions -= instructionLength;
            switch (type) {
            case 1:
                createGotoTableInstruction(builder, input);
                break;
            case 2:
                createMetadataInstruction(builder, input);
                break;
            case 3:
                builder.setType(WriteActions.class);
                createActionRelatedInstruction(input, builder,
                        instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);
                break;
            case 4:
                builder.setType(ApplyActions.class);
                createActionRelatedInstruction(input, builder,
                        instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);
                break;
            case 5:
                builder.setType(ClearActions.class);
                createActionRelatedInstruction(input, builder,
                        instructionLength - WRITE_APPLY_CLEAR_ACTION_LENGTH);
                break;
            case 6:
                builder.setType(Meter.class);
                MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
                meterBuilder.setMeterId(input.readUnsignedInt());
                builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
                break;
            case 65535:
                builder.setType(Experimenter.class);
                ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();
                expBuilder.setExperimenter(input.readUnsignedInt());
                int dataLength = instructionLength - EXPERIMENTER_HEADER_LENGTH;
                if (dataLength > 0) {
                    byte[] data = new byte[dataLength];
                    input.readBytes(data);
                    expBuilder.setData(data);
                }
                builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build());
                break;
            default:
                break;
            }
            instructions.add(builder.build());
        }
    }
    return instructions;
}

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

License:Open Source License

/**
 * Creates instruction ids (instructions without values)
 * @param input//from  w  w  w  .j ava2 s  . c om
 * @param length
 * @return list of ofp_instruction without values
 */
public static List<Instruction> createInstructionIds(ByteBuf input, int length) {
    List<Instruction> instructions = new ArrayList<>();
    if (input.readableBytes() != 0) {
        int lengthOfInstructions = length;
        while (lengthOfInstructions > 0) {
            InstructionBuilder builder = new InstructionBuilder();
            int type = input.readUnsignedShort();
            int instructionLength = input.readUnsignedShort();
            lengthOfInstructions -= instructionLength;
            switch (type) {
            case 1:
                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;
            case 65535:
                builder.setType(Experimenter.class);
                ExperimenterInstructionBuilder expBuilder = new ExperimenterInstructionBuilder();
                expBuilder.setExperimenter(input.readUnsignedInt());
                builder.addAugmentation(ExperimenterInstruction.class, expBuilder.build());
                break;
            default:
                break;
            }
            instructions.add(builder.build());
        }
    }
    return instructions;
}

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

License:Open Source License

/**
 * Testing instructions translation//  w  w w  . j av  a 2  s  .  c  om
 */
@Test
public void test() {
    List<Instruction> instructions = new ArrayList<>();
    // Goto_table instruction
    InstructionBuilder builder = new InstructionBuilder();
    builder.setType(GotoTable.class);
    TableIdInstructionBuilder tableIdBuilder = new TableIdInstructionBuilder();
    tableIdBuilder.setTableId((short) 5);
    builder.addAugmentation(TableIdInstruction.class, tableIdBuilder.build());
    instructions.add(builder.build());
    builder = new InstructionBuilder();
    // Write_metadata instruction
    builder.setType(WriteMetadata.class);
    MetadataInstructionBuilder metaBuilder = new MetadataInstructionBuilder();
    metaBuilder.setMetadata(ByteBufUtils.hexStringToBytes("00 01 02 03 04 05 06 07"));
    metaBuilder.setMetadataMask(ByteBufUtils.hexStringToBytes("07 06 05 04 03 02 01 00"));
    builder.addAugmentation(MetadataInstruction.class, metaBuilder.build());
    instructions.add(builder.build());
    // Clear_actions instruction
    builder = new InstructionBuilder();
    builder.setType(ClearActions.class);
    instructions.add(builder.build());
    // Meter instruction
    builder = new InstructionBuilder();
    builder.setType(Meter.class);
    MeterIdInstructionBuilder meterBuilder = new MeterIdInstructionBuilder();
    meterBuilder.setMeterId(42L);
    builder.addAugmentation(MeterIdInstruction.class, meterBuilder.build());
    instructions.add(builder.build());
    // Write_actions instruction
    builder = new InstructionBuilder();
    builder.setType(WriteActions.class);
    ActionsInstructionBuilder actionsBuilder = new ActionsInstructionBuilder();
    List<Action> actions = new ArrayList<>();
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setType(Output.class);
    PortActionBuilder portBuilder = new PortActionBuilder();
    portBuilder.setPort(new PortNumber(45L));
    actionBuilder.addAugmentation(PortAction.class, portBuilder.build());
    MaxLengthActionBuilder maxBuilder = new MaxLengthActionBuilder();
    maxBuilder.setMaxLength(55);
    actionBuilder.addAugmentation(MaxLengthAction.class, maxBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(SetNwTtl.class);
    NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();
    nwTtl.setNwTtl((short) 64);
    actionBuilder.addAugmentation(NwTtlAction.class, nwTtl.build());
    actions.add(actionBuilder.build());
    actionsBuilder.setAction(actions);
    builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
    instructions.add(builder.build());
    // Apply_actions instruction
    builder = new InstructionBuilder();
    builder.setType(ApplyActions.class);
    actionsBuilder = new ActionsInstructionBuilder();
    actions = new ArrayList<>();
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PushVlan.class);
    EthertypeActionBuilder ethertypeBuilder = new EthertypeActionBuilder();
    ethertypeBuilder.setEthertype(new EtherType(14));
    actionBuilder.addAugmentation(EthertypeAction.class, ethertypeBuilder.build());
    actions.add(actionBuilder.build());
    actionBuilder = new ActionBuilder();
    actionBuilder.setType(PopPbb.class);
    actions.add(actionBuilder.build());
    actionsBuilder.setAction(actions);
    builder.addAugmentation(ActionsInstruction.class, actionsBuilder.build());
    instructions.add(builder.build());

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    InstructionsSerializer.encodeInstructions(instructions, out);

    Assert.assertEquals("Wrong instruction type", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction table-id", 5, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
    out.skipBytes(4);
    byte[] actual = new byte[8];
    out.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata", "00 01 02 03 04 05 06 07",
            ByteBufUtils.bytesToHexString(actual));
    actual = new byte[8];
    out.readBytes(actual);
    Assert.assertEquals("Wrong instruction metadata-mask", "07 06 05 04 03 02 01 00",
            ByteBufUtils.bytesToHexString(actual));
    Assert.assertEquals("Wrong instruction type", 5, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong instruction type", 6, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction meter-id", 42, out.readUnsignedInt());
    Assert.assertEquals("Wrong instruction type", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 32, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 16, out.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 45, out.readUnsignedInt());
    Assert.assertEquals("Wrong action type", 55, out.readUnsignedShort());
    out.skipBytes(6);
    Assert.assertEquals("Wrong action type", 23, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action type", 64, out.readUnsignedByte());
    out.skipBytes(3);
    Assert.assertEquals("Wrong instruction type", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong instruction length", 24, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertEquals("Wrong action type", 17, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong action ethertype", 14, out.readUnsignedShort());
    out.skipBytes(2);
    Assert.assertEquals("Wrong action type", 27, out.readUnsignedShort());
    Assert.assertEquals("Wrong action length", 8, out.readUnsignedShort());
    out.skipBytes(4);
    Assert.assertTrue("Not all data were read", out.readableBytes() == 0);
}