2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
29 import java.util.Objects;
30 import java.util.Optional;
31 import org.eclipse.jdt.annotation.NonNull;
32 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
33 import org.onap.ccsdk.features.sdnr.wt.common.configuration.filechange.IConfigChangedListener;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.dataprovider.ORanDOMToInternalDataModel;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMChangeNotificationListener;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMFaultNotificationListener;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMSupervisionNotificationListener;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanNotificationObserverImpl;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.rpc.ORanSupervisionRPCImpl;
44 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDMDOMUtility;
45 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames;
46 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper.ORanRegistrationToVESpnfRegistrationMapper;
47 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM;
48 import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem;
49 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider;
50 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
51 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
52 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
53 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
54 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
55 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
56 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
57 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
58 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
60 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
64 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
65 import org.opendaylight.yangtools.yang.common.QName;
66 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
67 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
68 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
69 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
70 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
71 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
72 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
73 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
74 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
75 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
79 public class ORanDOMNetworkElement implements NetworkElement, IConfigChangedListener {
81 private static final Logger LOG = LoggerFactory.getLogger(ORanDOMNetworkElement.class);
83 private final @NonNull NetconfDomAccessor netconfDomAccessor;
84 private final @NonNull DataProvider databaseService;
85 private final @NonNull FaultService faultService;
86 private final @NonNull NotificationService notificationService;
87 private final @NonNull ORanDOMChangeNotificationListener oranDomChangeNotificationListener;
88 private final @NonNull ORanDOMFaultNotificationListener oranDomFaultNotificationListener;
89 private final @NonNull ORanDOMSupervisionNotificationListener oranDomSupervisionNotificationListener;
90 private final @NonNull VESCollectorService vesCollectorService;
91 private final @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper;
92 private final Optional<OnapSystem> onapSystem;
93 private final Optional<ORANFM> oranfm;
94 private ORanDMConfig oranSupervisionConfig;
96 public ORanDOMNetworkElement(@NonNull NetconfDomAccessor netconfDomAccessor,
97 @NonNull DeviceManagerServiceProvider serviceProvider, ORanDMConfig oranSupervisionConfig,
98 ConfigurationFileRepresentation configFileRepresentation) {
99 LOG.debug("Create {}", ORanDOMNetworkElement.class.getSimpleName());
100 this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
101 Objects.requireNonNull(serviceProvider);
102 this.databaseService = serviceProvider.getDataProvider();
103 this.vesCollectorService = serviceProvider.getVESCollectorService();
104 this.faultService = serviceProvider.getFaultService();
105 this.notificationService = serviceProvider.getNotificationService();
106 this.onapSystem = OnapSystem.getModule(netconfDomAccessor);
107 this.oranfm = ORANFM.getModule(netconfDomAccessor);
108 this.oranSupervisionConfig = oranSupervisionConfig;
110 configFileRepresentation.registerConfigChangedListener(this);
111 this.oranDomChangeNotificationListener =
112 new ORanDOMChangeNotificationListener(netconfDomAccessor, vesCollectorService, databaseService);
113 if(oranfm.isEmpty()) {
114 LOG.error("unable to detect ORAN FM module version");
115 throw new RuntimeException("unable to detect ORAN FM module version");
117 this.oranDomFaultNotificationListener =
118 new ORanDOMFaultNotificationListener(netconfDomAccessor, this.oranfm.get(), vesCollectorService,
119 serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService);
121 this.oranDomSupervisionNotificationListener = new ORanDOMSupervisionNotificationListener(netconfDomAccessor,
122 vesCollectorService, databaseService, oranSupervisionConfig);
124 this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfDomAccessor, vesCollectorService);
128 public void register() {
129 Collection<MapEntryNode> componentList = initialReadFromNetworkElement();
130 oranDomFaultNotificationListener.setComponentList(componentList);
131 publishMountpointToVES(componentList);
132 QName[] notifications = {ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE,
133 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIRMED_COMMIT,
134 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_START,
135 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_END,
136 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CAPABILITY_CHANGE};
137 netconfDomAccessor.doRegisterNotificationListener(oranDomChangeNotificationListener, notifications);
139 QName[] faultNotification = {oranfm.get().getAlarmNotifQName()};
140 netconfDomAccessor.doRegisterNotificationListener(oranDomFaultNotificationListener, faultNotification);
142 Capabilities x = netconfDomAccessor.getCapabilites();
143 if (x.isSupportingNamespaceAndRevision(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE)) {
144 LOG.debug("Device {} supports oran-supervision", netconfDomAccessor.getNodeId().getValue());
145 oranDomSupervisionNotificationListener.setComponentList(componentList);
146 QName[] supervisionNotification = {ORanDeviceManagerQNames.ORAN_SUPERVISION_NOTIFICATION};
147 netconfDomAccessor.doRegisterNotificationListener(oranDomSupervisionNotificationListener,
148 supervisionNotification);
150 // Output notification streams to LOG
151 @SuppressWarnings("unused")
152 Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
153 // Register to default stream
154 netconfDomAccessor.invokeCreateSubscription();
155 if (x.isSupportingNamespaceAndRevision(ORanDeviceManagerQNames.ORAN_SUPERVISION_MODULE)) {
156 ORanSupervisionRPCImpl.invokeWatchdogReset(netconfDomAccessor, oranSupervisionConfig);
157 oranDomSupervisionNotificationListener.registerForNotificationReceivedEvent(
158 new ORanNotificationObserverImpl(netconfDomAccessor, oranSupervisionConfig));
162 public Collection<MapEntryNode> initialReadFromNetworkElement() {
163 Collection<MapEntryNode> componentMapEntries = null;
164 NormalizedNode hwData = readHardware();
166 if (hwData != null) {
167 ContainerNode hwContainer = (ContainerNode) hwData;
168 MapNode componentMap = (MapNode) hwContainer
169 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST));
170 if (componentMap != null) {
171 componentMapEntries = componentMap.body();
172 List<Inventory> inventoryList =
173 ORanDOMToInternalDataModel.getInventoryList(netconfDomAccessor.getNodeId(), hwData);
174 databaseService.writeInventory(netconfDomAccessor.getNodeId().getValue(), inventoryList);
177 componentMapEntries = Collections.emptyList();
180 if (oranfm.isPresent()) {
183 if (onapSystem.isPresent()) {
185 Optional<Guicutthrough> oGuicutthrough =
186 ORanDOMToInternalDataModel.getGuicutthrough(
187 (DataContainerChild) onapSystem.get().getOnapSystemData(), onapSystem.get());
188 if (oGuicutthrough.isPresent()) {
189 databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfDomAccessor.getNodeId().getValue());
192 return componentMapEntries;
196 public void deregister() {
198 * if (oranDomChangeNotificationListener != null) {
199 * this.oranDomChangeNotificationListener.close(); } if
200 * (oRanFaultListenerRegistrationResult != null) {
201 * this.oRanFaultListenerRegistrationResult.close(); } ;
203 databaseService.clearGuiCutThroughEntriesOfNode(getMountpointId());
204 faultService.removeAllCurrentProblemsOfNode(getNodeId());
208 public NodeId getNodeId() {
209 return netconfDomAccessor.getNodeId();
213 public NetworkElementDeviceType getDeviceType() {
214 return NetworkElementDeviceType.ORAN;
218 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
219 return Optional.empty();
223 public void warmstart() {
224 faultService.removeAllCurrentProblemsOfNode(getNodeId());
228 public Optional<NetconfAccessor> getAcessor() {
229 return Optional.of(netconfDomAccessor);
234 private String getMountpointId() {
235 return getNodeId().getValue();
238 private NormalizedNode readHardware() {
239 InstanceIdentifierBuilder hardwareIIDBuilder =
240 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_HW_CONTAINER);
242 Optional<NormalizedNode> oData =
243 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, hardwareIIDBuilder.build());
244 if (oData.isPresent()) {
251 private void publishMountpointToVES(Collection<MapEntryNode> componentList) {
253 * 1. Check if this device is in the list of allowed-devices. 2. If device
254 * exists in allowed-devices, then create VES pnfRegistration event and publish
257 if (vesCollectorService.getConfig().isVESCollectorEnabled() && inAllowedDevices(getMountpointId())) {
258 for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) {
259 // Just get one component. At the moment we don't care which one. Also since
260 // there is only one management address, we assume there will be only one
262 // If the device supports subtended configuration then it is assumed that the
263 // Chassis containing the management interface will be the root component and
264 // there will be only one root.
265 VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(component);
266 VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(component);
268 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
269 } catch (JsonProcessingException e) {
270 LOG.warn("Error while serializing VES Event to String ", e);
276 private boolean inAllowedDevices(String mountpointName) {
277 InstanceIdentifierBuilder callhomeServerIID =
278 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.CALLHOME_SERVER_CONTAINER);
279 final InstanceIdentifierBuilder allowedDevicesIID = YangInstanceIdentifier.builder(callhomeServerIID.build())
280 .node(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE);
282 Optional<NormalizedNode> allowedDevices = netconfDomAccessor
283 .readControllerDataNode(LogicalDatastoreType.CONFIGURATION, allowedDevicesIID.build());
285 if (allowedDevices.isPresent()) {
286 ContainerNode allowedDevicesNode = (ContainerNode) allowedDevices.get();
287 MapNode deviceList = (MapNode) allowedDevicesNode
288 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_DEVICE_LIST));
289 if (deviceList != null) {
290 Collection<MapEntryNode> deviceListCollection = deviceList.body();
291 for (MapEntryNode device : deviceListCollection) {
292 // String deviceName = device.getIdentifier()
293 // .getValue(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY).toString();
294 String deviceName = ORanDMDOMUtility.getLeafValue(device,
295 ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY);
296 if (deviceName != null && deviceName.equals(mountpointName)) {
297 LOG.debug("Mountpoint {} is part of allowed-devices list", mountpointName);
304 LOG.debug("Mountpoint {} is not part of allowed-devices list", mountpointName);
308 private void getActiveAlarms() {
309 InstanceIdentifierBuilder activeAlarmListBuilder =
310 YangInstanceIdentifier.builder().node(oranfm.get().getFaultActiveAlarmListQName());
311 Optional<NormalizedNode> oData =
312 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, activeAlarmListBuilder.build());
313 if (oData.isPresent()) {
314 ContainerNode cn = (ContainerNode) oData.get();
315 UnkeyedListNode activeAlarmsList =
316 (UnkeyedListNode) cn.childByArg(new NodeIdentifier(oranfm.get().getFaultActiveAlarmsQName()));
317 if (activeAlarmsList == null) {
320 for (UnkeyedListEntryNode activeAlarmEntry : activeAlarmsList.body()) {
321 faultService.faultNotification(ORanDOMToInternalDataModel.getFaultLog(activeAlarmEntry, oranfm.get(),
322 netconfDomAccessor.getNodeId()));
328 public void onConfigChanged() {
329 LOG.info("O-RU Supervision Watchdog timers changed, resetting in O-RU via RPC");
330 ORanSupervisionRPCImpl.invokeWatchdogReset(netconfDomAccessor, oranSupervisionConfig);