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