Search in sources :

Example 1 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfDevice method handleSalInitializationSuccess.

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private synchronized void handleSalInitializationSuccess(final MountPointContext result, final NetconfSessionPreferences remoteSessionCapabilities, final DOMRpcService deviceRpc, final RemoteDeviceCommunicator<NetconfMessage> listener) {
    // since salFacade.onDeviceDisconnected was already called.
    if (connected) {
        this.messageTransformer = new NetconfMessageTransformer(result, true, resolveBaseSchema(remoteSessionCapabilities.isNotificationsSupported()));
        // salFacade.onDeviceConnected has to be called before the notification handler is initialized
        this.salFacade.onDeviceConnected(result, remoteSessionCapabilities, deviceRpc, this.deviceActionFactory == null ? null : this.deviceActionFactory.createDeviceAction(this.messageTransformer, listener, result.getEffectiveModelContext()));
        this.notificationHandler.onRemoteSchemaUp(this.messageTransformer);
        LOG.info("{}: Netconf connector initialized successfully", id);
    } else {
        LOG.warn("{}: Device communicator was closed before schema setup finished.", id);
    }
}
Also used : NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfDevice method createMountPointContext.

private ListenableFuture<MountPointContext> createMountPointContext(final EffectiveModelContext schemaContext, final BaseSchema baseSchema, final NetconfDeviceCommunicator listener) {
    final MountPointContext emptyContext = new EmptyMountPointContext(schemaContext);
    if (schemaContext.findModule(SchemaMountConstants.RFC8528_MODULE).isEmpty()) {
        return Futures.immediateFuture(emptyContext);
    }
    // Create a temporary RPC invoker and acquire the mount point tree
    LOG.debug("{}: Acquiring available mount points", id);
    final NetconfDeviceRpc deviceRpc = new NetconfDeviceRpc(schemaContext, listener, new NetconfMessageTransformer(emptyContext, false, baseSchema));
    return Futures.transform(deviceRpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_GET_QNAME, Builders.containerBuilder().withNodeIdentifier(NETCONF_GET_NODEID).withChild(NetconfMessageTransformUtil.toFilterStructure(RFC8528_SCHEMA_MOUNTS, schemaContext)).build()), rpcResult -> processSchemaMounts(rpcResult, emptyContext), MoreExecutors.directExecutor());
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) MountPointContext(org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)

Example 3 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfBaseOpsTest method setUp.

@Before
public void setUp() throws Exception {
    final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
    final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
    final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
    final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
    final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
    callback = new NetconfRpcFutureCallback("prefix", id);
    baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Example 4 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfToNotificationTest method testMostRecentWrongYangModel.

@Test
public void testMostRecentWrongYangModel() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
    messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    assertThrows(IllegalArgumentException.class, () -> messageTransformer.toNotification(userNotification));
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 5 with NetconfMessageTransformer

use of org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer in project netconf by opendaylight.

the class NetconfNestedNotificationTest method testNestedNotificationToNotificationFunction.

@Test
public void testNestedNotificationToNotificationFunction() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(Collections.singleton("/schemas/nested-notification.yang"));
    final NetconfMessage notificationMessage = prepareNotification("/nested-notification-payload.xml");
    NetconfMessageTransformer messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    final DOMNotification domNotification = messageTransformer.toNotification(notificationMessage);
    final ContainerNode root = domNotification.getBody();
    assertNotNull(root);
    assertEquals(1, root.body().size());
    assertEquals("interface-enabled", root.getIdentifier().getNodeType().getLocalName());
    assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2008-07-08T00:01:00Z").toInstant(), ((DOMEvent) domNotification).getEventInstant());
    assertEquals(Absolute.of(INTERFACES_QNAME, INTERFACE_QNAME, INTERFACE_ENABLED_NOTIFICATION_QNAME), domNotification.getType());
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Aggregations

NetconfMessageTransformer (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer)9 EmptyMountPointContext (org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext)8 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)5 Before (org.junit.Before)3 Test (org.junit.Test)3 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)3 NetconfDeviceRpc (org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc)3 DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)2 MountPointContext (org.opendaylight.yangtools.rfc8528.data.api.MountPointContext)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 InputStream (java.io.InputStream)1 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 BaseSchema (org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema)1 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)1 QName (org.opendaylight.yangtools.yang.common.QName)1