03e1706b906c4f5ac7aeab4298cefc55ad4e52d6
[ccsdk/features.git] /
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf.impl;
19
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;
45
46 /**
47  */
48 public class OnfNetworkElement implements NetworkElement {
49
50     private static final Logger log = LoggerFactory.getLogger(OnfNetworkElement.class);
51
52     private final INetconfAcessor netconfAccessor;
53
54     private final DataProvider databaseService;
55
56     private @NonNull final OnfListener ranListener;
57
58     private ListenerRegistration<NotificationListener> ranListenerRegistrationResult;
59
60     OnfNetworkElement(INetconfAcessor netconfAccess, DataProvider databaseService) {
61         log.info("Create {}",OnfNetworkElement.class.getSimpleName());
62         this.netconfAccessor = netconfAccess;
63         this.databaseService = databaseService;
64
65         this.ranListenerRegistrationResult = null;
66         this.ranListener = new OnfListener();
67
68     }
69
70     public void initialReadFromNetworkElement() {
71     }
72
73     @Override
74     public NetworkElementDeviceType getDeviceType() {
75         return NetworkElementDeviceType.ORAN;
76     }
77
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);
87     }
88
89     private class OnfListener implements IetfNetconfNotificationsListener {
90
91         @Override
92         public void onNetconfConfirmedCommit(NetconfConfirmedCommit notification) {
93             log.info("onNetconfConfirmedCommit ", notification);
94         }
95
96         @Override
97         public void onNetconfSessionStart(NetconfSessionStart notification) {
98             log.info("onNetconfSessionStart ", notification);
99         }
100
101         @Override
102         public void onNetconfSessionEnd(NetconfSessionEnd notification) {
103             log.info("onNetconfSessionEnd ", notification);
104         }
105
106         @Override
107         public void onNetconfCapabilityChange(NetconfCapabilityChange notification) {
108             log.info("onNetconfCapabilityChange ", notification);
109         }
110
111         @Override
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) {
118                     sb.append(", ");
119                 }
120                 sb.append(edit);
121
122                 EventlogBuilder eventlogBuilder = new EventlogBuilder();
123
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);
130                     }
131                 }
132                 eventlogBuilder.setNodeId(netconfAccessor.getNodeId().getValue());
133                 eventlogBuilder.setNewValue(String.valueOf(edit.getOperation()));
134                 databaseService.writeEventLog(eventlogBuilder.build());
135             }
136             log.info("onNetconfConfigChange (2) {}", sb);
137         }
138     }
139
140     @Override
141     public void register() {
142     }
143
144     @Override
145     public void deregister() {
146     }
147
148
149     @Override
150     public NodeId getNodeId() {
151         return netconfAccessor.getNodeId();
152     }
153
154     @Override
155     public <L extends NetworkElementService> Optional<L> getService(Class<L> clazz) {
156         return Optional.empty();
157     }
158
159     @Override
160     public void warmstart() {
161     }
162
163 }