Example usage for io.netty.buffer ByteBuf skipBytes

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

Introduction

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

Prototype

public abstract ByteBuf skipBytes(int length);

Source Link

Document

Increases the current readerIndex by the specified length in this buffer.

Usage

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

License:Open Source License

/**
 * Deserializes headers of items into list (used in MultipartReplyMessage - Table features)
 * @param version openflow wire version//w w  w . j  a va 2  s  .c o  m
 * @param length length of list in ByteBuf (bytes)
 * @param input input buffer
 * @param keyMaker creates keys for deserializer lookup
 * @param registry stores deserializers
 * @return list of items
 */
public static <E extends DataObject> List<E> deserializeHeaders(short version, int length, ByteBuf input,
        CodeKeyMaker keyMaker, DeserializerRegistry registry) {
    List<E> items = null;
    if (input.readableBytes() > 0) {
        items = new ArrayList<>();
        int startIndex = input.readerIndex();
        boolean exceptionLogged = false;
        while ((input.readerIndex() - startIndex) < length) {
            HeaderDeserializer<E> deserializer;
            MessageCodeKey key = keyMaker.make(input);
            try {
                deserializer = registry.getDeserializer(key);
            } catch (ClassCastException | IllegalStateException e) {
                // Following "if" is only hotfix to prevent log flooding. Log flooding is originally
                // caused by using OVS 2.4 which directly uses / reports Nicira extensions. These extensions
                // are not yet (2nd February 2016) fully supported by existing OF Plugin.
                // TODO - simplify to correctly report exception during deserialization
                if (!exceptionLogged) {
                    LOG.warn(
                            "Problem during reading table feature property. Skipping unknown feature property: {}."
                                    + "If more information is needed, set org.opendaylight.openflowjava do DEBUG log level.",
                            key, e.getMessage());
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Detailed exception: {}", e);
                        LOG.debug(
                                "This exception is logged only once for each multipart reply (table features) to "
                                        + "prevent log flooding. There might be more of table features related exceptions.");
                    }
                    exceptionLogged = true;
                }
                input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
                continue;
            }
            E item = deserializer.deserializeHeader(input);
            items.add(item);
        }
    }
    return items;
}

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

License:Open Source License

/**
 * Creates match/*w w  w  .  j a v  a  2s.  c om*/
 * @param in input ByteBuf
 * @return ofp_match (OpenFlow v1.3)
 */
public static Match createMatch(ByteBuf in) {
    if (in.readableBytes() > 0) {
        MatchBuilder builder = new MatchBuilder();
        int type = in.readUnsignedShort();
        int length = in.readUnsignedShort();
        switch (type) {
        case 0:
            builder.setType(StandardMatchType.class);
            break;
        case 1:
            builder.setType(OxmMatchType.class);
            break;
        default:
            break;
        }
        builder.setMatchEntries(createMatchEntries(in, length - 2 * (EncodeConstants.SIZE_OF_SHORT_IN_BYTES)));
        int paddingRemainder = length % EncodeConstants.PADDING;
        if (paddingRemainder != 0) {
            in.skipBytes(EncodeConstants.PADDING - paddingRemainder);
        }
        return builder.build();
    }
    return null;
}

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

License:Open Source License

