1 .. _alto-developer-guide:
9 The topics of this guide are:
11 1. How to add alto projects as dependencies;
13 2. How to put/fetch data from ALTO;
15 3. Basic API and DataType;
17 4. How to use customized service implementations.
19 Adding ALTO Projects as Dependencies
20 ------------------------------------
22 Most ALTO packages can be added as dependencies in Maven projects by
23 putting the following code in the *pom.xml* file.
28 <groupId>org.opendaylight.alto</groupId>
29 <artifactId>${THE_NAME_OF_THE_PACKAGE_YOU_NEED}</artifactId>
30 <version>${ALTO_VERSION}</version>
33 The current stable version for ALTO is ``0.3.0-Boron``.
35 Putting/Fetching data from ALTO
36 -------------------------------
41 There are two kinds of RESTful APIs for ALTO: the one provided by
42 ``alto-northbound`` which follows the formats defined in `RFC
43 7285 <https://tools.ietf.org/html/rfc7285>`__, and the one provided by
44 RESTCONF whose format is defined by the YANG model proposed in `this
45 draft <https://tools.ietf.org/html/draft-shi-alto-yang-model-03>`__.
47 One way to get the URLs for the resources from ``alto-northbound`` is to
48 visit the IRD service first where there is a ``uri`` field for every
49 entry. However, the IRD service is not yet implemented so currently the
50 developers have to construct the URLs themselves. The base URL is
51 ``/alto`` and below is a list of the specific paths defined in
52 ``alto-core/standard-northbound-route`` using Jersey ``@Path``
55 - ``/ird/{rid}``: the path to access *IRD* services;
57 - ``/networkmap/{rid}[/{tag}]``: the path to access *Network Map* and
58 *Filtered Network Map* services;
60 - ``/costmap/{rid}[/{tag}[/{mode}/{metric}]]``: the path to access
61 *Cost Map* and *Filtered Cost Map* services;
63 - ``/endpointprop``: the path to access *Endpoint Property* services;
65 - ``/endpointcost``: the path to access *Endpoint Cost* services.
69 The segments in brackets are optional.
71 If you want to fetch the data using RESTCONF, it is highly recommended
72 to take a look at the ``apidoc`` page
73 (`http://{controller\_ip}:8181/apidoc/explorer/index.html <http://{controller_ip}:8181/apidoc/explorer/index.html>`__)
74 after installing the ``odl-alto-release`` feature in karaf.
76 It is also worth pointing out that ``alto-northbound`` only supports
77 ``GET`` and ``POST`` operations so it is impossible to manipulate the
78 data through its RESTful APIs. To modify the data, use ``PUT`` and
79 ``DELETE`` methods with RESTCONF.
83 The current implementation uses the ``configuration`` data store and
84 that enables the developers to modify the data directly through
85 RESTCONF. In the future this approach might be disabled in the core
86 packages of ALTO but may still be available as an extension.
91 You can also fetch data from the datastore directly.
93 First you must get the access to the datastore by registering your
94 module with a data broker.
96 Then an ``InstanceIdentifier`` must be created. Here is an example of
97 how to build an ``InstanceIdentifier`` for a *network map*:
101 import org.opendaylight...alto...Resources;
102 import org.opendaylight...alto...resources.NetworkMaps;
103 import org.opendaylight...alto...resources.network.maps.NetworkMap;
104 import org.opendaylight...alto...resources.network.maps.NetworkMapKey;
107 InstanceIdentifier<NetworkMap> getNetworkMapIID(String resource_id) {
108 ResourceId rid = ResourceId.getDefaultInstance(resource_id);
109 NetworkMapKey key = new NetworkMapKey(rid);
110 InstanceIdentifier<NetworkMap> iid = null;
111 iid = InstanceIdentifier.builder(Resources.class)
112 .child(NetworkMaps.class)
113 .child(NetworkMap.class, key)
119 With the ``InstanceIdentifier`` you can use ``ReadOnlyTransaction``,
120 ``WriteTransaction`` and ``ReadWriteTransaction`` to manipulate the data
121 accordingly. The ``simple-impl`` package, which provides some of the
122 AD-SAL APIs mentioned above, is using this method to get data from the
123 datastore and then convert them into RFC7285-compatible objects.
125 Basic API and DataType
126 ----------------------
128 a. alto-basic-types: Defines basic types of ALTO protocol.
130 b. alto-service-model-api: Includes the YANG models for the five basic
131 ALTO services defined in `RFC
132 7285 <https://tools.ietf.org/html/rfc7285>`__.
134 c. alto-resourcepool: Manages the meta data of each ALTO service,
135 including capabilities and versions.
137 d. alto-northbound: Provides the root of RFC7285-compatible services at
138 http://localhost:8080/alto.
140 e. alto-northbound-route: Provides the root of the network map resources
141 at http://localhost:8080/alto/networkmap/.
143 How to customize service
144 ------------------------
146 Define new service API
147 ~~~~~~~~~~~~~~~~~~~~~~
149 Add a new module in ``alto-core/standard-service-models``. For example,
150 we named our service model module as ``model-example``.
152 Implement service RPC
153 ~~~~~~~~~~~~~~~~~~~~~
155 Add a new module in ``alto-basic`` to implement a service RPC in
158 Currently ``alto-core/standard-service-models/model-base`` has defined a
159 template of the service RPC. You can define your own RPC using
160 ``augment`` in YANG. Here is an example in ``alto-simpleird``.
164 grouping "alto-ird-request" {
165 container "ird-request" {
168 grouping "alto-ird-response" {
175 type "alto-types:resource-id";
180 augment "/base:query/base:input/base:request" {
181 case "ird-request-data" {
182 uses "alto-ird-request";
185 augment "/base:query/base:output/base:response" {
186 case "ird-response-data" {
187 uses "alto-ird-response";
191 Register northbound route
192 ~~~~~~~~~~~~~~~~~~~~~~~~~
194 If necessary, you can add a northbound route module in
195 ``alto-core/standard-northbound-routes``.