blob: 0740cc48ad9ae2e7fe7d26c291e7e1e8d813e30d [file] [log] [blame]
Yuta HIGUCHI348b3232017-04-20 10:19:48 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.netconf.ctl;
18
19import org.onosproject.netconf.NetconfDevice;
20import org.onosproject.netconf.NetconfDeviceInfo;
21import org.onosproject.netconf.NetconfException;
22import org.onosproject.netconf.NetconfSession;
23import org.onosproject.netconf.NetconfSessionFactory;
24import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
26
27import java.io.IOException;
28
29/**
30 * Default implementation of a NETCONF device.
31 *
32 * @deprecated in 1.10.0
33 */
34@Deprecated
35public class DefaultNetconfDevice implements NetconfDevice {
36
37 public static final Logger log = LoggerFactory
38 .getLogger(DefaultNetconfDevice.class);
39
40 private NetconfDeviceInfo netconfDeviceInfo;
41 private boolean deviceState = true;
42 protected NetconfSessionFactory sessionFactory = new SshNetconfSessionFactory();
43 private NetconfSession netconfSession;
44
45 /**
46 * Creates a new default NETCONF device with the information provided.
47 * The device gets created only if no exception is thrown while connecting to
48 * it and establishing the NETCONF session.
49 * @param deviceInfo information about the device to be created.
50 * @throws NetconfException if there are problems in creating or establishing
51 * the underlying NETCONF connection and session.
52 */
53 public DefaultNetconfDevice(NetconfDeviceInfo deviceInfo)
54 throws NetconfException {
55 netconfDeviceInfo = deviceInfo;
56 try {
57 netconfSession = sessionFactory.createNetconfSession(deviceInfo);
58 } catch (IOException e) {
59 deviceState = false;
60 throw new NetconfException("Cannot create connection and session for device " +
61 deviceInfo, e);
62 }
63 }
64
65 @Override
66 public boolean isActive() {
67 return deviceState;
68 }
69
70 @Override
71 public NetconfSession getSession() {
72 return netconfSession;
73 }
74
75 @Override
76 public void disconnect() {
77 deviceState = false;
78 try {
79 netconfSession.close();
80 } catch (IOException e) {
81 log.warn("Cannot communicate with the device {} session already closed", netconfDeviceInfo);
82 }
83 }
84
85 @Override
86 public NetconfDeviceInfo getDeviceInfo() {
87 return netconfDeviceInfo;
88 }
89
90 public class SshNetconfSessionFactory implements NetconfSessionFactory {
91
92 @Override
93 public NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException {
94 return new NetconfSessionImpl(netconfDeviceInfo);
95 }
96 }
97
98}