2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.client.mdsal;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import org.opendaylight.netconf.api.NetconfMessage;
14 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchemas;
15 import org.opendaylight.netconf.client.mdsal.api.NetconfSessionPreferences;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDevice;
17 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
18 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
19 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceServices;
20 import org.opendaylight.netconf.client.mdsal.impl.BaseRpcSchemalessTransformer;
21 import org.opendaylight.netconf.client.mdsal.impl.MessageCounter;
22 import org.opendaylight.netconf.client.mdsal.impl.SchemalessMessageTransformer;
23 import org.opendaylight.netconf.sal.connect.netconf.sal.SchemalessNetconfDeviceRpc;
25 public class SchemalessNetconfDevice implements RemoteDevice<NetconfDeviceCommunicator> {
26 private final BaseNetconfSchemas baseSchemas;
27 private final RemoteDeviceId id;
28 private final RemoteDeviceHandler salFacade;
29 private final SchemalessMessageTransformer messageTransformer;
30 private final BaseRpcSchemalessTransformer rpcTransformer;
32 public SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
33 final RemoteDeviceHandler salFacade) {
34 this.baseSchemas = requireNonNull(baseSchemas);
36 this.salFacade = salFacade;
37 final MessageCounter counter = new MessageCounter();
38 rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
39 messageTransformer = new SchemalessMessageTransformer(counter);
43 SchemalessNetconfDevice(final BaseNetconfSchemas baseSchemas, final RemoteDeviceId id,
44 final RemoteDeviceHandler salFacade, final SchemalessMessageTransformer messageTransformer) {
45 this.baseSchemas = requireNonNull(baseSchemas);
47 this.salFacade = salFacade;
48 final MessageCounter counter = new MessageCounter();
49 rpcTransformer = new BaseRpcSchemalessTransformer(baseSchemas, counter);
50 this.messageTransformer = messageTransformer;
54 public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
55 final NetconfDeviceCommunicator netconfDeviceCommunicator) {
56 salFacade.onDeviceConnected(
57 // FIXME: or bound from base schema rather?
58 new NetconfDeviceSchema(NetconfDeviceCapabilities.empty(),
59 baseSchemas.getBaseSchema().getMountPointContext()),
60 remoteSessionCapabilities, new RemoteDeviceServices(
61 new SchemalessNetconfDeviceRpc(id,netconfDeviceCommunicator, rpcTransformer, messageTransformer),
66 public void onRemoteSessionDown() {
67 salFacade.onDeviceDisconnected();
71 public void onRemoteSessionFailed(final Throwable throwable) {
72 salFacade.onDeviceFailed(throwable);
76 public void onNotification(final NetconfMessage notification) {
77 salFacade.onNotification(messageTransformer.toNotification(notification));