2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.yangspecs;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.List;
29 import java.util.Optional;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.Onf14Interfaces;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.interfaces.TechnologySpecificPacKeys;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util.Onf14DMDOMUtility;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.common.QNameModule;
38 import org.opendaylight.yangtools.yang.common.Revision;
39 import org.opendaylight.yangtools.yang.common.XMLNamespace;
40 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
41 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
42 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
43 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
44 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
45 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
49 public class CoreModel14 extends YangModule {
51 private static final Logger LOG = LoggerFactory.getLogger(CoreModel14.class);
53 private static final String NAMESPACE = "urn:onf:yang:core-model-1-4";
54 private static final List<QNameModule> MODULES =
55 Arrays.asList(QNameModule.create(XMLNamespace.of(NAMESPACE), Revision.of("2019-11-27")));
57 private final QName CONTROL_CONSTRUCT;
58 private final QName TOP_LEVEL_EQUIPMENT;
60 private CoreModel14(NetconfDomAccessor netconfDomAccessor, QNameModule module) {
61 super(netconfDomAccessor, module);
63 CONTROL_CONSTRUCT = QName.create(module, "control-construct");
64 TOP_LEVEL_EQUIPMENT = QName.create(module, "top-level-equipment");
67 public String getRevision() {
68 return module.getRevision().get().toString();
72 public QName getQName(String localName) {
73 return QName.create(module, localName);
76 public QName getControlConstructQName() {
77 return CONTROL_CONSTRUCT;
80 public YangInstanceIdentifier getTopLevelEquipment_IId() {
81 return YangInstanceIdentifier.builder().node(getControlConstructQName()).node(TOP_LEVEL_EQUIPMENT).build();
84 private YangInstanceIdentifier getLtp_IID() {
85 return YangInstanceIdentifier.builder().node(getQName("control-construct"))
86 .node(getQName("logical-termination-point")).build();
89 public YangInstanceIdentifier getLayerProtocolIId(String ltpUuid, String localId) {
90 return YangInstanceIdentifier.builder().node(getQName("control-construct"))
91 .node(getQName("logical-termination-point"))
92 .nodeWithKey(getQName("logical-termination-point"),
93 QName.create(getQName("logical-termination-point"), "uuid").intern(), ltpUuid)
94 .node(getQName("layer-protocol")).nodeWithKey(getQName("layer-protocol"),
95 QName.create(getQName("layer-protocol"), "local-id").intern(), localId)
99 public Optional<NormalizedNode> readLtpData(NetconfDomAccessor netconfDomAccessor) {
100 LOG.info("Reading Logical Termination Point data");
101 return netconfDomAccessor.readDataNode(LogicalDatastoreType.CONFIGURATION, getLtp_IID());
105 * Get the LP list, which should contain only 1 entry. the Layer Protocol list should contain only one item, since
106 * we have an 1:1 relationship between the LTP and the LP
111 private Collection<MapEntryNode> getInterfaceKeyList(DataContainerNode ltp) {
112 MapNode lpList = (MapNode) ltp.childByArg(new NodeIdentifier(getQName("layer-protocol")));
113 // the Layer Protocol list should contain only one item, since we have an 1:1
114 // relationship between the LTP and the LP
115 if (lpList != null && lpList.size() != 1) {
116 LOG.debug("Layer protocol has no 1:1 relationship with the LTP.");
117 return Collections.emptyList();
119 // accessing the LP, which should be only 1
120 return lpList.body();
124 * Search through the LayerProtocol list for specific layerProtocolNamesValues
127 * @param layerProtocolNameValue
130 private List<TechnologySpecificPacKeys> getTechnologySpecificPackKeys(DataContainerNode ltp, Collection<MapEntryNode> lp,
131 String layerProtocolNameValue) {
132 List<TechnologySpecificPacKeys> interfaceList = new ArrayList<>();
133 for (MapEntryNode lpEntry : lp) {
134 String layerProtocolName = Onf14DMDOMUtility.getLeafValue(lpEntry, getQName("layer-protocol-name"));
135 if (layerProtocolName != null && layerProtocolName.contains(layerProtocolNameValue)) {
136 TechnologySpecificPacKeys interfaceKey =
137 new TechnologySpecificPacKeys(Onf14DMDOMUtility.getLeafValue(ltp, getQName("uuid")),
138 Onf14DMDOMUtility.getLeafValue(lpEntry, getQName("local-id")));
139 interfaceList.add(interfaceKey);
140 LOG.debug("Adding Ltp with uuid {} and local-id {} to the {} list", interfaceKey.getLtpUuid(),
141 interfaceKey.getLocalId(), layerProtocolNameValue);
144 return interfaceList;
147 public Onf14Interfaces readKeys(Onf14Interfaces interfaces) {
149 Optional<NormalizedNode> ltpData = readLtpData(netconfDomAccessor);
150 LOG.debug("LTP Data is - {}", ltpData);
151 if (ltpData.isPresent()) {
152 LOG.debug("In readKeys - ltpData = {}", ltpData.get());
154 MapNode ccLtp = (MapNode) ltpData.get();
156 LOG.debug("Iterating the LTP list for node {}", netconfDomAccessor.getNodeId().getValue());
157 Collection<MapEntryNode> ltpList = ccLtp.body();
159 // iterating all the Logical Termination Point list
160 for (MapEntryNode ltp : ltpList) {
161 Collection<MapEntryNode> lp = getInterfaceKeyList(ltp);
163 interfaces.add(Onf14Interfaces.Key.AIRINTERFACE,
164 getTechnologySpecificPackKeys(ltp, lp, "LAYER_PROTOCOL_NAME_TYPE_AIR_LAYER"));
165 interfaces.add(Onf14Interfaces.Key.ETHERNETCONTAINER,
166 getTechnologySpecificPackKeys(ltp, lp, "LAYER_PROTOCOL_NAME_TYPE_ETHERNET_CONTAINER_LAYER"));
167 interfaces.add(Onf14Interfaces.Key.WIREINTERFACE,
168 getTechnologySpecificPackKeys(ltp, lp, "LAYER_PROTOCOL_NAME_TYPE_WIRE_LAYER"));
176 * Get specific module for device, depending on capabilities
178 public static Optional<CoreModel14> getModule(NetconfDomAccessor netconfDomAccessor) {
180 Capabilities capabilities = netconfDomAccessor.getCapabilites();
181 for (QNameModule module : MODULES) {
183 if (capabilities.isSupportingNamespaceAndRevision(module)) {
184 return Optional.of(new CoreModel14(netconfDomAccessor, module));
187 return Optional.empty();