2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package com.ericsson.testvnf.server;
23 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.InputStreamReader;
29 import java.util.Properties;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
34 import com.ericsson.testvnf.server.builder.ServerBuilder;
37 * Netconf server using Apache MINA SSHD and netconf4j
38 * The SSHD server extends a netconf subsystem
40 * @author Ajith Sreekumar
45 private static final int DEFAULT_PORT = 2052;
47 private static final String DEFAULT_HOST = "0.0.0.0";
49 private static final Log log = LogFactory.getLog(Server.class);
51 private static String netconfTemplatesDirectory;
53 private static String timeDelayForSendingEvents; // time delay in milliseconds
55 public static String getNetconfTemplatesDirectory() {
56 return netconfTemplatesDirectory;
59 public static void setNetconfTemplatesDirectory(String netconfTemplatesDirectory) {
60 Server.netconfTemplatesDirectory = netconfTemplatesDirectory;
63 public static String getTimeDelayForSendingEvents() {
64 return timeDelayForSendingEvents;
67 public static void setTimeDelayForSendingEvents(String timeDelayForSendingEvents) {
68 Server.timeDelayForSendingEvents = timeDelayForSendingEvents;
72 public static void main(String[] args) throws IOException{
73 setNetconfTemplatesDirectory(args[0]); // the directory which contains the groovy files to perform actions based on netconf requests, and also contains other netconf templates to be sent back to the client
74 setTimeDelayForSendingEvents(args[1]); // the delay between sending each event by the VNF
75 ServerBuilder serverBuilder = new ServerBuilder();
77 Properties prop = new Properties();
78 String host = DEFAULT_HOST;
79 int port = DEFAULT_PORT;
81 InputStream input = new FileInputStream(getNetconfTemplatesDirectory()+ "/netconftemplates/server-config.properties");
82 log.info("Setting host and port from the properties file.");
84 if(null!=prop.getProperty("host"))
85 host = prop.getProperty("host");
86 if(null!=prop.getProperty("port"))
87 port = Integer.parseInt(prop.getProperty("port"));
88 }catch(FileNotFoundException e) {
89 log.info("server-config.properties file not found. " + e);
90 log.info("Using default host and port");
94 serverBuilder.initializeServer(host,port);
95 serverBuilder.startServer();
97 // read lines from input
98 BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
101 if (buffer.readLine().equalsIgnoreCase("EXIT")) {
107 serverBuilder.stopServer();