Search in sources :

Example 1 with Codes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes in project bgpcep by opendaylight.

the class NumericOperandParserTest method testSerializeOneByte.

@Test
public void testSerializeOneByte() {
    final ByteBuf nlriByteBuf = Unpooled.buffer();
    final List<Codes> codes = new ArrayList<>();
    // create 3 ports without end-of-list bit set
    for (int i = 0; i < 3; i++) {
        codes.add(new CodesBuilder().setOp(new NumericOperand(false, false, true, false, false)).setValue((short) (100 + i)).build());
    }
    NumericOneByteOperandParser.INSTANCE.serialize(codes, nlriByteBuf);
    assertArrayEquals(ONE_BYTE_CODE_LIST, ByteArray.readAllBytes(nlriByteBuf));
}
Also used : NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand) Codes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) CodesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder) Test(org.junit.Test)

Example 2 with Codes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes in project bgpcep by opendaylight.

the class AbstractFlowspecNlriParser method createCodes.

private static List<Codes> createCodes(final UnkeyedListNode codesData) {
    final List<Codes> codes = new ArrayList<>();
    for (final UnkeyedListEntryNode node : codesData.getValue()) {
        final CodesBuilder codesBuilder = new CodesBuilder();
        final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(OP_NID);
        if (opValue.isPresent()) {
            codesBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
        }
        final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(VALUE_NID);
        if (valueNode.isPresent()) {
            codesBuilder.setValue((Short) valueNode.get().getValue());
        }
        codes.add(codesBuilder.build());
    }
    return codes;
}
Also used : Codes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes) Set(java.util.Set) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) CodesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder)

Example 3 with Codes

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes in project bgpcep by opendaylight.

the class FSIcmpCodeHandler method parseIcmpCode.

private static List<Codes> parseIcmpCode(final ByteBuf nlri) {
    final List<Codes> codes = new ArrayList<>();
    boolean end = false;
    // we can do this as all fields will be rewritten in the cycle
    final CodesBuilder builder = new CodesBuilder();
    while (!end) {
        final byte b = nlri.readByte();
        final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
        builder.setOp(op);
        builder.setValue(nlri.readUnsignedByte());
        end = op.isEndOfList();
        codes.add(builder.build());
    }
    return codes;
}
Also used : NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand) Codes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes) ArrayList(java.util.ArrayList) CodesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder)

Aggregations

ArrayList (java.util.ArrayList)3 Codes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.Codes)3 CodesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.icmp.code._case.CodesBuilder)3 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand)2 ByteBuf (io.netty.buffer.ByteBuf)1 Set (java.util.Set)1 Test (org.junit.Test)1 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)1 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)1 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)1