Search in sources :

Example 1 with ProtocolIpsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder in project bgpcep by opendaylight.

the class FlowspecL3vpnIpv4NlriParserTest method testExtractFlowspecProtocolIps.

@Test
public void testExtractFlowspecProtocolIps() {
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
    entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
    entry.withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.choiceBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID).withChild(Builders.unkeyedListBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(100)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(200)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(FlowspecL3vpnIpv4NlriParser.VALUE_NID).withValue(Uint8.valueOf(240)).build()).build()).build()).build()).build()).build());
    final FlowspecBuilder expectedFS = new FlowspecBuilder().setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.newArrayList(new ProtocolIpsBuilder().setValue(Uint8.valueOf(100)).setOp(new NumericOperand(true, true, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(200)).setOp(new NumericOperand(true, false, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(240)).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
    final List<Flowspec> expected = new ArrayList<>();
    expected.add(expectedFS.build());
    assertEquals(expected, this.fsParser.extractFlowspec(entry.build()));
}
Also used : FlowspecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder) NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand) ProtocolIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder) ArrayList(java.util.ArrayList) Flowspec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) ProtocolIpCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder) Test(org.junit.Test)

Example 2 with ProtocolIpsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder in project bgpcep by opendaylight.

the class SimpleFlowspecIpv4NlriParserTest method testExtractFlowspecProtocolIps.

@Test
public void testExtractFlowspecProtocolIps() {
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entry = Builders.mapEntryBuilder();
    entry.withNodeIdentifier(NodeIdentifierWithPredicates.of(FlowspecRoute.QNAME, FlowspecRoute.QNAME, entry));
    entry.withChild(Builders.unkeyedListBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_NID).withChild(Builders.choiceBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.FLOWSPEC_TYPE_NID).withChild(Builders.unkeyedListBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint8.valueOf(100)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.AND_BIT_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint8.valueOf(200)).build()).build()).withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(PROTOCOL_IP_NID).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.OP_NID).withValue(Sets.newHashSet(AbstractOperandParser.END_OF_LIST_VALUE, AbstractOperandParser.AND_BIT_VALUE, AbstractNumericOperandParser.EQUALS_VALUE)).build()).withChild(Builders.leafBuilder().withNodeIdentifier(AbstractFlowspecNlriParser.VALUE_NID).withValue(Uint8.valueOf(240)).build()).build()).build()).build()).build()).build());
    final FlowspecBuilder expectedFS = new FlowspecBuilder();
    expectedFS.setFlowspecType(new ProtocolIpCaseBuilder().setProtocolIps(Lists.newArrayList(new ProtocolIpsBuilder().setValue(Uint8.valueOf(100)).setOp(new NumericOperand(true, true, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(200)).setOp(new NumericOperand(true, false, false, false, false)).build(), new ProtocolIpsBuilder().setValue(Uint8.valueOf(240)).setOp(new NumericOperand(true, true, true, false, false)).build())).build());
    final List<Flowspec> expected = new ArrayList<>();
    expected.add(expectedFS.build());
    assertEquals(expected, this.fsParser.extractFlowspec(entry.build()));
}
Also used : FlowspecBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder) NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand) ProtocolIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder) ArrayList(java.util.ArrayList) Flowspec(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) ProtocolIpCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder) Test(org.junit.Test)

Example 3 with ProtocolIpsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder in project bgpcep by opendaylight.

the class FlowspecIpv4NlriParserHelper method createProtocolsIps.

private static List<ProtocolIps> createProtocolsIps(final UnkeyedListNode protocolIpsData) {
    final List<ProtocolIps> protocolIps = new ArrayList<>();
    for (final UnkeyedListEntryNode node : protocolIpsData.body()) {
        final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
        node.findChildByArg(AbstractFlowspecNlriParser.OP_NID).ifPresent(dataContainerChild -> ipsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) dataContainerChild.body())));
        node.findChildByArg(AbstractFlowspecNlriParser.VALUE_NID).ifPresent(dataContainerChild -> ipsBuilder.setValue((Uint8) dataContainerChild.body()));
        protocolIps.add(ipsBuilder.build());
    }
    return protocolIps;
}
Also used : Uint8(org.opendaylight.yangtools.yang.common.Uint8) ProtocolIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder) ProtocolIps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)

Example 4 with ProtocolIpsBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder in project bgpcep by opendaylight.

the class FSIpProtocolHandler method parseProtocolIp.

private static List<ProtocolIps> parseProtocolIp(final ByteBuf nlri) {
    final List<ProtocolIps> ips = new ArrayList<>();
    boolean end = false;
    // we can do this as all fields will be rewritten in the cycle
    final ProtocolIpsBuilder builder = new ProtocolIpsBuilder();
    while (!end) {
        final byte b = nlri.readByte();
        final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
        builder.setOp(op);
        builder.setValue(ByteBufUtils.readUint8(nlri));
        end = op.getEndOfList();
        ips.add(builder.build());
    }
    return ips;
}
Also used : NumericOperand(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand) ProtocolIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder) ProtocolIps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)4 ProtocolIpsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder)4 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.NumericOperand)3 Test (org.junit.Test)2 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.Flowspec)2 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.FlowspecBuilder)2 ProtocolIpCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.ProtocolIpCaseBuilder)2 ProtocolIps (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev200120.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 Uint8 (org.opendaylight.yangtools.yang.common.Uint8)1 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)1