/** * Test case: one SupportingNode translation<br> * - includes TopologyRef and NodeRef */ @Test public void testSupportingNode() { String logicalName = "node:1"; String physicalName = "node:11"; UnderlayItem physicalNode1 = new UnderlayItem( mockNormalizedNode, null, TOPOLOGY_NAME, physicalName, CorrelationItemEnum.Node); OverlayItem logicalNode = new OverlayItem(Collections.singletonList(physicalNode1), CorrelationItemEnum.Node); OverlayItemWrapper wrapper = new OverlayItemWrapper(logicalName, logicalNode); NormalizedNode<?, ?> normalizedNode = translator.translate(wrapper); Map<QName, Object> keyValues = new HashMap<>(); keyValues.put(TopologyQNames.TOPOLOGY_REF, TOPOLOGY_NAME); keyValues.put(TopologyQNames.NODE_REF, physicalName); // topologyRef YangInstanceIdentifier yiidTopoRef = YangInstanceIdentifier.builder() .node(SupportingNode.QNAME) .nodeWithKey(SupportingNode.QNAME, keyValues) .node(TopologyQNames.TOPOLOGY_REF) .build(); Optional<NormalizedNode<?, ?>> topologyRef = NormalizedNodes.findNode(normalizedNode, yiidTopoRef); Assert.assertTrue("TopologyRef should be provided", topologyRef.isPresent()); Assert.assertEquals( "TopologyRef from SupportingNodes should be the same as the PhysicalNode's Topology", TOPOLOGY_NAME, topologyRef.get().getValue()); // nodeRef YangInstanceIdentifier yiidNodeRef = YangInstanceIdentifier.builder() .node(SupportingNode.QNAME) .nodeWithKey(SupportingNode.QNAME, keyValues) .node(TopologyQNames.NODE_REF) .build(); Optional<NormalizedNode<?, ?>> nodeRef = NormalizedNodes.findNode(normalizedNode, yiidNodeRef); Assert.assertTrue("NodeRef should be provided", nodeRef.isPresent()); Assert.assertEquals( "NodeRef from SupportingNodes should be the same as the PhysicalNode's Id", physicalName, nodeRef.get().getValue()); }
@Override protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc( final NormalizedNode<?, ?> input) { final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId); // Routing key is present, attempt to deliver as a routed RPC if (maybeKey.isPresent()) { final NormalizedNode<?, ?> key = maybeKey.get(); final Object value = key.getValue(); if (value instanceof YangInstanceIdentifier) { final YangInstanceIdentifier iid = (YangInstanceIdentifier) value; // Find a DOMRpcImplementation for a specific iid final List<DOMRpcImplementation> specificImpls = getImplementations(iid); if (specificImpls != null) { return specificImpls .get(0) .invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input); } LOG.debug("No implementation for context {} found will now look for wildcard id", iid); // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register // an // implementation this way final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY); if (mayBeRemoteImpls != null) { return mayBeRemoteImpls .get(0) .invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input); } } else { LOG.warn("Ignoring wrong context value {}", value); } } final List<DOMRpcImplementation> impls = getImplementations(null); if (impls != null) { return impls.get(0).invokeRpc(globalRpcId, input); } else { return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture( new DOMRpcImplementationNotAvailableException( "No implementation of RPC %s available", getSchemaPath())); } }
/** Test case: NodeId translation */ @Test public void testNodeId() { String logicalName = "node:1"; UnderlayItem physicalNode = new UnderlayItem( mockNormalizedNode, null, TOPOLOGY_NAME, "node:1", CorrelationItemEnum.Node); OverlayItem logicalNode = new OverlayItem(Collections.singletonList(physicalNode), CorrelationItemEnum.Node); OverlayItemWrapper wrapper = new OverlayItemWrapper(logicalName, logicalNode); NormalizedNode<?, ?> normalizedNode = translator.translate(wrapper); NormalizedNode<?, ?> nodeId = NormalizedNodes.findNode( normalizedNode, YangInstanceIdentifier.of(TopologyQNames.NETWORK_NODE_ID_QNAME)) .get(); Assert.assertEquals( "NormalizedNode ID should be the same as the LogicalNodeWrapper ID", logicalName, nodeId.getValue()); }