f48eb60fe3e3ddaee3ff69942156364211cd0de3
[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.onf.ne;
19
20 import org.eclipse.jdt.annotation.NonNull;
21 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl.DeviceManagerOnfConfiguration;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EquipmentService;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.EventHandlingService;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.MaintenanceService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.PerformanceManager;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.FaultData;
31 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
32 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementConnectionBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * Get information over NETCONF device according to ONF Coremodel. Read networkelement and conditional packages.
42  *
43  * Get conditional packages from Networkelement Possible interfaces are: MWPS, LTP(MWPS-TTP), MWAirInterfacePac,
44  * MicrowaveModel-ObjectClasses-AirInterface ETH-CTP,LTP(Client), MW_EthernetContainer_Pac MWS, LTP(MWS-CTP-xD),
45  * MWAirInterfaceDiversityPac, MicrowaveModel-ObjectClasses-AirInterfaceDiversity MWS, LTP(MWS-TTP),
46  * ,MicrowaveModel-ObjectClasses-HybridMwStructure MWS, LTP(MWS-TTP),
47  * ,MicrowaveModel-ObjectClasses-PureEthernetStructure
48  *
49  * @author herbert
50  *
51  */
52 public class ONFCoreNetworkElement12Basic extends ONFCoreNetworkElement12Base {
53
54     private static final Logger LOG = LoggerFactory.getLogger(ONFCoreNetworkElement12Basic.class);
55
56     /*-----------------------------------------------------------------------------
57      * Class members
58      */
59     private final @NonNull FaultService faultService;
60     private final @NonNull EquipmentService equipmentService;
61     private final @NonNull MaintenanceService maintenanceService;
62     private final @NonNull AaiService aaiProviderClient;
63     private final @NonNull PerformanceManager performanceManager;
64     private final @NonNull EventHandlingService eventListenerHandler;
65     private final @NonNull DataProvider dataProvider;
66
67
68     private final @NonNull String mountPointNodeName;
69     private final @NonNull NetconfAccessor acessor;
70     private final @NonNull DeviceManagerOnfConfiguration pollAlarmConfig;
71
72     /*-----------------------------------------------------------------------------
73      * Construction
74      */
75
76     /**
77      * Basic element for netconf device with ONF Core model V1.2
78      *
79      * @param acessor to manage device connection
80      * @param serviceProvider to get devicemanager services
81      */
82     public ONFCoreNetworkElement12Basic(@NonNull NetconfAccessor acessor,
83             @NonNull DeviceManagerServiceProvider serviceProvider, DeviceManagerOnfConfiguration configuration) {
84
85         super(acessor);
86         this.mountPointNodeName = acessor.getNodeId().getValue();
87         this.acessor = acessor;
88         this.pollAlarmConfig = configuration;
89
90         this.faultService = serviceProvider.getFaultService();
91         this.equipmentService = serviceProvider.getEquipmentService();
92         this.maintenanceService = serviceProvider.getMaintenanceService();
93         this.aaiProviderClient = serviceProvider.getAaiService();
94         this.performanceManager = serviceProvider.getPerformanceManagerService();
95         this.eventListenerHandler = serviceProvider.getEventHandlingService();
96         this.dataProvider = serviceProvider.getDataProvider();
97
98
99     }
100
101     /*-----------------------------------------------------------------------------
102      * Functions
103      */
104
105     /**
106      * DeviceMonitor Prepare check by updating NE state and reading all interfaces.
107      */
108     @Override
109     public void prepareCheck() {
110         synchronized (dmLock) {
111             boolean change = readNetworkElementAndInterfaces();
112             if (change || pollAlarmConfig.isPollAlarmsEnabled()) {
113                 int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
114                 FaultData resultList = readAllCurrentProblemsOfNode();
115                 faultService.initCurrentProblemStatus(nodeId, resultList);
116                 LOG.info("Resync mountpoint {} for device {}. Removed {}. Current problems: {}", getMountpoint(),
117                         getUuId(), problems, resultList.size());
118             }
119         }
120     }
121
122     // public boolean checkIfConnectionToMediatorIsOk() -> Shifted to super class
123     // public boolean checkIfConnectionToNeIsOk() -> Shifted to super class
124
125     /*-----------------------------------------------------------------------------
126      * Synchronization
127      */
128
129     // public void initSynchronizationExtension() -> Shifted to super class
130     // private InstanceList readPTPClockInstances() -> Shifted to super class
131
132
133     /*-----------------------------------------------------------------------------
134      * Problem/Fault related functions
135      */
136
137     /**
138      * Read during startup all relevant structure and status parameters from device
139      */
140     @Override
141     public void initialReadFromNetworkElement() {
142
143         LOG.debug("Get info about {}", getMountpoint());
144
145         int problems = faultService.removeAllCurrentProblemsOfNode(nodeId);
146         LOG.debug("Removed all {} problems from database at registration", problems);
147
148         // Step 2.1: access data broker within this mount point
149         LOG.debug("DBRead start");
150
151         // Step 2.2: read ne from data store
152         readNetworkElementAndInterfaces();
153         LOG.debug("NETCONF read network element and interfaces completed");
154         equipment.readNetworkElementEquipment();
155         LOG.debug("NETCONF read equipment completed");
156
157         // Step 2.3: read the existing faults and add to DB
158         FaultData resultList = readAllCurrentProblemsOfNode();
159         LOG.debug("NETCONF read current problems completed");
160         equipment.addProblemsofNode(resultList);
161
162         faultService.initCurrentProblemStatus(nodeId, resultList);
163         LOG.debug("DB write current problems completed");
164
165         equipmentService.writeEquipment(equipment.getEquipmentData());
166
167         LOG.info("Found info at {} for device {} number of problems: {}", getMountpoint(), getUuId(),
168                 resultList.size());
169     }
170
171     /**
172      * @param nNode
173      * set core-model-capability
174      */
175     public void setCoreModel(@NonNull NetconfNode nNode) {
176         NetworkElementConnectionBuilder eb = new NetworkElementConnectionBuilder();
177
178         String namespaceRevision;
179         QName QNAME_COREMODEL = QName.create("urn:onf:params:xml:ns:yang:core-model", "2017-03-20", "core-model").intern();
180
181         Capabilities availableCapabilities = Capabilities.getAvailableCapabilities(nNode);
182         namespaceRevision = availableCapabilities.getRevisionForNamespace(QNAME_COREMODEL);
183         if (Capabilities.isNamespaceSupported(namespaceRevision)) {
184             eb.setCoreModelCapability(namespaceRevision);
185         } else {
186             eb.setCoreModelCapability("Unsupported");
187         }
188         dataProvider.updateNetworkConnection22(eb.build(), acessor.getNodeId().getValue());
189     }
190     /**
191      * Remove all entries from list
192      */
193     @Override
194     public int removeAllCurrentProblemsOfNode() {
195         return faultService.removeAllCurrentProblemsOfNode(nodeId);
196     }
197
198     @Override
199     public void register() {
200
201         // Setup microwaveEventListener for notification service
202         doRegisterEventListener(acessor.getMountpoint());
203
204         // Register netconf stream
205         acessor.registerNotificationsStream(NetconfAccessor.DefaultNotificationsStream);
206
207         // Set core-model revision value in "core-model-capability" field
208         setCoreModel(acessor.getNetconfNode());
209
210         // -- Read data from NE
211         initialReadFromNetworkElement();
212
213         // create automatic empty maintenance entry into db before reading and listening
214         // for problems
215         maintenanceService.createIfNotExists(mountPointNodeName);
216
217         aaiProviderClient.onDeviceRegistered(mountPointNodeName);
218         // -- Register NE to performance manager
219         performanceManager.registration(mountPointNodeName, this);
220
221         //events will be already pushed by base devmgr (needs more clarification SDNC-1123)
222         //eventListenerHandler.registration(mountPointNodeName, acessor.getNetconfNode());
223         //LOG.debug("refresh necon entry for {} with type {} not",mountPointNodeName,this.getDeviceType());
224         //eventListenerHandler.connectIndication(mountPointNodeName, getDeviceType());
225         LOG.info("Starting Event listener finished. Added Netconf device:{} type:{}", mountPointNodeName,
226                 getDeviceType());
227
228     }
229
230
231     @Override
232     public void deregister() {
233         maintenanceService.deleteIfNotRequired(mountPointNodeName);
234         performanceManager.deRegistration(mountPointNodeName);
235         aaiProviderClient.onDeviceUnregistered(mountPointNodeName);
236         faultService.removeAllCurrentProblemsOfNode(acessor.getNodeId());
237     }
238
239     @Override
240     public void close() throws Exception {
241         // Close to be implemented
242     }
243
244
245     @Override
246     public NetworkElementDeviceType getDeviceType() {
247         return NetworkElementDeviceType.Optical;
248     }
249
250 }