private static List<MatchEntries> createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) {
    List<MatchEntries> matchEntriesList = new ArrayList<>();
    int currLength = 0;
    while (currLength < matchLength) {
        MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
        switch (in.readUnsignedShort()) {
        case 0x0000:
            matchEntriesBuilder.setOxmClass(Nxm0Class.class);
            break;
        case 0x0001:
            matchEntriesBuilder.setOxmClass(Nxm1Class.class);
            break;
        case 0x8000:
            matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
            break;
        case 0xFFFF:
            matchEntriesBuilder.setOxmClass(ExperimenterClass.class);
            break;
        default:/*w  w  w. j ava  2 s  .c o  m*/
            break;
        }

        int fieldAndMask = in.readUnsignedByte();
        boolean hasMask = (fieldAndMask & 1) != 0;
        matchEntriesBuilder.setHasMask(hasMask);
        int matchField = fieldAndMask >> 1;
        int matchEntryLength = in.readUnsignedByte();
        currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES + (2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES)
                + matchEntryLength;

        switch (matchField) {
        case 0:
            matchEntriesBuilder.setOxmMatchField(InPort.class);
            PortNumberMatchEntryBuilder port = new PortNumberMatchEntryBuilder();
            port.setPortNumber(new PortNumber(in.readUnsignedInt()));
            matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, port.build());
            break;
        case 1:
            matchEntriesBuilder.setOxmMatchField(InPhyPort.class);
            PortNumberMatchEntryBuilder phyPort = new PortNumberMatchEntryBuilder();
            phyPort.setPortNumber(new PortNumber(in.readUnsignedInt()));
            matchEntriesBuilder.addAugmentation(PortNumberMatchEntry.class, phyPort.build());
            break;
        case 2:
            matchEntriesBuilder.setOxmMatchField(Metadata.class);
            addMetadataAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
            }
            break;
        case 3:
            matchEntriesBuilder.setOxmMatchField(EthDst.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
            }
            break;
        case 4:
            matchEntriesBuilder.setOxmMatchField(EthSrc.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
            }
            break;
        case 5:
            matchEntriesBuilder.setOxmMatchField(EthType.class);
            EthTypeMatchEntryBuilder ethertypeBuilder = new EthTypeMatchEntryBuilder();
            ethertypeBuilder.setEthType(new EtherType(in.readUnsignedShort()));
            matchEntriesBuilder.addAugmentation(EthTypeMatchEntry.class, ethertypeBuilder.build());
            break;
        case 6:
            matchEntriesBuilder.setOxmMatchField(VlanVid.class);
            VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
            int vidEntryValue = in.readUnsignedShort();
            vlanVidBuilder.setCfiBit((vidEntryValue & (1 << 12)) != 0); // cfi is 13-th bit
            vlanVidBuilder.setVlanVid(vidEntryValue & ((1 << 12) - 1)); // value without 13-th bit
            matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
            }
            break;
        case 7:
            matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
            VlanPcpMatchEntryBuilder vlanPcpBuilder = new VlanPcpMatchEntryBuilder();
            vlanPcpBuilder.setVlanPcp(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(VlanPcpMatchEntry.class, vlanPcpBuilder.build());
            break;
        case 8:
            matchEntriesBuilder.setOxmMatchField(IpDscp.class);
            DscpMatchEntryBuilder dscpBuilder = new DscpMatchEntryBuilder();
            dscpBuilder.setDscp(new Dscp(in.readUnsignedByte()));
            matchEntriesBuilder.addAugmentation(DscpMatchEntry.class, dscpBuilder.build());
            break;
        case 9:
            matchEntriesBuilder.setOxmMatchField(IpEcn.class);
            EcnMatchEntryBuilder ecnBuilder = new EcnMatchEntryBuilder();
            ecnBuilder.setEcn(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(EcnMatchEntry.class, ecnBuilder.build());
            break;
        case 10:
            matchEntriesBuilder.setOxmMatchField(IpProto.class);
            ProtocolNumberMatchEntryBuilder protoNumberBuilder = new ProtocolNumberMatchEntryBuilder();
            protoNumberBuilder.setProtocolNumber(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(ProtocolNumberMatchEntry.class, protoNumberBuilder.build());
            break;
        case 11:
            matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);
            addIpv4AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
            }
            break;
        case 12:
            matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);
            addIpv4AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
            }
            break;
        case 13:
            matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 14:
            matchEntriesBuilder.setOxmMatchField(TcpDst.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 15:
            matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 16:
            matchEntriesBuilder.setOxmMatchField(UdpDst.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 17:
            matchEntriesBuilder.setOxmMatchField(SctpSrc.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 18:
            matchEntriesBuilder.setOxmMatchField(SctpDst.class);
            addPortAugmentation(matchEntriesBuilder, in);
            break;
        case 19:
            matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
            Icmpv4TypeMatchEntryBuilder icmpv4TypeBuilder = new Icmpv4TypeMatchEntryBuilder();
            icmpv4TypeBuilder.setIcmpv4Type(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeBuilder.build());
            break;
        case 20:
            matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
            Icmpv4CodeMatchEntryBuilder icmpv4CodeBuilder = new Icmpv4CodeMatchEntryBuilder();
            icmpv4CodeBuilder.setIcmpv4Code(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeBuilder.build());
            break;
        case 21:
            matchEntriesBuilder.setOxmMatchField(ArpOp.class);
            OpCodeMatchEntryBuilder opcodeBuilder = new OpCodeMatchEntryBuilder();
            opcodeBuilder.setOpCode(in.readUnsignedShort());
            matchEntriesBuilder.addAugmentation(OpCodeMatchEntry.class, opcodeBuilder.build());
            break;
        case 22:
            matchEntriesBuilder.setOxmMatchField(ArpSpa.class);
            addIpv4AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
            }
            break;
        case 23:
            matchEntriesBuilder.setOxmMatchField(ArpTpa.class);
            addIpv4AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
            }
            break;
        case 24:
            matchEntriesBuilder.setOxmMatchField(ArpSha.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
            }
            break;
        case 25:
            matchEntriesBuilder.setOxmMatchField(ArpTha.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.MAC_ADDRESS_LENGTH);
            }
            break;
        case 26:
            matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);
            addIpv6AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
            }
            break;
        case 27:
            matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);
            addIpv6AddressAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES);
            }
            break;
        case 28:
            matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
            Ipv6FlabelMatchEntryBuilder ipv6FlabelBuilder = new Ipv6FlabelMatchEntryBuilder();
            ipv6FlabelBuilder.setIpv6Flabel(new Ipv6FlowLabel(in.readUnsignedInt()));
            matchEntriesBuilder.addAugmentation(Ipv6FlabelMatchEntry.class, ipv6FlabelBuilder.build());
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES);
            }
            break;
        case 29:
            matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
            Icmpv6TypeMatchEntryBuilder icmpv6TypeBuilder = new Icmpv6TypeMatchEntryBuilder();
            icmpv6TypeBuilder.setIcmpv6Type(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeBuilder.build());
            break;
        case 30:
            matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
            Icmpv6CodeMatchEntryBuilder icmpv6CodeBuilder = new Icmpv6CodeMatchEntryBuilder();
            icmpv6CodeBuilder.setIcmpv6Code(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeBuilder.build());
            break;
        case 31:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
            addIpv6AddressAugmentation(matchEntriesBuilder, in);
            break;
        case 32:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            break;
        case 33:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class);
            addMacAddressAugmentation(matchEntriesBuilder, in);
            break;
        case 34:
            matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
            MplsLabelMatchEntryBuilder mplsLabelBuilder = new MplsLabelMatchEntryBuilder();
            mplsLabelBuilder.setMplsLabel(in.readUnsignedInt());
            matchEntriesBuilder.addAugmentation(MplsLabelMatchEntry.class, mplsLabelBuilder.build());
            break;
        case 35:
            matchEntriesBuilder.setOxmMatchField(MplsTc.class);
            TcMatchEntryBuilder tcBuilder = new TcMatchEntryBuilder();
            tcBuilder.setTc(in.readUnsignedByte());
            matchEntriesBuilder.addAugmentation(TcMatchEntry.class, tcBuilder.build());
            break;
        case 36:
            matchEntriesBuilder.setOxmMatchField(MplsBos.class);
            BosMatchEntryBuilder bosBuilder = new BosMatchEntryBuilder();
            if (in.readUnsignedByte() != 0) {
                bosBuilder.setBos(true);
            } else {
                bosBuilder.setBos(false);
            }
            matchEntriesBuilder.addAugmentation(BosMatchEntry.class, bosBuilder.build());
            break;
        case 37:
            matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
            IsidMatchEntryBuilder isidBuilder = new IsidMatchEntryBuilder();
            Integer isid = in.readUnsignedMedium();
            isidBuilder.setIsid(isid.longValue());
            matchEntriesBuilder.addAugmentation(IsidMatchEntry.class, isidBuilder.build());
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_3_BYTES);
            }
            break;
        case 38:
            matchEntriesBuilder.setOxmMatchField(TunnelId.class);
            addMetadataAugmentation(matchEntriesBuilder, in);
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_LONG_IN_BYTES);
            }
            break;
        case 39:
            matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
            PseudoFieldMatchEntryBuilder pseudoBuilder = new PseudoFieldMatchEntryBuilder();
            int bitmap = in.readUnsignedShort();
            final Boolean NONEXT = ((bitmap) & (1 << 0)) != 0;
            final Boolean ESP = ((bitmap) & (1 << 1)) != 0;
            final Boolean AUTH = ((bitmap) & (1 << 2)) != 0;
            final Boolean DEST = ((bitmap) & (1 << 3)) != 0;
            final Boolean FRAG = ((bitmap) & (1 << 4)) != 0;
            final Boolean ROUTER = ((bitmap) & (1 << 5)) != 0;
            final Boolean HOP = ((bitmap) & (1 << 6)) != 0;
            final Boolean UNREP = ((bitmap) & (1 << 7)) != 0;
            final Boolean UNSEQ = ((bitmap) & (1 << 8)) != 0;
            pseudoBuilder.setPseudoField(
                    new Ipv6ExthdrFlags(AUTH, DEST, ESP, FRAG, HOP, NONEXT, ROUTER, UNREP, UNSEQ));
            matchEntriesBuilder.addAugmentation(PseudoFieldMatchEntry.class, pseudoBuilder.build());
            if (hasMask) {
                addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
            }
            break;
        default:
            break;
        }
        matchEntriesList.add(matchEntriesBuilder.build());
        if (oneEntry) {
            break;
        }
    }
    if ((matchLength - currLength) > 0) {
        in.skipBytes(matchLength - currLength);
    }
    return matchEntriesList;
}

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

