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.sal.connect.netconf;
10 import com.google.common.annotations.VisibleForTesting;
11 import org.opendaylight.netconf.api.NetconfMessage;
12 import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
13 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
14 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
15 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
16 import org.opendaylight.netconf.sal.connect.netconf.sal.SchemalessNetconfDeviceRpc;
17 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
18 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
19 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
20 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
21 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
23 public class SchemalessNetconfDevice implements
24 RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
26 private RemoteDeviceId id;
27 private RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
28 private final SchemalessMessageTransformer messageTransformer;
29 private final BaseRpcSchemalessTransformer rpcTransformer;
31 public SchemalessNetconfDevice(final RemoteDeviceId id,
32 final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
34 this.salFacade = salFacade;
35 final MessageCounter counter = new MessageCounter();
36 rpcTransformer = new BaseRpcSchemalessTransformer(counter);
37 messageTransformer = new SchemalessMessageTransformer(counter);
41 SchemalessNetconfDevice(final RemoteDeviceId id, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade,
42 final SchemalessMessageTransformer messageTransformer) {
44 this.salFacade = salFacade;
45 final MessageCounter counter = new MessageCounter();
46 rpcTransformer = new BaseRpcSchemalessTransformer(counter);
47 this.messageTransformer = messageTransformer;
50 @Override public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
51 final NetconfDeviceCommunicator netconfDeviceCommunicator) {
52 final SchemalessNetconfDeviceRpc schemalessNetconfDeviceRpc = new SchemalessNetconfDeviceRpc(id,
53 netconfDeviceCommunicator, rpcTransformer, messageTransformer);
55 salFacade.onDeviceConnected(BaseSchema.BASE_NETCONF_CTX.getSchemaContext(),
56 remoteSessionCapabilities, schemalessNetconfDeviceRpc);
60 @Override public void onRemoteSessionDown() {
61 salFacade.onDeviceDisconnected();
64 @Override public void onRemoteSessionFailed(final Throwable throwable) {
65 salFacade.onDeviceFailed(throwable);
68 @Override public void onNotification(final NetconfMessage notification) {
69 salFacade.onNotification(messageTransformer.toNotification(notification));