0a63b744952b4d0529084f201c06100ffb16e224
[ccsdk/features.git] /
1 /*
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
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.onf14.impl;
19
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;
47
48 /**
49  * Representation of ONF Core model 1.4 device Top level element is "ControlConstruct" (replaces "NetworkElement" of
50  * older ONF Version)
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   
52  */
53 public class Onf14DomNetworkElement implements NetworkElement {
54
55     private static final Logger log = LoggerFactory.getLogger(Onf14DomNetworkElement.class);
56
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();
61
62     private final NetconfDomAccessor netconfDomAccessor;
63     private final DataProvider databaseService;
64     private final @NonNull FaultService faultService;
65     private final @NonNull NotificationService notificationService;
66
67     private final Onf14ToInternalDataModel onf14Mapper;
68
69     private final @NonNull Onf14DomEquipmentManager equipmentManager;
70     private final @NonNull Onf14DomInterfacePacManager interfacePacManager;
71
72
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);
82     }
83
84     /**
85      * reading the inventory (CoreModel 1.4 Equipment Model) and adding it to the DB
86      */
87     public void initialReadFromNetworkElement() {
88
89         //Read complete device tree
90         Optional<ControlConstruct> oControlConstruct = readControlConstruct(netconfDomAccessor);
91
92         if (oControlConstruct.isPresent()) {
93             ControlConstruct controlConstruct = oControlConstruct.get();
94
95             equipmentManager.setEquipmentData(controlConstruct);
96
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");
102
103                 Optional<ControlConstruct> res2 = equipmentManager.readEquipmentList(netconfDomAccessor, uuid);
104                 log.info("Res2: {}", res2.isPresent() ? res2.get() : "No data2");
105
106                 equipmentManager.readTopLevelEquipment(netconfDomAccessor);
107                 //Do it only once for test purpose
108                 break;
109             }
110             //-- End For test purpose
111
112             // storing all the LTP UUIDs internally, for later usage, for air-interface and ethernet-container
113             interfacePacManager.readKeys(controlConstruct);
114
115             // Read all fault data
116             FaultData resultList = new FaultData();
117
118             int problems = faultService.removeAllCurrentProblemsOfNode(netconfDomAccessor.getNodeId());
119             log.debug("Removed all {} problems from database at registration", problems);
120
121             interfacePacManager.readAllAirInterfaceCurrentProblems(netconfDomAccessor, controlConstruct, resultList);
122             problems = resultList.size();
123             log.debug("NETCONF read air interface current problems completed. Got back {} problems.", problems);
124             /*
125             readAllEhernetContainerCurrentProblems(resultList);
126             problems = resultList.size() - problems;
127             log.debug("NETCONF read current problems completed. Got back {} problems.", resultList.size());
128
129             readAllWireInterfaceCurrentProblems(resultList);
130             problems = resultList.size();
131             log.debug("NETCONF read wire interface current problems completed. Got back {} problems.", problems);
132             */
133             faultService.initCurrentProblemStatus(netconfDomAccessor.getNodeId(), resultList);
134             log.debug("DB write current problems completed");
135         }
136     }
137
138     /**
139      * @param nNode set core-model-capability
140      */
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();
145
146         Capabilities availableCapabilities = Capabilities.getAvailableCapabilities(nNode);
147         namespaceRevision = availableCapabilities.getRevisionForNamespace(QNAME_COREMODEL14);
148
149         if (Capabilities.isNamespaceSupported(namespaceRevision)) {
150             eb.setCoreModelCapability(namespaceRevision);
151         } else {
152             eb.setCoreModelCapability("Unsupported");
153         }
154         databaseService.updateNetworkConnection22(eb.build(), netconfDomAccessor.getNodeId().getValue());
155     }
156
157     @Override
158     public void register() {
159         // Set core-model revision value in "core-model-capability" field
160         setCoreModel(netconfDomAccessor.getNetconfNode());
161         initialReadFromNetworkElement();
162
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);
173         //        }
174     }
175
176     @Override
177     public void deregister() {}
178
179
180     @Override
181     public NodeId getNodeId() {
182         return netconfDomAccessor.getNodeId();
183     }
184
185     @Override
186     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
187         return Optional.empty();
188     }
189
190     @Override
191     public void warmstart() {}
192
193     @Override
194     public Optional<NetconfAccessor> getAcessor() {
195         return Optional.of(netconfDomAccessor);
196     }
197
198     @Override
199     public NetworkElementDeviceType getDeviceType() {
200         return NetworkElementDeviceType.Wireless;
201     }
202
203     private static Optional<ControlConstruct> readControlConstruct(NetconfDomAccessor netconfDomAccessor) {
204         return netconfDomAccessor.readData(LogicalDatastoreType.CONFIGURATION, CONTROLCONSTRUCT_IID, ControlConstruct.class);
205     }
206
207
208
209 }