License:Open Source License

/** Decodes oxm ids
 * @param in input ByteBuf//from  w  w w .  java2  s  .c  o m
 * @param matchLength match entries length
 * @return list of match ids
 */
public static List<MatchEntries> createOxmIds(ByteBuf in, int matchLength) {
    List<MatchEntries> matchEntriesList = new ArrayList<>();
    int currLength = 0;
    while (currLength < matchLength) {
        MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
        switch (in.readUnsignedShort()) {
        case 0x0000:
            matchEntriesBuilder.setOxmClass(Nxm0Class.class);
            break;
        case 0x0001:
            matchEntriesBuilder.setOxmClass(Nxm1Class.class);
            break;
        case 0x8000:
            matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
            break;
        case 0xFFFF:
            matchEntriesBuilder.setOxmClass(ExperimenterClass.class);
            break;
        default:
            break;
        }

        int fieldAndMask = in.readUnsignedByte();
        boolean hasMask = (fieldAndMask & 1) != 0;
        matchEntriesBuilder.setHasMask(hasMask);
        int matchField = fieldAndMask >> 1;
        in.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        currLength += EncodeConstants.SIZE_OF_SHORT_IN_BYTES + (2 * EncodeConstants.SIZE_OF_BYTE_IN_BYTES);

        switch (matchField) {
        case 0:
            matchEntriesBuilder.setOxmMatchField(InPort.class);
            break;
        case 1:
            matchEntriesBuilder.setOxmMatchField(InPhyPort.class);
            break;
        case 2:
            matchEntriesBuilder.setOxmMatchField(Metadata.class);
            break;
        case 3:
            matchEntriesBuilder.setOxmMatchField(EthDst.class);
            break;
        case 4:
            matchEntriesBuilder.setOxmMatchField(EthSrc.class);
            break;
        case 5:
            matchEntriesBuilder.setOxmMatchField(EthType.class);
            break;
        case 6:
            matchEntriesBuilder.setOxmMatchField(VlanVid.class);
            break;
        case 7:
            matchEntriesBuilder.setOxmMatchField(VlanPcp.class);
            break;
        case 8:
            matchEntriesBuilder.setOxmMatchField(IpDscp.class);
            break;
        case 9:
            matchEntriesBuilder.setOxmMatchField(IpEcn.class);
            break;
        case 10:
            matchEntriesBuilder.setOxmMatchField(IpProto.class);
            break;
        case 11:
            matchEntriesBuilder.setOxmMatchField(Ipv4Src.class);
            break;
        case 12:
            matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class);
            break;
        case 13:
            matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
            break;
        case 14:
            matchEntriesBuilder.setOxmMatchField(TcpDst.class);
            break;
        case 15:
            matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
            break;
        case 16:
            matchEntriesBuilder.setOxmMatchField(UdpDst.class);
            break;
        case 17:
            matchEntriesBuilder.setOxmMatchField(SctpSrc.class);
            break;
        case 18:
            matchEntriesBuilder.setOxmMatchField(SctpDst.class);
            break;
        case 19:
            matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
            break;
        case 20:
            matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
            break;
        case 21:
            matchEntriesBuilder.setOxmMatchField(ArpOp.class);
            break;
        case 22:
            matchEntriesBuilder.setOxmMatchField(ArpSpa.class);
            break;
        case 23:
            matchEntriesBuilder.setOxmMatchField(ArpTpa.class);
            break;
        case 24:
            matchEntriesBuilder.setOxmMatchField(ArpSha.class);
            break;
        case 25:
            matchEntriesBuilder.setOxmMatchField(ArpTha.class);
            break;
        case 26:
            matchEntriesBuilder.setOxmMatchField(Ipv6Src.class);
            break;
        case 27:
            matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class);
            break;
        case 28:
            matchEntriesBuilder.setOxmMatchField(Ipv6Flabel.class);
            break;
        case 29:
            matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
            break;
        case 30:
            matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
            break;
        case 31:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
            break;
        case 32:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdSll.class);
            break;
        case 33:
            matchEntriesBuilder.setOxmMatchField(Ipv6NdTll.class);
            break;
        case 34:
            matchEntriesBuilder.setOxmMatchField(MplsLabel.class);
            break;
        case 35:
            matchEntriesBuilder.setOxmMatchField(MplsTc.class);
            break;
        case 36:
            matchEntriesBuilder.setOxmMatchField(MplsBos.class);
            break;
        case 37:
            matchEntriesBuilder.setOxmMatchField(PbbIsid.class);
            break;
        case 38:
            matchEntriesBuilder.setOxmMatchField(TunnelId.class);
            break;
        case 39:
            matchEntriesBuilder.setOxmMatchField(Ipv6Exthdr.class);
            break;
        default:
            break;
        }
        matchEntriesList.add(matchEntriesBuilder.build());
    }
    return matchEntriesList;
}

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

