Java Code Examples for org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#NodeIdentifier

The following examples show how to use org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#NodeIdentifier . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EthSegRParserTest.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void parserTest() {
    final EsRouteCase expected = new EsRouteCaseBuilder().setEsRoute(new EsRouteBuilder()
            .setEsi(LAN_AUT_GEN_CASE).setOrigRouteIp(IP).build()).build();
    assertArrayEquals(RESULT, ByteArray.getAllBytes(this.parser.serializeEvpn(expected,
            Unpooled.wrappedBuffer(ROUDE_DISTIN))));

    final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE));
    assertEquals(expected, result);

    final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> choice = Builders
            .choiceBuilder();
    choice.withNodeIdentifier(EthSegRParser.ES_ROUTE_NID);
    final ContainerNode arbitraryC = createContBuilder(EthSegRParser.ES_ROUTE_NID)
            .addChild(LanParserTest.createLanChoice())
            .addChild(createValueBuilder(IP_MODEL, ORI_NID).build()).build();
    final EvpnChoice modelResult = this.parser.serializeEvpnModel(arbitraryC);
    assertEquals(expected, modelResult);

    final EvpnChoice keyResult = this.parser.createRouteKey(arbitraryC);
    assertEquals(expected, keyResult);
}
 
Example 2
Source File: EthSegRParserTest.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void parser2Test() {
    final EsRouteCase expected = new EsRouteCaseBuilder().setEsRoute(new EsRouteBuilder()
            .setEsi(LAN_AUT_GEN_CASE).setOrigRouteIp(IPV6).build()).build();
    assertArrayEquals(RESULT2, ByteArray.getAllBytes(this.parser.serializeEvpn(expected,
            Unpooled.wrappedBuffer(ROUDE_DISTIN))));

    final EvpnChoice result = this.parser.parseEvpn(Unpooled.wrappedBuffer(VALUE2));
    assertEquals(expected, result);

    final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ChoiceNode> choice = Builders
            .choiceBuilder();
    choice.withNodeIdentifier(EthSegRParser.ES_ROUTE_NID);
    final ContainerNode arbitraryC = createContBuilder(EthSegRParser.ES_ROUTE_NID)
            .addChild(LanParserTest.createLanChoice())
            .addChild(createValueBuilder(IPV6_MODEL, ORI_NID).build()).build();
    final EvpnChoice modelResult = this.parser.serializeEvpnModel(arbitraryC);
    assertEquals(expected, modelResult);

    final EvpnChoice keyResult = this.parser.createRouteKey(arbitraryC);
    assertEquals(expected, keyResult);
}
 
Example 3
Source File: ConfigStatementValidationTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test(expected = SchemaValidationFailedException.class)
public void testOnPathCaseLeafFail() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
        DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
    final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
            TestModel.TEST_QNAME, "choice1"));
    final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier(
            QName.create(TestModel.TEST_QNAME, "case2-cont"));
    final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId);
    final ContainerNode case2Cont = Builders.containerBuilder().withNodeIdentifier(case2ContId)
            .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")).build();

    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(ii, case2Cont);
    modificationTree.ready();
}
 
Example 4
Source File: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testMapNodeDirectEmptyWrite() {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    // Prepare root container
    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.TEST_QNAME);
    addListEntryModification.write(YangInstanceIdentifier.create(rootContainerId),
        Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

    final YangInstanceIdentifier outerListParentPath = YangInstanceIdentifier.create(getNId(TestModel.TEST_QNAME),
        getNId(TestModel.OUTER_LIST_QNAME));
    addListEntryModification.merge(outerListParentPath, ImmutableNodes.mapNode(TestModel.OUTER_LIST_QNAME));

    // Check empty map node auto deleted
    assertNodeExistence(outerListParentPath, false);
}
 
Example 5
Source File: LabeledUnicastIpv6RIBSupport.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected IpPrefix extractPrefix(final DataContainerNode<? extends YangInstanceIdentifier.PathArgument> route,
        final YangInstanceIdentifier.NodeIdentifier prefixTypeNid) {
    if (route.getChild(prefixTypeNid).isPresent()) {
        final String prefixType = (String) route.getChild(prefixTypeNid).get().getValue();
        return new IpPrefix(new Ipv6Prefix(prefixType));
    }
    return null;
}
 
Example 6
Source File: ConfigStatementValidationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = SchemaValidationFailedException.class)
public void testOnDataCaseLeafFail() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
        DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
    final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(
            TestModel.TEST_QNAME, "choice1"));
    final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id);
    final ChoiceNode choice1 = Builders.choiceBuilder().withNodeIdentifier(choice1Id)
            .withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case1-leaf1"), "leaf-value")).build();

    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(ii, choice1);

    modificationTree.ready();
}
 
