2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2020 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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl;
20 import java.util.Optional;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.dataprovider.Onf14ToInternalDataModel;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.equipment.Onf14DomEquipmentManager;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14DomInterfacePacManager;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
37 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
38 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
42 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
43 import org.opendaylight.yangtools.yang.common.QName;
44 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Representation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
51 * NOTE: This class is still under development due to unmet dependencies (especially the ones related to DOM notifications) in ODL. Once the dependencies are complete, this class will replace the ONF14NetworkElement
53 public class Onf14DomNetworkElement implements NetworkElement {
55 private static final Logger log = LoggerFactory.getLogger(Onf14DomNetworkElement.class);
57 // protected static final InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID =
58 // InstanceIdentifier.builder(ControlConstruct.class).build();
59 protected static final YangInstanceIdentifier CONTROLCONSTRUCT_IID =
60 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME).build();
62 private final NetconfDomAccessor netconfDomAccessor;
63 private final DataProvider databaseService;
64 private final @NonNull FaultService faultService;
65 private final @NonNull NotificationService notificationService;
67 private final Onf14ToInternalDataModel onf14Mapper;
69 private final @NonNull Onf14DomEquipmentManager equipmentManager;
70 private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
73 public Onf14DomNetworkElement(NetconfDomAccessor netconfDomAccessor, DeviceManagerServiceProvider serviceProvider) {
74 log.info("Create {}", Onf14DomNetworkElement.class.getSimpleName());
75 this.netconfDomAccessor = netconfDomAccessor;
76 this.databaseService = serviceProvider.getDataProvider();
77 this.notificationService = serviceProvider.getNotificationService();
78 this.faultService = serviceProvider.getFaultService();
79 this.onf14Mapper = new Onf14ToInternalDataModel();
80 this.equipmentManager = new Onf14DomEquipmentManager(netconfDomAccessor, databaseService, onf14Mapper);
81 this.interfacePacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider);
85 * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
87 public void initialReadFromNetworkElement() {
89 //Read complete device tree
90 Optional<ControlConstruct> oControlConstruct = readControlConstruct(netconfDomAccessor);
92 if (oControlConstruct.isPresent()) {
93 ControlConstruct controlConstruct = oControlConstruct.get();
95 equipmentManager.setEquipmentData(controlConstruct);
97 //-- Start For test purpose
98 for (UniversalId uuid : equipmentManager.getEquipmentUuidList()) {
99 log.info("Read data with id {}", uuid);
100 Optional<Equipment> res1 = equipmentManager.readEquipmentInstance(netconfDomAccessor, uuid);
101 log.info("Res1: {}", res1.isPresent() ? res1.get() : "No data1");
103 Optional<ControlConstruct> res2 = equipmentManager.readEquipmentList(netconfDomAccessor, uuid);
104 log.info("Res2: {}", res2.isPresent() ? res2.get() : "No data2");
106 equipmentManager.readTopLevelEquipment(netconfDomAccessor);
107 //Do it only once for test purpose
110 //-- End For test purpose
112 // storing all the LTP UUIDs internally, for later usage, for air-interface and ethernet-container
113 interfacePacManager.readKeys(controlConstruct);
115 // Read all fault data
116 FaultData resultList = new FaultData();
118 int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
119 log.debug("Removed all {} problems from database at registration", problems);
121 interfacePacManager.readAllAirInterfaceCurrentProblems(netconfDomAccessor, controlConstruct, resultList);
122 problems = resultList.size();
123 log.debug("NETCONF read air interface current problems completed. Got back {} problems.", problems);
125 readAllEhernetContainerCurrentProblems(resultList);
126 problems = resultList.size() - problems;
127 log.debug("NETCONF read current problems completed. Got back {} problems.", resultList.size());
129 readAllWireInterfaceCurrentProblems(resultList);
130 problems = resultList.size();
131 log.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);
133 faultService.initCurrentProblemStatus(netconfDomAccessor.getNodeId(), resultList);
134 log.debug("DB write current problems completed");
139 * @param nNode set core-model-capability
141 public void setCoreModel(@NonNull NetconfNode nNode) {
142 NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
143 String namespaceRevision;
144 QName QNAME_COREMODEL14 = QName.create("urn:onf:yang:core-model-1-4", "2019-11-27", "core-model-1-4").intern();
146 Capabilities availableCapabilities = Capabilities.getAvailableCapabilities(nNode);
147 namespaceRevision = availableCapabilities.getRevisionForNamespace(QNAME_COREMODEL14);
149 if (Capabilities.isNamespaceSupported(namespaceRevision)) {
150 eb.setCoreModelCapability(namespaceRevision);
152 eb.setCoreModelCapability("Unsupported");
154 databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
158 public void register() {
159 // Set core-model revision value in "core-model-capability" field
160 setCoreModel(netconfDomAccessor.getNetconfNode());
161 initialReadFromNetworkElement();
163 // Register netconf stream
164 // airInterfaceNotificationListenerHandler =
165 // netconfDomAccessor.doRegisterNotificationListener(airInterfaceNotificationListener);
166 // etherneContainerNotificationListenerHandler =
167 // netconfDomAccessor.doRegisterNotificationListener(ethernetContainerNotificationListener);
168 // wireInterfaceNotificationListenerHandler =
169 // netconfDomAccessor.doRegisterNotificationListener(wireInterfaceNotificationListener);
170 // Optional<NetconfNotifications> notificationsSupport = netconfDomAccessor.getNotificationAccessor();
171 // if (notificationsSupport.isPresent()) {
172 // notificationsSupport.get().registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream);
177 public void deregister() {}
181 public NodeId getNodeId() {
182 return netconfDomAccessor.getNodeId();
186 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
187 return Optional.empty();
191 public void warmstart() {}
194 public Optional<NetconfAccessor> getAcessor() {
195 return Optional.of(netconfDomAccessor);
199 public NetworkElementDeviceType getDeviceType() {
200 return NetworkElementDeviceType.Wireless;
203 private static Optional<ControlConstruct> readControlConstruct(NetconfDomAccessor netconfDomAccessor) {
204 return netconfDomAccessor.readData(LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID, ControlConstruct.class);