License:Open Source License

/**
 * Test for correct serialization of Ipv4Address match entry
 *///ww  w . j  ava  2s  .  c  o m
@Test
public void testIpv4Src() {
    MatchBuilder builder = new MatchBuilder();
    builder.setType(OxmMatchType.class);
    List<MatchEntries> entries = new ArrayList<>();
    MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(Ipv4Src.class);
    entriesBuilder.setHasMask(false);
    Ipv4AddressMatchEntryBuilder addressBuilder = new Ipv4AddressMatchEntryBuilder();
    addressBuilder.setIpv4Address(new Ipv4Address("1.2.3.4"));
    entriesBuilder.addAugmentation(Ipv4AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    builder.setMatchEntries(entries);
    Match match = builder.build();

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    MatchSerializer.encodeMatch(match, out);

    Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 22, out.readUnsignedByte());
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    Assert.assertEquals("Wrong ip address (first number)", 1, out.readUnsignedByte());
    Assert.assertEquals("Wrong ip address (second number)", 2, out.readUnsignedByte());
    Assert.assertEquals("Wrong ip address (third number)", 3, out.readUnsignedByte());
    Assert.assertEquals("Wrong ip address (fourth number)", 4, out.readUnsignedByte());
}

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

License:Open Source License

/**
 * Test for correct serialization of Ipv6Address match entry
 *//*from  w  ww.j ava2s. c  o m*/
