Search in sources :

Example 6 with DataContainerChild

use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild 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.getValue()) {
        final ProtocolIpsBuilder ipsBuilder = new ProtocolIpsBuilder();
        final Optional<DataContainerChild<? extends PathArgument, ?>> opValue = node.getChild(AbstractFlowspecNlriParser.OP_NID);
        if (opValue.isPresent()) {
            ipsBuilder.setOp(NumericOneByteOperandParser.INSTANCE.create((Set<String>) opValue.get().getValue()));
        }
        final Optional<DataContainerChild<? extends PathArgument, ?>> valueNode = node.getChild(AbstractFlowspecNlriParser.VALUE_NID);
        if (valueNode.isPresent()) {
            ipsBuilder.setValue((Short) valueNode.get().getValue());
        }
        protocolIps.add(ipsBuilder.build());
    }
    return protocolIps;
}
Also used : ProtocolIpsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIpsBuilder) Set(java.util.Set) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ProtocolIps(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.group.ipv4.flowspec.flowspec.type.protocol.ip._case.ProtocolIps) ArrayList(java.util.ArrayList) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 7 with DataContainerChild

use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project controller by opendaylight.

the class EntityOwnershipShard method notifyAllListeners.

private void notifyAllListeners() {
    searchForEntities((entityTypeNode, entityNode) -> {
        java.util.Optional<DataContainerChild<?, ?>> possibleType = entityTypeNode.getChild(ENTITY_TYPE_NODE_ID);
        if (possibleType.isPresent()) {
            final boolean hasOwner;
            final boolean isOwner;
            java.util.Optional<DataContainerChild<?, ?>> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID);
            if (possibleOwner.isPresent()) {
                isOwner = localMemberName.getName().equals(possibleOwner.get().getValue().toString());
                hasOwner = true;
            } else {
                isOwner = false;
                hasOwner = false;
            }
            DOMEntity entity = new DOMEntity(possibleType.get().getValue().toString(), (YangInstanceIdentifier) entityNode.getChild(ENTITY_ID_NODE_ID).get().getValue());
            listenerSupport.notifyEntityOwnershipListeners(entity, isOwner, isOwner, hasOwner);
        }
    });
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity)

Example 8 with DataContainerChild

use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project controller by opendaylight.

the class CarEntryDataTreeCommitCohort method canCommit.

@Override
public CheckedFuture<PostCanCommitStep, DataValidationFailedException> canCommit(final Object txId, final DOMDataTreeCandidate candidate, final SchemaContext ctx) {
    // Simple data validation - verify the year, if present, is >= 1990
    final DataTreeCandidateNode rootNode = candidate.getRootNode();
    final Optional<NormalizedNode<?, ?>> dataAfter = rootNode.getDataAfter();
    LOG.info("In canCommit: modificationType: {}, dataBefore: {}, dataAfter: {}", rootNode.getModificationType(), rootNode.getDataBefore(), dataAfter);
    // MapEntryNode but we verify anyway.
    if (dataAfter.isPresent()) {
        final NormalizedNode<?, ?> normalizedNode = dataAfter.get();
        Verify.verify(normalizedNode instanceof DataContainerNode, "Expected type DataContainerNode, actual was %s", normalizedNode.getClass());
        DataContainerNode<?> entryNode = (DataContainerNode<?>) normalizedNode;
        final Optional<DataContainerChild<? extends PathArgument, ?>> possibleYear = entryNode.getChild(YEAR_NODE_ID);
        if (possibleYear.isPresent()) {
            final Number year = (Number) possibleYear.get().getValue();
            LOG.info("year is {}", year);
            if (!(year.longValue() >= 1990)) {
                return Futures.immediateFailedCheckedFuture(new DataValidationFailedException(DOMDataTreeIdentifier.class, candidate.getRootPath(), String.format("Invalid year %d - year must be >= 1990", year)));
            }
        }
    }
    // remaining 3PC stages (pre-commit and commit).
    return PostCanCommitStep.NOOP_SUCCESS_FUTURE;
}
Also used : DataValidationFailedException(org.opendaylight.mdsal.common.api.DataValidationFailedException) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 9 with DataContainerChild

use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project bgpcep by opendaylight.

the class AbstractLabeledUnicastRIBSupport method createRouteKey.

private NodeIdentifierWithPredicates createRouteKey(final UnkeyedListEntryNode labeledUnicast) {
    final ByteBuf buffer = Unpooled.buffer();
    final CLabeledUnicastDestination dest = extractCLabeledUnicastDestination(labeledUnicast);
    LUNlriParser.serializeNlri(Collections.singletonList(dest), false, buffer);
    final String routeKeyValue = ByteArray.encodeBase64(buffer);
    final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = labeledUnicast.getChild(routePathIdNid());
    final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
    return routeKey;
}
Also used : CLabeledUnicastDestination(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.destination.CLabeledUnicastDestination) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ByteBuf(io.netty.buffer.ByteBuf) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 10 with DataContainerChild

use of org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild in project bgpcep by opendaylight.

the class AbstractLabeledUnicastRIBSupport 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)

Aggregations

DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)33 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)31 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)18 ArrayList (java.util.ArrayList)14 Set (java.util.Set)12 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)6 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)2 DestinationPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPorts)2 DestinationPortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.destination.port._case.DestinationPortsBuilder)2 SourcePorts (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePorts)2 SourcePortsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.flowspec.flowspec.type.source.port._case.SourcePortsBuilder)2 DataContainerNode (org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1