Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / netconf / executor / mocks / NetconfDeviceSimulator.kt
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
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 org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.utils.NetconfSubsystemFactory
26 import java.util.*
27
28
29 class NetconfDeviceSimulator(private val port: Int) {
30
31     private var sshd: SshServer? = null
32
33     fun start() {
34         sshd = SshServer.setUpDefaultServer()
35         sshd!!.port = port
36         sshd!!.keyPairProvider = SimpleGeneratorHostKeyProvider()
37
38         val userAuthFactories = ArrayList<NamedFactory<UserAuth>>()
39         userAuthFactories.add(UserAuthNoneFactory())
40         sshd!!.userAuthFactories = userAuthFactories
41
42         val namedFactoryList = ArrayList<NamedFactory<Command>>()
43         namedFactoryList.add(NetconfSubsystemFactory())
44         sshd!!.subsystemFactories = namedFactoryList
45
46         try {
47             sshd!!.start()
48         } catch (e: Exception) {
49             e.printStackTrace()
50         }
51
52     }
53
54     fun stop() {
55         try {
56             sshd!!.stop(true)
57         } catch (e: Exception) {
58             e.printStackTrace()
59         }
60
61     }
62 }