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