@@ -2,3 +2,164 @@ OpenDaylight Examples
2
2
---------------------
3
3
4
4
* [ ODL mock binding project] ( mock-binding-project ) Simple starting project skeleton for new ODL users.
5
+
6
+
7
+ ## First Steps
8
+
9
+ First, you can try to build the ` netconf ` and ` controller ` projects:
10
+
11
+ ``` sh
12
+ mvn clean install # Builds and installs artifacts into .m2, runs all checks and unit tests
13
+ mvn clean install -DskipTests # Same as above but skips unit tests
14
+ mvn clean install -Pq # Fast profile, skips all checks and unit tests, only compiles
15
+ ```
16
+
17
+ Then, you can try running the Karaf distribution. You can find it in the ` karaf ` directory in the corresponding project.
18
+
19
+ ``` sh
20
+ sh ./karaf/target/assembly/bin/karaf
21
+ ```
22
+
23
+ Or for a clean run of Karaf:
24
+
25
+ ``` sh
26
+ sh ./karaf/target/assembly/bin/karaf clean
27
+ ```
28
+
29
+ This distribution will only have features from the project and its dependencies.
30
+ If you need the full distribution, you need to build the ` integration/distribution ` project and use the distribution
31
+ from there.
32
+
33
+ ## ODL Mock Binding Project
34
+
35
+ First, you will need a YANG model.
36
+ You can get familiar with YANG [ here] ( https://www.rfc-editor.org/rfc/rfc7950.html ) and create your own model, or use an
37
+ existing one.
38
+
39
+ For the purpose of this tutorial, this simple YANG module is used:
40
+
41
+ ``` yang
42
+ module example {
43
+ yang-version 1.1;
44
+ namespace "urn:opendaylight:example";
45
+ prefix "ex";
46
+ revision "2024-07-10";
47
+
48
+ container cont {
49
+ leaf l {
50
+ type string;
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ To implement your YANG model, put it into the [ api module directory] ( mock-binding-project/api/src/main/yang ) .
57
+ Then build the project; it should generate Java bindings(Java classes in
58
+ the [ target directory] ( mock-binding-project/api/target/classes/org/opendaylight/yang/gen ) ).
59
+
60
+ You can then use those bindings with the ` DataBroker ` that is injected in the ` impl ` module to write/read data to/from
61
+ the datastore in the [ MockBindingProvider] ( mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java )
62
+ #init() method.
63
+
64
+ ** Example code for writing data to the datastore:**
65
+
66
+ ``` java
67
+ // Create write transaction
68
+ final WriteTransaction tx = dataBroker. newWriteOnlyTransaction();
69
+
70
+ // Create data
71
+ Cont data = new ContBuilder (). setL(" example string" ). build();
72
+
73
+ // Create InstanceIdentifier for Cont container
74
+ InstanceIdentifier<Cont > instanceIdentifier = InstanceIdentifier . create(Cont . class);
75
+
76
+ // Put data to datastore and commit them
77
+ tx. put(LogicalDatastoreType . CONFIGURATION , instanceIdentifier, data);
78
+ tx. commit(). get();
79
+ ```
80
+
81
+ ** Example code for reading data from the datastore:**
82
+
83
+ ``` java
84
+ // Create read transaction
85
+ final ReadTransaction rx = dataBroker. newReadOnlyTransaction();
86
+
87
+ // Get optional data which can be empty
88
+ FluentFuture<Optional<Cont > > future = rx. read(LogicalDatastoreType . CONFIGURATION , instanceIdentifier);
89
+ Optional<Cont > optionalData = future. get();
90
+
91
+ // Check if data is present and get them
92
+ if (optionalData. isPresent()){
93
+ Cont dataOut = optionalData. get();
94
+ }
95
+ ```
96
+
97
+ Build the project, run Karaf, and install the ` mock-binding-project ` feature to run your code:
98
+
99
+ ``` sh
100
+ feature:install features-mock-binding-project
101
+ ```
102
+
103
+ ### Using RESTCONF
104
+
105
+ If you add the RESTCONF dependency to the Karaf POM, you can install the ` odl-restconf-nb ` feature and use RESTCONF
106
+ to manipulate data.
107
+
108
+ Add the dependency and rebuild the project:
109
+
110
+ ``` xml
111
+ <dependency >
112
+ <groupId >org.opendaylight.netconf</groupId >
113
+ <artifactId >odl-restconf-nb</artifactId >
114
+ <version >8.0.0-SNAPSHOT</version >
115
+ <classifier >features</classifier >
116
+ <type >xml</type >
117
+ <scope >runtime</scope >
118
+ </dependency >
119
+ ```
120
+
121
+ Run Karaf and install the features:
122
+
123
+ ``` sh
124
+ feature:install features-mock-binding-project odl-restconf-nb
125
+ ```
126
+
127
+ Then, you can use Postman to access and modify data:
128
+
129
+ For authentication, use Basic Auth with username and password set to "admin"
130
+ or use the header ` Authorization ` with the value ` Basic YWRtaW46YWRtaW4= `
131
+
132
+ ** Writing data:**
133
+
134
+ To write data to the datastore, execute the request:
135
+
136
+ ``` http
137
+ POST http://127.0.0.1:8181/rests/data/
138
+ ```
139
+
140
+ With payload:
141
+
142
+ ``` xml
143
+ <cont xmlns =" urn:opendaylight:example" >
144
+ <l >Example content</l >
145
+ </cont >
146
+ ```
147
+
148
+ ** Reading data:**
149
+
150
+ To read data from the datastore, execute the request:
151
+
152
+ ``` http
153
+ GET http://127.0.0.1:8181/rests/data?content=config
154
+ ```
155
+
156
+ Or for direct targeting of the container ` Cont ` :
157
+
158
+ ``` http
159
+ GET http://127.0.0.1:8181/rests/data/example:cont?content=config
160
+ ```
161
+
162
+ ## Next Steps
163
+
164
+ As the next step, you can try the NETCONF test tool, which is part of the NETCONF project. More about the test tool
165
+ can be found in the [ documentation] ( https://docs.opendaylight.org/projects/netconf/en/latest/testtool.html ) .
0 commit comments