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.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.Hardware;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.hardware.rev180313.hardware.Component;
39 import org.opendaylight.yang.gen.v1.urn.onap.system.rev201026.System1;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Guicutthrough;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.NetworkElementDeviceType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.NetconfCallhomeServer;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.AllowedDevices;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev161109.netconf.callhome.server.allowed.devices.Device;
46 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
47 import org.opendaylight.yangtools.concepts.ListenerRegistration;
48 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
49 import org.opendaylight.yangtools.yang.binding.NotificationListener;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
53 public class ORanNetworkElement implements NetworkElement {
55 private static final Logger log = LoggerFactory.getLogger(ORanNetworkElement.class);
57 private final NetconfBindingAccessor netconfAccessor;
59 private final DataProvider databaseService;
61 @SuppressWarnings("unused")
62 private final VESCollectorService vesCollectorService;
64 private ListenerRegistration<NotificationListener> oRanListenerRegistrationResult;
65 private @NonNull final ORanChangeNotificationListener oRanListener;
66 private ListenerRegistration<NotificationListener> oRanFaultListenerRegistrationResult;
67 private @NonNull final ORanFaultNotificationListener oRanFaultListener;
68 private final NotificationProxyParser notificationProxyParser;
69 private @NonNull ORanRegistrationToVESpnfRegistrationMapper mapper;
70 private Collection<Component> componentList;
71 private static int sequenceNo = 0;
73 ORanNetworkElement(NetconfBindingAccessor netconfAccess, DataProvider databaseService,
74 VESCollectorService vesCollectorService) {
75 log.info("Create {}", ORanNetworkElement.class.getSimpleName());
76 this.netconfAccessor = netconfAccess;
77 this.databaseService = databaseService;
78 this.vesCollectorService = vesCollectorService;
79 this.notificationProxyParser = vesCollectorService.getNotificationProxyParser();
81 this.oRanListenerRegistrationResult = null;
82 this.oRanListener = new ORanChangeNotificationListener(netconfAccessor, databaseService, vesCollectorService,
83 notificationProxyParser);
85 this.oRanFaultListenerRegistrationResult = null;
86 this.oRanFaultListener =
87 new ORanFaultNotificationListener(netconfAccessor, databaseService, vesCollectorService);
90 private void initialReadFromNetworkElement() {
91 Hardware hardware = readHardware();
92 if (hardware != null) {
93 componentList = YangHelper.getCollection(hardware.nonnullComponent());
94 List<Inventory> inventoryList =
95 ORanToInternalDataModel.getInventoryList(netconfAccessor.getNodeId(), componentList);
96 databaseService.writeInventory(netconfAccessor.getNodeId().getValue(), inventoryList);
99 Optional<Guicutthrough> oGuicutthrough = ORanToInternalDataModel.getGuicutthrough(getOnapSystemData());
100 if (oGuicutthrough.isPresent()) {
101 databaseService.writeGuiCutThroughData(oGuicutthrough.get(), netconfAccessor.getNodeId().getValue());
106 public NetworkElementDeviceType getDeviceType() {
107 return NetworkElementDeviceType.ORAN;
111 public void register() {
112 initialReadFromNetworkElement();
113 // Publish the mountpoint to VES if enabled
114 publishMountpointToVES();
115 // Register call back class for receiving notifications
116 this.oRanListenerRegistrationResult = netconfAccessor.doRegisterNotificationListener(oRanListener);
117 this.oRanFaultListenerRegistrationResult =
118 netconfAccessor.doRegisterNotificationListener(oRanFaultListener);
119 // Register notifications stream
120 if (netconfAccessor.isNotificationsRFC5277Supported()) {
121 List<Stream> streamList = netconfAccessor.getNotificationStreams();
122 netconfAccessor.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream); // Always register first to default stream
123 netconfAccessor.registerNotificationsStream(streamList);
125 netconfAccessor.registerNotificationsStream(NetconfBindingAccessor.DefaultNotificationsStream);
130 public void deregister() {
131 if (oRanListenerRegistrationResult != null) {
132 this.oRanListenerRegistrationResult.close();
134 if (oRanFaultListenerRegistrationResult != null) {
135 this.oRanFaultListenerRegistrationResult.close();
141 public NodeId getNodeId() {
142 return netconfAccessor.getNodeId();
146 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
147 return Optional.empty();
151 public void warmstart() {}
154 public Optional<NetconfAccessor> getAcessor() {
155 return Optional.of(netconfAccessor);
159 private System1 getOnapSystemData() {
160 log.info("Get System1 for class {} from mountpoint {}", netconfAccessor.getNodeId().getValue());
162 InstanceIdentifier<System1> system1IID = InstanceIdentifier
163 .builder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev140806.System.class)
164 .augmentation(System1.class).build();
165 System1 res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
166 LogicalDatastoreType.OPERATIONAL, system1IID);
167 log.debug("Result of System1 = {}", res);
171 private Hardware readHardware() {
172 final Class<Hardware> clazzPac = Hardware.class;
173 log.info("DBRead Get hardware for class {} from mountpoint {}", clazzPac.getSimpleName(),
174 netconfAccessor.getNodeId().getValue());
175 InstanceIdentifier<Hardware> hardwareIID = InstanceIdentifier.builder(clazzPac).build();
176 Hardware res = netconfAccessor.getTransactionUtils().readData(netconfAccessor.getDataBroker(),
177 LogicalDatastoreType.OPERATIONAL, hardwareIID);
178 log.debug("Result of Hardware = {}", res);
182 private void publishMountpointToVES() {
183 log.debug("In publishMountpointToVES()");
186 * 1. Check if this device is in the list of allowed-devices.
187 * 2. If device exists in allowed-devices, then create VES pnfRegistration event and publish to VES
189 if (inAllowedDevices(netconfAccessor.getNodeId().getValue())) {
190 if (vesCollectorService.getConfig().isVESCollectorEnabled()) {
192 for (Component component : ORanToInternalDataModel.getRootComponents(componentList)) {
193 //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.
194 //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.
195 this.mapper = new ORanRegistrationToVESpnfRegistrationMapper(netconfAccessor,
196 vesCollectorService, component);
197 VESCommonEventHeaderPOJO header =
198 mapper.mapCommonEventHeader(sequenceNo++);
199 VESPNFRegistrationFieldsPOJO body = mapper.mapPNFRegistrationFields();
201 vesCollectorService.publishVESMessage(vesCollectorService.generateVESEvent(header, body));
202 } catch (JsonProcessingException e) {
203 log.warn("Error while serializing VES Event to String ", e);
214 private boolean inAllowedDevices(String mountpointName) {
215 final InstanceIdentifier<AllowedDevices> ALL_DEVICES =
216 InstanceIdentifier.create(NetconfCallhomeServer.class).child(AllowedDevices.class);
218 AllowedDevices allowedDevices;
219 allowedDevices = netconfAccessor.getTransactionUtils().readData(
220 netconfAccessor.getControllerBindingDataBroker(), LogicalDatastoreType.CONFIGURATION, ALL_DEVICES);
222 if (allowedDevices != null) {
223 Collection<Device> deviceList = YangHelper.getCollection(allowedDevices.nonnullDevice());
224 for (Device device : deviceList) {
225 log.info("Device in allowed-devices is - {}", device.getUniqueId());
226 if (device.getUniqueId().equals(netconfAccessor.getNodeId().getValue())) {
227 log.info("Mountpoint is part of allowed-devices list");
233 log.info("Mountpoint {} is not part of allowed-devices list", mountpointName);