Search in sources :

Example 61 with NodeIdentifierWithPredicates

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

the class AbstractFlowspecRIBSupport method processDestination.

@Override
protected final void processDestination(final DOMDataWriteTransaction tx, final YangInstanceIdentifier routesPath, final ContainerNode destination, final ContainerNode attributes, final ApplyRoute function) {
    if (destination != null) {
        final YangInstanceIdentifier base = routesPath.node(routesContainerIdentifier()).node(routeQName());
        final Optional<DataContainerChild<? extends PathArgument, ?>> maybePathIdLeaf = destination.getChild(routePathIdNid());
        final String routeKeyValue = this.nlriParser.stringNlri(destination);
        final NodeIdentifierWithPredicates routeKey = PathIdUtil.createNidKey(routeQName(), routeKeyQName(), pathIdQName(), routeKeyValue, maybePathIdLeaf);
        function.apply(tx, base, routeKey, destination, attributes);
    }
}
Also used : DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) 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)

Example 62 with NodeIdentifierWithPredicates

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

the class AbstractRIBTestSetup method ipv4Input.

public Collection<DataTreeCandidate> ipv4Input(final YangInstanceIdentifier target, final ModificationType type, final Ipv4Prefix... prefix) {
    final Collection<DataTreeCandidate> col = new HashSet<>();
    final DataTreeCandidate candidate = mock(DataTreeCandidate.class);
    final DataTreeCandidateNode rootNode = mock(DataTreeCandidateNode.class);
    doReturn(rootNode).when(candidate).getRootNode();
    doReturn(type).when(rootNode).getModificationType();
    doCallRealMethod().when(rootNode).toString();
    doReturn(target).when(candidate).getRootPath();
    doCallRealMethod().when(candidate).toString();
    final Collection<DataTreeCandidateNode> children = new HashSet<>();
    for (final Ipv4Prefix p : prefix) {
        final NodeIdentifierWithPredicates routekey = new NodeIdentifierWithPredicates(Ipv4Route.QNAME, PREFIX_QNAME, p);
        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> b = ImmutableNodes.mapEntryBuilder();
        b.withNodeIdentifier(routekey);
        b.addChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(PREFIX_QNAME)).withValue(p).build());
        final DataTreeCandidateNode child = mock(DataTreeCandidateNode.class);
        doReturn(createIdentifier(p)).when(child).getIdentifier();
        doReturn(java.util.Optional.of(b.build())).when(child).getDataAfter();
        doReturn(type).when(child).getModificationType();
        children.add(child);
    }
    doReturn(children).when(rootNode).getChildNodes();
    col.add(candidate);
    return col;
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) HashSet(java.util.HashSet)

Example 63 with NodeIdentifierWithPredicates

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

the class RIBImpl method instantiateServiceInstance.

public synchronized void instantiateServiceInstance() {
    this.isServiceInstantiated = true;
    setActive(true);
    this.domChain = this.domDataBroker.createTransactionChain(this);
    LOG.debug("Instantiating RIB table {} at {}", this.ribId, this.yangRibId);
    final ContainerNode bgpRib = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(BgpRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Rib.QNAME).build()).build();
    final MapEntryNode ribInstance = Builders.mapEntryBuilder().withNodeIdentifier(new NodeIdentifierWithPredicates(Rib.QNAME, RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.leafNode(RIB_ID_QNAME, this.ribId.getValue())).addChild(ImmutableNodes.mapNodeBuilder(Peer.QNAME).build()).addChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(LocRib.QNAME)).addChild(ImmutableNodes.mapNodeBuilder(Tables.QNAME).build()).build()).build();
    final DOMDataWriteTransaction trans = this.domChain.newWriteOnlyTransaction();
    // merge empty BgpRib + Rib, to make sure the top-level parent structure is present
    trans.merge(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BgpRib.QNAME).build(), bgpRib);
    trans.put(LogicalDatastoreType.OPERATIONAL, this.yangRibId, ribInstance);
    try {
        trans.submit().checkedGet();
    } catch (final TransactionCommitFailedException e) {
        LOG.error("Failed to initiate RIB {}", this.yangRibId, e);
    }
    LOG.debug("Effective RIB created.");
    this.localTablesKeys.forEach(this::startLocRib);
    this.localTablesKeys.forEach(this::createLocRibWriter);
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 64 with NodeIdentifierWithPredicates

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

the class RIBSupportContextImpl method createEmptyTableStructure.

@Override
public void createEmptyTableStructure(final DOMDataWriteTransaction tx, final YangInstanceIdentifier tableId) {
    final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> tb = ImmutableNodes.mapEntryBuilder();
    tb.withNodeIdentifier((NodeIdentifierWithPredicates) tableId.getLastPathArgument());
    tb.withChild(EMPTY_TABLE_ATTRIBUTES);
    // tableId is keyed, but that fact is not directly visible from YangInstanceIdentifier, see BUG-2796
    final NodeIdentifierWithPredicates tableKey = (NodeIdentifierWithPredicates) tableId.getLastPathArgument();
    for (final Entry<QName, Object> e : tableKey.getKeyValues().entrySet()) {
        tb.withChild(ImmutableNodes.leafNode(e.getKey(), e.getValue()));
    }
    final ChoiceNode routes = this.ribSupport.emptyRoutes();
    Verify.verifyNotNull(routes, "Null empty routes in %s", this.ribSupport);
    Verify.verify(Routes.QNAME.equals(routes.getNodeType()), "Empty routes have unexpected identifier %s, expected %s", routes.getNodeType(), Routes.QNAME);
    tx.put(LogicalDatastoreType.OPERATIONAL, tableId, tb.withChild(routes).build());
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 65 with NodeIdentifierWithPredicates

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates 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)

Aggregations

NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)97 Test (org.junit.Test)52 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)49 ArrayList (java.util.ArrayList)37 Flowspec (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.Flowspec)34 FlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.FlowspecBuilder)34 NumericOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.NumericOperand)20 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)20 QName (org.opendaylight.yangtools.yang.common.QName)15 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv4.DestinationFlowspecBuilder)12 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)11 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 BitmaskOperand (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.BitmaskOperand)6 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)5 DestinationFlowspecBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.destination.ipv6.DestinationFlowspecBuilder)5