8072acb2091f5deb060928cabded482718a91753
[netconf.git] / netconf / tools / netconf-testtool / README.adoc
1 # NetConf TestTool
2
3 This project is used to simulate NetConf devices in order to test NetConf
4 south-bound plugin and applications using this plugin. *netconf-testtool*
5 project is designed as versatile java library to be used for custom NetConf device
6 test simulations.
7
8 ## How to use as standalone application
9 * compile project
10 * start org.opendaylight.netconf.test.tool.Main
11
12 ## How to use it in your code
13 * Use maven dependency in your project
14 ----
15 <dependency>
16     <groupId>org.opendaylight.netconf</groupId>
17     <artifactId>netconf-testtool-core</artifactId>
18     <version>0.1.0-SNAPSHOT</version>
19 </dependency>
20 ----
21 * Prepare configuration - models are loaded by classloader
22   from classpath.
23 ----
24 Set<String> models = ImmutableSet.of(
25     "models/iana-afn-safi@2013-07-04.yang",
26     "models/ietf-inet-types@2013-07-15.yang",
27     "models/ietf-netconf@2011-06-01.yang",
28     "models/ietf-netconf-monitoring@2010-10-04.yang",
29     "models/ietf-netconf-monitoring-extension@2013-12-10.yang",
30     "models/ietf-yang-library@2016-06-21.yang",
31     "models/ietf-yang-types@2013-07-15.yang",
32     "models/nc-notifications@2008-07-14.yang",
33     "models/notifications@2008-07-14.yang",
34     ...
35 );
36 ----
37 * Prepare list of capabilities
38 ----
39 Set<String> capabilities = ImmutableSet.of(
40     "urn:ietf:params:netconf:base:1.0",
41     "urn:ietf:params:netconf:base:1.1",
42     ...
43 );
44 ----
45 * Override RPC mapping provider org.opendaylight.netconf.test.tool.rpchandler.RpcHandler
46 ----
47 public class RpcHandlerImpl implements RpcHandler {
48     @Override
49     public Optional<Document> getResponse(XmlElement rpcElement) {
50         ...
51         return response;
52     }
53 }
54
55 ----
56 * Override operations creator org.opendaylight.netconf.test.tool.operations.OperationsCreator
57   in order to inject custom simulated behavior.
58 ----
59 public class OperationsCreatorImpl implements OperationsCreator {
60     @Override
61     public NetconfOperationService getNetconfOperationService(Set<Capability> capabilities,
62             SessionIdProvider idProvider,
63             String netconfSessionIdForReporting) {
64             ...
65             return netconfOperationService;
66     }
67 }
68 ----
69 * Start NetConf device simulator in your code
70 ----
71 public class Main {
72
73     public static void main(String[] args) {
74         Configuration configuration = new ConfigurationBuilder()
75                 .setModels(models)
76                 .setCapabilities(capabilities)
77                 .setRpcHandler(new RpcHandlerImpl())
78                 .setOperationsCreator(new OperationsCreatorImpl());
79                 .build();
80         NetConfDeviceSimulator netConfDeviceSimulator =
81                 new NetConfDeviceSimulator(configuration);
82         netConfDeviceSimulator.start();
83     }
84
85 }
86 ----