/** * Construct an Entity with an with a name. The general-entity schema is used to construct the * YangInstanceIdentifier. * * @param type the type of the entity * @param entityName the name of the entity used to construct a general-entity YangInstanceIdentifier */ public Entity(@Nonnull String type, @Nonnull String entityName) { this.type = Preconditions.checkNotNull(type, "type should not be null"); this.id = YangInstanceIdentifier.builder().node(ENTITY_QNAME).nodeWithKey(ENTITY_QNAME, ENTITY_NAME, Preconditions.checkNotNull(entityName, "entityName should not be null")).build(); }
private static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBIPathForTopology(final String name) { final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder builder = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder(); builder .node(NetworkTopology.QNAME) .node(Topology.QNAME) .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), TopologyNetconf.QNAME.getLocalName()) .node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME) .nodeWithKey(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME, QName.create(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.QNAME, "node-id"), name); return builder.build(); }
private static org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier createBIPath(final String name) { final org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder builder = org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.builder(); builder.node(Nodes.QNAME).node(Node.QNAME).nodeWithKey(Node.QNAME, QName.create(Node.QNAME.getNamespace(), Node.QNAME.getRevision(), "id"), name); return builder.build(); }
private BmpRouterPeerImpl(final DOMTransactionChain domTxChain, final YangInstanceIdentifier peersYangIId, final PeerId peerId, final RIBExtensionConsumerContext extensions, final PeerUpNotification peerUp, final BindingCodecTree tree) { this.domTxChain = Preconditions.checkNotNull(domTxChain); this.peerId = peerId; this.peerYangIId = YangInstanceIdentifier.builder(peersYangIId).nodeWithKey(Peer.QNAME, PEER_ID_QNAME, this.peerId.getValue()).build(); this.sentOpenCodec = tree.getSubtreeCodec(SENT_OPEN_IID); this.receivedOpenCodec = tree.getSubtreeCodec(RECEIVED_OPEN_IID); final Set<TablesKey> peerTables = setPeerTables(peerUp.getReceivedOpen()); final DOMDataWriteTransaction wTx = this.domTxChain.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, this.peerYangIId, createPeerEntry(peerUp)); wTx.submit(); this.prePolicyWriter = BmpRibInWriter.create(this.peerYangIId.node(PrePolicyRib.QNAME).node(BMP_TABLES_QNAME), this.domTxChain, extensions, peerTables, tree); this.postPolicyWriter = BmpRibInWriter.create(this.peerYangIId.node(PostPolicyRib.QNAME).node(BMP_TABLES_QNAME), this.domTxChain, extensions, peerTables, tree); }
@Override public void onSessionUp(final BmpSession session) { this.session = session; this.routerIp = InetAddresses.toAddrString(this.session.getRemoteAddress()); this.routerId = new RouterId(Ipv4Util.getIpAddress(this.session.getRemoteAddress())); // check if this session is redundant if (!this.sessionManager.addSessionListener(this)) { LOG.warn("Redundant BMP session with remote router {} ({}) detected. This BMP session will be abandoned.", this.routerIp, this.session); this.close(); } else { this.routerYangIId = YangInstanceIdentifier.builder(this.sessionManager.getRoutersYangIId()).nodeWithKey(Router.QNAME, ROUTER_ID_QNAME, this.routerIp).build(); this.peersYangIId = YangInstanceIdentifier.builder(routerYangIId).node(Peer.QNAME).build(); createRouterEntry(); LOG.info("BMP session with remote router {} ({}) is up now.", this.routerIp, this.session); } }
@Test public void testNormalizedNodeAndYangInstanceIdentifierStreaming() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); NormalizedNodeOutputStreamWriter writer = new NormalizedNodeOutputStreamWriter( ByteStreams.newDataOutput(byteArrayOutputStream)); NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder().build(); writer.writeNormalizedNode(testContainer); YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey( TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build(); writer.writeYangInstanceIdentifier(path); NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput( ByteStreams.newDataInput(byteArrayOutputStream.toByteArray())); NormalizedNode<?,?> node = reader.readNormalizedNode(); Assert.assertEquals(testContainer, node); YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier(); Assert.assertEquals(path, newPath); writer.close(); }
@Test public void testInnerContainerNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INVALID_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").build()).build()).build(); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
@Test public void testInnerListNodeWithParentPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode innerList = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNode<?, ?> input = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .withChild(innerList).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> expected = mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", expected, actual); }
private void createEmptyMonitor() { final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction(); ensureParentExists(wTx, YangInstanceIdentifier.of(BmpMonitor.QNAME)); wTx.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME) .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()).build(), ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()) .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, this.monitorId.getValue())) .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build()) .build()); try { wTx.submit().checkedGet(); } catch (final TransactionCommitFailedException e) { LOG.error("Failed to initiate BMP Monitor {}.", this.monitorId.getValue(), e); } }
private YangInstanceIdentifier domMountPath(final NodeId nodeId) { return YangInstanceIdentifier.builder(NETCONF_DEVICE_DOM_PATH) .nodeWithKey(Node.QNAME, NODE_ID_QNAME, nodeId.getValue()).build(); }
@Test public void testInnerListNodeWithFullPathNotPruned() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INNER_LIST_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INNER_LIST_QNAME).withChild(mapEntryBuilder( TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }
static YangInstanceIdentifier candidatePath(YangInstanceIdentifier entityPath, String candidateName) { return YangInstanceIdentifier.builder(entityPath).node(Candidate.QNAME).nodeWithKey( Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName).build(); }
static YangInstanceIdentifier entityPath(String entityType, YangInstanceIdentifier entityId) { return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME). nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME). nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).build(); }
@Test public void testInnerContainerNodeWithFullPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one") .node(TestModel.INVALID_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); NormalizedNode<?, ?> input = ImmutableNodes.containerNode(TestModel.INVALID_QNAME); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertNull(actual); }
@Test public void testInnerListNodeWithFullPathPrunedWhenSchemaMissing() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INVALID_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); MapNode input = mapNodeBuilder(TestModel.INVALID_QNAME).withChild(mapEntryBuilder( TestModel.INVALID_QNAME, TestModel.NAME_QNAME, "one").withChild( ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME)).build()).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertNull(actual); }
@Test public void testYangInstanceIdentifierStreaming() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey( TestModel.INNER_LIST_QNAME, TestModel.ID_QNAME, 10).build(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos)); nnout.writeYangInstanceIdentifier(path); NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput( bos.toByteArray())); YangInstanceIdentifier newPath = nnin.readYangInstanceIdentifier(); Assert.assertEquals(path, newPath); }
static YangInstanceIdentifier candidatePath(String entityType, YangInstanceIdentifier entityId, String candidateName) { return YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH).node(EntityType.QNAME). nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME). nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).node(Candidate.QNAME). nodeWithKey(Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName).build(); }
private void installAdjRibInTables(final YangInstanceIdentifier newPeerPath, final TablesKey tableKey, final RIBSupportContext rs, final NodeIdentifierWithPredicates instanceIdentifierKey, final DOMDataWriteTransaction tx, final Builder<TablesKey, TableContext> tb) { // We will use table keys very often, make sure they are optimized final InstanceIdentifierBuilder idb = YangInstanceIdentifier.builder(newPeerPath.node(EMPTY_ADJRIBIN.getIdentifier()).node(TABLES)); idb.nodeWithKey(instanceIdentifierKey.getNodeType(), instanceIdentifierKey.getKeyValues()); final TableContext ctx = new TableContext(rs, idb.build()); ctx.createEmptyTableStructure(tx); tx.merge(LogicalDatastoreType.OPERATIONAL, ctx.getTableId().node(Attributes.QNAME).node(ATTRIBUTES_UPTODATE_FALSE.getNodeType()), ATTRIBUTES_UPTODATE_FALSE); LOG.debug("Created table instance {}", ctx.getTableId()); tb.put(tableKey, ctx); }
@Override public void instantiateServiceInstance() { if(this.configurationWriter != null) { this.configurationWriter.apply(); } LOG.info("Application Peer Singleton Service {} instantiated", getIdentifier()); final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME) .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, this.appRibId.getValue()).node(Tables.QNAME).node(Tables.QNAME).build(); this.applicationPeer.instantiateServiceInstance(); this.registration = this.dataTreeChangeService .registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId), this.applicationPeer); }
@Test public void testInnerContainerNodeWithFullPathPathNotPruned() throws IOException { YangInstanceIdentifier path = YangInstanceIdentifier.builder().node(TestModel.TEST_QNAME) .node(TestModel.OUTER_LIST_QNAME).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1) .node(TestModel.INNER_LIST_QNAME).nodeWithKey(TestModel.INNER_LIST_QNAME, TestModel.NAME_QNAME, "one") .node(TestModel.INNER_CONTAINER_QNAME).build(); NormalizedNodePruner pruner = prunerFullSchema(path); NormalizedNode<?, ?> input = ImmutableNodes.containerNode(TestModel.INNER_CONTAINER_QNAME); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }