f1ddbe73cd81e7342276090d4d2bfc9cd9b8c2a5
[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.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceList;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.InstanceListKey;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.instance.list.PortDsList;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ptp.dataset.rev170208.port.ds.entry.PortIdentity;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 /**
35  * Reading PTP specific information from networkelement and creating log-trace output.
36  *
37  * @author herbert
38  */
39 public class WrapperPTPModelRev170208 {
40
41     private static final Logger LOG = LoggerFactory.getLogger(WrapperPTPModelRev170208.class);
42
43     protected static final InstanceIdentifier<InstanceList> PTPINSTANCES_IID =
44             InstanceIdentifier.builder(InstanceList.class, new InstanceListKey(1)).build();
45
46     /**
47      * Query synchronization information out of NE
48      */
49
50     public static void initSynchronizationExtension(NetconfAccessor acessor) {
51
52         String mountPointNodeName = acessor.getNodeId().getValue();
53         Capabilities capabilities = acessor.getCapabilites();
54         try {
55             if (!capabilities.isSupportingNamespaceAndRevision(InstanceList.QNAME)) {
56                 LOG.debug("Mountpoint {} does not support PTP", mountPointNodeName);
57             } else {
58                 StringBuffer sb = new StringBuffer();
59                 sb.append("NE ");
60                 sb.append(mountPointNodeName);
61                 sb.append(" does support synchronisation.\n");
62                 InstanceList ptpInstance = readPTPClockInstances(acessor);
63                 if (ptpInstance != null) {
64                     Collection<PortDsList> dsList = YangHelper.getCollection(ptpInstance.getPortDsList());
65                     if (dsList != null) {
66                         int t = 0;
67                         for (PortDsList portDs : dsList) {
68                             PortIdentity portId = portDs.getPortIdentity();
69                             if (portId != null) {
70                                 sb.append("Port[");
71                                 sb.append(portId.getPortNumber());
72                                 sb.append("]{ ClockId: ");
73                                 sb.append(portId.getClockIdentity());
74                                 sb.append(", Portstate: ");
75                                 sb.append(portDs.getPortState());
76                                 sb.append("}, ");
77                             } else {
78                                 sb.append("Incomplete port #" + t + ", ");
79                             }
80                             t++;
81                         }
82                     } else {
83                         sb.append("dsList contains null");
84                     }
85                 } else {
86                     sb.append("ptpInstance equals null");
87                 }
88                 LOG.trace(sb.toString());
89             }
90         } catch (Exception e) {
91             LOG.info("Inconsistent synchronisation structure: " + e.getMessage());
92         }
93     }
94
95     @Nullable
96     private static InstanceList readPTPClockInstances(NetconfAccessor acessor) {
97         return acessor.getTransactionUtils().readData(acessor.getDataBroker(), LogicalDatastoreType.OPERATIONAL,
98                 PTPINSTANCES_IID);
99     }
100
101 }