1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl;
20 import java.util.List;
21 import java.util.Optional;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.NetworkElement;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.NetworkElementService;
26 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.INetconfAcessor;
27 import org.opendaylight.mdsal.binding.api.MountPoint;
28 import org.opendaylight.mdsal.binding.api.NotificationService;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.IetfNetconfNotificationsListener;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfigChange;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfConfirmedCommit;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionEnd;
34 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfSessionStart;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.netconf.config.change.Edit;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.EventlogBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.NetworkElementDeviceType;
38 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
39 import org.opendaylight.yangtools.concepts.ListenerRegistration;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
42 import org.opendaylight.yangtools.yang.binding.NotificationListener;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
48 public class OnfNetworkElement implements NetworkElement {
50 private static final Logger log = LoggerFactory.getLogger(OnfNetworkElement.class);
52 private final INetconfAcessor netconfAccessor;
54 private final DataProvider databaseService;
56 private @NonNull final OnfListener ranListener;
58 private ListenerRegistration<NotificationListener> ranListenerRegistrationResult;
60 OnfNetworkElement(INetconfAcessor netconfAccess, DataProvider databaseService) {
61 log.info("Create {}",OnfNetworkElement.class.getSimpleName());
62 this.netconfAccessor = netconfAccess;
63 this.databaseService = databaseService;
65 this.ranListenerRegistrationResult = null;
66 this.ranListener = new OnfListener();
70 public void initialReadFromNetworkElement() {
74 public NetworkElementDeviceType getDeviceType() {
75 return NetworkElementDeviceType.ORAN;
78 private void doRegisterNotificationListener(MountPoint mountPoint) {
79 log.info("Begin register listener for Mountpoint {}", mountPoint.getIdentifier().toString());
80 final Optional<NotificationService> optionalNotificationService = mountPoint
81 .getService(NotificationService.class);
82 final NotificationService notificationService = optionalNotificationService.get();
83 // notificationService.registerNotificationListener(microwaveEventListener);
84 ranListenerRegistrationResult = notificationService.registerNotificationListener(ranListener);
85 log.info("End registration listener for Mountpoint {} Listener: {} Result: {}",
86 mountPoint.getIdentifier().toString(), optionalNotificationService, ranListenerRegistrationResult);
89 private class OnfListener implements IetfNetconfNotificationsListener {
92 public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
93 log.info("onNetconfConfirmedCommit ", notification);
97 public void onNetconfSessionStart(NetconfSessionStart notification) {
98 log.info("onNetconfSessionStart ", notification);
102 public void onNetconfSessionEnd(NetconfSessionEnd notification) {
103 log.info("onNetconfSessionEnd ", notification);
107 public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
108 log.info("onNetconfCapabilityChange ", notification);
112 public void onNetconfConfigChange(NetconfConfigChange notification) {
113 log.info("onNetconfConfigChange (1) {}", notification);
114 StringBuffer sb = new StringBuffer();
115 List<Edit> editList = notification.nonnullEdit();
116 for (Edit edit : editList) {
117 if (sb.length() > 0) {
122 EventlogBuilder eventlogBuilder = new EventlogBuilder();
124 InstanceIdentifier<?> target = edit.getTarget();
125 if (target != null) {
126 eventlogBuilder.setObjectId(target.toString());
127 log.info("TARGET: {} {} {}", target.getClass(), target.getTargetType());
128 for (PathArgument pa : target.getPathArguments()) {
129 log.info("PathArgument {}", pa);
132 eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
133 eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
134 databaseService.writeEventLog(eventlogBuilder.build());
136 log.info("onNetconfConfigChange (2) {}", sb);
141 public void register() {
145 public void deregister() {
150 public NodeId getNodeId() {
151 return netconfAccessor.getNodeId();
155 public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
156 return Optional.empty();
160 public void warmstart() {