blob: 762c21cdff6ed97b21d975e68c2dc1956693a74e [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
2 * Copyright 2015 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.NetconfSession;
Andrea Campanella1cd641b2015-12-07 17:28:34 -080022import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
andreaeb70a942015-10-16 21:34:46 -070024
25import java.io.IOException;
26
27/**
28 * Implementation of a NETCONF device.
29 */
30public class NetconfDeviceImpl implements NetconfDevice {
31
Andrea Campanella1cd641b2015-12-07 17:28:34 -080032 public static final Logger log = LoggerFactory
33 .getLogger(NetconfSessionImpl.class);
34
andreaeb70a942015-10-16 21:34:46 -070035 private NetconfDeviceInfo netconfDeviceInfo;
36 private boolean deviceState = false;
37 private NetconfSession netconfSession;
andreaeb70a942015-10-16 21:34:46 -070038
39 public NetconfDeviceImpl(NetconfDeviceInfo deviceInfo) throws IOException {
40 netconfDeviceInfo = deviceInfo;
41 try {
42 netconfSession = new NetconfSessionImpl(netconfDeviceInfo);
43 } catch (IOException e) {
44 throw new IOException("Cannot create connection and session", e);
45 }
46 deviceState = true;
andreaeb70a942015-10-16 21:34:46 -070047 }
48
49 @Override
50 public boolean isActive() {
51 return deviceState;
52 }
53
54 @Override
55 public NetconfSession getSession() {
56 return netconfSession;
57 }
58
59 @Override
60 public void disconnect() {
61 deviceState = false;
Andrea Campanella1cd641b2015-12-07 17:28:34 -080062 try {
63 netconfSession.close();
64 } catch (IOException e) {
65 log.warn("Cannot communicate with the device {} ", netconfDeviceInfo);
66 }
andreaeb70a942015-10-16 21:34:46 -070067 }
68
69 @Override
70 public NetconfDeviceInfo getDeviceInfo() {
71 return netconfDeviceInfo;
72 }
73}