b870224c5081d401942ebfa9bb9693cf739feb01
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / util / InfoSubtree.java
1 /*
2  * Copyright © 2019 AT&T and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.networkmodel.util;
10
11 import java.util.Optional;
12
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;
23
24 public class InfoSubtree {
25
26     private static final Logger LOG = LoggerFactory.getLogger(InfoSubtree.class);
27
28     String clli;
29     String vendor;
30     String model;
31     IpAddress ipAddress;
32     int nodeType;
33     String openRoadmVersion;
34
35     public InfoSubtree(String openRoadmVersion) {
36
37         this.clli = new String();
38         this.vendor = new String();
39         this.model = new String();
40         this.ipAddress = null;
41         this.nodeType = 0;
42         this.openRoadmVersion = openRoadmVersion;
43
44
45     }
46
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);
53             default:
54                 LOG.info("Device version {} not supported",this.openRoadmVersion);
55                 return false;
56         }
57
58     }
59
60     private boolean getDeviceInfo121(String nodeId, DeviceTransactionManager deviceTransactionManager) {
61
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);
67
68         Info deviceInfo = null;
69
70         if (deviceInfoOpt.isPresent()) {
71             deviceInfo = deviceInfoOpt.get();
72         } else {
73             LOG.error("Unable to get device info from device {}!", nodeId);
74             return false;
75
76         }
77
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();
83
84         return true;
85
86     }
87
88     private boolean getDeviceInfo221(String nodeId, DeviceTransactionManager deviceTransactionManager) {
89
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);
101
102         org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container
103                 .org.openroadm.device.Info deviceInfo = null;
104
105         if (deviceInfoOpt.isPresent()) {
106             deviceInfo = deviceInfoOpt.get();
107         } else {
108             LOG.error("Unable to get device info from device {}!", nodeId);
109             return false;
110
111         }
112
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();
118         return true;
119     }
120
121     public String getClli() {
122         return clli;
123     }
124
125     public String getVendor() {
126         return vendor;
127     }
128
129     public String getModel() {
130         return model;
131     }
132
133     public IpAddress getIpAddress() {
134         return ipAddress;
135     }
136
137     public int getNodeType() {
138         return nodeType;
139     }
140 }
141
142