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 com.google.common.collect.Sets;
26 import java.util.Collection;
27 import java.util.Collections;
28 import java.util.List;
30 import java.util.Objects;
31 import java.util.Optional;
32 import org.eclipse.jdt.annotation.NonNull;
33 import org.eclipse.jdt.annotation.Nullable;
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.service.DeviceManagerServiceProvider;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationService;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
43 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities;
44 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
45 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor;
46 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
47 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
48 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.StreamKey;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
52 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
53 import org.opendaylight.yangtools.yang.common.QName;
54 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
55 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
56 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.InstanceIdentifierBuilder;
57 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
58 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
59 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
60 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
61 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
62 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory;
65 public class ORanDOMNetworkElement implements NetworkElement {
67 private static final Logger LOG = LoggerFactory.getLogger(ORanDOMNetworkElement.class);
69 private final @NonNull NetconfDomAccessor netconfDomAccessor;
70 private final @NonNull DataProvider databaseService;
71 private final @NonNull FaultService faultService;
72 private final @NonNull NotificationService notificationService;
73 private final @NonNull ORanDOMChangeNotificationListener oranDomChangeNotificationListener;
74 private final @NonNull ORanDOMFaultNotificationListener oranDomFaultNotificationListener;
75 private final @NonNull VESCollectorService vesCollectorService;
76 private final @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper;
78 public ORanDOMNetworkElement(@NonNull NetconfDomAccessor netconfDomAccessor,
79 @NonNull DeviceManagerServiceProvider serviceProvider) {
80 LOG.info("Create {}", ORanDOMNetworkElement.class.getSimpleName());
81 this.netconfDomAccessor = Objects.requireNonNull(netconfDomAccessor);
82 Objects.requireNonNull(serviceProvider);
83 this.databaseService = serviceProvider.getDataProvider();
84 this.vesCollectorService = serviceProvider.getVESCollectorService();
85 this.faultService = serviceProvider.getFaultService();
86 this.notificationService = serviceProvider.getNotificationService();
88 this.oranDomChangeNotificationListener =
89 new ORanDOMChangeNotificationListener(netconfDomAccessor, vesCollectorService, databaseService);
91 this.oranDomFaultNotificationListener =
92 new ORanDOMFaultNotificationListener(netconfDomAccessor, vesCollectorService,
93 serviceProvider.getFaultService(), serviceProvider.getWebsocketService(), databaseService);
95 this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfDomAccessor, vesCollectorService);
99 public void register() {
100 Collection<MapEntryNode> componentList = initialReadFromNetworkElement();
101 oranDomFaultNotificationListener.setComponentList(componentList);
102 publishMountpointToVES(componentList);
103 QName[] notifications = {ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIG_CHANGE,
104 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CONFIRMED_COMMIT,
105 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_START,
106 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_SESSION_END,
107 ORanDeviceManagerQNames.IETF_NETCONF_NOTIFICATIONS_NETCONF_CAPABILITY_CHANGE};
108 netconfDomAccessor.doRegisterNotificationListener(oranDomChangeNotificationListener, notifications);
109 QName[] faultNotification = {ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF};
110 netconfDomAccessor.doRegisterNotificationListener(oranDomFaultNotificationListener, faultNotification);
111 // Output notification streams to LOG
112 @SuppressWarnings("unused")
113 Map<StreamKey, Stream> streams = netconfDomAccessor.getNotificationStreamsAsMap();
114 // Register to default stream
115 netconfDomAccessor.invokeCreateSubscription();
118 public Collection<MapEntryNode> initialReadFromNetworkElement() {
119 Collection<MapEntryNode> componentMapEntries = null;
120 NormalizedNode hwData = readHardware();
122 if (hwData != null) {
123 ContainerNode hwContainer = (ContainerNode) hwData;
124 MapNode componentMap = (MapNode) hwContainer
125 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST));
126 if (componentMap != null) {
127 componentMapEntries = componentMap.body();
128 List<Inventory> inventoryList =
129 ORanDOMToInternalDataModel.getInventoryList(netconfDomAccessor.getNodeId(), hwData);
130 databaseService.writeInventory(netconfDomAccessor.getNodeId().getValue(), inventoryList);
133 componentMapEntries = Collections.emptyList();
136 Optional<Guicutthrough> oGuicutthrough = ORanDOMToInternalDataModel.getGuicutthrough(getOnapSystemData());
137 if (oGuicutthrough.isPresent()) {
138 databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfDomAccessor.getNodeId().getValue());
140 return componentMapEntries;
144 public void deregister() {
146 * if (oranDomChangeNotificationListener != null) {
147 * this.oranDomChangeNotificationListener.close(); } if
148 * (oRanFaultListenerRegistrationResult != null) {
149 * this.oRanFaultListenerRegistrationResult.close(); } ;
151 databaseService.clearGuiCutThroughEntriesOfNode(getMountpointId());
155 public NodeId getNodeId() {
156 return netconfDomAccessor.getNodeId();
160 public NetworkElementDeviceType getDeviceType() {
161 return NetworkElementDeviceType.ORAN;
165 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
166 return Optional.empty();
170 public void warmstart() {}
173 public Optional<NetconfAccessor> getAcessor() {
174 return Optional.of(netconfDomAccessor);
179 private String getMountpointId() {
180 return getNodeId().getValue();
183 private NormalizedNode readHardware() {
184 InstanceIdentifierBuilder hardwareIIDBuilder =
185 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_HW_CONTAINER);
187 Optional<NormalizedNode> oData =
188 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, hardwareIIDBuilder.build());
189 if (oData.isPresent()) {
197 * Read system data with GUI cut through information from device if ONAP_SYSTEM YANG is supported.
199 * @return NormalizedNode data with GUI cut through information or null if not available.
201 private @Nullable NormalizedNode getOnapSystemData() {
202 LOG.info("Get System1 for mountpoint {}", netconfDomAccessor.getNodeId().getValue());
204 InstanceIdentifierBuilder ietfSystemIID =
205 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.IETF_SYSTEM_CONTAINER);
207 AugmentationIdentifier onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier.create(
208 Sets.newHashSet(ORanDeviceManagerQNames.ONAP_SYSTEM_NAME, ORanDeviceManagerQNames.ONAP_SYSTEM_WEB_UI));
209 InstanceIdentifierBuilder augmentedOnapSystem =
210 YangInstanceIdentifier.builder(ietfSystemIID.build()).node(onapSystemIID);
211 Capabilities x = netconfDomAccessor.getCapabilites();
212 LOG.info("Capabilites: {}", x);
213 if (x.isSupportingNamespace(ORanDeviceManagerQNames.ONAP_SYSTEM_QNAME)) {
214 Optional<NormalizedNode> res =
215 netconfDomAccessor.readDataNode(LogicalDatastoreType.OPERATIONAL, augmentedOnapSystem.build());
216 LOG.debug("Result of System1 = {}", res);
217 return res.isPresent() ? res.get() : null;
219 LOG.debug("No GUI cut through support");
225 private void publishMountpointToVES(Collection<MapEntryNode> componentList) {
227 * 1. Check if this device is in the list of allowed-devices. 2. If device
228 * exists in allowed-devices, then create VES pnfRegistration event and publish
231 if (vesCollectorService.getConfig().isVESCollectorEnabled() && inAllowedDevices(getMountpointId())) {
232 for (MapEntryNode component : ORanDOMToInternalDataModel.getRootComponents(componentList)) {
233 // Just get one component. At the moment we don't care which one. Also since
234 // there is only one management address, we assume there will be only one
236 // If the device supports subtended configuration then it is assumed that the
237 // Chassis containing the management interface will be the root component and
238 // there will be only one root.
239 VESCommonEventHeaderPOJO header = mapper.mapCommonEventHeader(component);
240 VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields(component);
242 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
243 } catch (JsonProcessingException e) {
244 LOG.warn("Error while serializing VES Event to String ", e);
250 private boolean inAllowedDevices(String mountpointName) {
251 InstanceIdentifierBuilder callhomeServerIID =
252 YangInstanceIdentifier.builder().node(ORanDeviceManagerQNames.CALLHOME_SERVER_CONTAINER);
253 final InstanceIdentifierBuilder allowedDevicesIID = YangInstanceIdentifier.builder(callhomeServerIID.build())
254 .node(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE);
256 Optional<NormalizedNode> allowedDevices = netconfDomAccessor
257 .readControllerDataNode(LogicalDatastoreType.CONFIGURATION, allowedDevicesIID.build());
259 if (allowedDevices.isPresent()) {
260 ContainerNode allowedDevicesNode = (ContainerNode) allowedDevices.get();
261 MapNode deviceList = (MapNode) allowedDevicesNode
262 .childByArg(new NodeIdentifier(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_DEVICE_LIST));
263 if (deviceList != null) {
264 Collection<MapEntryNode> deviceListCollection = deviceList.body();
265 for (MapEntryNode device : deviceListCollection) {
266 // String deviceName = device.getIdentifier()
267 // .getValue(ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY).toString();
268 String deviceName = ORanDMDOMUtility.getLeafValue(device,
269 ORanDeviceManagerQNames.CALLHOME_SERVER_ALLOWED_DEVICE_KEY);
270 if (deviceName != null && deviceName.equals(mountpointName)) {
271 LOG.info("Mountpoint {} is part of allowed-devices list", mountpointName);
278 LOG.info("Mountpoint {} is not part of allowed-devices list", mountpointName);