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