Example 7
Source File: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMapNodeParentAutoCreateDelete() throws DataValidationFailedException {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    // Prepare root
    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.TEST_QNAME);
    addListEntryModification.write(YangInstanceIdentifier.create(rootContainerId),
        Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

    final NodeIdentifierWithPredicates outerListEntryId = NodeIdentifierWithPredicates.of(
        TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);

    // Write list entry (MapEntryNode) without creating list parent (MapNode)
    final MapEntryNode outerListEntry = Builders.mapEntryBuilder().withNodeIdentifier(outerListEntryId).build();
    final YangInstanceIdentifier outerListParentPath = YangInstanceIdentifier.create(getNId(TestModel.TEST_QNAME),
        getNId(TestModel.OUTER_LIST_QNAME));
    final YangInstanceIdentifier outerListEntryPath = outerListParentPath.node(outerListEntryId);
    addListEntryModification.write(outerListEntryPath, outerListEntry);

    addListEntryModification.ready();
    inMemoryDataTree.validate(addListEntryModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(addListEntryModification));

    // Check list parent auto created
    assertNodeExistence(outerListParentPath, true);

    // Now delete
    final DataTreeModification deleteListEntryModification = inMemoryDataTree.takeSnapshot().newModification();
    deleteListEntryModification.delete(outerListEntryPath);
    deleteListEntryModification.ready();
    inMemoryDataTree.validate(deleteListEntryModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(deleteListEntryModification));

    // Check list parent auto deleted
    assertNodeExistence(outerListParentPath, false);
}
 
Example 8
Source File: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNonPresenceContainerDirectEmptyWrite() throws DataValidationFailedException {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.NON_PRESENCE_QNAME);
    final YangInstanceIdentifier path = YangInstanceIdentifier.create(rootContainerId);
    addListEntryModification.write(path, Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

    addListEntryModification.ready();
    inMemoryDataTree.validate(addListEntryModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(addListEntryModification));

    // Check empty container auto deleted
    assertNodeExistence(path, false);
}
 
