81e7d85a9c9f992220158b01e67c07a557376e8c
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.ifpac;
19
20 import java.util.Collection;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
23 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
24 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
25 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceListKey;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.instance.list.PortDsList;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.port.ds.entry.PortIdentity;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.Uint16;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * Reading PTP specific information from networkelement and creating log-trace output.
38  *
39  * @author herbert
40  */
41 public class WrapperPTPModelRev170208 {
42
43     private static final Logger LOG = LoggerFactory.getLogger(WrapperPTPModelRev170208.class);
44
45     protected static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID =
46             InstanceIdentifier.builder(InstanceList.class, new InstanceListKey(Uint16.valueOf(1))).build();
47
48     /**
49      * Query synchronization information out of NE
50      */
51
52     public static void initSynchronizationExtension(NetconfBindingAccessor acessor) {
53
54         String mountPointNodeName = acessor.getNodeId().getValue();
55         Capabilities capabilities = acessor.getCapabilites();
56         try {
57             if (!capabilities.isSupportingNamespaceAndRevision(InstanceList.QNAME)) {
58                 LOG.debug("Mountpoint {} does not support PTP", mountPointNodeName);
59             } else {
60                 StringBuffer sb = new StringBuffer();
61                 sb.append("NE ");
62                 sb.append(mountPointNodeName);
63                 sb.append(" does support synchronisation.\n");
64                 InstanceList ptpInstance = readPTPClockInstances(acessor);
65                 if (ptpInstance != null) {
66                     Collection<PortDsList> dsList = YangHelper.getCollection(ptpInstance.getPortDsList());
67                     if (dsList != null) {
68                         int t = 0;
69                         for (PortDsList portDs : dsList) {
70                             PortIdentity portId = portDs.getPortIdentity();
71                             if (portId != null) {
72                                 sb.append("Port[");
73                                 sb.append(portId.getPortNumber());
74                                 sb.append("]{ ClockId: ");
75                                 sb.append(portId.getClockIdentity());
76                                 sb.append(", Portstate: ");
77                                 sb.append(portDs.getPortState());
78                                 sb.append("}, ");
79                             } else {
80                                 sb.append("Incomplete port #" + t + ", ");
81                             }
82                             t++;
83                         }
84                     } else {
85                         sb.append("dsList contains null");
86                     }
87                 } else {
88                     sb.append("ptpInstance equals null");
89                 }
90                 LOG.trace(sb.toString());
91             }
92         } catch (Exception e) {
93             LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
94         }
95     }
96
97     @Nullable
98     private static InstanceList readPTPClockInstances(NetconfBindingAccessor acessor) {
99         return acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
100                 PTPINSTANCES_IID);
101     }
102
103 }