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.List;
22 import java.util.Optional;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.dataprovider.Onf14ToInternalDataModel;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.equipment.Onf14DomEquipmentManager;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.impl.interfaces.Onf14DomInterfacePacManager;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
36 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
39 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.ControlConstruct;
40 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.UniversalId;
41 import org.opendaylight.yang.gen.v1.urn.onf.yang.core.model._1._4.rev191127.control.construct.Equipment;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
44 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
45 import org.opendaylight.yangtools.yang.binding.DataObject;
46 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * Representation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
52 * older ONF Version) NOTE: This class is still under development due to unmet dependencies (especially the ones related
53 * to DOM notifications) in ODL. Once the dependencies are complete, this class will replace the ONF14NetworkElement
55 public class Onf14DomNetworkElement implements NetworkElement {
57 private static final Logger log = LoggerFactory.getLogger(Onf14DomNetworkElement.class);
59 // protected static final InstanceIdentifier<ControlConstruct> CONTROLCONSTRUCT_IID =
60 // InstanceIdentifier.builder(ControlConstruct.class).build();
61 protected static final YangInstanceIdentifier CONTROLCONSTRUCT_IID =
62 YangInstanceIdentifier.builder().node(ControlConstruct.QNAME).build();
64 private final NetconfDomAccessor netconfDomAccessor;
65 private final DataProvider databaseService;
66 private final @NonNull FaultService faultService;
67 private final @NonNull NotificationService notificationService;
69 private final Onf14ToInternalDataModel onf14Mapper;
71 private final @NonNull Onf14DomEquipmentManager equipmentManager;
72 private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
73 private final @NonNull String namespaceRevision;
75 private boolean experimental;
78 public Onf14DomNetworkElement(NetconfDomAccessor netconfDomAccessor, DeviceManagerServiceProvider serviceProvider,
79 String namespaceRevision) {
80 log.info("Create {}", Onf14DomNetworkElement.class.getSimpleName());
81 this.netconfDomAccessor = netconfDomAccessor;
82 this.databaseService = serviceProvider.getDataProvider();
83 this.notificationService = serviceProvider.getNotificationService();
84 this.faultService = serviceProvider.getFaultService();
85 this.namespaceRevision = namespaceRevision;
86 this.onf14Mapper = new Onf14ToInternalDataModel();
87 this.equipmentManager = new Onf14DomEquipmentManager(netconfDomAccessor, databaseService, onf14Mapper);
89 this.interfacePacManager = new Onf14DomInterfacePacManager(netconfDomAccessor, serviceProvider);
90 this.experimental = false;
94 * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
96 public void initialReadFromNetworkElement() {
98 //Read complete device tree
99 Optional<ControlConstruct> oControlConstruct = readControlConstruct(netconfDomAccessor);
101 if (oControlConstruct.isPresent()) {
102 ControlConstruct controlConstruct = oControlConstruct.get();
104 equipmentManager.setEquipmentData(controlConstruct);
106 //-- Start for experimental purpose
108 log.warn("Experimental code activated");
109 for (UniversalId uuid : equipmentManager.getEquipmentUuidList()) {
110 log.info("Read data with id {}", uuid);
111 Optional<Equipment> res1 = equipmentManager.readEquipmentInstance(netconfDomAccessor, uuid);
112 log.info("Res1: {}", res1.isPresent() ? res1.get() : "No data1");
114 /*List<DataObject> res2 = equipmentManager.readEquipmentList(netconfDomAccessor);
115 log.info("Res2: {}", res2.isPresent() ? res2.get() : "No data2");*/
117 equipmentManager.readTopLevelEquipment(netconfDomAccessor);
118 //Do it only once for test purpose and break
121 List<DataObject> res2 = equipmentManager.readEquipmentList(netconfDomAccessor);
122 //log.info("Res2: {}", res2.isPresent() ? res2.get() : "No data2");
123 for (DataObject dobj : res2) {
124 Equipment eqpt = (Equipment) dobj;
125 log.info("Equipment local ID is : {}", eqpt.getLocalId());
128 equipmentManager.readTopLevelEquipment(netconfDomAccessor);
130 //-- End for experimental purpose
132 // storing all the LTP UUIDs internally, for later usage, for air-interface and ethernet-container
133 interfacePacManager.readKeys(controlConstruct);
135 // Read all fault data
136 FaultData resultList = new FaultData();
138 int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
139 log.debug("Removed all {} problems from database at registration", problems);
141 interfacePacManager.readAllAirInterfaceCurrentProblems(netconfDomAccessor, controlConstruct, resultList);
142 problems = resultList.size();
143 log.debug("NETCONF read air interface current problems completed. Got back {} problems.", problems);
145 readAllEhernetContainerCurrentProblems(resultList);
146 problems = resultList.size() - problems;
147 log.debug("NETCONF read current problems completed. Got back {} problems.", resultList.size());
149 readAllWireInterfaceCurrentProblems(resultList);
150 problems = resultList.size();
151 log.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);
153 faultService.initCurrentProblemStatus(netconfDomAccessor.getNodeId(), resultList);
154 log.debug("DB write current problems completed");
159 * @param nNode set core-model-capability
161 public void setCoreModel() {
162 NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
163 eb.setCoreModelCapability(namespaceRevision);
164 databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
168 public void register() {
169 // Set core-model revision value in "core-model-capability" field
171 initialReadFromNetworkElement();
173 if (netconfDomAccessor.isNotificationsRFC5277Supported()) {
175 interfacePacManager.subscribeNotifications();
176 // Output notification streams to LOG
177 Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
178 log.info("Available notifications streams: {}", streams);
179 // Register to default stream
180 netconfDomAccessor.invokeCreateSubscription();
185 public void deregister() {}
189 public NodeId getNodeId() {
190 return netconfDomAccessor.getNodeId();
194 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
195 return Optional.empty();
199 public void warmstart() {}
202 public Optional<NetconfAccessor> getAcessor() {
203 return Optional.of(netconfDomAccessor);
207 public NetworkElementDeviceType getDeviceType() {
208 return NetworkElementDeviceType.Wireless;
211 private static Optional<ControlConstruct> readControlConstruct(NetconfDomAccessor netconfDomAccessor) {
212 return netconfDomAccessor.readData(LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID,
213 ControlConstruct.class);