Example 9
Source File: LinkstateNlriParserTest.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testNodeNlri() throws BGPParsingException {
    setUp(this.nodeNlri);

    // test BA form
    assertNull(this.dest.getRouteDistinguisher());
    assertEquals(ProtocolId.IsisLevel2, this.dest.getProtocolId());
    assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
    final NodeCase nCase = (NodeCase) this.dest.getObjectType();

    final NodeDescriptors nodeD = nCase.getNodeDescriptors();
    assertEquals(new AsNumber(Uint32.valueOf(72)), nodeD.getAsNumber());
    assertEquals(new DomainIdentifier(Uint32.valueOf(0x28282828L)), nodeD.getDomainId());
    assertEquals(new IsisPseudonodeCaseBuilder().setIsisPseudonode(
        new IsisPseudonodeBuilder().setPsn(Uint8.valueOf(5)).setIsIsRouterIdentifier(
           new IsIsRouterIdentifierBuilder().setIsoSystemId(
               new IsoSystemIdentifier(new byte[] { 0, 0, 0, 0, 0, (byte) 0x39 })).build()).build()).build(),
        nodeD.getCRouterIdentifier());

    final ByteBuf buffer = Unpooled.buffer();
    this.registry.serializeNlriType(this.dest, buffer);
    assertArrayEquals(this.nodeNlri, ByteArray.readAllBytes(buffer));

    // test BI form
    final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
            ImmutableUnkeyedListEntryNodeBuilder.create();
    linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);

    final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
    protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
    protocolId.withValue("isis-level2");
    linkstateBI.addChild(protocolId.build());

    final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
    identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
    identifier.withValue(Uint64.ONE);
    linkstateBI.addChild(identifier.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
    objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);

    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> nodeDescriptors = Builders.containerBuilder();
    nodeDescriptors.withNodeIdentifier(LinkstateNlriParser.NODE_DESCRIPTORS_NID);

    final ImmutableLeafNodeBuilder<Uint32> asNumber = new ImmutableLeafNodeBuilder<>();
    asNumber.withNodeIdentifier(NodeNlriParser.AS_NUMBER_NID);
    asNumber.withValue(Uint32.valueOf(72));
    nodeDescriptors.addChild(asNumber.build());

    final ImmutableLeafNodeBuilder<Uint32> areaID = new ImmutableLeafNodeBuilder<>();
    areaID.withNodeIdentifier(NodeNlriParser.AREA_NID);
    areaID.withValue(Uint32.valueOf(2697513L));
    nodeDescriptors.addChild(areaID.build());

    final ImmutableLeafNodeBuilder<Uint32> domainID = new ImmutableLeafNodeBuilder<>();
    domainID.withNodeIdentifier(NodeNlriParser.DOMAIN_NID);
    domainID.withValue(Uint32.valueOf(0x28282828L));
    nodeDescriptors.addChild(domainID.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> crouterId = Builders.choiceBuilder();
    crouterId.withNodeIdentifier(C_ROUTER_ID_NID);

    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisNode = Builders.containerBuilder();
    isisNode.withNodeIdentifier(NodeNlriParser.ISIS_PSEUDONODE_NID);

    final ImmutableLeafNodeBuilder<byte[]> isoSystemID = new ImmutableLeafNodeBuilder<>();
    isoSystemID.withNodeIdentifier(NodeNlriParser.ISO_SYSTEM_NID);
    isoSystemID.withValue(new byte[]{0, 0, 0, 0, 0, (byte) 0x39});

    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> isisPseudoRouter =
            Builders.containerBuilder();
    isisPseudoRouter.withNodeIdentifier(NodeNlriParser.ISIS_ROUTER_NID);
    isisPseudoRouter.addChild(isoSystemID.build());

    isisNode.addChild(isisPseudoRouter.build());
    isisNode.addChild(Builders.leafBuilder().withNodeIdentifier(NodeNlriParser.PSN_NID).withValue(Uint8.valueOf(5))
        .build());
    crouterId.addChild(isisNode.build());

    nodeDescriptors.addChild(crouterId.build());
    objectType.addChild(nodeDescriptors.build());
    linkstateBI.addChild(objectType.build());

    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
 
Example 10
Source File: LinkstateNlriParserTest.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testTELspNlri() throws BGPParsingException {
    setUp(this.teLspNlri);
    // test BA form
    assertNull(this.dest.getRouteDistinguisher());
    assertEquals(ProtocolId.RsvpTe, this.dest.getProtocolId());
    assertEquals(Uint64.ONE, this.dest.getIdentifier().getValue());
    final TeLspCase teCase = (TeLspCase) this.dest.getObjectType();

    assertEquals(new LspId(Uint32.ONE), teCase.getLspId());
    assertEquals(new TunnelId(Uint16.ONE), teCase.getTunnelId());
    assertEquals(new Ipv4Address("1.2.3.4"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelSenderAddress());
    assertEquals(new Ipv4Address("4.3.2.1"), ((Ipv4Case) teCase.getAddressFamily()).getIpv4TunnelEndpointAddress());

    // test BI form
    final DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, UnkeyedListEntryNode> linkstateBI =
            ImmutableUnkeyedListEntryNodeBuilder.create();
    linkstateBI.withNodeIdentifier(C_LINKSTATE_NID);

    final ImmutableLeafNodeBuilder<String> protocolId = new ImmutableLeafNodeBuilder<>();
    protocolId.withNodeIdentifier(LinkstateNlriParser.PROTOCOL_ID_NID);
    protocolId.withValue("rsvp-te");
    linkstateBI.addChild(protocolId.build());

    final ImmutableLeafNodeBuilder<Uint64> identifier = new ImmutableLeafNodeBuilder<>();
    identifier.withNodeIdentifier(LinkstateNlriParser.IDENTIFIER_NID);
    identifier.withValue(Uint64.ONE);
    linkstateBI.addChild(identifier.build());

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> objectType = Builders.choiceBuilder();
    objectType.withNodeIdentifier(LinkstateNlriParser.OBJECT_TYPE_NID);

    final ImmutableLeafNodeBuilder<Uint32> lspId = new ImmutableLeafNodeBuilder<>();
    lspId.withNodeIdentifier(AbstractTeLspNlriCodec.LSP_ID);
    lspId.withValue(Uint32.ONE);

    final ImmutableLeafNodeBuilder<Uint16> tunnelId = new ImmutableLeafNodeBuilder<>();
    tunnelId.withNodeIdentifier(AbstractTeLspNlriCodec.TUNNEL_ID);
    tunnelId.withValue(Uint16.ONE);

    final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> addressFamily = Builders.choiceBuilder();
    addressFamily.withNodeIdentifier(AbstractTeLspNlriCodec.ADDRESS_FAMILY);

    final ImmutableLeafNodeBuilder<String> ipv4TunnelSenderAddress = new ImmutableLeafNodeBuilder<>();
    ipv4TunnelSenderAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_SENDER_ADDRESS);
    ipv4TunnelSenderAddress.withValue("1.2.3.4");

    final ImmutableLeafNodeBuilder<String> ipv4TunnelEndPointAddress = new ImmutableLeafNodeBuilder<>();
    ipv4TunnelEndPointAddress.withNodeIdentifier(AbstractTeLspNlriCodec.IPV4_TUNNEL_ENDPOINT_ADDRESS);
    ipv4TunnelEndPointAddress.withValue("4.3.2.1");

    addressFamily.addChild(ipv4TunnelSenderAddress.build());
    addressFamily.addChild(ipv4TunnelEndPointAddress.build());

    objectType.addChild(lspId.build());
    objectType.addChild(tunnelId.build());
    objectType.addChild(addressFamily.build());

    linkstateBI.addChild(objectType.build());
    assertEquals(this.dest, LinkstateNlriParser.extractLinkstateDestination(linkstateBI.build()));
}
 
Example 11
Source File: SchemaOrderedNormalizedNodeWriterTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String ns, final String name) {
    return YangInstanceIdentifier.NodeIdentifier.create(createQName(ns, name));
}