Search in sources :

Example 16 with DataTreeCandidateNode

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

the class LabeledUnicastIpv6RIBSupportTest method testChangedRoutes.

@Test
public void testChangedRoutes() {
    final Routes emptyCase = new LabeledUnicastIpv6RoutesCaseBuilder().build();
    DataTreeCandidateNode tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyCase)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes emptyRoutes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(new LabeledUnicastIpv6RoutesBuilder().build()).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(emptyRoutes)).getRootNode();
    Assert.assertTrue(RIB_SUPPORT.changedRoutes(tree).isEmpty());
    final Routes routes = new LabeledUnicastIpv6RoutesCaseBuilder().setLabeledUnicastIpv6Routes(ROUTES).build();
    tree = DataTreeCandidates.fromNormalizedNode(getRoutePath(), createRoutes(routes)).getRootNode();
    final Collection<DataTreeCandidateNode> result = RIB_SUPPORT.changedRoutes(tree);
    Assert.assertFalse(result.isEmpty());
}
Also used : LabeledUnicastIpv6RoutesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.ipv6.routes.LabeledUnicastIpv6RoutesBuilder) LabeledUnicastIpv6RoutesCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.bgp.rib.rib.loc.rib.tables.routes.LabeledUnicastIpv6RoutesCaseBuilder) 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) LabeledUnicastIpv6Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.labeled.unicast.rev171207.labeled.unicast.ipv6.routes.LabeledUnicastIpv6Routes) AbstractRIBSupportTest(org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest) Test(org.junit.Test)

Example 17 with DataTreeCandidateNode

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

the class AbstractRIBSupport method changedRoutes.

@Override
public final Collection<DataTreeCandidateNode> changedRoutes(final DataTreeCandidateNode routes) {
    final DataTreeCandidateNode myRoutes = routes.getModifiedChild(this.routesContainerIdentifier);
    if (myRoutes == null) {
        return Collections.emptySet();
    }
    final DataTreeCandidateNode routesMap = myRoutes.getModifiedChild(routeNid());
    if (routesMap == null) {
        return Collections.emptySet();
    }
    // to make sure the type matches what routeType() reports.
    return routesMap.getChildNodes();
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)

Example 18 with DataTreeCandidateNode

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

the class LinkstateRIBSupportTest method testChangedRoutes.

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

Example 19 with DataTreeCandidateNode

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

the class MultiPathAbstractRIBSupportTest method setUp.

@Before
public void setUp() {
    this.routesMap = new HashMap<>();
    MockitoAnnotations.initMocks(this);
    this.emptyTree = Mockito.mock(DataTreeCandidateNode.class);
    this.emptySubTree = Mockito.mock(DataTreeCandidateNode.class);
    this.subTree = Mockito.mock(DataTreeCandidateNode.class);
    final DataTreeCandidateNode emptyNode = Mockito.mock(DataTreeCandidateNode.class);
    final DataTreeCandidateNode node = Mockito.mock(DataTreeCandidateNode.class);
    doReturn(null).when(this.emptyTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(emptyNode).when(this.emptySubTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(null).when(emptyNode).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
    doReturn(node).when(this.subTree).getModifiedChild(IPV4_ROUTES_IDENTIFIER);
    doReturn(node).when(node).getModifiedChild(new NodeIdentifier(Ipv4Route.QNAME));
    final Collection<DataTreeCandidateNode> emptyCollection = new HashSet<>();
    doReturn(emptyCollection).when(node).getChildNodes();
    this.tx = Mockito.mock(DOMDataWriteTransaction.class);
    this.nlri = Mockito.mock(ContainerNode.class);
    this.attributes = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(QName.create(Ipv4Routes.QNAME, Attributes.QNAME.getLocalName().intern()))).build();
    final ContainerNode destination = Mockito.mock(ContainerNode.class);
    final ChoiceNode destinations = Mockito.mock(ChoiceNode.class);
    final ContainerNode route = Mockito.mock(ContainerNode.class);
    final Optional<?> optional = Optional.of(destination);
    final Optional<?> destinationOptional = Optional.of(destinations);
    final Optional<?> destinationsOptional = Optional.of(route);
    doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(WithdrawnRoutes.QNAME));
    doReturn(optional).when(this.nlri).getChild(new NodeIdentifier(AdvertizedRoutes.QNAME));
    doReturn(destinationOptional).when(destination).getChild(new NodeIdentifier(DestinationType.QNAME));
    doReturn(destinationsOptional).when(destinations).getChild(new NodeIdentifier(Ipv4Prefixes.QNAME));
    doReturn(emptyCollection).when(route).getValue();
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        MultiPathAbstractRIBSupportTest.this.routesMap.remove(args[1]);
        return args[1];
    }).when(this.tx).delete(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class));
    doAnswer(invocation -> {
        final Object[] args = invocation.getArguments();
        final NormalizedNode<?, ?> node1 = (NormalizedNode<?, ?>) args[2];
        MultiPathAbstractRIBSupportTest.this.routesMap.put((YangInstanceIdentifier) args[1], node1);
        return args[1];
    }).when(this.tx).put(Mockito.eq(LogicalDatastoreType.OPERATIONAL), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
    this.mapEntryNode = Mockito.mock(MapEntryNode.class);
}
Also used : MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 20 with DataTreeCandidateNode

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

the class LazyDataObjectModification method getModifiedChild.

@Override
public DataObjectModification<? extends DataObject> getModifiedChild(final PathArgument arg) {
    final List<YangInstanceIdentifier.PathArgument> domArgumentList = new ArrayList<>();
    final BindingCodecTreeNode<?> childCodec = codec.bindingPathArgumentChild(arg, domArgumentList);
    final Iterator<YangInstanceIdentifier.PathArgument> toEnter = domArgumentList.iterator();
    DataTreeCandidateNode current = domData;
    while (toEnter.hasNext() && current != null) {
        current = current.getModifiedChild(toEnter.next());
    }
    if (current != null) {
        return create(childCodec, current);
    }
    return null;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument)

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