2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
7 * =================================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software distributed under the License
14 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15 * or implied. See the License for the specific language governing permissions and limitations under
17 * ============LICENSE_END==========================================================================
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.vesdomain.pnfreg;
22 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.xml;
23 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.PUT;
25 import java.io.UnsupportedEncodingException;
26 import java.net.URLEncoder;
27 import java.nio.charset.StandardCharsets;
28 import java.util.HashMap;
29 import java.util.List;
31 import org.eclipse.jdt.annotation.NonNull;
32 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 public class PNFMountPointClient extends MessageClient {
38 private static final Logger LOG = LoggerFactory.getLogger(PNFMountPointClient.class);
40 private static final String MOUNTPOINT_URI =
41 "rests/data/network-topology:network-topology/topology=topology-netconf/node=";
42 public static final String DEVICE_NAME = "@device-name@", DEVICE_IP = "@device-ip@", DEVICE_PORT = "@device-port@",
43 USERNAME = "@username@", PASSWORD = "@password@", KEY_ID = "@key-id@";
44 private static final String PROTOCOL = "protocol_sec";
45 public static List<String> REQUIRED_FIELDS_SSH = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME,
47 public static List<String> REQUIRED_FIELDS_TLS = List.of(PROTOCOL, DEVICE_NAME, DEVICE_IP, DEVICE_PORT, USERNAME,
50 private static final String SSH_PAYLOAD = "<node xmlns=\"urn:TBD:params:xml:ns:yang:network-topology\">\n"
51 + " <node-id>" + DEVICE_NAME + "</node-id>\n"
52 + " <host xmlns=\"urn:opendaylight:netconf-node-topology\">" + DEVICE_IP + "</host>\n"
53 + " <port xmlns=\"urn:opendaylight:netconf-node-topology\">" + DEVICE_PORT + "</port>\n"
54 + " <username xmlns=\"urn:opendaylight:netconf-node-topology\">" + USERNAME + "</username>\n"
55 + " <password xmlns=\"urn:opendaylight:netconf-node-topology\">" + PASSWORD + "</password>\n"
56 + " <tcp-only xmlns=\"urn:opendaylight:netconf-node-topology\">false</tcp-only>\n"
57 + " <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->\n"
58 + " <reconnect-on-changed-schema xmlns=\"urn:opendaylight:netconf-node-topology\">false</reconnect-on-changed-schema>\n"
59 + " <connection-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">20000</connection-timeout-millis>\n"
60 + " <max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">0</max-connection-attempts>\n"
61 + " <between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>\n"
62 + " <sleep-factor xmlns=\"urn:opendaylight:netconf-node-topology\">1.5</sleep-factor>\n"
63 + " <!-- keepalive-delay set to 0 turns off keepalives-->\n"
64 + " <keepalive-delay xmlns=\"urn:opendaylight:netconf-node-topology\">120</keepalive-delay>\n"
67 private static final String TLS_PAYLOAD = "<node xmlns=\"urn:TBD:params:xml:ns:yang:network-topology\">\n"
68 + " <node-id>" + DEVICE_NAME + "</node-id>\n"
69 + " <host xmlns=\"urn:opendaylight:netconf-node-topology\">" + DEVICE_IP + "</host>\n"
70 + " <port xmlns=\"urn:opendaylight:netconf-node-topology\">" + DEVICE_PORT + "</port>\n"
71 + " <key-based xmlns=\"urn:opendaylight:netconf-node-topology\">\n"
72 + " <username xmlns=\"urn:opendaylight:netconf-node-topology\">" + USERNAME + "</username>\n"
73 + " <key-id>" + KEY_ID + "</key-id>\n"
75 + " <tcp-only xmlns=\"urn:opendaylight:netconf-node-topology\">false</tcp-only>\n"
76 + " <protocol xmlns=\"urn:opendaylight:netconf-node-topology\">\n"
77 + " <name>TLS</name>\n"
79 + "<!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->\n"
80 + "<reconnect-on-changed-schema xmlns=\"urn:opendaylight:netconf-node-topology\">false</reconnect-on-changed-schema>\n"
81 + "<connection-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">20000</connection-timeout-millis>\n"
82 + "<max-connection-attempts xmlns=\"urn:opendaylight:netconf-node-topology\">0</max-connection-attempts>\n"
83 + "<between-attempts-timeout-millis xmlns=\"urn:opendaylight:netconf-node-topology\">2000</between-attempts-timeout-millis>\n"
84 + "<sleep-factor xmlns=\"urn:opendaylight:netconf-node-topology\">1.5</sleep-factor>\n"
85 + "<!-- keepalive-delay set to 0 turns off keepalives-->\n"
86 + "<keepalive-delay xmlns=\"urn:opendaylight:netconf-node-topology\">120</keepalive-delay>\n"
90 public PNFMountPointClient(String baseUrl) {
91 super(baseUrl, MOUNTPOINT_URI);
95 public String prepareMessageFromPayloadMap(Map<String, String> notificationPayloadMap) {
96 updateNotificationUriWithPnfName(notificationPayloadMap.get(DEVICE_NAME));
98 if (!notificationPayloadMap.containsKey(PROTOCOL)) {
101 if (notificationPayloadMap.get(PROTOCOL).equals("SSH")) {
102 message = super.prepareMessageFromPayloadMap(notificationPayloadMap, SSH_PAYLOAD, REQUIRED_FIELDS_SSH);
103 } else if (notificationPayloadMap.get(PROTOCOL).equals("TLS")) {
104 message = super.prepareMessageFromPayloadMap(notificationPayloadMap, TLS_PAYLOAD, REQUIRED_FIELDS_TLS);
109 private void updateNotificationUriWithPnfName(String pnfName) {
110 setNotificationUri(MOUNTPOINT_URI + urlEncodeValue(pnfName));
113 public static String urlEncodeValue(String value) {
118 return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()).replace("+", "%20");
119 } catch (UnsupportedEncodingException ex) {
120 LOG.warn("encoding problem: {}", ex.getMessage());
126 public boolean sendNotification(String message) {
127 return super.sendNotification(message, PUT, xml);
130 public static Map<String, String> createPNFNotificationPayloadMap(@NonNull String pnfName,
131 @NonNull String ipAddress,
132 @NonNull String commPort, @NonNull String protocol,
133 String username, String password, String keyId) {
134 HashMap<String, String> map = new HashMap<>();
135 map.put(DEVICE_NAME, pnfName);
136 map.put(DEVICE_IP, ipAddress);
137 map.put(DEVICE_PORT, commPort);
138 map.put(PROTOCOL, protocol);
139 map.put(USERNAME, username);
140 map.put(PASSWORD, password);
141 map.put(KEY_ID, keyId);