@Test
public void testIpv6Various() {
    MatchBuilder builder = new MatchBuilder();
    builder.setType(OxmMatchType.class);
    List<MatchEntries> entries = new ArrayList<>();
    // ipv6 match entry with correct Ipv6 address
    MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(Ipv6Src.class);
    entriesBuilder.setHasMask(false);
    Ipv6AddressMatchEntryBuilder addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    // ipv6 match entry with abbreviated Ipv6 address
    entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(Ipv6NdTarget.class);
    entriesBuilder.setHasMask(false);
    addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("1:2::6:7:8"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    // ipv6 match entry with abbreviated Ipv6 address
    entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(Nxm1Class.class);
    entriesBuilder.setOxmMatchField(Ipv6Dst.class);
    entriesBuilder.setHasMask(false);
    addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("1::8"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    // ipv6 match entry with abbreviated Ipv6 address
    entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(Nxm1Class.class);
    entriesBuilder.setOxmMatchField(Ipv6Dst.class);
    entriesBuilder.setHasMask(false);
    addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("::1"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    // ipv6 match entry with abbreviated Ipv6 address
    entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(Nxm0Class.class);
    entriesBuilder.setOxmMatchField(Ipv6Dst.class);
    entriesBuilder.setHasMask(false);
    addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("::"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    // ipv6 match entry with incorrect Ipv6 address (longer)
    entriesBuilder = new MatchEntriesBuilder();
    entriesBuilder.setOxmClass(OpenflowBasicClass.class);
    entriesBuilder.setOxmMatchField(Ipv6Dst.class);
    entriesBuilder.setHasMask(false);
    addressBuilder = new Ipv6AddressMatchEntryBuilder();
    addressBuilder.setIpv6Address(new Ipv6Address("1:2:3:4:5:6:7:8:9"));
    entriesBuilder.addAugmentation(Ipv6AddressMatchEntry.class, addressBuilder.build());
    entries.add(entriesBuilder.build());
    builder.setMatchEntries(entries);
    Match match = builder.build();
    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    MatchSerializer.encodeMatch(match, out);

    Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 52, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 62, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
    Assert.assertEquals("Wrong class", 0x0001, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong class", 0x0000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 0, out.readUnsignedShort());
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 54, out.readUnsignedByte());
    Assert.assertEquals("Wrong entry length", 16, out.readUnsignedByte());
    Assert.assertEquals("Wrong ipv6 address", 1, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 2, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 3, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 4, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 5, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 6, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 7, out.readUnsignedShort());
    Assert.assertEquals("Wrong ipv6 address", 8, out.readUnsignedShort());
}

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

License:Open Source License

/**
 * Test for correct serialization of Ipv4Address match entry
 *//*from   ww  w.j  a  v  a2s  .c o m*/
@Test
public void testIpv6Flabel() {
    Match match = buildIpv6FLabelMatch(0x0f9e8dL, false, null);

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    MatchSerializer.encodeMatch(match, out);

    Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 28 << 1, out.readUnsignedByte());
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    byte[] label = new byte[4];
    out.readBytes(label);

    LOG.debug("label: " + ByteBufUtils.bytesToHexString(label));
    Assert.assertArrayEquals("Wrong ipv6FLabel", new byte[] { 0, 0x0f, (byte) 0x9e, (byte) 0x8d }, label);
}

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

License:Open Source License

/**
 * Test for correct serialization of Ipv4Address match entry with mask
 *///  ww  w.j a  v a  2s.  co m
@Test
public void testIpv6FlabelWithMask() {
    Match match = buildIpv6FLabelMatch(0x0f9e8dL, true, new byte[] { 0, 0x0c, 0x7b, 0x6a });

    ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
    MatchSerializer.encodeMatch(match, out);

    Assert.assertEquals("Wrong type", 1, out.readUnsignedShort());
    out.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    Assert.assertEquals("Wrong class", 0x8000, out.readUnsignedShort());
    Assert.assertEquals("Wrong field and mask", 28 << 1 | 1, out.readUnsignedByte());
    out.skipBytes(EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
    byte[] labelAndMask = new byte[8];
    out.readBytes(labelAndMask);

    LOG.debug("label: " + ByteBufUtils.bytesToHexString(labelAndMask));
    Assert.assertArrayEquals("Wrong ipv6FLabel",
            new byte[] { 0, 0x0f, (byte) 0x9e, (byte) 0x8d, 0, 0x0c, 0x7b, 0x6a }, labelAndMask);
}

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

License:Open Source License

/**
 * Creates list of actions (OpenFlow v1.0) from ofp_action structures
 * @param input input ByteBuf/*w  w w . j av  a 2s. c  o  m*/
 * @return ActionsList list of actions
 */
public static List<Action> createActionsList(ByteBuf input) {
    List<Action> actions = new ArrayList<>();
    while (input.readableBytes() > 0) {
        int type = input.readUnsignedShort();
        input.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        actions.add(decodeAction(input, type));
    }
    return actions;
}