Search in sources :

Example 31 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode 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 32 with DataTreeCandidateNode

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

the class AdjRibOutListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
    LOG.debug("Data change received for AdjRibOut {}", changes);
    for (final DataTreeCandidate tc : changes) {
        LOG.trace("Change {} type {}", tc.getRootNode(), tc.getRootNode().getModificationType());
        for (final DataTreeCandidateNode child : tc.getRootNode().getChildNodes()) {
            processSupportedFamilyRoutes(child);
        }
    }
    this.session.flush();
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)

Example 33 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode 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 34 with DataTreeCandidateNode

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

the class FlowspecL3vpnIpv6RIBSupportTest method testChangedRoutes.

@Test
public void testChangedRoutes() {
    final Routes emptyCase = new FlowspecL3vpnIpv6RoutesCaseBuilder().build();
    DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes emptyRoutes = new FlowspecL3vpnIpv6RoutesCaseBuilder().setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().build()).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes routes = new FlowspecL3vpnIpv6RoutesCaseBuilder().setFlowspecL3vpnIpv6Routes(new FlowspecL3vpnIpv6RoutesBuilder().setFlowspecL3vpnRoute(Collections.singletonList(ROUTE)).build()).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
    final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
    Assert.assertFalse(result.isEmpty());
}
Also used : FlowspecL3vpnIpv6RoutesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecL3vpnIpv6RoutesCaseBuilder) FlowspecL3vpnIpv6RoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6RoutesBuilder) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes) FlowspecL3vpnIpv6Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.l3vpn.ipv6.routes.FlowspecL3vpnIpv6Routes) AdvertizedRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.update.attributes.mp.reach.nlri.AdvertizedRoutes) AbstractRIBSupportTest(org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest) Test(org.junit.Test)

Example 35 with DataTreeCandidateNode

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

the class FlowspecIpv4RIBSupportTest method testChangedRoutes.

@Test
public void testChangedRoutes() {
    final Routes emptyCase = new FlowspecRoutesCaseBuilder().build();
    DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes emptyRoutes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().build()).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes routes = new FlowspecRoutesCaseBuilder().setFlowspecRoutes(new FlowspecRoutesBuilder().setFlowspecRoute(Collections.singletonList(ROUTE)).build()).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
    final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
    Assert.assertFalse(result.isEmpty());
}
Also used : FlowspecRoutesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.bgp.rib.rib.loc.rib.tables.routes.FlowspecRoutesCaseBuilder) FlowspecRoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.routes.FlowspecRoutesBuilder) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) FlowspecRoutes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev171207.flowspec.routes.FlowspecRoutes) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes) AbstractRIBSupportTest(org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest) Test(org.junit.Test)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)38 Test (org.junit.Test)18 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)13 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)12 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)2 Collection (java.util.Collection)1 Before (org.junit.Before)1 CandidateAdded (org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded)1