Search in sources :

Example 46 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class IdentifierUtils method firstKeyOf.

// FIXME: implement as id.firstIdentifierOf(IS_PEER), null indicating not found
private static NodeIdentifierWithPredicates firstKeyOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) {
    final PathArgument ret = id.getPathArguments().stream().filter(match::apply).findFirst().get();
    Preconditions.checkArgument(ret instanceof NodeIdentifierWithPredicates, "Non-key peer identifier %s", ret);
    return (NodeIdentifierWithPredicates) ret;
}
Also used : PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 47 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class EvpnRibSupport method processDestination.

@Override
protected void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
    if (destination != null) {
        final Optional<DataContainerChild<? extends PathArgument, ?>> maybeRoutes = destination.getChild(NLRI_ROUTES_LIST);
        if (maybeRoutes.isPresent()) {
            final DataContainerChild<? extends PathArgument, ?> routes = maybeRoutes.get();
            if (routes instanceof UnkeyedListNode) {
                final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeNid());
                for (final UnkeyedListEntryNode e : ((UnkeyedListNode) routes).getValue()) {
                    final NodeIdentifierWithPredicates routeKey = createRouteKey(e);
                    function.apply(tx, base, routeKey, e, attributes);
                }
            } else {
                LOG.warn("Routes {} are not a map", routes);
            }
        }
    }
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)

Example 48 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class ApplicationPeer method onDataTreeChanged.

/**
 * Routes come from application RIB that is identified by (configurable) name.
 * Each route is pushed into AdjRibsInWriter with it's whole context. In this
 * method, it doesn't matter if the routes are removed or added, this will
 * be determined in LocRib.
 */
@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
    if (this.chain == null) {
        LOG.trace("Skipping data changed called to Application Peer. Change : {}", changes);
        return;
    }
    final DOMDataWriteTransaction tx = this.chain.newWriteOnlyTransaction();
    LOG.debug("Received data change to ApplicationRib {}", changes);
    for (final DataTreeCandidate tc : changes) {
        LOG.debug("Modification Type {}", tc.getRootNode().getModificationType());
        final YangInstanceIdentifier path = tc.getRootPath();
        final PathArgument lastArg = path.getLastPathArgument();
        Verify.verify(lastArg instanceof NodeIdentifierWithPredicates, "Unexpected type %s in path %s", lastArg.getClass(), path);
        final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) lastArg;
        if (!this.supportedTables.contains(tableKey)) {
            LOG.trace("Skipping received data change for non supported family {}.", tableKey);
            continue;
        }
        for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
            final PathArgument childIdentifier = child.getIdentifier();
            final YangInstanceIdentifier tableId = this.adjRibsInId.node(tableKey).node(childIdentifier);
            switch(child.getModificationType()) {
                case DELETE:
                    LOG.trace("App peer -> AdjRibsIn path delete: {}", childIdentifier);
                    tx.delete(LogicalDatastoreType.OPERATIONAL, tableId);
                    break;
                case UNMODIFIED:
                    // No-op
                    break;
                case SUBTREE_MODIFIED:
                    if (EffectiveRibInWriter.TABLE_ROUTES.equals(childIdentifier)) {
                        processRoutesTable(child, tableId, tx, tableId);
                        break;
                    }
                case WRITE:
                    if (child.getDataAfter().isPresent()) {
                        final NormalizedNode<?, ?> dataAfter = child.getDataAfter().get();
                        LOG.trace("App peer -> AdjRibsIn path : {}", tableId);
                        LOG.trace("App peer -> AdjRibsIn data : {}", dataAfter);
                        tx.put(LogicalDatastoreType.OPERATIONAL, tableId, dataAfter);
                    }
                    break;
                default:
                    break;
            }
        }
    }
    tx.submit();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 49 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class FlowspecIpv6NlriParserHelper method createNextHeaders.

private static List<NextHeaders> createNextHeaders(final UnkeyedListNode nextHeadersData) {
    final List<NextHeaders> nextHeaders = new ArrayList<>();
    for (final UnkeyedListEntryNode node : nextHeadersData.getValue()) {
        final NextHeadersBuilder nextHeadersBuilder = new NextHeadersBuilder();
        final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
        if (opValue.isPresent()) {
            nextHeadersBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
        }
        final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
        if (valueNode.isPresent()) {
            nextHeadersBuilder.setValue((Short) valueNode.get().getValue());
        }
        nextHeaders.add(nextHeadersBuilder.build());
    }
    return nextHeaders;
}
Also used : Set(java.util.Set) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) NextHeaders(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeaders) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) NextHeadersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeadersBuilder) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 50 with PathArgument

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project bgpcep by opendaylight.

the class FlowspecIpv6NlriParserHelper method createFlowLabels.

private static List<FlowLabel> createFlowLabels(final UnkeyedListNode flowLabelsData) {
    final List<FlowLabel> flowLabels = new ArrayList<>();
    for (final UnkeyedListEntryNode node : flowLabelsData.getValue()) {
        final FlowLabelBuilder flowLabelsBuilder = new FlowLabelBuilder();
        final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
        if (opValue.isPresent()) {
            flowLabelsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
        }
        final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
        if (valueNode.isPresent()) {
            flowLabelsBuilder.setValue((Long) valueNode.get().getValue());
        }
        flowLabels.add(flowLabelsBuilder.build());
    }
    return flowLabels;
}
Also used : FlowLabel(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabel) Set(java.util.Set) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) FlowLabelBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv6.flowspec.flowspec.type.flow.label._case.FlowLabelBuilder) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Aggregations

PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)55 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)31 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)18 ArrayList (java.util.ArrayList)17 Set (java.util.Set)12 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)11 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 Test (org.junit.Test)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 DataNormalizationException (org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)3 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)3 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)3 ImmutableList (com.google.common.collect.ImmutableList)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2