blob: 7e2d77c8c740745d59e069b9c51d236b2c28709c [file] [log] [blame]
Gaurav Agrawalb102b012016-08-02 12:52:48 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.yms.ych;
18
VinodKumarS-Huaweiaf9c7a72016-08-30 19:43:39 +053019import java.util.List;
20import java.util.Map;
21
22import org.onosproject.yms.ydt.YmsOperationType;
23
Gaurav Agrawalb102b012016-08-02 12:52:48 +053024/**
25 * Abstraction of an entity which provides interfaces to YANG codec handler.
26 *
27 * In SBI, the provider or driver uses YANG management system as a CODEC
VinodKumarS-Huaweiaf9c7a72016-08-30 19:43:39 +053028 * utility. Providers/drivers register the device schema with YANG management
29 * system. YANG utils is used to generate the java files corresponding to the
30 * device schema. Provider or driver use these classes to seamlessly manage
31 * the device as java objects. While sending the request to device, drivers
32 * use the utility to translate the objects to protocol specific data
33 * representation and then send to the device. Protocol or driver use the
34 * same instance of the codec utility across multiple translation request.
Gaurav Agrawalb102b012016-08-02 12:52:48 +053035 * Protocol or driver should not use the same instance of utility concurrently.
36 */
37public interface YangCodecHandler {
VinodKumarS-Huaweiaf9c7a72016-08-30 19:43:39 +053038 /**
39 * Provider / driver needs to register the device schema with code handler.
40 * Then the provider / driver can use the codec handler to perform the
41 * codec operation. When the codec operation is being performed, the
42 * codec utility finds the mapping registered device model and perform the
43 * translation against the device schema.
44 *
45 * @param yangModule YANG utils generated class corresponding to SBI
46 * device schema module
47 */
48 void addDeviceSchema(Class yangModule);
49
50
51 /**
52 * When the drivers / providers need to encode a protocol operation
53 * requests, which is in a single block, this encode API is used.
54 * A single protocol operation can span across multiple application, then
55 * the driver / provider need to provide the list of application(s) module
56 * object. Each module object contains the request information
57 * corresponding to that application.
58 *
59 * The protocols can have a logical root node which acts as a container
60 * of applications module node. For example in NETCONF, it could be
61 * data/filter/config, etc. Protocols needs to pass this parameter in the
62 * encode request, so that it is part of the encoded protocol packet.
63 * There is no validation done on the value of this parameter. It is up to
64 * the protocol to use it. It is a mandatory parameter and protocols must
65 * pass this parameter. In protocols like NETCONF, these logical root
66 * node may be in a specific name space, in such cases, it needs to be
67 * passed to encode it as part of the request. There could be additional
68 * tags that can be attached to the root node, for example in NETCONF,
69 * the tag type="subtree" can be specified. In such scenarios the
70 * required tags should be sent as a parameter.
71 *
72 * The provider / driver would require to operate on multiple schema
73 * nodes in a single request, for example it may be require to configure
74 * a tunnel and associate a QOS to this tunnel, in this scenario, it
75 * needs to have the tunnel related information in the tunnel module's
76 * Java object and and QOS related information in QOS modules Java
77 * object. So in a single request, it can send the list of Java objects
78 * corresponding to the modules which need to participate in the operation.
79 * If the request to be generated needs to be a wild card for no
80 * application(s), then this parameter needs to be null. For example a
81 * "empty filter" request in NETCONF get request.
82 * If the request to be generated needs to be a wild card for all
83 * application(s), then the driver / provider should not invoke this API,
84 * as there is no encoding of application related information for the
85 * operation, it is only limited to the protocol operation. For example a
86 * "no filter" request in NETCONF get request.
87 *
88 * @param rootName name of logical root node as required by
89 * the protocol
90 * @param rootNamespace namespace of logical root node as
91 * required by the protocol encoding. It is
92 * an optional parameter.
93 * @param tagAttributeLinkedMap Specifies the list of attributes that
94 * needs to be tagged with the logical root
95 * node. It is an optional parameter
96 * if not required for the protocol.
97 * @param yangModuleList list of YANG module's object(s)
98 * participating in the operation.
99 * @param dataFormat data format to which encoding to be done.
100 * @param protocolOperation protocol operation being performed
101 * @return string containing the requested applications object
102 * information encoded in protocol format.
103 */
104 String encodeOperation(String rootName, String rootNamespace,
105 Map<String, String> tagAttributeLinkedMap,
106 List<Object> yangModuleList,
107 YangProtocolEncodingFormat dataFormat,
108 YmsOperationType protocolOperation);
109
110 /**
111 * When the drivers / providers need to encode protocol composite
112 * operation requests, which is split in a composite blocks, this encode
113 * composite operation API is used. The application module object
114 * containing the request information has both the resource identifier
115 * part and the resource information part.
116 *
117 * The protocols can have a logical root node which acts as a container
118 * of applications module node. For example in RESTCONF, it could be
119 * RootResource/data, etc. There is no validation done on the value
120 * of this parameter. It is upto the protocol to use it. It is a
121 * mandatory parameter and protocols must pass this parameter.
122 *
123 * The resource to be operated upon in the device is identified in a
124 * module's schema object. This modules object should contain the
125 * information about the resource on which the operation needs to be
126 * performed. The resource is identified by initial chain of objects for
127 * which operation type is none. Once the resource is reached using none
128 * operations, the actual information about the operation on the device
129 * is encoded.
130 *
131 * @param rootName name of logical root node as required by the
132 * protocol
133 * @param rootNamespace namespace of logical root node as required by
134 * the
135 * protocol encoding. It is optional, and there
136 * is no
137 * namespace set to the logical root node
138 * @param appModuleObject object containing the information about the
139 * resource on which the operation is being
140 * performed
141 * @param dataFormat data format to which request needs to
142 * be encoded
143 * @param protocolOperation protocol operation being performed
144 * @return the composite protocol operation request.
145 */
146 YangCompositeEncoding encodeCompositeOperation(String rootName,
147 String rootNamespace,
148 Object appModuleObject,
149 YangProtocolEncodingFormat
150 dataFormat,
151 YmsOperationType
152 protocolOperation);
153
154 /**
155 * When the driver or provider receive the data from the SBI protocol, It
156 * will be in the protocol specific data representation. Drivers /
157 * provider need to interact with the device using native JAVA objects.
158 * Drivers use this decode method to translate the received
159 * protocol specific simple data to YANG modeled Java objects.
160 * If the response received is not in line with the schema, for example,
161 * there is some error info, etc, then the decode operation will throw an
162 * exception and decode operation will fail.
163 *
164 * @param protocolData input string containing the resource information
165 * in protocol format
166 * @param dataFormat data format from which decoding has to be done
167 * @param protocolOperation protocol operation being performed
168 * @return list of applications module/notification objects corresponding
169 * to the protocol data input
170 */
171 List<Object> decode(String protocolData,
172 YangProtocolEncodingFormat dataFormat,
173 YmsOperationType protocolOperation);
174
175 /**
176 * When the driver or provider receive the composite data from the SBI
177 * protocol, It will be in the protocol specific data representation.
178 * Drivers / provider need to interact with the device
179 * using native JAVA objects. Drivers use this Decode method to translate
180 * the received protocol specific composite data to YANG modeled Java
181 * objects.
182 * If the response received is not in line with the schema, for example,
183 * there is some error info, etc, then the decode operation will throw an
184 * exception and decode operation will fail.
185 *
186 * @param protocolData composite protocol data containing the resource
187 * information
188 * @param dataFormat data format from which decoding has to be done
189 * @param protocolOperation protocol operation being performed
190 * @return application module/notification object corresponding to the
191 * protocol data infput
192 */
193 Object decode(YangCompositeEncoding protocolData,
194 YangProtocolEncodingFormat dataFormat,
195 YmsOperationType protocolOperation);
196
197 /**
198 * Register the provider / driver specific overridden codec. This is can
199 * be used by provider to support any protocol specific extension or
200 * vendor specific implementation. This framework can also be used
201 * by providers / drivers to support any new protocol data format which
202 * is not supported by default in YANG codec utility.
203 *
204 * @param overriddenCodec provider / driver specific overridden instance
205 * of the codec
206 * @param dataFormat data format to which encoding to be done.
207 */
208 void registerOverriddenCodec(YangDataTreeCodec overriddenCodec,
209 YangProtocolEncodingFormat dataFormat);
Gaurav Agrawalb102b012016-08-02 12:52:48 +0530210}