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