2b7aa76c9cb631149eb2fa1b0498e481a55ba70f
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.mocks
17
18
19 import org.apache.sshd.common.NamedFactory
20 import org.apache.sshd.server.command.Command
21 import org.apache.sshd.server.SshServer
22 import org.apache.sshd.server.auth.UserAuth
23 import org.apache.sshd.server.auth.UserAuthNoneFactory
24 import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
25 import java.util.*
26
27
28 class NetconfDeviceSimulator(private val port: Int) {
29
30     private var sshd: SshServer? = null
31
32     fun start() {
33         sshd = SshServer.setUpDefaultServer()
34         sshd!!.port = port
35         sshd!!.keyPairProvider = SimpleGeneratorHostKeyProvider()
36
37         val userAuthFactories = ArrayList<NamedFactory<UserAuth>>()
38         userAuthFactories.add(UserAuthNoneFactory())
39         sshd!!.userAuthFactories = userAuthFactories
40
41         val namedFactoryList = ArrayList<NamedFactory<Command>>()
42         namedFactoryList.add(NetconfSubsystemFactory())
43         sshd!!.subsystemFactories = namedFactoryList
44
45         try {
46             sshd!!.start()
47         } catch (e: Exception) {
48             e.printStackTrace()
49         }
50
51     }
52
53     fun stop() {
54         try {
55             sshd!!.stop(true)
56         } catch (e: Exception) {
57             e.printStackTrace()
58         }
59
60     }
61 }