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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl;
20 import com.fasterxml.jackson.core.JsonProcessingException;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.Optional;
24 import org.eclipse.jdt.annotation.NonNull;
25 import org.onap.ccsdk.features.sdnr.wt.common.YangHelper;
26 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElementService;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor;
34 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
35 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNotifications;
36 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
40 import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.NetconfCallhomeServer;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.AllowedDevices;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.Device;
47 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
48 import org.opendaylight.yangtools.concepts.ListenerRegistration;
49 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
50 import org.opendaylight.yangtools.yang.binding.NotificationListener;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 public class ORanNetworkElement implements NetworkElement {
56 private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class);
58 private final NetconfBindingAccessor netconfAccessor;
60 private final DataProvider databaseService;
62 @SuppressWarnings("unused")
63 private final VESCollectorService vesCollectorService;
65 private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult;
66 private @NonNull final ORanChangeNotificationListener oRanListener;
67 private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult;
68 private @NonNull final ORanFaultNotificationListener oRanFaultListener;
69 private final NotificationProxyParser notificationProxyParser;
70 private @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper;
71 private Collection<Component> componentList;
72 private static int sequenceNo = 0;
74 ORanNetworkElement(NetconfBindingAccessor netconfAccess, DataProvider databaseService,
75 VESCollectorService vesCollectorService) {
76 log.info("Create {}", ORanNetworkElement.class.getSimpleName());
77 this.netconfAccessor = netconfAccess;
78 this.databaseService = databaseService;
79 this.vesCollectorService = vesCollectorService;
80 this.notificationProxyParser = vesCollectorService.getNotificationProxyParser();
82 this.oRanListenerRegistrationResult = null;
83 this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService,
84 notificationProxyParser);
86 this.oRanFaultListenerRegistrationResult = null;
87 this.oRanFaultListener =
88 new ORanFaultNotificationListener(netconfAccessor, databaseService, vesCollectorService);
91 private void initialReadFromNetworkElement() {
92 Hardware hardware = readHardware();
93 if (hardware != null) {
94 componentList = YangHelper.getCollection(hardware.nonnullComponent());
95 List<Inventory> inventoryList =
96 ORanToInternalDataModel.getInventoryList(netconfAccessor.getNodeId(), componentList);
97 inventoryList.forEach(databaseService::writeInventory);
100 Optional<Guicutthrough> oGuicutthrough = ORanToInternalDataModel.getGuicutthrough(getOnapSystemData());
101 if (oGuicutthrough.isPresent()) {
102 databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfAccessor.getNodeId().getValue());
107 public NetworkElementDeviceType getDeviceType() {
108 return NetworkElementDeviceType.ORAN;
112 public void register() {
113 initialReadFromNetworkElement();
114 // Publish the mountpoint to VES if enabled
115 publishMountpointToVES();
116 // Register call back class for receiving notifications
117 Optional<NetconfNotifications> oNotifications = netconfAccessor.getNotificationAccessor();
118 if (oNotifications.isPresent()) {
119 NetconfNotifications notifications = oNotifications.get();
120 this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener);
121 this.oRanFaultListenerRegistrationResult =
122 netconfAccessor.doRegisterNotificationListener(oRanFaultListener);
123 // Register notifications stream
124 if (notifications.isNCNotificationsSupported()) {
125 List<Stream> streamList = notifications.getNotificationStreams();
126 notifications.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream); // Always register first to default stream
127 notifications.registerNotificationsStream(streamList);
129 notifications.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream);
135 public void deregister() {
136 if (oRanListenerRegistrationResult != null) {
137 this.oRanListenerRegistrationResult.close();
139 if (oRanFaultListenerRegistrationResult != null) {
140 this.oRanFaultListenerRegistrationResult.close();
146 public NodeId getNodeId() {
147 return netconfAccessor.getNodeId();
151 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
152 return Optional.empty();
156 public void warmstart() {}
159 public Optional<NetconfAccessor> getAcessor() {
160 return Optional.of(netconfAccessor);
164 private System1 getOnapSystemData() {
165 log.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue());
167 InstanceIdentifier<System1> system1IID = InstanceIdentifier
168 .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class)
169 .augmentation(System1.class).build();
170 System1 res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
171 LogicalDatastoreType.OPERATIONAL, system1IID);
172 log.debug("Result of System1 = {}", res);
176 private Hardware readHardware() {
177 final Class<Hardware> clazzPac = Hardware.class;
178 log.info("DBRead Get hardware for class {} from mountpoint {}", clazzPac.getSimpleName(),
179 netconfAccessor.getNodeId().getValue());
180 InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build();
181 Hardware res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
182 LogicalDatastoreType.OPERATIONAL, hardwareIID);
183 log.debug("Result of Hardware = {}", res);
187 private void publishMountpointToVES() {
188 log.debug("In publishMountpointToVES()");
191 * 1. Check if this device is in the list of allowed-devices.
192 * 2. If device exists in allowed-devices, then create VES pnfRegistration event and publish to VES
194 if (inAllowedDevices(netconfAccessor.getNodeId().getValue())) {
195 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
197 for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) {
198 //Just get one component. At the moment we don't care which one. Also since there is only one management address, we assume there will be only one chassis.
199 //If the device supports subtended configuration then it is assumed that the Chassis containing the management interface will be the root component and there will be only one root.
200 this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor,
201 vesCollectorService, component);
202 VESCommonEventHeaderPOJO header =
203 mapper.mapCommonEventHeader(sequenceNo++);
204 VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields();
206 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
207 } catch (JsonProcessingException e) {
208 log.warn("Error while serializing VES Event to String ", e);
219 private boolean inAllowedDevices(String mountpointName) {
220 final InstanceIdentifier<AllowedDevices> ALL_DEVICES =
221 InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class);
223 AllowedDevices allowedDevices;
224 allowedDevices = netconfAccessor.getTransactionUtils().readData(
225 netconfAccessor.getControllerBindingDataBroker(), LogicalDatastoreType.CONFIGURATION, ALL_DEVICES);
227 if (allowedDevices != null) {
228 Collection<Device> deviceList = YangHelper.getCollection(allowedDevices.nonnullDevice());
229 for (Device device : deviceList) {
230 log.info("Device in allowed-devices is - {}", device.getUniqueId());
231 if (device.getUniqueId().equals(netconfAccessor.getNodeId().getValue())) {
232 log.info("Mountpoint is part of allowed-devices list");
238 log.info("Mountpoint {} is not part of allowed-devices list", mountpointName);