2 * Copyright © 2019 AT&T 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
9 package org.opendaylight.transportpce.networkmodel.util;
11 import java.util.Optional;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.transportpce.common.StringConstants;
15 import org.opendaylight.transportpce.common.Timeouts;
16 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class InfoSubtree {
26 private static final Logger LOG = LoggerFactory.getLogger(InfoSubtree.class);
33 String openRoadmVersion;
35 public InfoSubtree(String openRoadmVersion) {
37 this.clli = new String();
38 this.vendor = new String();
39 this.model = new String();
40 this.ipAddress = null;
42 this.openRoadmVersion = openRoadmVersion;
47 public boolean getDeviceInfo(String nodeId, DeviceTransactionManager deviceTransactionManager) {
48 switch (this.openRoadmVersion) {
49 case StringConstants.OPENROADM_DEVICE_VERSION_1_2_1:
50 return getDeviceInfo121(nodeId, deviceTransactionManager);
51 case StringConstants.OPENROADM_DEVICE_VERSION_2_2_1:
52 return getDeviceInfo221(nodeId, deviceTransactionManager);
54 LOG.info("Device version {} not supported",this.openRoadmVersion);
60 private boolean getDeviceInfo121(String nodeId, DeviceTransactionManager deviceTransactionManager) {
62 //Read clli from the device
63 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
64 Optional<Info> deviceInfoOpt =
65 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, infoIID,
66 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
68 Info deviceInfo = null;
70 if (deviceInfoOpt.isPresent()) {
71 deviceInfo = deviceInfoOpt.get();
73 LOG.error("Unable to get device info from device {}!", nodeId);
78 this.clli = deviceInfo.getClli();
79 this.vendor = deviceInfo.getVendor();
80 this.model = deviceInfo.getModel();
81 this.ipAddress = deviceInfo.getIpAddress();
82 this.nodeType = deviceInfo.getNodeType().getIntValue();
88 private boolean getDeviceInfo221(String nodeId, DeviceTransactionManager deviceTransactionManager) {
90 //TODO : change back to operational when testing on real device
91 //Read clli from the device
92 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm
93 .device.container.org.openroadm.device.Info> infoIID = InstanceIdentifier.create(org
94 .opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
95 .container.OrgOpenroadmDevice.class).child(org.opendaylight.yang.gen.v1.http.org
96 .openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Info.class);
97 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
98 .container.org.openroadm.device.Info> deviceInfoOpt =
99 deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.CONFIGURATION, infoIID,
100 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
102 org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container
103 .org.openroadm.device.Info deviceInfo = null;
105 if (deviceInfoOpt.isPresent()) {
106 deviceInfo = deviceInfoOpt.get();
108 LOG.error("Unable to get device info from device {}!", nodeId);
113 this.clli = deviceInfo.getClli();
114 //this.vendor = deviceInfo.getVendor();
115 //this.model = deviceInfo.getModel();
116 this.ipAddress = deviceInfo.getIpAddress();
117 this.nodeType = deviceInfo.getNodeType().getIntValue();
121 public String getClli() {
125 public String getVendor() {
129 public String getModel() {
133 public IpAddress getIpAddress() {
137 public int getNodeType() {