2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.vesagent.controller;
\r
21 import com.fasterxml.jackson.core.JsonProcessingException;
\r
22 import com.fasterxml.jackson.databind.ObjectMapper;
\r
24 import java.text.SimpleDateFormat;
\r
25 import java.util.Date;
\r
27 import org.commscope.tr069adapter.acs.common.DeviceInform;
\r
28 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
\r
29 import org.commscope.tr069adapter.mapper.model.VESNotification;
\r
30 import org.commscope.tr069adapter.mapper.model.VESNotificationResponse;
\r
31 import org.commscope.tr069adapter.vesagent.VesConfiguration;
\r
32 import org.commscope.tr069adapter.vesagent.fault.Parser;
\r
33 import org.commscope.tr069adapter.vesagent.http.HttpRequestSender;
\r
34 import org.commscope.tr069adapter.vesagent.model.CommonEventHeader;
\r
35 import org.commscope.tr069adapter.vesagent.model.Event;
\r
36 import org.commscope.tr069adapter.vesagent.model.EventMessage;
\r
37 import org.commscope.tr069adapter.vesagent.model.PnfRegEventAdditionalFeilds;
\r
38 import org.commscope.tr069adapter.vesagent.model.PnfRegEventFields;
\r
39 import org.commscope.tr069adapter.vesagent.util.EventUtil;
\r
40 import org.slf4j.Logger;
\r
41 import org.slf4j.LoggerFactory;
\r
42 import org.springframework.beans.factory.annotation.Autowired;
\r
43 import org.springframework.stereotype.Component;
\r
46 public class PnfRegMappingHandler {
\r
47 private static final Logger logger = LoggerFactory.getLogger(PnfRegMappingHandler.class);
\r
48 public static final String SSH_USERNAME = "netconf";
\r
49 public static final String SSH_PSSWORD = "netconf";
\r
52 VesConfiguration config;
\r
55 HttpRequestSender sender;
\r
57 public VESNotificationResponse handlePnfRegNotification(VESNotification vesNoti)
\r
58 throws JsonProcessingException {
\r
59 Event event = convertNotificationToVESEvent(vesNoti.getDevnotification(),
\r
60 vesNoti.getNetconfDetails(), vesNoti.geteNodeBName());
\r
61 if (null != event) {
\r
62 EventMessage evMsg = new EventMessage();
\r
63 evMsg.setEvent(event);
\r
65 ObjectMapper mapper = new ObjectMapper();
\r
67 String requestBody = mapper.writeValueAsString(evMsg);
\r
68 if (requestBody.isEmpty()) {
\r
69 logger.debug("VES Event body is empty");
\r
72 String url = config.getPnfRegVesUrl();
\r
73 return sender.postRequest(url, requestBody);
\r
75 return new VESNotificationResponse(-1,
\r
76 "unable to prepare ves event due to insufficient data");
\r
80 public VESNotificationResponse handlePnfRegNotificationOnRestart(VESNotification vesNoti)
\r
81 throws JsonProcessingException {
\r
82 Event event = convertNotificationToVESEventOnRestart(vesNoti.getNetconfDetails());
\r
84 EventMessage evMsg = new EventMessage();
\r
85 evMsg.setEvent(event);
\r
87 ObjectMapper mapper = new ObjectMapper();
\r
89 String requestBody = mapper.writeValueAsString(evMsg);
\r
90 if (requestBody.isEmpty()) {
\r
91 logger.debug("VES Event body is empty");
\r
94 String url = config.getPnfRegVesUrl();
\r
95 return sender.postRequest(url, requestBody);
\r
98 Event convertNotificationToVESEvent(DeviceInform notification,
\r
99 NetConfServerDetails netconfServerDetails, String eNodeBName) {
\r
100 logger.debug("Converting Notification to VES pnfevent started");
\r
101 Parser parser = new Parser();
\r
104 Event regEvent = new Event();
\r
105 CommonEventHeader eventHeader = new CommonEventHeader();
\r
107 eventHeader.setDomain("pnfRegistration");
\r
108 eventHeader.setEventId(
\r
109 "PnfReg" + notification.getDeviceDetails().getDeviceId() + System.currentTimeMillis());
\r
110 eventHeader.setEventName("pnfReg_" + notification.getDeviceDetails().getProductClass() + "-"
\r
111 + config.getVendorName());
\r
112 eventHeader.setEventType(config.getPnfRegEventType());
\r
113 eventHeader.setPriority("High");
\r
114 EventUtil.populateEventHeaderFields(eventHeader, notification, eNodeBName, config);
\r
115 regEvent.setCommonEventHeader(eventHeader);
\r
117 PnfRegEventFields pnfRegistrationFields =
\r
118 parser.parseNotificationParams(notification.getParameters());
\r
119 populatePnfRegFeilds(netconfServerDetails, pnfRegistrationFields);
\r
120 pnfRegistrationFields.setModelNumber(notification.getDeviceDetails().getProductClass());
\r
122 regEvent.setPnfRegistrationFields(pnfRegistrationFields);
\r
123 logger.debug("Converting Notification to VES pnfevent completed");
\r
127 Event convertNotificationToVESEventOnRestart(NetConfServerDetails netconfServerDetails) {
\r
128 logger.debug("Converting Notification to VES pnfevent started");
\r
130 Event regEvent = new Event();
\r
131 CommonEventHeader eventHeader = new CommonEventHeader();
\r
133 if (null == netconfServerDetails) {
\r
134 logger.error("netconf server details as received as null {}", netconfServerDetails);
\r
137 eventHeader.setDomain("pnfRegistration");
\r
139 .setEventId("PnfReg" + netconfServerDetails.getDeviceId() + System.currentTimeMillis());
\r
140 eventHeader.setEventName(
\r
141 "pnfReg_" + netconfServerDetails.getDeviceId() + "-" + config.getVendorName());
\r
142 eventHeader.setEventType(config.getPnfRegEventType());
\r
143 eventHeader.setLastEpochMicrosec(System.currentTimeMillis());
\r
145 eventHeader.setPriority("High");
\r
146 eventHeader.setSequence(0);
\r
148 if (netconfServerDetails.getEnodeBName() == null) {
\r
149 eventHeader.setReportingEntityName(netconfServerDetails.getDeviceId());
\r
150 eventHeader.setReportingEntityId(netconfServerDetails.getDeviceId());
\r
151 eventHeader.setSourceId(netconfServerDetails.getDeviceId());
\r
152 eventHeader.setSourceName(netconfServerDetails.getDeviceId());
\r
154 eventHeader.setReportingEntityName(netconfServerDetails.getEnodeBName());
\r
155 eventHeader.setSourceName(netconfServerDetails.getEnodeBName());
\r
157 eventHeader.setReportingEntityId(netconfServerDetails.getDeviceId());
\r
158 eventHeader.setSourceId(netconfServerDetails.getDeviceId());
\r
161 eventHeader.setStartEpochMicrosec(System.currentTimeMillis());
\r
162 eventHeader.setVersion(config.getEventVersion());
\r
163 eventHeader.setNfNamingCode("");
\r
164 eventHeader.setNfcNamingCode("");
\r
165 eventHeader.setNfVendorName(config.getVendorName());
\r
166 eventHeader.setVesEventListenerVersion(config.getVesVersion());
\r
167 regEvent.setCommonEventHeader(eventHeader);
\r
168 PnfRegEventFields pnfRegistrationFields = new PnfRegEventFields();
\r
169 regEvent.setPnfRegistrationFields(
\r
170 populatePnfRegFeilds(netconfServerDetails, pnfRegistrationFields));
\r
171 logger.debug("Converting Notification to VES pnfevent completed");
\r
175 private PnfRegEventFields populatePnfRegFeilds(NetConfServerDetails netconfServerDetails,
\r
176 PnfRegEventFields pnfRegistrationFields) {
\r
178 pnfRegistrationFields.setSerialNumber(netconfServerDetails.getDeviceId());
\r
179 pnfRegistrationFields.setPnfRegistrationFieldsVersion(config.getPnfFeildVersion());
\r
180 pnfRegistrationFields.setMacAddress(netconfServerDetails.getDeviceId());
\r
181 pnfRegistrationFields.setVendorName(config.getVendorName());
\r
182 PnfRegEventAdditionalFeilds additionalFields = new PnfRegEventAdditionalFeilds();
\r
184 pnfRegistrationFields.setOamV4IpAddress(netconfServerDetails.getListenAddress());
\r
185 // TODO: since not supporting 1pv6 we are configuring empty value
\r
186 pnfRegistrationFields.setOamV6IpAddress("");
\r
188 pnfRegistrationFields.setManufactureDate("");
\r
189 pnfRegistrationFields.setUnitType(config.getUnitType());
\r
190 pnfRegistrationFields.setUnitFamily(config.getUnitFamily());
\r
191 pnfRegistrationFields.setLastServiceDate(new SimpleDateFormat("ddMMyyyy").format(new Date()));
\r
192 additionalFields.setOamPort(netconfServerDetails.getListenPort());
\r
193 additionalFields.setProtocol("SSH");
\r
194 additionalFields.setUsername(SSH_USERNAME);
\r
195 additionalFields.setPassword(SSH_PSSWORD);
\r
196 additionalFields.setReconnectOnChangedSchema(Boolean.FALSE.toString());
\r
197 additionalFields.setSleepfactor("1.5");
\r
198 additionalFields.setTcpOnly(Boolean.FALSE.toString());
\r
199 additionalFields.setConnectionTimeout("20000");
\r
200 additionalFields.setMaxConnectionAttempts("100");
\r
201 additionalFields.setBetweenAttemptsTimeout("2000");
\r
202 additionalFields.setKeepaliveDelay("120");
\r
204 pnfRegistrationFields.setAdditionalFields(additionalFields);
\r
206 return pnfRegistrationFields;
\r